schist._utils._gt_utils

Module Contents

Functions

get_graph_tool_from_adjacency(adjacency[, directed, ...])

Get graph-tool graph from adjacency matrix.

prune_groups(groups[, inverse])

Returns the index of informative levels after the nested_model has

get_graph_tool_from_adata(adata[, restrict_to, ...])

Get graph-tool graph from adata.

get_multi_graph_from_adata(adatas[, adjacency, ...])

Get a multigraph from multiple adata objects.

plug_state(→ Optional[anndata.AnnData])

Add a state to a dataset, populate the AnnData.obs consistenly

state_from_blocks(adata[, state_key, neighbors_key, ...])

Returns a gt state object given an AnnData

schist._utils._gt_utils.get_graph_tool_from_adjacency(adjacency, directed=False, use_weights=False)

Get graph-tool graph from adjacency matrix.

schist._utils._gt_utils.prune_groups(groups, inverse=False)

Returns the index of informative levels after the nested_model has been run. It works by looking at level entropy and, moreover, checks if two consecutive levels have the same clustering

schist._utils._gt_utils.get_graph_tool_from_adata(adata: anndata.AnnData, restrict_to: Tuple[str, Sequence[str]] | None = None, adjacency: scipy.sparse.spmatrix | None = None, neighbors_key: str | None = 'neighbors', directed: bool = False, use_weights: bool = False)

Get graph-tool graph from adata.

schist._utils._gt_utils.get_multi_graph_from_adata(adatas: List[anndata.AnnData], adjacency: List[scipy.sparse.spmatrix] | None = None, neighbors_key: List[str] | None = ['neighbors'], directed: bool = False, use_weights: bool = False)

Get a multigraph from multiple adata objects. To be used in multi-omics analysis with some cells paired.

schist._utils._gt_utils.plug_state(adata: anndata.AnnData, state: graph_tool.all.NestedBlockState | graph_tool.all.BlockState | graph_tool.all.PPBlockState, nested: bool = True, key_added: str = 'nsbm', calculate_affinity: bool = False, copy: bool = False) anndata.AnnData | None

Add a state to a dataset, populate the AnnData.obs consistenly

Parameters

adata

The annotated data matrix.

state

The graph_tool state. Supported types are NestedBlockState BlockState and PPBlockState

nested

If False plug only the lowest level, otherwise the full hierarchy

key_added

The prefix for annotations

schist._utils._gt_utils.state_from_blocks(adata: anndata.AnnData, state_key: str | None = 'nsbm', neighbors_key: str | None = 'neighbors', adjacency: scipy.sparse.spmatrix | None = None, directed: bool = False, use_weights: bool = False, deg_corr: bool = True)

Returns a gt state object given an AnnData

Parameters

adata

The annotated data matrix.

state_key

The key under which the state has been saved

neighbors_key

The key passed to sc.pp.neighbors

adjacency

Sparse adjacency matrix of the graph, defaults to adata.uns[‘neighbors’][‘connectivities’] in case of scanpy<=1.4.6 or adata.obsp[neighbors_key][connectivity_key] for scanpy>1.4.6

directed

Whether to treat the graph as directed or undirected.

use_weights

If True, edge weights from the graph are used in the computation (placing more emphasis on stronger edges). Note that this increases computation times

deg_corr

Whether to use degree correction in the minimization step. In many real world networks this is the case, although this doesn’t seem the case for KNN graphs used in scanpy.

Returns

Nothing, adds a gt.block_state object in adata.uns