scranpy.clustering package#

Submodules#

scranpy.clustering.build_snn_graph module#

class scranpy.clustering.build_snn_graph.BuildSnnGraphOptions(num_neighbors=15, weight_scheme='ranked', build_neighbor_index_options=<factory>, num_threads=1)[source]#

Bases: object

Optional arguments for build_snn_graph().

num_neighbors#

Number of neighbors to use. Larger values result in a more interconnected graph and generally broader clusters from community detection. Ignored if input is a NeighborResults object. Defaults to 15.

weight_scheme#

Weighting scheme for the edges between cells. This can be based on the top ranks of the shared neighbors (“rank”), the number of shared neighbors (“number”) or the Jaccard index of the neighbor sets between cells (“jaccard”). Defaults to “ranked”.

build_neighbor_index_options#

Optional arguments to use for building a nearest neighbors index. Only used if input is a ndarray.

num_threads#

Number of threads to use for the SNN graph construction. This is also used for the neighbor search if input is not already a NeighborResults. Defaults to 1.

Raises:

ValueError – If weight_scheme is not an expected value.

__annotations__ = {'build_neighbor_index_options': <class 'scranpy.nearest_neighbors.build_neighbor_index.BuildNeighborIndexOptions'>, 'num_neighbors': <class 'int'>, 'num_threads': <class 'int'>, 'weight_scheme': typing.Literal['ranked', 'jaccard', 'number']}#
__dataclass_fields__ = {'build_neighbor_index_options': Field(name='build_neighbor_index_options',type=<class 'scranpy.nearest_neighbors.build_neighbor_index.BuildNeighborIndexOptions'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'scranpy.nearest_neighbors.build_neighbor_index.BuildNeighborIndexOptions'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'num_neighbors': Field(name='num_neighbors',type=<class 'int'>,default=15,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'num_threads': Field(name='num_threads',type=<class 'int'>,default=1,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'weight_scheme': Field(name='weight_scheme',type=typing.Literal['ranked', 'jaccard', 'number'],default='ranked',default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)}#
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)#
__eq__(other)#

Return self==value.

__hash__ = None#
__post_init__()[source]#
__repr__()#

Return repr(self).

build_neighbor_index_options: BuildNeighborIndexOptions#
num_neighbors: int = 15#
num_threads: int = 1#
set_threads(num_threads)[source]#
weight_scheme: Literal['ranked', 'jaccard', 'number'] = 'ranked'#
scranpy.clustering.build_snn_graph.build_snn_graph(input, options=BuildSnnGraphOptions(num_neighbors=15, weight_scheme='ranked', build_neighbor_index_options=BuildNeighborIndexOptions(approximate=True), num_threads=1))[source]#

Build a shared nearest neighbor (SNN) graph where each cell is a node and edges are formed between cells that share one or more nearest neighbors. This can be used for community detection to define clusters of similar cells.

Parameters:
  • input (Union[NeighborIndex, NeighborResults, ndarray]) –

    Object containing per-cell nearest neighbor results or data that can be used to derive them.

    This may be a a 2-dimensional ndarray containing per-cell coordinates, where rows are cells and columns are dimensions. This is most typically the result of the PCA step (run_pca()).

    Alternatively, input may be a pre-built neighbor search index (NeighborIndex) for the dataset, typically constructed from the PC coordinates for all cells.

    Alternatively, input may be a pre-computed set of neighbor search results (NeighborResults). for all cells in the dataset.

  • options (BuildSnnGraphOptions) – Optional parameters.

Raises:

TypeError – If input is not a nearest neighbor search index or search result (NeighborIndex, NeighborResults).

Return type:

Graph

Returns:

An igraph object.

Module contents#