Utility functions
To simulate patterns consistent with cell morphology we use actual cell templates. The dataset is available here. This dataset includes 318 shapes (cell, nucleus and protrusion coordinates) we can used to build an authentic cell morphology. Precomputed distance maps and an index file saved as CSV are also available.
Download and extract the template dataset:
Load an index dataframe that summarize templates metadata:
Load and build templates:
- simfish.load_extract_template(path_output, verbose=True)
Download template dataset zipfile and extract it.
- Parameters
- path_outputstr
Path location to save dataset.
- verbosebool, default=True
Show download progression.
- Returns
- path_finalstr
Path of the downloaded dataset.
- simfish.read_index_template(path_template_directory)
Load and read dataframe with templates metadata.
- Parameters
- path_template_directorystr
Path of the templates directory.
- Returns
- dfpd.DataFrame
Dataframe with the templates metadata. Columns are:
‘id’ instance id.
‘shape’ shape of the cell image (with the format ‘{z}_{y}_{x}’).
‘protrusion_flag’ presence or not of protrusion in the instance.
- simfish.build_templates(path_template_directory, protrusion=None)
Return a generator to simulate several templates.
- Parameters
- path_template_directorystr
Path of the templates directory.
- protrusionbool, optional
Generate only templates with protrusion or not. If None, all the templates are generated.
- Returns
- _Tuple generator
- cell_masknp.ndarray, bool
Binary mask of the cell surface with shape (z, y, x).
- cell_mapnp.ndarray, np.float32
Distance map from cell membrane with shape (z, y, x).
- nuc_masknp.ndarray, bool
Binary mask of the nucleus surface with shape (z, y, x).
- nuc_mapnp.ndarray, np.float32
Distance map from nucleus membrane with shape (z, y, x).
- protrusion_masknp.ndarray, bool
Binary mask of the protrusion surface with shape (y, x).
- protrusion_mapnp.ndarray, np.float32
Distance map from protrusion region with shape (y, x).
- simfish.build_template(path_template_directory, i_cell=None, index_template=None, protrusion=None)
Build template from sparse coordinates. Outcomes are binary masks and distance maps, for cell, nucleus and protrusion.
- Parameters
- path_template_directorystr
Path of the templates directory.
- i_cellint, optional
Template id to build (between 0 and 317). If None, a random template is built.
- index_templatepd.DataFrame, optional
Dataframe with the templates metadata. If None, dataframe is load from ‘path_template_directory’. Columns are:
‘id’ instance id.
‘shape’ shape of the cell image (with the format ‘{z}_{y}_{x}’).
‘protrusion_flag’ presence or not of protrusion in the instance.
- protrusionbool, optional
Generate only templates with protrusion or not. If None, all the templates are generated.
- Returns
- cell_masknp.ndarray, bool
Binary mask of the cell surface with shape (z, y, x).
- cell_mapnp.ndarray, np.float32
Distance map from cell membrane with shape (z, y, x).
- nuc_masknp.ndarray, bool
Binary mask of the nucleus surface with shape (z, y, x).
- nuc_mapnp.ndarray, np.float32
Distance map from nucleus membrane with shape (z, y, x).
- protrusion_masknp.ndarray, bool
Binary mask of the protrusion surface with shape (y, x).
- protrusion_mapnp.ndarray, np.float32
Distance map from protrusion region with shape (y, x).