heteromotility/hmdetail module

class heteromotility.hmdetail.DetailedBalance(cell_ids, min_split=20, tau_max=None)

Bases: object

Splits cell paths into discrete segments and calculates motility statistics on these sub-segments. Allows ‘motility state’ transitions to be assessed within a single cell.

min_split

int – minimum length of a subpath for splitting.

tau_max

int – maximum length of a subpath for splitting. >= min_split

cell_ids

dict – cell paths, keyed by an id, valued are a list of tuple (x,y) coordinates.

split_ids(cell_ids, tau)

Splits cell paths into multiple discrete segments of length tau Returns a dict of lists where each list is a subpath for easy stat calculations with existing Heteromotility infrastructure

Parameters:
  • cell_ids (dict) – cell paths, keyed by an id, valued are a list of tuple (x,y) coordinates.
  • tau (int) – time lag, size of each split path
Returns:

split_ids – keyed by “cell_id-subpath_id”, valued as in cell_ids

Return type:

dict

sliding_windows(cell_ids, tau=20, stride=1, max_windows=None)

Generates multiple tracks using a sliding window of length tau, shifted by stride for each frame until the track is finished or max_windows is reached.

Parameters:
  • cell_ids (dict) – cell paths, keyed by an id, valued are a list of tuple (x,y) coordinates.
  • tau (int, optional) – size of the sliding window in time step units.
  • stride (int, optional) – stride of the sliding window in time step units.
  • max_windows (int, optional) – maximum number of sliding windows to extract. if None, extracts the maximum number of windows across the track.
Returns:

sliding_ids – dict of lists, keyed by “cell_id-subpath_id” where subpath_id is equal to the window location, indexed from 0.

Return type:

dict

multi_tau_split(cell_ids, tau_min=20, tau_max=None)

Makes dict keyed by tau with split_ids for a range of time lags

Parameters:
  • cell_ids (dict) – cell paths, keyed by an id, valued are a list of tuple (x,y) coordinates.
  • tau_min (int) – minimum time lag to consider
  • tau_max (int, optional) – maximum size of windows to be considered. defaults to len(cell_ids[cell_ids.keys()[0]])//2.
Returns:

multi_split – keyes by window size tau, values by cell_ids dicts for each tau as generated by split_ids.

Return type:

dict

split_id_features(multi_split, output_dir, output_suffix=False)

Calculates motility features for subsegments of cell paths. Exports data as ‘motility_statistics_split_$TAU.csv’ where $TAU is the size of the segments being considered

Parameters:
  • multi_split (dict) – keyed by int window sizes tau, containing cell_id style dicts.
  • output_dir (string) – directory for output files.
  • output_suffix (string) – suffix for CSV outputs.