topostats.tracing.tracingfuncs#

Classes#

getSkeleton

Skeltonisation algorithm based on the paper "A Fast Parallel Algorithm for

reorderTrace

genTracingFuncs

Module Contents#

class topostats.tracing.tracingfuncs.getSkeleton(image_data, binary_map, number_of_columns, number_of_rows, pixel_size)#

Bases: object

Skeltonisation algorithm based on the paper “A Fast Parallel Algorithm for Thinning Digital Patterns” by Zhang et al., 1984

image_data#
binary_map#
number_of_columns#
number_of_rows#
pixel_size#
p2 = 0#
p3 = 0#
p4 = 0#
p5 = 0#
p6 = 0#
p7 = 0#
p8 = 0#
mask_being_skeletonised = []#
output_skeleton = []#
skeleton_converged = False#
pruning = True#
average_height = 0#
highest_points#
search_window#
getDNAmolHeightStats()#
doSkeletonising()#

Simple while loop to check if the skeletonising is finished

_doSkeletonisingIteration()#

Do an iteration of skeletonisation - check for the local binary pixel environment and assess the local height values to decide whether to delete a point

_deletePixelSubit1(point)#

Function to check whether a single point should be deleted based on both its local binary environment and its local height values

_deletePixelSubit2(point)#

Function to check whether a single point should be deleted based on both its local binary environment and its local height values

_binaryThinCheck_a()#
_binaryThinCheck_b()#
_binaryThinCheck_c()#
_binaryThinCheck_d()#
_binaryThinCheck_csharp()#
_binaryThinCheck_dsharp()#
_checkHeights(candidate_points)#
_checkWhichHeightPoints()#
_initialiseHeightFindingDict()#
_getHorizontalLeftHeights(x, y)#
_getHorizontalRightHeights(x, y)#
_getVerticalUpwardHeights(x, y)#
_getVerticalDonwardHeights(x, y)#
_getDiaganolLeftUpwardHeights(x, y)#
_getDiaganolLeftDownwardHeights(x, y)#
_getDiaganolRightUpwardHeights(x, y)#
_getDiaganolRightDownwardHeights(x, y)#
_condemnPoint(x, y)#
_identifyHighestPoint(x, y, index_direction, indexed_heights)#
finalSkeletonisationIteration()#

A final skeletonisation iteration that removes “hanging” pixels. Examples of such pixels are:

[0, 0, 0] [0, 1, 0] [0, 0, 0] [0, 1, 1] [0, 1, 1] [0, 1, 1]

case 1: [0, 1, 0] or case 2: [0, 1, 0] or case 3: [1, 1, 0]

This is useful for the future functions that rely on local pixel environment to make assessments about the overall shape/structure of traces

_binaryFinalThinCheck_a()#
_binaryFinalThinCheck_b()#
_binaryThinCheck_b_returncount()#
pruneSkeleton()#

Function to remove the hanging branches from the skeletons - these are a persistent problem in the overall tracing process.

_findBranchEnds(coordinates)#
_deleteSquareEnds(coordinates)#
class topostats.tracing.tracingfuncs.reorderTrace[source]#
static linearTrace(trace_coordinates)[source]#

My own function to order the points from a linear trace.

This works by checking the local neighbours for a given pixel (starting at one of the ends). If this pixel has only one neighbour in the array of unordered points, this must be the next pixel in the trace – and it is added to the ordered points trace and removed from the remaining_unordered_coords array.

If there is more than one neighbouring pixel, a fairly simple function (checkVectorsCandidatePoints) finds which pixel incurs the smallest change in angle compared with the rest of the trace and chooses that as the next point.

This process is repeated until all the points are placed in the ordered trace array or the other end point is reached.

static circularTrace(trace_coordinates)[source]#

An alternative implementation of the linear tracing algorithm but with some adaptations to work with circular dna molecules

static circularTrace_old(trace_coordinates)#

Reorders the coordinates of a trace from a circular DNA molecule (with no loops) using a polar coordinate system with reference to the center of mass

I think every step of this can be vectorised for speed up

This is vulnerable to bugs if the dna molecule folds in on itself slightly

loopedCircularTrace()#
loopedLinearTrace()#
class topostats.tracing.tracingfuncs.genTracingFuncs[source]#
static getLocalPixelsBinary(binary_map, x, y)#
static countNeighbours(x, y, trace_coordinates)#

Counts the number of neighbouring points for a given coordinate in a list of points

static getNeighbours(x, y, trace_coordinates)#

Returns an array containing the neighbouring points for a given coordinate in a list of points

static countandGetNeighbours(x, y, trace_coordinates)#

Returns the number of neighbouring points for a coordinate and an array containing the those points

static returnPointsInArray(points_array, trace_coordinates)#
static makeGrid(x, y, size)#
static findBestNextPoint(x, y, ordered_points, candidate_points)#
static checkVectorsCandidatePoints(x, y, ordered_points, candidate_points)#

Finds which neighbouring pixel incurs the smallest angular change with reference to a previous pixel in the ordered trace, and chooses that as the next point