API Reference¶
organelle_morphology
¶
Analysis
¶
Bases: ABC
Analysis base class. Specific analysis workflows should subclass this.
DataSource
¶
basic_geometric_properties
property
¶
get basic properties from scikit-image
cache
property
¶
Get the cache for this source.
Returns the same cache object on consecutive calls.
On clipping or level change, this cache must be invalidated by calling
source.clear_memory_cache()
clipping_corners
property
writable
¶
Lower and upper clipping corner in units of the resolution
clipping_corners_data
property
writable
¶
Lower and upper clipping corner matching the raw data
coarse_data
property
¶
Return the coarsest version of the dataset.
This can be used for algorithms that do not critically depend on the data resolution and should be fast.
coarse_resolution
property
¶
Return the resolution of our data at the coarsest compression level.
curvature_map
property
¶
Get the curvature map for all organelles
data_resolution
property
¶
Return the resolution in micrometers at which the data is stored.
labels
property
¶
Return the list of labels present in the data source.
mesh_fragments
property
¶
Get the mesh fragments from cache, or calculate them.
The mesh fragments are delayed read from the source.cache, so reads are cached in memory.
Returns:
| Type | Description |
|---|---|
dict[int, list[tuple[int]]]
|
dict[int, list[tuple[int]]]: dict to translate mesh ids to a list of chunk indices to find all chunks containing parts of this mesh. |
ndarray
|
np.ndarray: Array containing the delayed chunks. Shape matches storage on disk, after applying the clipping. |
metadata
property
¶
Return the metadata of this source. Loads the metadata, if necessary
coarse_level: coarsest level available data_root: path to n5 data directory downsampling: list of factors by which the resolution can be decreased levels: names of downsampling levels, aligned with downsampling list name: name resolution: size of one voxel at highest resolution size: number of voxels at highest resolution
resolution
property
¶
Return the resolution of our data at the chosen compression level.
__init__(project, xml_path, organelle, background_label=0)
¶
Initialize a data source.
Initialize a data source for organelle morphology analysis. The data source is linked to a CebraEM/Mobie project and contains information about a single organelle data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
The CebraEM/Mobie project this data source is linked to. |
required |
xml_path
|
Path
|
The path to the XML file describing the source data. |
required |
organelle
|
str
|
The name of the organelle being analyzed. |
required |
background_label
|
int
|
The label used for background pixels. |
0
|
calc_curvature(labels=None)
¶
calculate_mesh(reduction_factor=0, overlap=True, debug_color=None)
¶
Compute meshes for this source.
Meshes crossing chunks are merged.
Respects the set compression and clipping of the project. Computation is done in parallel using the dask client of the project.
clear_memory_cache()
¶
Invalidates memory caches. Necessary after change of compression level or clipping.
generate_skeletons(labels, skeletonization_type='wavefront', theta=0.4, waves=1, step_size=2, epsilon=0.1, sampling_dist=0.1, path_sample_dist=0.1, recompute=False)
¶
Generates a skeleton for the organelle. The skeleton is generated and cleaned using the skeletor library.
The last generated skeleton will be kept in memory and can be accessed using the skeleton or sampled_skeleton property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeletonization_type
|
str
|
The type of skeletonization to use. Can be either "wavefront" or "vertex_clusters". |
'wavefront'
|
waves
|
int
|
The number of waves to use for the wavefront skeletonization. The higher the number of waves, the more branches are removed. |
1
|
step_size
|
int
|
The step size for the wavefront skeletonization. The higher the step size, the less vertices are used for the skeleton. |
2
|
theta
|
float
|
The threshold for the clean_up function. The higher the threshold, the more branches are removed. |
0.4
|
epsilon
|
float
|
The epsilon value for the contract function. The higher the epsilon, the more the mesh is contracted. |
0.1
|
sampling_dist
|
float
|
The sampling distance for the skeletonize function. The higher the sampling distance, the less vertices are used for the skeleton. |
0.1
|
path_sample_dist
|
float
|
The distance between the sample points on the skeleton arms. The higher the distance, the less sample points are used. |
0.1
|
Returns: List of organelles which have a skeleton.
get_data(compression_level=None, clipping=None)
¶
Get data of this source as array.
Sets self.clipping_corners and self.clipping_corners_data, if project clipping is not overwritten
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compression_level
|
Optional[str]
|
Override the compression level specified in the project. Default: None, get level from project. |
None
|
clipping
|
Override the clipping specified in the project. Default: None, get clipping from project |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Dask array of the data. Respects the in the project set clipping. |
get_organelle_ids(ids='*', permanent_whitelist=None, permanent_blacklist=None)
¶
Return a list of organelle ids. Computes self._organelles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
str | list[str]
|
glob pattern to match the ids. Default "*" includes all. |
'*'
|
permanent_whitelist
|
ids to always include, does not respect the project setting. |
None
|
|
permanent_blacklist
|
ids to always exclude, does not respect the project setting. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of organelle ids |
get_organelles(ids='*', permanent_whitelist=None, permanent_blacklist=None)
¶
Return a list of organelle objects. Apply filters by id glob pattern and permanent filter lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
str | list[str]
|
glob pattern to match the ids. Default "*" includes all. |
'*'
|
permanent_whitelist
|
ids to always include, does not respect the project setting. |
None
|
|
permanent_blacklist
|
ids to always exclude, does not respect the project setting. |
None
|
Returns:
| Type | Description |
|---|---|
list[Organelle]
|
List of organelle objects |
Organelle
¶
curvature_map
property
¶
Get the mesh data for this organelle
data
property
¶
Get the raw data for this organelle by filtering the data of the source object
geometric_data
property
¶
Get the geometric data for this organelle Possible keywords are: "voxel_volume": for 3d this is the volume "voxel_bbox", "voxel_slice": the slice of the bounding box "voxel_centroid" "voxel_moments" "voxel_extent": how much volume of the bounding box is occupied by the object "voxel_solidity":ratio of pixels in the convex hull to those in the region
id
property
¶
Get the organelle ID of this organelle
mesh
property
¶
Get the mesh for this organelle
mesh_properties
property
¶
Get properties of the mesh for this organelle
Causes a compute call, if you need this for many organelles,
use get_mesh_properties_delayed
sampled_skeleton
property
writable
¶
Get the sampled skeleton for this organelle. This included the sampled points, as well as the corresponding reference point to later get the correct plane normal vector
skeleton
property
writable
¶
Get the skeleton for this organelle
__init__(source, label)
¶
The organelle base class
Holds references to its mesh and label. Also holds analysis results.
Note that instances of Organelle typically are not instantiated directly, but through the corresponding subclass of OrganelleFactory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
DataSource
|
The source object containing this organelle |
required |
label
|
int
|
label used in the original data for this organelle. |
required |
add_mcs(mcs_dict, mcs_meta)
¶
Add mcs information to this organelle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcs_dict
|
dict
|
mcs_dict created by the MembraneContactSiteCalculator |
required |
calc_mcs_dict_entry(mcs_label)
¶
Calculate the properties of the mcs partners for the given mcs label
construct(source, labels)
classmethod
¶
A trivial factory method for organelle instances.
It constructs an instance per label. The construction process for each organelle is independent of all others. Other organelles can subclass this to implement a construction process that e.g. takes into account all organelle instances.
get_mesh_mcs_colored(mcs_label=None)
¶
Get mcs colored delayed meshes
Project
¶
cache
property
¶
Get the cache for this project.
Unique for sum of sources, compression level and clipping setting.
Returns the same cache object on consecutive calls.
On clipping or level change, this cache must be invalidated by calling
project.clear_caches()
clipping
property
writable
¶
The subcube of the original data to work with. All operations performed in this project must respect the clipping region set here.
Attribute clipping
Tuple of two tuples of length three. Must be the lower corner and the upper corner.
compression_level
property
writable
¶
The compression level used for our computations.
curvature_map
property
¶
Get the curvature map for all organelles
distance_matrix
property
¶
Returns the distance matrix of all organeles in the project in micro meters.
geometric_properties
property
¶
The geometry properties of the organelles Possible keywords are: "voxel_volume": for 3d this is the volume "voxel_bbox", "voxel_slice": the slice of the bounding box "voxel_centroid" "voxel_moments" "voxel_extent": how much volume of the bounding box is occupied by the object "voxel_solidity":ratio of pixels in the convex hull to those in the region "mesh_volume" "mesh_area" "mesh_centroid" "mesh_inertia" "water_tight" "sphericity": how spherical the mesh is (0-1) "flatness_ratio": how cubic the mesh is (0-1)
__init__(project_path, clipping=None, compression_level='s0', loglevel=None, client=None, n_workers=4)
¶
Instantiate an EM project
The given path is expected to contain either a CebraEM or Mobie project JSON file. This is a lazy operation. No data except metadata is loaded until it is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
Path | str
|
The location of the project. |
required |
clipping
|
Optional[clipping_type]
|
If not None, the data is clipped with the given lower left and the given upper right corner as the bounding box of the clipping. Coordinates are expected to be in micrometer. |
None
|
compression_level
|
str
|
The compression level at which we operate. This is used to determine the resolution of the data that we work with. The default of 0 corresponds to the highest resolution. |
's0'
|
add_source(xml_path, organelle, background_label=0)
¶
Connect a data source in the project with an organelle type
Parameters¶
source_path The path to the xml source to add. organelle The name of the organelle that is labelled in the data source. Must be on the strings returned by organelle_morphology.organelle_types background_label The label in the data source that is used to encode the background. Assumed to be 0.
Returns¶
DataSource
Also accessable as project[xml_name]
Raises¶
ValueError Source already loaded ValueError Compression level of project not available
blacklist_by_volume(max_vol)
¶
Add organlles to the permanent blacklist based on their volume.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_vol
|
float
|
Max volume of organlles allowed. Smaller organelles are added to the blacklist. |
required |
calculate_meshes()
¶
Trigger the calculation of meshes for all organelles
clear_caches(clear_disk=False, silent=False)
¶
Clear all caches related to this project, optionally also from disk
clear_memory_cache()
¶
(Re)initialize project-level storage.
distance_analysis(ids_source='*', ids_target='*', attribute='dist')
¶
get more information about the distance between two filtered organelle lists. These can be from one or more types depending on the given filter.
:param ids_source: Filter string for the source ids, defaults to "" :type ids_source: str, optional :param ids_target: filter string for the target ids, defaults to "" :type ids_target: str, optional :param attribute: The attribute to be used for the distance analysis. Possible values are "dist", "min", "mean". dist: the distance matrix between the organelles min: the minimum distance between all sources for any target and the corresponding target id mean: the mean distance between the organelles :type attribute: type
distance_filtering(ids_source='*', ids_target='*', filter_distance=0.01, attribute='labels')
¶
Filter the organelles based on the distance between two filtered organelle lists.
These can be from one or more types depending on the given filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids_source
|
Filter string for the source ids, defaults to "*" |
'*'
|
|
ids_target
|
filter string for the target ids, defaults to "*" |
'*'
|
|
filter_distance
|
The distance in micro meter used for filtering, defaults to 0.01 |
0.01
|
|
attribute
|
Show names, number of contacts (contacts) or return the organelle objects ("objects"), defaults to "names" |
'labels'
|
Returns: Dictionary with the source organelle ids as keys and the target organelle ids or number of contact sites as values
get_organelle_ids(ids='*')
¶
Return a list of organelle ids found in the dataset
This requires previous adding of data sources using add_source. The ids parameter is used to filter based on organelle ids.
get_organelles(ids='*')
¶
Return a list of organelles found in the dataset
This requires previous adding of data sources using add_source. The ids parameter is used to filter based on organelle ids. Filtering using the permanent_blacklist and permanent_whitelist is respected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
str | list[str]
|
The glob-style filtering expression for organelle ids to return. The default of "*" returns all organelles. |
'*'
|
merged_meshes(ids='*', color=1, delayed=False)
¶
Get a mesh composed of all or some organelles
Set the compression level and clipping in the project.
ids Glob style filter for the organelles. The default "*" returns all organelles in the project. color 0: don't color the mesh 1: color per source or per id filter if multiple are supplied (default) 2: color per face delayed If True, return a dask delayed object instead of the computed mesh. Default: False
search_mcs(max_distance, min_distance=0.0, ids_filter_1='*', ids_filter_2='*', overwrite_mcs_label=False)
¶
This function is used to search for membrane contact sites within a project. Pairs will only be selected when their minimum mesh distance is between the requested min and max distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
Project
|
The project object containing the distance matrix and organelles. |
required |
mcs_label
|
str
|
The label for the MCS pairs. |
required |
max_distance
|
float
|
The maximum distance for the MCS pairs. |
required |
min_distance
|
float
|
The minimum distance for the MCS pairs. Defaults to 0. |
0.0
|
ids_filter_1
|
str
|
Filter for the first set of organelles using glob-style patterns. Defaults to "*". |
'*'
|
ids_filter_2
|
str
|
Filter for the second set of organelles using glob-style patterns. Defaults to "*". |
'*'
|
overwrite_mcs_label
|
bool
|
If the label exists, it should be overwritten. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The label of this mcs search |
set_curvature_radius(radius)
¶
Set the radius for curvature calculations. Resets the cached curvature.
skeletonize_wavefront(ids='*', theta=0.4, waves=1, step_size=2, path_sample_dist=0.1, recompute=False)
¶
Note that some meshes will be skipped if they are too small to be skeletonized.
merge_meshes(meshes, color=None, transp=False)
¶
Merges delayed meshes into one delayed Mesh object
Needs overlapping meshes, otherwise the intersections will not be connected.