scviva.tools.vision.VisionToolsAccessor#
- class scviva.tools.vision.VisionToolsAccessor(va)[source]#
Lower-level VISION tool functions accessible as
va.tl.<method>.Created automatically by
VisionAnalysis; users do not instantiate it directly.- Parameters:
- va
VisionAnalysis The analysis object whose AnnData is used when
adatais not passed.
- va
Methods table
|
Partition cells into micro-clusters (supercells) via Louvain + K-means. |
|
Cluster cells by their position in a phylogenetic tree. |
|
Compute VISION exponential KNN weights and store in |
|
Compute per-cell Fitch-Hartigan parsimony plasticity scores. |
|
Generate 2D visualisation projections and store in |
|
Pool |
|
Pool |
|
Rank genes for characterizing groups. |
Methods
- VisionToolsAccessor.apply_micro_clustering(adata=None, *, cells_per_partition=10, filter_input=True, filter_threshold=None, filter_num_mad=2.0, latent_space_key=None, K=None, uns_key='micro_clusters', random_state=0)[source]#
Partition cells into micro-clusters (supercells) via Louvain + K-means.
Forwards to
apply_micro_clustering().adatadefaults to the AnnData held by the analysis object.Mirrors R VISION’s
applyMicroClustering.If latent_space_key is provided and present in
adata.obsm, those coordinates are used directly. Otherwise a lightweight internal PCA (max 10 components) is computed on log-transformed, filtered expression.- Parameters:
- adata AnnData | None
Annotated data matrix.
- cells_per_partition
int Target number of cells per micro-cluster, by default 10.
- filter_input
bool Apply threshold + fano gene filters before internal PCA, by default
True. Ignored when latent_space_key is provided.- filter_threshold
int|None Minimum expressing-cell count for the threshold filter. Defaults to
round(0.05 * n_cells)(matching R VISION’sapplyMicroClusteringdefault of 5% of cells) whenNone.- filter_num_mad
float MAD multiplier for the fano filter, by default 2.0.
- latent_space_key
str|None Key in
adata.obsmfor pre-computed latent-space coordinates. WhenNone(default), coordinates are computed internally.- K
int|None Number of KNN neighbors for the Louvain graph. Defaults to
min(round(sqrt(n_cells)), 30), matching R VISION (no lower floor – R’s own formula has none either).- uns_key
str Key under which the pool mapping is stored in
adata.uns, by default"micro_clusters".- random_state
int Seed for the internal PCA, Louvain clustering, and K-means readjustment steps, by default 0. Passing the same value across runs makes the whole micro-clustering pipeline reproducible.
- Return type:
Pools
- Returns:
dict mapping str → list[str]
pools["microcluster_<i>"]is the list ofobs_namesbelonging to that micro-cluster.
- VisionToolsAccessor.cluster_cells_tree(adata=None, *, newick, target=10, obs_key='VISION_Clusters_Tree')[source]#
Cluster cells by their position in a phylogenetic tree.
Forwards to
cluster_cells_tree().adatadefaults to the AnnData held by the analysis object.Mirrors R VISION’s tree-based clustering path in
clusterCells()(methods-Vision.R), which callsmaxSizeCladewiseTreeCluster(Microclusters.R) when a tree is available.The algorithm greedily splits the largest sub-clade until
√n_cellspartitions exist, then merges small partitions back down to target using tree-distance (trivial_dist) as the merge criterion. Results are stored as a categorical column inadata.obs[obs_key].- Parameters:
- adata AnnData | None
AnnData whose
obs_namesmust match leaf labels in newick.- newick
str Newick-format tree string (or the value of
adata.uns["vision_tree"]).- target
int Desired number of clusters. Default 10, matching R VISION’s default.
- obs_key
str Column name written to
adata.obs. Default"VISION_Clusters_Tree".
- Return type:
- Returns:
None Modifies adata in-place, adding a categorical
adata.obs[obs_key]column.
- VisionToolsAccessor.compute_knn_weights(adata=None, *, obsm_key='X_pca', K=None, obsp_key='weights', exact=False)[source]#
Compute VISION exponential KNN weights and store in
adata.obsp.Forwards to
compute_knn_weights_anndata().adatadefaults to the AnnData held by the analysis object.Reads the latent space from
adata.obsm[obsm_key]and writes the resulting(n_cells, n_cells)sparse weight matrix toadata.obsp[obsp_key]. This replaces the L1-normalised scanpy connectivities previously used by visionpy as a proxy for VISION weights.- Parameters:
- adata AnnData | None
Annotated data matrix. Must have
obsm_keyinadata.obsm(e.g. produced bycompute_latent_space()).- obsm_key
str Key in
adata.obsmfor the latent-space coordinates, by default"X_pca".- K
int|None Number of neighbors. Defaults to
round(sqrt(n_cells)).- obsp_key
str Key under which to store the weight matrix in
adata.obsp, by default"weights".- exact
bool If
True, use sklearn’s exact neighbor search instead ofpynndescent. Seefind_knn().
- Return type:
AnnData
- Returns:
AnnData The input adata modified in-place with
adata.obsp[obsp_key]populated.- Raises:
KeyError – If obsm_key is not present in
adata.obsm.
- VisionToolsAccessor.compute_plasticity_scores(adata=None, *, newick)[source]#
Compute per-cell Fitch-Hartigan parsimony plasticity scores.
Forwards to
compute_plasticity_scores().adatadefaults to the AnnData held by the analysis object.For every categorical variable in
adata.obs, a{var}_plasticitycolumn is added toadata.obs. The score for cell c is the average normalised Fitch-Hartigan parsimony across all internal nodes on the path from the tree root to c.High plasticity: the metadata label switches often along the lineage path → the trait is labile / plastic.
Low plasticity: the label is conserved along the lineage path.
Mirrors R VISION’s
computePlasticityScores().
- VisionToolsAccessor.generate_projections(adata=None, *, projection_methods=('tSNE30', 'tSNE10', 'UMAP', 'ISOMap', 'ICA', 'RBFPCA'), obsm_key='X_pca', K=None, projection_genes=None)[source]#
Generate 2D visualisation projections and store in
adata.obsm.Forwards to
generate_projections().adatadefaults to the AnnData held by the analysis object.Mirrors R VISION’s
generateProjectionsInner. Dispatches each method to the appropriate input:"ICA"— filtered log-transformed expression (cells × genes), not the latent space, to match R VISION’s behaviour."UMAP"— scanpy neighbour graph built onadata.obsm[obsm_key]."tSNE30","tSNE10","ISOMap","RBFPCA"—adata.obsm[obsm_key].
Results are stored in
adata.obsm[f"X_{{method}}"](e.g."X_tSNE30","X_UMAP","X_RBFPCA").- Parameters:
- adata AnnData | None
Annotated data matrix. Must have
obsm_keyinadata.obsm(produced bycompute_latent_space()).- projection_methods Sequence[str]
Ordered list of projection names. Choose from
"tSNE30","tSNE10","UMAP","ISOMap","ICA","RBFPCA". Default: all six methods.- obsm_key
str Key in
adata.obsmfor the latent-space coordinates used by UMAP, tSNE, and ISOMap, by default"X_pca".- K
int|None Number of neighbours for UMAP and ISOMap. Defaults to
round(sqrt(n_cells)).- projection_genes Sequence[str] | None
Subset of genes to use for the ICA projection. When
None, all genes inadata.var_namesare used.
- Return type:
dict[str, np.ndarray]
- Returns:
dict mapping str → ndarray of shape (n_cells, 2) Same mapping as the
adata.obsmentries written by this function.- Raises:
KeyError – If obsm_key is not present in
adata.obsm.ValueError – If an unrecognised method name is requested.
- VisionToolsAccessor.pool_matrix(adata=None, *, pools=None, layer_key=None, uns_key='micro_clusters', result_uns_key='pool_expression')[source]#
Pool
adata.X(or a layer) into per-micro-cluster mean expression.Forwards to
pool_matrix_anndata().adatadefaults to the AnnData held by the analysis object.Convenience wrapper around
pool_matrix()that reads pools fromadata.unswhen pools is not provided explicitly.- Parameters:
- Return type:
np.ndarray
- Returns:
ndarray of shape (n_pools, n_genes)
- VisionToolsAccessor.pool_metadata(adata=None, *, pools=None, uns_key='micro_clusters', result_uns_key='pool_metadata')[source]#
Pool
adata.obsinto per-micro-cluster metadata.Forwards to
pool_metadata_anndata().adatadefaults to the AnnData held by the analysis object.Convenience wrapper around
pool_metadata().
- VisionToolsAccessor.rank_genes_groups(adata=None, **kwargs)[source]#
Rank genes for characterizing groups.
Forwards to
rank_genes_groups()(imported lazily because it depends on scanpy).adatadefaults to the AnnData held by the analysis object.- Parameters:
- adata
AnnData|None AnnData to use. Defaults to the analysis object’s AnnData.
- **kwargs
Keyword arguments forwarded to
rank_genes_groups()(e.g.groupby,method,reference,n_genes).
- adata