User API#

Import scviva-tools as:

import scviva

Models#

model.SCVIVA

scVIVA: variational auto-encoder with niche decoders for ST:cite:p:Levy25.

model.DestVI

Multi-resolution deconvolution of Spatial Transcriptomics data (DestVI) [Lopez et al., 2022].

model.ResolVI

ResolVI addresses noise and bias in single-cell resolved spatial transcriptomics data.

model.GIMVI

Joint VAE for imputing missing genes in spatial data [Lopez et al., 2019].

External models#

external.DIAGVI

Diagonal Multi-Modal Integration Variational Inference (DIAGVI) model.

external.RNAStereoscope

Reimplementation of Stereoscope for the scRNA-seq component [Andersson et al., 2020].

external.SpatialStereoscope

Reimplementation of Stereoscope for the spatial component [Andersson et al., 2020].

external.Tangram

Torch reimplementation of Tangram [Biancalani et al., 2021].

Tools#

tl.HarremanAnalysis

Downstream spatial metabolic cell-cell communication analysis.

tl.VisionAnalysis

Unsupervised transcriptome analysis and gene-signature scoring.

Analysis accessors#

HarremanAnalysis and VisionAnalysis group lower-level functions under accessors (ha.hs, ha.vs, ha.tl, ha.pl and va.tl). Each accessor method takes the same arguments as the function it forwards to, with adata defaulting to the analysis object’s AnnData.

harreman.HarremanHotspotAccessor

Hotspot analysis methods accessible as ha.hs.<method>.

harreman.HarremanVisionAccessor

VISION signature analysis methods accessible as ha.vs.<method>.

harreman.HarremanToolsAccessor

Tool methods accessible as ha.tl.<method>.

harreman.HarremanPlottingAccessor

Plotting methods accessible as ha.pl.<method>.

vision.VisionToolsAccessor

Lower-level VISION tool functions accessible as va.tl.<method>.

Harreman functions#

Hotspot (hs)

hotspot.compute_local_autocorrelation

Compute gene-level spatial autocorrelation using spatial weights and centered expression.

hotspot.compute_local_correlation

Computes pairwise local correlation between selected genes using a spatial weight matrix.

hotspot.create_modules

Perform hierarchical clustering on gene-gene local correlation Z-scores to assign gene modules.

hotspot.calculate_module_scores

Calculate module scores for gene modules across cells.

hotspot.calculate_super_module_scores

Calculate super-module scores for gene super-modules across cells.

hotspot.compute_top_scoring_modules

Identify the top-scoring module (or super-module) for each cell.

hotspot.load_metabolic_genes

Load the list of metabolic genes for a given species.

vision.integrate_vision_hotspot_results

Integrate VISION signature scoring with Hotspot module assignments.

Cell-cell communication tools (tl)

tools.compute_knn_graph

Computes the spatial proximity graph.

tools.apply_gene_filtering

Applies multi-step gene filtering to an AnnData object.

tools.compute_gene_pairs

Identify biologically plausible gene pairs.

tools.compute_cell_communication

Compute spatially informed cell-type-agnostic CCC scores.

tools.compute_ct_cell_communication

Compute cell type-aware cell-cell communication scores.

tools.compute_interacting_cell_scores

Compute interacting cell scores for gene pairs and metabolites.

tools.compute_ct_interacting_cell_scores

Compute cell-type-aware interacting cell scores for gene pairs and metabolites.

tools.select_significant_interactions

Select significant gene pairs or metabolite-mediated interactions.

tools.compute_interaction_module_correlation

Compute correlations between interacting cell scores and module scores.

Preprocessing (pp)

preprocessing.extract_interaction_db

Extract the metabolite transporter or ligand-receptor (LR) database from .csv files.

preprocessing.setup_deconv_adata

Set up deconvolution AnnData.

preprocessing.read_h5ad

Load an AnnData object from disk and restore Harreman-specific metadata.

preprocessing.write_h5ad

Save an AnnData object to disk with Harreman-compatible preprocessing.

Datasets (ds)

datasets.load_visium_mouse_colon_dataset

Load the mouse colon 10x Visium dataset (Parigi et al.).

datasets.load_slide_seq_human_lung_dataset

Load the human lung Slide-seq dataset (Liu et al.).

VISION functions#

Results and data containers

VisionResults

Typed view over the adata.uns/adata.obsm keys written by analysis steps.

NormData

Sparse expression matrix with pre-computed normalisation parameters.

