gridgene.mask_properties module#
- gridgene.mask_properties.timeit(func)[source]
- class gridgene.mask_properties.MaskDefinition(mask, mask_name, analysis_type='per_object', grid_size=None)[source]
Bases:
objectDefinition of a mask to analyze.
- Parameters:
mask (np.ndarray) – Binary mask array.
mask_name (str) – Name identifier for the mask.
analysis_type (str, optional) – Type of analysis (‘per_object’, ‘bulk’, or ‘grid’), by default “per_object”.
grid_size (int or None, optional) – Grid size for ‘grid’ analysis type, by default None.
-
mask:
ndarray
-
mask_name:
str
-
analysis_type:
str= 'per_object'
-
grid_size:
Optional[int] = None
- class gridgene.mask_properties.MaskAnalysisResult(mask_name, analysis_type, features)[source]
Bases:
objectContainer for the results of mask analysis.
- Parameters:
mask_name (str) – Name of the analyzed mask.
analysis_type (str) – Analysis type performed.
features (list of dict) – List of extracted features per object.
-
mask_name:
str
-
analysis_type:
str
-
features:
List[Dict[str,Any]]
- class gridgene.mask_properties.MorphologyExtractor[source]
Bases:
objectExtracts morphological features from labeled masks.
- extract_per_object_features(labeled_mask)[source]
Extract per-object morphological features from a labeled mask.
- Parameters:
labeled_mask (np.ndarray) – Mask where each object is labeled with an integer.
- Returns:
List of dictionaries containing features per object.
- Return type:
list of dict
- extract_bulk_features(mask)[source]
Extract bulk features for a whole mask (e.g., total area).
- Parameters:
mask (np.ndarray) – Binary mask.
- Returns:
Single-item list with total area and object_id=’bulk’.
- Return type:
list of dict
- extract_grid_features_per_object(labeled_mask, grid_size)[source]
Extract features per grid tile for each labeled object.
- Return type:
List[Dict[str,Any]]
- class gridgene.mask_properties.GeneCounter[source]
Bases:
objectCounts gene expression values within masks.
- count_genes_per_object(labeled_mask, array_counts, target_dict)[source]
Count genes per labeled object.
- Parameters:
labeled_mask (np.ndarray) – Labeled mask array.
array_counts (np.ndarray) – 3D array of gene counts per pixel.
target_dict (dict) – Mapping from gene names to indices in array_counts.
- Returns:
List of gene counts per object.
- Return type:
list of dict
- count_genes_bulk(mask, array_counts, target_dict)[source]
Count genes in a bulk mask.
- Parameters:
mask (np.ndarray) – Binary mask.
array_counts (np.ndarray) – 3D array of gene counts.
target_dict (dict) – Mapping from gene names to indices.
- Returns:
Single-item list with gene counts.
- Return type:
list of dict
- count_genes_grid_per_object(labeled_mask, array_counts, target_dict, grid_size)[source]
Count genes per grid tile within each object.
- Return type:
List[Dict[str,Any]]
- class gridgene.mask_properties.HierarchyMapper[source]
Bases:
objectMaps child objects to parent objects based on label overlaps.
- map_hierarchy(source_labels, target_labels)[source]
Map each source object ID to a list of parent object IDs from target mask.
- Parameters:
source_labels (np.ndarray) – Labeled source mask.
target_labels (np.ndarray) – Labeled target mask (parent).
- Returns:
Mapping from source object ID to list of parent IDs.
- Return type:
dict
- class gridgene.mask_properties.MaskAnalysisPipeline(mask_definitions, array_counts, target_dict, logger=None)[source]
Bases:
objectMain pipeline for analyzing masks with gene counts and morphology.
- run()[source]
Run the full analysis pipeline on all mask definitions.
- Returns:
List of results per mask.
- Return type:
list of MaskAnalysisResult
- get_results_df()[source]
Get all results concatenated into a single pandas DataFrame.
- Returns:
DataFrame with all extracted features.
- Return type:
pandas.DataFrame
- map_hierarchies(hierarchy_definitions, save_dir=None)[source]
Map child objects to their parent objects using reference labeled masks.
- Parameters:
hierarchy_definitions (dict) – Dictionary defining the hierarchy relationships.
save_dir (str or None, optional) – Directory to save labeled masks, by default None.
- Returns:
DataFrame with mapping of child to parent objects.
- Return type:
pandas.DataFrame