schist._utils
Package Contents
Functions
|
Returns the matrix of log-likelihood differences |
|
Returns the matrix of proabilities of moving a cell back to its |
|
Get graph-tool graph from adjacency matrix. |
|
Returns the index of informative levels after the nested_model has |
|
Get graph-tool graph from adata. |
|
Get a multigraph from multiple adata objects. |
|
Add a state to a dataset, populate the AnnData.obs consistenly |
|
Returns a gt state object given an AnnData |
- schist._utils.get_cell_loglikelihood(state: Union[graph_tool.inference.nested_blockmodel.NestedBlockState, graph_tool.inference.planted_partition.PPBlockState], level: int = 0, rescale: bool = False, as_prob: bool = False)
Returns the matrix of log-likelihood differences when moving a cell into a different block
- state
A graphtool BlockState or NestedBlockState objexct
- level
The level in NestedBlockState to consider
- rescale
For some models, moving a cell into a different block may result in a negative log-likelihood, indicating that cells may be better assigned to another group. Set this parameter to True if you want every cell to have LL=0 for the best group and avoid negative values
- as_prob
Return values as probabilites
- M
Array of dim (n_cells, n_blocks) that stores the entropy difference of moving a cell into a specific group
- schist._utils.get_cell_back_p(state: Union[graph_tool.inference.nested_blockmodel.NestedBlockState, graph_tool.inference.planted_partition.PPBlockState], level: int = 0, rescale: bool = False, as_prob: bool = False)
Returns the matrix of proabilities of moving a cell back to its group from a different block
- state
A graphtool BlockState or NestedBlockState objexct
- level
The level in NestedBlockState to consider
- M
Array of dim (n_cells, n_blocks) that stores the entropy difference of moving a cell into a specific group
- schist._utils.get_graph_tool_from_adjacency(adjacency, directed=False, use_weights=False)
Get graph-tool graph from adjacency matrix.
- schist._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.get_graph_tool_from_adata(adata: anndata.AnnData, restrict_to: Optional[Tuple[str, Sequence[str]]] = None, adjacency: Optional[scipy.sparse.spmatrix] = None, neighbors_key: Optional[str] = 'neighbors', directed: bool = False, use_weights: bool = False)
Get graph-tool graph from adata.
- schist._utils.get_multi_graph_from_adata(adatas: List[anndata.AnnData], adjacency: Optional[List[scipy.sparse.spmatrix]] = None, neighbors_key: Optional[List[str]] = ['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.plug_state(adata: anndata.AnnData, state: Union[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) Optional[anndata.AnnData]
Add a state to a dataset, populate the AnnData.obs consistenly
- 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.state_from_blocks(adata: anndata.AnnData, state_key: Optional[str] = 'nsbm', neighbors_key: Optional[str] = 'neighbors', adjacency: Optional[scipy.sparse.spmatrix] = None, directed: bool = False, use_weights: bool = False, deg_corr: bool = True)
Returns a gt state object given an AnnData
- 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.
Nothing, adds a gt.block_state object in adata.uns