Compocyte.core.tools¶
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Infer hierarchical levels for labels based on a hierarchy graph. This function takes a hierarchy (either as a dict or NetworkX DiGraph) and assigns hierarchical levels to labels by finding the shortest path from a root node to each label in the hierarchy graph. :param hierarchy: The hierarchy structure. Can be either a dictionary of edges or a NetworkX directed graph. If a dict is provided, it will be converted to a DiGraph. :type hierarchy: dict or nx.DiGraph :param labels: The labels to infer levels for. Can be: - A string key referring to a column in adata.obs - A list of labels - An array-like object (with tolist() method) of labels :type labels: str, list, or array-like :param root_node: The root node of the hierarchy from which to compute shortest paths. :type root_node: str or int :param adata: An AnnData object. If provided, the obs dataframe from this object will be used as the base dataframe. If None, a new empty DataFrame is created. Default is None. :type adata: anndata.AnnData, optional :param prefix_obs: Prefix for the level column names. Default is 'Level_'. Level columns will be named 'Level_0', 'Level_1', etc. :type prefix_obs: str, optional. |
|
Determines whether or not a matrix (such as adata.X, adata.raw.X or an adata layer) contains count data by manually checking a subsample of the supplied matrix. |
|
Add explanation |
|
|
|
Calculates a z transformation to center properties across cells in data_arr around mean zero |
Classes
|
- Compocyte.core.tools.is_counts(matrix, n_rows_to_try=100)[source]¶
Determines whether or not a matrix (such as adata.X, adata.raw.X or an adata layer) contains count data by manually checking a subsample of the supplied matrix.
- Compocyte.core.tools.infer_levels(hierarchy, labels, root_node, adata=None, prefix_obs='Level_')[source]¶
Infer hierarchical levels for labels based on a hierarchy graph. This function takes a hierarchy (either as a dict or NetworkX DiGraph) and assigns hierarchical levels to labels by finding the shortest path from a root node to each label in the hierarchy graph. :param hierarchy: The hierarchy structure. Can be either a dictionary of edges or a NetworkX
directed graph. If a dict is provided, it will be converted to a DiGraph.
- Parameters:
labels (str, list, or array-like) – The labels to infer levels for. Can be: - A string key referring to a column in adata.obs - A list of labels - An array-like object (with tolist() method) of labels
root_node (str or int) – The root node of the hierarchy from which to compute shortest paths.
adata (anndata.AnnData, optional) – An AnnData object. If provided, the obs dataframe from this object will be used as the base dataframe. If None, a new empty DataFrame is created. Default is None.
prefix_obs (str, optional) – Prefix for the level column names. Default is ‘Level_’. Level columns will be named ‘Level_0’, ‘Level_1’, etc.
- Returns:
pd.DataFrame – A DataFrame with the original labels and new columns for each hierarchical level, containing the nodes at each level of the hierarchy for each label.
list – A list of the new level column names.
Notes
Paths shorter than the maximum depth are padded with empty strings.
The number of levels is determined by the depth of the hierarchy.
- Compocyte.core.tools.z_transform_properties(data_arr, discretization=False)[source]¶
Calculates a z transformation to center properties across cells in data_arr around mean zero
- Compocyte.core.tools.delete_dict_entries(dictionary, del_key='classifier', first_run=True, deleted_key=False)[source]¶
- class Compocyte.core.tools.Hierarchical_Metric(true_labels, predicted_labels, hierarchy_structure, root_node='Blood')[source]¶
Bases:
object- __init__(true_labels, predicted_labels, hierarchy_structure, root_node='Blood')[source]¶
hierarchy_structure: NetworkX graph of hierarchical classifier