Preprocessing

apply_filters

Apply one or more gene filters sequentially and return a boolean gene mask.

filter_genes_fano

Select overdispersed genes via within-bin Fano factor filtering.

filter_genes_novar

Remove genes with zero variance across cells.

filter_genes_threshold

Keep genes expressed (count > 0) in at least threshold cells.

get_normalized_copy

Log2-transform then normalise X using the chosen method.

get_normalized_copy_sparse

Log2-transform then build a sparse-preserving NormData object.

log2p1

Sparse-preserving log2(x + 1) transform.

Latent space and projections

compute_latent_space

Filter genes, log-transform, and compute PCA; store result in adata.obsm.

apply_pca

PCA via randomized truncated SVD with gene-mean centering.

apply_permutation_wpca

PCA with permutation significance test for automatic PC selection.

apply_ica

ICA 2D projection via sklearn FastICA.

apply_isomap

ISOMap 2D projection via sklearn.

apply_rbfpca

RBF-kernel PCA 2D projection.

apply_tsne

t-SNE 2D projection via sklearn.

apply_umap

UMAP 2D projection via scanpy.

generate_projections

Generate 2D visualisation projections and store in adata.obsm.

Neighbor graphs

find_knn

Find K nearest neighbors for every point in data.

compute_knn_weights

Build an exponential-kernel KNN weight matrix from a latent space.

compute_knn_weights_anndata

Compute VISION exponential KNN weights and store in adata.obsp.

compute_knn_weights_from_tree

Build exponential-kernel KNN weights from a phylogenetic tree.

compute_knn_weights_from_tree_anndata

Compute tree-based KNN weights and store in adata.obsp[obsp_key].

compute_knn_weights_from_tree_lca

Build LCA-based uniform KNN weights from a phylogenetic tree.

compute_knn_weights_from_tree_lca_anndata

Compute LCA-based tree KNN weights and store in adata.obsp[obsp_key].

Micro-clustering

apply_micro_clustering

Partition cells into micro-clusters (supercells) via Louvain + K-means.

pool_matrix

Average expression within each micro-cluster via sparse matrix multiply.

pool_matrix_anndata

Pool adata.X (or a layer) into per-micro-cluster mean expression.

pool_metadata

Build a pooled metadata table for micro-clusters.

pool_metadata_anndata

Pool adata.obs into per-micro-cluster metadata.

Signatures

load_signatures

Compute signature scores from .gmt/.txt files or dictionaries.

split_signed_signatures

Auto-split bidirectional signatures into _UP / _DOWN sub-signatures.

compute_signature_scores

Compute Geary's C spatial/graph autocorrelation for all signatures.

compute_signatures_anndata

Compute per-cell signature scores.

compute_obs_df_scores

Compute Geary's C (numerical) / Cramer's V (categorical) for obs metadata.

Phylogeny

cluster_cells_tree

Cluster cells by their position in a phylogenetic tree.

compute_plasticity_scores

Compute per-cell Fitch-Hartigan parsimony plasticity scores.

Differential expression

rank_genes_groups

Rank genes for characterizing groups.

Plotting#

pl.harreman.local_correlation_plot

Plot a hierarchical-clustered heatmap of pairwise correlation Z-scores.

pl.harreman.average_local_correlation_plot

Plot the average pairwise correlation Z-scores between modules.

pl.harreman.module_score_correlation_plot

Plot correlations between module scores across cells.

pl.harreman.plot_interacting_cell_scores

Plot spatial maps of interacting cell scores for selected gene pairs or metabolites.

pl.harreman.plot_ct_interacting_cell_scores

Plot cell-type–specific interacting cell scores across spatial coordinates.

pl.harreman.plot_interaction_module_correlation

Plot interaction-module correlation heatmap.

pl.vision.plot_vision_autocorrelation

Plot vision autocorrelation results.

pl.vision.plot_vision_de_results

Plot vision differential expression results.

pl.vision.plot_signature_for_selection

Plot signature scores on spatial coordinates for selection.

pl.vision.plot_selection_histplot

Plot histogram of signature scores for selection vs remainder.

pl.plot_cell_type_map

Plot spatial map of cell type proportion(s).

pl.scviva_de.plot_niche_de_decision_boundary

Plot the results of the niche differential expression analysis.

pl.scviva_de.plot_connectivity_distribution

Plot a histogram of the number of non-zero entries per row of a sparse matrix.

Settings#

settings

Config manager for scviva.