topostats.tracing.dnatracing#

Perform DNA Tracing

Attributes#

Classes#

dnaTrace

This class gets all the useful functions from the old tracing code and staples

traceStats

Combine and save trace statistics.

Module Contents#

topostats.tracing.dnatracing.LOGGER#
class topostats.tracing.dnatracing.dnaTrace(full_image_data, grains, filename, pixel_size, convert_nm_to_m: bool = True)#

Bases: object

This class gets all the useful functions from the old tracing code and staples them together to create an object that contains the traces for each DNA molecule in an image and functions to calculate stats from those traces.

The traces are stored in dictionaries labelled by their gwyddion defined grain number and are represented as numpy arrays.

The object also keeps track of the skeletonised plots and other intermediates in case these are useful for other things in the future.

full_image_data#
grains_orig#
filename#
pixel_size#
number_of_rows#
number_of_columns#
sigma#
gauss_image = []#
grains#
dna_masks#
skeletons#
disordered_trace#
ordered_traces#
fitted_traces#
splined_traces#
contour_lengths#
end_to_end_distance#
mol_is_circular#
curvature#
number_of_traces = 0#
num_circular = 0#
num_linear = 0#
neighbours = 5#
trace_dna()#

Perform DNA tracing.

get_numpy_arrays()#

Function to get each grain as a numpy array which is stored in a dictionary

Currently the grains are unnecessarily large (the full image) as I don’t know how to handle the cropped versions

I find using the gwyddion objects clunky and not helpful once the grains have been found

There is some kind of discrepency between the ordering of arrays from gwyddion and how they’re usually handled in np arrays meaning you need to be careful when indexing from gwyddion derived numpy arrays

_get_grain_array(grain_number: int) numpy.ndarray#

Extract a single grains.

_get_bounding_box() numpy.ndarray#

Calculate bounding box for each grain.

_crop_array(bounding_box: Tuple) numpy.ndarray#

Crop an array.

Parameters:
  • array (np.ndarray) – 2D Numpy array to be cropped.

  • bounding_box (Tuple) – Tuple of co-ordinates to crop, should be of form (max_x, min_x, max_y, min_y) as returned by

  • _get_bounding_box().

Returns:

Cropped array

Return type:

np.ndarray()

gaussian_filter(**kwargs) numpy.array#

Apply Gaussian filter

get_disordered_trace()#

Create a skeleton for each of the grains in the image.

Uses my own skeletonisation function from tracingfuncs module. I will eventually get round to editing this function to try to reduce the branching and to try to better trace from looped molecules

purge_obvious_crap()#
linear_or_circular(traces)#

Determines whether each molecule is circular or linear based on the local environment of each pixel from the trace

This function is sensitive to branches from the skeleton so might need to implement a function to remove them

get_ordered_traces()#
report_basic_stats()#

Report number of circular and linear DNA molecules detected.

get_fitted_traces()#

Create trace coordinates (for each identified molecule) that are adjusted to lie along the highest points of each traced molecule

get_splined_traces()#

Gets a splined version of the fitted trace - useful for finding the radius of gyration etc

This function actually calculates the average of several splines which is important for getting a good fit on the lower res data

show_traces()#
saveTraceFigures(filename: str | pathlib.Path, channel_name: str, vmaxval, vminval, output_dir: str | pathlib.Path = None)#
_checkForSaveDirectory(filename, new_directory_name)#
findWrithe()#
find_curvature()#
saveCurvature()#
plotCurvature(dna_num)#

Plot the curvature of the chosen molecule as a function of the contour length (in metres)

measure_contour_length()#

Measures the contour length for each of the splined traces taking into account whether the molecule is circular or linear

Contour length units are nm

writeContourLengths(filename, channel_name)#
writeCoordinates(dna_num)#
measure_end_to_end_distance()#

Calculate the Euclidean distance between the start and end of linear molecules. The hypotenuse is calculated between the start ([0,0], [0,1]) and end ([-1,0], [-1,1]) of linear molecules. If the molecule is circular then the distance is set to zero (0).

class topostats.tracing.dnatracing.traceStats(trace_object: dnaTrace, image_path: str | pathlib.Path)#

Bases: object

Combine and save trace statistics.

trace_object#
image_path#
df = []#
create_trace_stats()#

Creates a pandas dataframe of the contour length, whether its circular and end to end distance combined with details of the working directory, directory images were found in and the image name.

save_trace_stats(save_path: str | pathlib.Path, json: bool = True, csv: bool = True) None#

Write trace statistics to JSON and/or CSV.

Parameters:
  • save_path (Union[str, Path]) – Directory to save results to.

  • json (bool) – Whether to save a JSON version of statistics.

  • csv (bool) – Whether to save a CSV version of statistics.