pcnaDeep.data

pcnaDeep.data.annotate

pcnaDeep.data.annotate.relabel_trackID(label_table)[source]

Relabel trackID in tracking table, starting from 1.

Parameters:

label_table (pandas.DataFrame) – tracked object table.

Returns:

pandas.DataFrame – tracked object table with relabeled trackID.

pcnaDeep.data.annotate.label_by_track(mask, label_table)[source]

Label objects in mask with track ID

Parameters:
Returns:

numpy.ndarray – uint8/16 dtype based on track count.

pcnaDeep.data.annotate.get_lineage_txt(label_table)[source]

Generate txt table in Cell Tracking Challenge (CTC) format.

Parameters:

label_table (pandas.DataFrame) – table processed, should not has gaped tracks.

Returns:

pandas.DataFrame – lineage table in .txt format that fits CTC.

pcnaDeep.data.annotate.break_track(label_table)[source]

Break tracks in a lineage table into single tracks, where NO gaped tracks allowed. All gaps will be transferred into parent-daughter relationship.

Parameters:

label_table (pandas.DataFrame) – tracked object table to process.

Algorithm:
  1. Rename raw parentTrackId to mtParTrk.

  2. Initiate new parentTrackId column with 0.

  3. Separate all tracks individually.

Notes

In original lineage table, single track can be gaped, lineage only associates mitosis tracks, not gaped tracks.

Returns:

pandas.DataFrame – processed tracked object table.

pcnaDeep.data.annotate.separate(frame_list, mtPar_list, ori_id, base)[source]

For single gaped track, separate it into all complete tracks.

Parameters:
  • frame_list (list) – frames list, length equals to label table.

  • mtPar_list (list) – mitosis parent list, for solving mitosis relationship.

  • ori_id (int) – original track ID.

  • base (int) – base track ID, will assign new track ID sequentially from base + 1.

Returns:

dict – Dictionary of having following keys: frame, trackId, parentTrackId, mtParTrk.

pcnaDeep.data.annotate.save_seq(stack, out_dir, prefix, dig_num=3, dtype='uint16', base=0, img_format='.tif', keep_chn=True, sep='-')[source]

Save image stack and label sequentially.

Parameters:
  • stack (numpy array) – image stack in THW format (Time, Height, Width).

  • out_dir (str) – output directory.

  • prefix (str) – prefix of single slice, output will be prefix-000x.tif/png. (see sep below for separator).

  • dig_num (int) – digit number (3 -> 00x) for labeling image sequentially.

  • dtype (numpy.dtype) – data type to save, either ‘uint8’ or ‘uint16’.

  • base (int) – base number of the label (starting from).

  • img_format (str) – image format, ‘.tif’ or ‘.png’, remind the dot.

  • keep_chn (bool) – whether to keep full channel or not.

  • sep (str) – separator between file name and id, default ‘-‘.

pcnaDeep.data.annotate.findM(gt_cls, direction='begin')[source]

Find M exit/entry from ground truth classification.

The method assumes that all mitosis classification is continuous, therefore only suitable. for processing classification ground truth. For processing prediction, use pcnaDeep.refiner.deduce_transition.

Parameters:
  • gt_cls (list) – list of classifications.

  • direction (str) – begin/end, search M from which terminal of the classification list.

Returns:

int – index of the mitosis entry/exit.

pcnaDeep.data.annotate.check_continuous_track(table)[source]

Check if every track is continuous (no gap). Returns trackID list that is gaped.

pcnaDeep.data.preparePCNA

pcnaDeep.data.preparePCNA.load_PCNA_from_json(json_path, image_path, width=1200, height=1200)[source]

Load PCNA training data and ground truth from json.

Parameters:
  • json_path (str) – path to .json ground truth in VIA2 format.

  • image_path (str) – path to raw image.

  • width (int) – width of the image.

  • height (int) – height of the image.

pcnaDeep.data.preparePCNA.load_PCNAs_json(json_paths, image_paths)[source]

Load multiple training dataset.

pcnaDeep.data.utils

pcnaDeep.data.utils.json2mask(ip, height, width, out=None, label_phase=False, mask_only=False)[source]

Draw mask according to VIA2 annotation and summarize information

Parameters:
  • ip (str) – input directory of the json file.

  • out (str) – optonal, output directory of the image and summary table.

  • height (int) – image height.

  • width (int) – image width.

  • label_phase (bool) – whether to label the mask with values corresponding to cell cycle classification or not. If true, will label as the following values: ‘G1/G2’:10, ‘S’:50, ‘M’:100; If false, will output binary masks.

  • mask_only (bool) – whether to suppress file output and return mask only.

Outputs:

png files of object masks.

pcnaDeep.data.utils.mask2json(in_dir, out_dir, phase_labeled=False, phase_dic={10: 'G1/G2', 50: 'S', 100: 'M', 200: 'E'}, prefix='object_info')[source]

Generate VIA2-readable json file from masks

