ctrappy.tracking

Code for detecting, tracking and colocalizing spots.

class ctrappy.tracking.BeadDetector(initial_guess)

Class (experimental) for bead detection.

detect(intensity_profile)

Run bead detection on a projected intensity profile.

class ctrappy.tracking.Colocalizer(colocalization_distance, crosstalk_matrices, colocalization_frames=5, cf_res=0.05)

Class for determining colocalizations.

Parameters:
  • colocalization_distance (float) – Threshold distance under which two spots can be considered colocalized.

  • crosstalk_matrices (numpy array of floats with shape (3, 3, 3)) – Matrices for crosstalk correction; see explanation in config.yaml under “CROSSTALK CORRECTION”.

  • colocalization_frames (int) – Number of frames for colocalization calculation. Set to None for all frames.

  • cf_res (float) – Microns per pixel in the confocal image. Default: 0.05.

colocalize(df_tracks_input, laser_colors)

Find colocalized tracks; give colocalized tracks the same ‘trace_id’.

Parameters:
  • df_tracks_input (pandas DataFrame) – Input dataframe with columns [‘frame’, ‘color’, ‘intensity’, ‘x_pixel’, ‘y_pixel’, ‘track_id’].

  • laser_colors (str) – ‘r’, ‘g’, ‘b’, ‘rg’, ‘rb’, ‘gb’ or ‘rgb’

Returns:

df_tracks – Output dataframe - same as input, but with added columns [‘colocalized’, ‘col_dist’, ‘trace_id’, ‘corrected_intensity’] (bool, float, int, float).

Return type:

pandas DataFrame

class ctrappy.tracking.Detector(radius=4, thresholds=None, overlap=0.5)

Spot detector using Laplacian of Gaussian.

Parameters:
  • radius (int or list of 3 ints) – Detection radius (or radii per color).

  • thresholds (list of 3 floats) – Detection threshold for each (r,g,b) color. Default: [0.5, 0.5, 0.5].

  • overlap (float) – Allowed overlap between detections.

detect(images, colors=None)

Detect spots for all frames in a 4D numpy array with axes (frames, y, x, colors).

Parameters:
  • images (numpy array of floats) – 4D array containing (frames, y, x, colors).

  • colors (list of integers) – Color indices to include (default: [0, 1, 2])

Returns:

df_out – DataFrame containing spots.

Return type:

pandas DataFrame

class ctrappy.tracking.Tracker(skip_frames=1, max_dist=10, max_segment_dist=10)

Class for tracking spots between frames.

Parameters:
  • skip_frames (int) – Max number of frames to skip for segment linking.

  • max_dist (float) – Maximum distance between points for frame-to-frame linking (pixels).

  • max_segment_dist (float) – Maximum distance between end and start points for segment linking (pixels).

lap_matrix(blobs0, blobs1)

Populate LAP matrix for frame-to-frame linking - see https://www.nature.com/articles/nmeth.1237.pdf

lap_matrix_segments(df_tracks)

Populate LAP matrix for segment linking - see https://www.nature.com/articles/nmeth.1237.pdf

track(df_tracks_input)

Do LAP tracking. df_tracks_input needs to be a dataframe with columns [‘frame’, ‘x’, ‘y’]; output will contain a new column ‘track_id’.

Parameters:

df_tracks_input (pandas DataFrame) – Input dataframe with columns [‘frame’, ‘frame_subindex’, ‘x’, ‘y’].

Returns:

df_tracks – Output dataframe - same as input, but with added column ‘track_id’.

Return type:

pandas DataFrame

ctrappy.tracking.double_step_func(x, amplitude, x0, x1, x2, x3, background)

Fitting function for bead detection; trying to find steps in the projected intensity at the bead edges.

ctrappy.tracking.fermi_dirac(x, mu, beta)

Fermi-Dirac distribution.

ctrappy.tracking.fit_gauss2d(imgdata, mu_x, mu_y, sigma, amplitude)

Wrapper function for fitting a 2D Gaussian.

ctrappy.tracking.gaussian(x, mu, sigma)

Gaussian function.

ctrappy.tracking.gaussian2d(x, y, mu_x, mu_y, sigma)

2D Gaussian function.