API documentation¶
cell_track.tools¶
-
cell_track.tools.get_session()¶ Gets the modified tensorflow session.
Returns: tensorflow.Session
-
cell_track.tools.safe_load_model(model_path)¶ Wrapper function for keras_retinanet.load_model to account for different required arguments in different versions.
Parameters: model_path – path to the .hd5 model file Returns: keras.models.model
cell_track.tools.trackmate¶
-
class
cell_track.tools.trackmate.Track(xml_track, xml_root)¶ Class for handling a ‘track’ as defined in the trackmate XML document. Initialization of this class will parse the trackmate XML track.
Because most attributes are extracted from an xml (text file) they are represented as str objects.
Parameters: - xml_track (ElementTree) – root.findall(‘Model/AllTracks/Track’) for each individual track
- xml_root (ElementTree) – tree.getroot(), the root of the XML tree
Variables: - id (str) – The ID of the track
- num_spots (str) – Number of spots in the track
- num_gaps (str) – Number of gaps in the track
- total_displacement (str) – Total displacement of the track
- index (str) – The track index (different than track ID)
- mean_speed (str) – Mean speed of the track
- median_speed (str) – Median speed of the track
- total_dist_traveled (str) – Total distance traveled (sum of edges)
- max_dist_traveled (str) – Maximum distance traveled
- processivity (str) – total displacement / total distance traveled
- x_loc (int) – Center x location of the track
- y_loc (int) – Center y location of the track
- include (bool) – Did this pass the trackmate filtering?
- edges (list) – List of IDs for the edges in the track
- spots_in_track (list) – IDs of the spots in the track
- spot_objs (list) – List of Spot objects, representing all spots
- lines (list) – List of Line objects for each line in the track
Examples
>>> tree = ET.parse(inxml) >>> root = tree.getroot() >>> >>> tracks = [Track(xml_track, root) for xml_track in root.findall('Model/AllTracks/Track')] >>> filt_tracks = [x for x in tracks if x.include] >>> edge_nest = [x.lines for x in tracks if x.include] >>> line_list = [item for sublist in edge_nest for item in sublist]
-
cell_track.tools.trackmate.drawTrackmateVideo(infile, out_csv)¶ Takes a tif file, with a matching trackmate file, and makes a mp4 video of the tracked output. This will draw a spot ID, and a trail on the video.
This will also write a csv file containing the x position, y position, spot frame, and track id. This can be used later to draw lines using
Parameters: - infile (str) – .tif filename to convert
- out_csv (str) – The csv file to write to. This is opened in append mode.
Returns: - This does not return any value, but will write a .mp4 file and
.csv file.
Return type: None
-
cell_track.tools.trackmate.process_imagestack(well)¶ Processes a single image stack (xml file) and returns three lists, mean_speed, processivity, max_displacement.
-
cell_track.tools.trackmate.process_well_list(well_string, xml_file_list)¶ Takes a well name (well_string) and an xml_file_list (all XML file paths) returns three pandas dataframes
-
class
cell_track.tools.trackmate.trackmateXML¶ Class for constructing, and writing the trackmate XML from the ML tracking tools.
Note, this currently has a hard-coded frame duration of 300 seconds. Todo: Update the hardcoded frame duration.
Parameters: None
Variables: - spot_id (int) – The ID of the spot being added. This will auto increment.
- frame (int) – The frame being added.
- total_spots (int) – Total number of spots added to the obejct.
- filename (str) – The name of the output xml file
- content (str) – The ‘body’ of the XMl file
- imagepath (str) – The path to the tiff file that the trackmate XMl is associated with
- header (str) – The trackmate header
- footer1 (str) – First trackmate footer
- footer2 (str) – Second trackmate footer
- footer3 (str) – Third trackmate footer
-
add_frame_spots(box, scores)¶ This is the public method to add spots to the trackmate xml. This will add the required header to tell trackmate which frame the spots belong to.
When adding spots to the trackmate XML object, it is necessary to set the ‘frame’ attribute of the object instance to the correct frame.
_add_spots() does the heavy lifting here.
Parameters: - box (list) – List of tuples in the form (x1, x2, y1, y2) of boxes to add.
- score (list) – List of scores to accompany the boxes. THe score is stored in the ‘QUALITY’ attribute of the trackmate XML.
Returns:
-
write_xml()¶ This method writes the trackmate XML with all of the spot data.
The location that it is written to is the ‘imagepath’ + ‘filename’ with .xml appended to the end.
Returns: None