ctrappy.scan

Main ctrappy functionality.

An Experiment contains multiple Scans. A Scan contains multiple Traces, consisting of colocalized Tracks. This Experiment object can then be used as input for plotting functions in ctrappy.gui_figures

class ctrappy.scan.Experiment(data, config_calibration, laser_colors, dna_length_kbp=None, redo_step_fitting=True)

An Experiment contains all data that comes from processing a tiff directory. It is initialized with a DataFrame, usually named ‘scans.csv’.

This input DataFrame (data) contains (at least) the columns: file_name, scan_id, trace_id, track_id color_id, color_str, frame, corrected_intensity, x_pixel, dna_start_pixel, dna_end_pixel, n_scans, n_frames. The config_calibration dictionary is read from a config.yaml file. Laser colors are ‘r’, ‘g’, ‘b’, ‘rg’, ‘rb’, ‘gb’ or ‘rgb’, corresponding to which lasers were on during the experiment. The dna length in kbp is given by dna_length_kbp.

convert_to_kbp(dna_length_kbp)

Convert track locations to kbp; only input is the DNA length in kbp.

convert_to_kbp_autocorrelation(dna_length_kbp, loc_filter=None, color='r', n_bins=32, offsets=None)

Use autocorrelation to convert track locations to kbp.

Parameters:
  • dna_length_kbp (float) – Dna length in kilobasepairs

  • loc_filter (2-tuple of floats) – Keep spots within these kbp-location values, to perform autocorrelation.

  • color (str) – ‘r’, ‘g’ or ‘b’.

  • n_bins (int) – Number of bins for binning before calculating autocorrelation.

  • offsets (list of floats or ints) – List of offsets to try (in pixels), relative to initial guess.

Returns:

corr_val – Correlation values corresponding to offsets list.

Return type:

list of floats

count_traces()

Count total number of traces in Experiment.

filter_by_color(color_str)

Filter entire Experiment, keep only data of 1 color given by color_str (string).

filter_by_loc_interval_kbp(intervals, reverse=False, keep_coloc=False)

Filter tracks by their entire location interval (kbp), keep (or remove, by setting reverse=True) tracks that overlap with the input intervals [(x0, x1), …] - return new Experiment object. keep_coloc=True does the filtering on Trace level.

filter_by_loc_kbp(x0, x1, keep_coloc=False)

Filter tracks by starting location (kbp), keep locations between x0 and x1 - return new Experiment object. keep_coloc=True does the filtering on Trace level.

filter_by_starting_frame(frame)

Filter tracks by starting frame - return new Experiment object.

filter_by_stoichiometry(r_range, g_range, b_range)

Filter traces by stoichiometry, keep traces within color ranges - return new Experiment object. Input ranges are 2-tuples of integers.

filter_by_total_count(count, keep_coloc=False)

Filter tracks by count, keep tracks under input - return new Experiment object. keep_coloc=True does the filtering on Trace level.

get_splits(d)

For each scan, check if any traces split off of other traces, with a maximum distance of d. Detected splits are stored in trace.split_parent. It is important not to filter by starting frame before running this method.

get_summary_table()

Output a summary table of the Experiment.

set_t(frame_time_s)

Convert track frame values to time (s) values; only input is the frame time in seconds.

to_dataframe()

Export Experiment to pandas DataFrame.

class ctrappy.scan.Scan(data, step_calibration, confocal_pixel_size, step_counting_divide, redo_step_fitting=True)

Contains spots, tracks and traces extracted from a single tiff file.

total_spot_count()

Get total spot (Trace) count in Scan.

class ctrappy.scan.Trace(data, step_calibration, confocal_pixel_size, step_counting_divide, redo_step_fitting=True)

Contains colocalized Tracks.

get_loc_interval(x_micron=True)

Get location interval of tracks within trace. Default units: micron; witch to kbp with x_micron=False.

get_starting_loc(x_micron=True)

Get average starting location of tracks within trace. Default units: micron; witch to kbp with x_micron=False.

run_calibration_step_count(step_calibration)

Run the step counter on all Tracks in the Trace, using a step_calibration dictionary containing min_step_sizes and avg_step_sizes.

total_count()

Get total fluorophore step count of the Trace.

class ctrappy.scan.Track(data, confocal_pixel_size)

Contains single color spots that have been tracked throughout different frames.

count_steps(step_calibration, divide_by_avg=True)

Count steps using ctrappy.stepfinder, using a step_calibration dictionary. By default we divide by the average step size to process large steps correctly; for pure step counting, set divide_by_avg to False.

get_starting_loc(x_micron=True)

Get starting location by averaging the first 5 frames. Units are microns by default; switch to kbp with x_micron=False.

ctrappy.scan.filter_experiment(experiment, starting_frame, kbp_locs, total_count, keep_coloc=False)

Filter experiment tracks (or traces) by starting frame, kbp location interval, and total count.

Parameters:
  • experiment (Experiment) – Input experiment object.

  • starting_frame (int) – Any tracks starting from this frame onwards are filtered out.

  • kbp_locs (2-tuple of floats) – Any tracks outside this location interval (in kbps) are filtered out.

  • total_count (int) – Any tracks above this count are filtered out.

  • keep_coloc (bool) – If True, do the filtering on the Trace level, preserving colocalizations. Default: False.

Returns:

experiment_filtered – Filtered experiment object.

Return type:

Experiment

ctrappy.scan.get_step_calibration(config_calibration, laser_colors)

Convenience wrapper for set_laser_colors().

ctrappy.scan.rerun_colocalization(experiment)

Rerun colocalization on an Experiment, using ctrappy.tracking.Colocalizer, which takes a dataframe input.

ctrappy.scan.set_laser_colors(laser_colors, config)

Get appropriate parameters from config, depending on laser colors.

Parameters:
  • laser_colors (str) – Laser colors (‘r’, ‘g’, ‘b’, ‘rg’, ‘rb’, ‘gb’, or ‘rgb’).

  • config (dict) – Config dictionary from yaml file.

Returns:

  • min_step_sizes (array of floats) – List of minimum step sizes for stoichiometry with step counting for [r, g, b].

  • avg_step_sizes (array of floats) – List of average step sizes for stoichiometry with step counting for [r, g, b].

  • color_ids (array of ints) – List of laser color indices in experiment.

  • color_strs (array of strs) – List of laser colors in experiment.