Parameters:
  • in_dir (str) – input directory of mask slices in .png format. Stack input is not implemented.

  • out_dir (str) – output directory for .json output

  • phase_labeled (bool) – whether cell cycle phase has already been labeled. If true, a phase_dic variable should be supplied to resolve phase information.

  • phase_dic (dic) – lookup dictionary of cell cycle phase labeling on the mask.

  • prefix (str) – prefix of .json output.

Outputs:
prefix.json in VIA2 format. Note the output is not a VIA2 project, so default image directory

must be set for the first time of labeling.

pcnaDeep.data.utils.getDetectInput(pcna, dic, gamma=1, sat=1, torch_gpu=False)[source]

Generate pcna-mScarlet and DIC channel to RGB format for detectron2 model prediction

Parameters:
  • pcna (numpy.ndarray) – uint16 PCNA-mScarlet image stack (T*H*W).

  • dic (numpy.ndarray) – uint16 DIC or phase contrast image stack.

  • gamma (float) – gamma adjustment, >0, default 0.8.

  • sat (float) – percent saturation, 0~100, default 0.

  • torch_gpu (bool) – use torch to speed up calculation.

Returns:

(numpy.ndarray) – uint8 composite image (T*H*W*C)

pcnaDeep.data.utils.retrieve(table, mask, image, rp_fields=[], funcs=[])[source]
Retrieve extra skimage.measure.regionprops fields of every object;

Or apply customized functions to extract features form the masked object.

Parameters:
  • table (pandas.DataFrame) – object table tracked or untracked, should have 2 fields: 1. frame: time location; 2. continuous label: region label on mask

  • mask (numpy.ndarray) – labeled mask corresponding to table

  • image (numpy.ndarray) – intensity image, only the first channel allowed

  • rp_fields (list(str)) – skimage.measure.regionpprops allowed fields

  • funcs (list(function)) – customized function that outputs one value from an array input

Returns:

labeled object table with additional columns

pcnaDeep.data.utils.mt_dic2mt_lookup(mt_dic)[source]

Convert mt_dic to mitosis lookup

Parameters:

mt_dic (dict) – standard mitosis info dictionary in pcnaDeep

Returns:

mt_lookup (pd.DataFrame)

mitosis lookup table with 3 columns:

trackA (int) | trackB (int) | Mitosis? (int, 0/1)

pcnaDeep.data.utils.get_outlier(array, col_ids=None)[source]

Get outlier index in an array, specify target column

Parameters:
  • array (numpy.ndarray) – original array

  • col_ids ([int]) – target columns to remove outliers. Default all

Returns:

index of row containing at least one outlier

pcnaDeep.data.utils.deduce_transition(l, tar, confidence, min_tar, max_res, escape=0, casual_end=True)[source]

Deduce mitosis exit and entry based on adaptive searching

Parameters:
  • l (list) – list of the target cell cycle phase

  • tar (str) – target cell cycle phase

  • min_tar (int) – minimum duration of an entire target phase

  • confidence (numpy.ndarray) – matrix of confidence

  • max_res (int) – maximum accumulative duration of unwanted phase

  • escape (int) – do not consider the first n instances

  • casual_end (bool) – at the end of the track, whether loosen criteria of a match

Returns:

tuple – two indices of the classification list corresponding to entry and exit

pcnaDeep.data.utils.find_daugs(track, track_id)[source]

Return list of daughters according to certain parent track ID.

Parameters:
pcnaDeep.data.utils.filter_edge(img, props, edge_flt)[source]

Filter objects at the edge

Parameters:
  • img (numpy.ndarray) – mask image with object labels.

  • props (pandas.DataFrame) – part of the object table.

  • edge_flt (int) – pixel width of the edge area.

pcnaDeep.data.utils.expand_bbox(bbox, factor, limit)[source]

Expand bounding box by factor times.

Parameters:
  • bbox (tuple) – (x1, y1, x2, y2).

  • factor (float) – positive value, expand height and width by multiplying the factor. Round if result is not integer. The output shape will be (factor + 1) ** 2 times of the original size.

  • limit (tuple) – (x_max, y_max), limit values to avoid boundary crush.

Returns:

(tuple) – new bounding box (x1, y1, x2, y2).

pcnaDeep.data.utils.align_table_and_mask(table, mask)[source]

For every object in the mask, check if is consistent with the table. If no, remove the object in the mask.

Parameters:
  • table (pandas.DataFrame) – (tracked) object table.

  • mask (numpy.ndarray) – labeled object mask, object label should be corresponding to continuous_label column in the table.

pcnaDeep.data.utils.merge_obj_tables(a, b, col, mode='label')[source]

Merge two object tables according to shared frame and continuous label / location identity.

Parameters:
  • a (pandas.DataFrame) – donor table. Record not found in acceptor will be ignored.

  • b (pandas.DataFrame) – acceptor table. Record cannot be matched with donor will results in NA and warned.

  • col (str) – key in both a and b that aimed to merge. Only allow one key and a time

  • mode (str) – either ‘label’ or ‘loc’.

Note

Both a and b tables must have the keys:
  • Center_of_the_object_0

  • Center_of_the_object_1

  • continuous label

  • frame

  • (key to merge)

In loc mode, location will be rounded to 3 digits before matching.