Skip to content

Commit

Permalink
Addition of Metric Calculation Methods (#131)
Browse files Browse the repository at this point in the history
* Added LiSi evaulation metric and helper methods in datastore

* datastore.py: added metrics methods for lisi, silhouette, and integration (adjusted rand score, normalized mutual information score). Uses the latest knn location when calculating default. Provide all parameter otherwise.

metrics.py: function for computing all scores.

graph_datastore.py: rename functions

* All:
	- Added DocString and typing
datastore.py:
	- lisi: filtered metadata as per 'I'
	- doc strings and typing
metrics.py:
	- formatted & typing
tests:
	- Added test for metrics

* comment cleanup

* Added progress bar on Lisi

* datastore.py: updated metric_lisi, metric_silhouette, and metric_integration to use latest KNN location and option to provide KNN location as input; assay.py and metrics.py: ruff formatting
  • Loading branch information
Gautam8387 authored Jan 16, 2025
1 parent f686d09 commit 89a5149
Show file tree
Hide file tree
Showing 5 changed files with 773 additions and 36 deletions.
18 changes: 8 additions & 10 deletions scarf/assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from .metadata import MetaData
from .utils import controlled_compute, logger, show_dask_progress

zarrGroup = z_hierarchy.Group

__all__ = ["Assay", "RNAassay", "ATACassay", "ADTassay"]


Expand Down Expand Up @@ -102,7 +100,7 @@ class Assay:
for later KNN graph construction.
Args:
z (zarrGroup): Zarr hierarchy where raw data is located
z (z_hierarchy.Group): Zarr hierarchy where raw data is located
name (str): A label/name for assay.
cell_data: Metadata class object for the cell attributes.
nthreads: number for threads to use for dask parallel computations
Expand All @@ -122,7 +120,7 @@ class Assay:

def __init__(
self,
z: zarrGroup,
z: z_hierarchy.Group,
workspace: Union[str, None],
name: str, # FIXME change to assay_name
cell_data: MetaData,
Expand Down Expand Up @@ -757,7 +755,7 @@ class RNAassay(Assay):
normalization of scRNA-Seq data.
Args:
z (zarrGroup): Zarr hierarchy where raw data is located
z (z_hierarchy.Group): Zarr hierarchy where raw data is located
name (str): A label/name for assay.
cell_data: Metadata class object for the cell attributes.
**kwargs: kwargs to be passed to the Assay class
Expand All @@ -769,7 +767,7 @@ class RNAassay(Assay):
It is set to None until normed method is called.
"""

def __init__(self, z: zarrGroup, name: str, cell_data: MetaData, **kwargs):
def __init__(self, z: z_hierarchy.Group, name: str, cell_data: MetaData, **kwargs):
super().__init__(z=z, name=name, cell_data=cell_data, **kwargs)
self.normMethod = norm_lib_size
if "size_factor" in self.attrs:
Expand Down Expand Up @@ -1076,12 +1074,12 @@ class ATACassay(Assay):
"""This subclass of Assay is designed for feature selection and
normalization of scATAC-Seq data."""

def __init__(self, z: zarrGroup, name: str, cell_data: MetaData, **kwargs):
def __init__(self, z: z_hierarchy.Group, name: str, cell_data: MetaData, **kwargs):
"""This Assay subclass is designed for feature selection and
normalization of scATAC-Seq data.
Args:
z (zarrGroup): Zarr hierarchy where raw data is located
z (z_hierarchy.Group): Zarr hierarchy where raw data is located
name (str): A label/name for assay.
cell_data: Metadata class object for the cell attributes.
**kwargs:
Expand Down Expand Up @@ -1208,7 +1206,7 @@ class ADTassay(Assay):
(feature-barcodes library) data from CITE-Seq experiments.
Args:
z (zarrGroup): Zarr hierarchy where raw data is located
z (z_hierarchy.Group): Zarr hierarchy where raw data is located
name (str): A label/name for assay.
cell_data: Metadata class object for the cell attributes.
**kwargs:
Expand All @@ -1217,7 +1215,7 @@ class ADTassay(Assay):
normMethod: Pointer to the function to be used for normalization of the raw data
"""

def __init__(self, z: zarrGroup, name: str, cell_data: MetaData, **kwargs):
def __init__(self, z: z_hierarchy.Group, name: str, cell_data: MetaData, **kwargs):
"""This subclass of Assay is designed for normalization of ADT/HTO
(feature-barcodes library) data from CITE-Seq experiments."""
super().__init__(z=z, name=name, cell_data=cell_data, **kwargs)
Expand Down
Loading

0 comments on commit 89a5149

Please sign in to comment.