topostats.tracing.tracingfuncs#

Miscellaneous tracing functions.

Classes#

reorderTrace

Class to aid the consecutive ordering of adjacent coordinates of a pixel grid.

genTracingFuncs

Class of tracing functions.

Functions#

order_branch(binary_image, anchor)

Order a linear branch by identifying an endpoint, and looking at the local area of the point to find the next.

order_branch_from_start(→ numpy.typing.NDArray)

Order an unbranching skeleton from an end (startpoint) along a specified length.

local_area_sum(→ numpy.typing.NDArray)

Evaluate the local area around a point in a binary map.

coord_dist(→ numpy.typing.NDArray)

Accumulate a real distance traversing from pixel to pixel from a list of coordinates.

Module Contents#

class topostats.tracing.tracingfuncs.reorderTrace[source]#

Class to aid the consecutive ordering of adjacent coordinates of a pixel grid.

static linearTrace(trace_coordinates: list | numpy.typing.NDArray) numpy.typing.NDArray[source]#

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 (check_vectors_candidate_points) 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.

Parameters:

trace_coordinates (list | npt.NDArray) – Unordered trace coordinates.

Returns:

An array of ordered coordinates from one end of a linear trace to the other.

Return type:

npt.NDArray

static circularTrace(trace_coordinates)[source]#

Alternative implementation of the linear tracing algorithm but adapted to work with circular DNA molecules.

Parameters:

trace_coordinates (list | npt.NDArray) – Unordered trace coordinates.

Returns:

An array of ordered coordinates from one end of a linear trace to the other.

Return type:

npt.NDArray

class topostats.tracing.tracingfuncs.genTracingFuncs[source]#

Class of tracing functions.

static count_and_get_neighbours(x: int, y: int, trace_coordinates: list) tuple[int, list][source]#

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

Parameters:
  • x (int) – X coordinate.

  • y (int) – Y coordinate.

  • trace_coordinates (list) – Coordinates of the trace.

Returns:

The number of neighbours and the coordinates of the neighbouring points.

Return type:

tuple

static return_points_in_array(points_array: list | numpy.typing.NDArray, trace_coordinates: list | numpy.typing.NDArray) list[source]#

Return a subset co ordinates for the given set of points.

Parameters:
  • points_array (list | npt.NDArray) – The subset of points for which coordinates are required.

  • trace_coordinates (list | npt.NDArray) – Coordinates of all points.

Returns:

Coordinates for the subset of points.

Return type:

list

static make_grid(x: int, y: int, size: int) list[source]#

Make a Grid of coordinates around the points x and y.

Parameters:
  • x (int) – The x coordinate.

  • y (int) – They y coordinate.

  • size (int) – Size of surrounding grid.

Returns:

List of coordinates that form a grid around x and y of size.

Return type:

list

static find_best_next_point(x: int, y: int, ordered_points: list | numpy.typing.NDArray, candidate_points: list | numpy.typing.NDArray) list | None[source]#

Find the next best point.

Parameters:
  • x (int) – The x coordinate.

  • y (int) – They y coordinate.

  • ordered_points (list | npt.NDArray) – Ordered points.

  • candidate_points (list | npt.NDArray) – Points to be checked.

Returns:

Coordinates of the neighbouring pixel with the smallest angular change.

Return type:

list

static check_vectors_candidate_points(ordered_points: list | numpy.typing.NDArray, candidate_points: list | numpy.typing.NDArray) list[source]#

Find which neighbouring pixels incur the smallest angular change.

This is done with reference to a previous pixel in the ordered trace, and chooses that as the next point.

Parameters:
  • ordered_points (list | npt.NDArray) – Ordered points.

  • candidate_points (list | npt.NDArray) – Points to be checked.

Returns:

Coordinates of the neighbouring pixel with the smallest angular change.

Return type:

list

topostats.tracing.tracingfuncs.order_branch(binary_image: numpy.typing.NDArray, anchor: list)[source]#

Order a linear branch by identifying an endpoint, and looking at the local area of the point to find the next.

Parameters:
  • binary_image (npt.NDArray) – A binary image of a skeleton segment to order it’s points.

  • anchor (list) – A list of 2 integers representing the coordinate to order the branch from the endpoint closest to this.

Returns:

An array of ordered coordinates.

Return type:

npt.NDArray

topostats.tracing.tracingfuncs.order_branch_from_start(nodeless: numpy.typing.NDArray, start: numpy.typing.NDArray, max_length: float | numpy.inf = np.inf) numpy.typing.NDArray[source]#

Order an unbranching skeleton from an end (startpoint) along a specified length.

Parameters:
  • nodeless (npt.NDArray) – A 2D array of a binary unbranching skeleton.

  • start (npt.NDArray) – 2x1 coordinate that must exist in ‘nodeless’.

  • max_length (float | np.inf, optional) – Maximum length to traverse along while ordering, by default np.inf.

Returns:

Ordered coordinates.

Return type:

npt.NDArray

topostats.tracing.tracingfuncs.local_area_sum(binary_map: numpy.typing.NDArray, point: list | tuple | numpy.typing.NDArray) numpy.typing.NDArray[source]#

Evaluate the local area around a point in a binary map.

Parameters:
  • binary_map (npt.NDArray) – A binary array of an image.

  • point (Union[list, tuple, npt.NDArray]) – A single object containing 2 integers relating to a point within the binary_map.

Returns:

  • npt.NDArray – An array values of the local coordinates around the point.

  • int – A value corresponding to the number of neighbours around the point in the binary_map.

topostats.tracing.tracingfuncs.coord_dist(coords: numpy.typing.NDArray, pixel_to_nm_scaling: float = 1) numpy.typing.NDArray[source]#

Accumulate a real distance traversing from pixel to pixel from a list of coordinates.

Parameters:
  • coords (npt.NDArray) – A Nx2 integer array corresponding to the ordered coordinates of a binary trace.

  • pixel_to_nm_scaling (float) – The pixel to nanometer scaling factor.

Returns:

An array of length N containing thcumulative sum of the distances.

Return type:

npt.NDArray