mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 11:58:11 +08:00
Better documentation for driver/engines
Removed the REST v2.0 documentation in favor of getting v1.0 working with driver/engine model
This commit is contained in:
+21
-18
@@ -14,18 +14,10 @@ class CXGDriver(metaclass=ABCMeta):
|
|||||||
def _load_or_infer_schema(data):
|
def _load_or_infer_schema(data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def _set_cell_ids(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def cells(self):
|
def cells(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def cellids(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def genes(self):
|
def genes(self):
|
||||||
pass
|
pass
|
||||||
@@ -34,21 +26,25 @@ class CXGDriver(metaclass=ABCMeta):
|
|||||||
def filter_cells(self, filter):
|
def filter_cells(self, filter):
|
||||||
"""
|
"""
|
||||||
Filter cells from data and return a subset of the data
|
Filter cells from data and return a subset of the data
|
||||||
|
A filter is a dictionary where the key is a metadatata category
|
||||||
|
Value is dictionary
|
||||||
|
value_type: int, float, string
|
||||||
|
variable_type: continuous, categorical
|
||||||
|
query: filter value, for categorical [val1, val2], for continuous {min: x, max:y}
|
||||||
|
Filters are combined with the and operator
|
||||||
:param filter:
|
:param filter:
|
||||||
:return: filtered dataframe
|
:return: filtered dataframe
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Should this return the order of metadata fields as the first value?
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def metadata(self, df, fields=None):
|
def metadata(self, df, fields=None):
|
||||||
"""
|
"""
|
||||||
Generator for metadata. Gets the metadata values cell by cell and returns all value
|
Gets metadata key:value for each cells
|
||||||
or only certain values if names is not None
|
|
||||||
|
|
||||||
:param df: from filter_cells, dataframe
|
:param df: from filter_cells, dataframe
|
||||||
:param fields: list of keys for metadata to return, returns all metadata values if not set.
|
:param fields: list of keys for metadata to return, returns all metadata values if not set.
|
||||||
:return: Iterator for cellid + list of cells metadata values ex. [cell-id, val1, val2, val3]
|
:return: list of metadata values
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -57,7 +53,7 @@ class CXGDriver(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
Computes a n-d layout for cells through dimensionality reduction.
|
Computes a n-d layout for cells through dimensionality reduction.
|
||||||
:param df: from filter_cells, dataframe
|
:param df: from filter_cells, dataframe
|
||||||
:return: Iterator for [cellid-1, pos1, pos2], [cellid-2, pos1, pos2]
|
:return: [cellid, x, y]
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -65,14 +61,21 @@ class CXGDriver(metaclass=ABCMeta):
|
|||||||
def diffexp(self, df1, df2):
|
def diffexp(self, df1, df2):
|
||||||
"""
|
"""
|
||||||
Computes the top differentially expressed genes between two clusters
|
Computes the top differentially expressed genes between two clusters
|
||||||
|
:param df1: from filter_cells, dataframe containing first set of cells
|
||||||
:param df1: First set of cells
|
:param df2: from filter_cells, dataframe containing second set of cells
|
||||||
:param df2: Second set of cells
|
:return: top genes, stats and expression values for top genes
|
||||||
:return: Up in the air: I recommend [gene name, mean_expression_cells1,
|
|
||||||
mean_expression_cells2, average_difference, statistic_value]
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def expression(self, df):
|
def expression(self, df):
|
||||||
|
"""
|
||||||
|
Retrieves expression for each gene for cells in data frame
|
||||||
|
:param df:
|
||||||
|
:return: {
|
||||||
|
"genes": list of genes,
|
||||||
|
"cells": list of cells and expression list,
|
||||||
|
"nonzero_gene_count": number of nonzero genes
|
||||||
|
}
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -52,7 +52,14 @@ class ScanpyEngine(CXGDriver):
|
|||||||
def filter_cells(self, filter):
|
def filter_cells(self, filter):
|
||||||
"""
|
"""
|
||||||
Filter cells from data and return a subset of the data
|
Filter cells from data and return a subset of the data
|
||||||
|
A filter is a dictionary where the key is a metadatata category
|
||||||
|
Value is dictionary
|
||||||
|
value_type: int, float, string
|
||||||
|
variable_type: continuous, categorical
|
||||||
|
query: filter value, for categorical [val1, val2], for continuous {min: x, max:y}
|
||||||
|
Filters are combined with the and operator
|
||||||
:param filter:
|
:param filter:
|
||||||
|
:return: filtered dataframe
|
||||||
"""
|
"""
|
||||||
cell_idx = np.ones((self.cell_count,), dtype=bool)
|
cell_idx = np.ones((self.cell_count,), dtype=bool)
|
||||||
for key, value in filter.items():
|
for key, value in filter.items():
|
||||||
@@ -91,9 +98,11 @@ class ScanpyEngine(CXGDriver):
|
|||||||
|
|
||||||
def metadata(self, df, fields=None):
|
def metadata(self, df, fields=None):
|
||||||
"""
|
"""
|
||||||
Generator for metadata. Gets the metadata values cell by cell and returns all value
|
Gets metadata key:value for each cells
|
||||||
or only certain values if names is not None
|
|
||||||
|
|
||||||
|
:param df: from filter_cells, dataframe
|
||||||
|
:param fields: list of keys for metadata to return, returns all metadata values if not set.
|
||||||
|
:return: list of metadata values
|
||||||
"""
|
"""
|
||||||
metadata = df.obs.to_dict(orient="records")
|
metadata = df.obs.to_dict(orient="records")
|
||||||
for idx in range(len(metadata)):
|
for idx in range(len(metadata)):
|
||||||
@@ -103,6 +112,8 @@ class ScanpyEngine(CXGDriver):
|
|||||||
def create_graph(self, df):
|
def create_graph(self, df):
|
||||||
"""
|
"""
|
||||||
Computes a n-d layout for cells through dimensionality reduction.
|
Computes a n-d layout for cells through dimensionality reduction.
|
||||||
|
:param df: from filter_cells, dataframe
|
||||||
|
:return: [cellid, x, y]
|
||||||
"""
|
"""
|
||||||
getattr(sc.tl, self.graph_method)(df)
|
getattr(sc.tl, self.graph_method)(df)
|
||||||
graph = df.obsm["X_{graph_method}".format(graph_method=self.graph_method)]
|
graph = df.obsm["X_{graph_method}".format(graph_method=self.graph_method)]
|
||||||
@@ -110,6 +121,12 @@ class ScanpyEngine(CXGDriver):
|
|||||||
return np.hstack((df.obs["cell_name"].values.reshape(len(df.obs.index), 1), normalized_graph)).tolist()
|
return np.hstack((df.obs["cell_name"].values.reshape(len(df.obs.index), 1), normalized_graph)).tolist()
|
||||||
|
|
||||||
def diffexp(self, cell_list_1, cell_list_2, pval, num_genes):
|
def diffexp(self, cell_list_1, cell_list_2, pval, num_genes):
|
||||||
|
"""
|
||||||
|
Computes the top differentially expressed genes between two clusters
|
||||||
|
:param df1: from filter_cells, dataframe containing first set of cells
|
||||||
|
:param df2: from filter_cells, dataframe containing second set of cells
|
||||||
|
:return: top genes, stats and expression values for top genes
|
||||||
|
"""
|
||||||
cells_idx_1 = np.in1d(self.data.obs["cell_name"], cell_list_1)
|
cells_idx_1 = np.in1d(self.data.obs["cell_name"], cell_list_1)
|
||||||
cells_idx_2 = np.in1d(self.data.obs["cell_name"], cell_list_2)
|
cells_idx_2 = np.in1d(self.data.obs["cell_name"], cell_list_2)
|
||||||
expression_1 = self.data.X[cells_idx_1, :]
|
expression_1 = self.data.X[cells_idx_1, :]
|
||||||
@@ -150,8 +167,13 @@ class ScanpyEngine(CXGDriver):
|
|||||||
|
|
||||||
def expression(self, cells=None, genes=None):
|
def expression(self, cells=None, genes=None):
|
||||||
"""
|
"""
|
||||||
|
Retrieves expression for each gene for cells in data frame
|
||||||
:param df:
|
:param df:
|
||||||
:return:
|
:return: {
|
||||||
|
"genes": list of genes,
|
||||||
|
"cells": list of cells and expression list,
|
||||||
|
"nonzero_gene_count": number of nonzero genes
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
if cells:
|
if cells:
|
||||||
cells_idx = np.in1d(self.data.obs["cell_name"], cells)
|
cells_idx = np.in1d(self.data.obs["cell_name"], cells)
|
||||||
|
|||||||
Reference in New Issue
Block a user