scviva.tl.HarremanAnalysis#
- class scviva.tl.HarremanAnalysis(adata, model=None, layer_key=None)[source]#
Downstream spatial metabolic cell-cell communication analysis.
- Parameters:
- adata
AnnData Spatial AnnData. Must have neighbor coordinates in
obsm.- model
BaseModelClass|None Optional trained scvi spatial model (RESOLVI, SCVIVA, DestVI).
DestVI: calls
model.get_proportions()and attaches each cell-type proportion-weighted count matrix asadata.layers[cell_type].RESOLVI: calls
model.get_normalized_expression()and attaches asadata.layers[HARREMAN_DENOISED_LAYER].SCVIVA: calls
model.get_latent_representation()and attaches asadata.obsm[HARREMAN_LATENT_OBSM].
Model reference is dropped after extraction.
- layer_key
str|None Layer to use for counts.
Noneusesadata.X.
- adata
Notes
Lower-level functions are grouped under accessors that default to this object’s AnnData:
ha.hs– hotspot analysis, seeHarremanHotspotAccessor.ha.vs– VISION signatures, seeHarremanVisionAccessor.ha.tl– graph and interaction tools, seeHarremanToolsAccessor.ha.pl– plotting, seeHarremanPlottingAccessor.
Examples
Without model:
>>> ha = HarremanAnalysis(adata) >>> ha.setup(compute_neighbors_on_key="spatial", species="human") >>> ha.filter_genes() >>> ha.compute_gene_pairs() >>> ha.compute_cell_communication() >>> ha.select_significant_interactions() >>> results = ha.results
With DestVI model:
>>> ha = HarremanAnalysis(adata, model=destvi_model) >>> ha.setup(compute_neighbors_on_key="spatial", cell_type_key="cell_type") >>> ha.compute_gene_pairs() >>> ha.compute_cell_communication(mode="cell_type")
Attributes table
The working AnnData object. |
|
True if model-extracted cell-type proportion layers are present. |
|
True if setup() has been called. |
|
Typed view over the analysis results stored in |
Methods table
|
Compute ligand-receptor / metabolite CCC scores. |
|
Compute local correlations for gene pairs in the metabolite database. |
|
Compute per-cell interaction scores. |
|
Filter genes before gene pair computation. |
Filter to statistically significant interactions. |
|
|
Register adata with HarremanDB and build the spatial proximity graph. |
Attributes
- HarremanAnalysis.adata#
The working AnnData object.
- HarremanAnalysis.is_deconvolved#
True if model-extracted cell-type proportion layers are present.
- HarremanAnalysis.is_set_up#
True if setup() has been called.
- HarremanAnalysis.results#
Typed view over the analysis results stored in
adata.uns.
Methods
- HarremanAnalysis.compute_cell_communication(mode='standard', model=None, n_permutations=1000, seed=42, test='both', mean='algebraic', layer_key_p_test=None, layer_key_np_test=None, device=None, verbose=False)[source]#
Compute ligand-receptor / metabolite CCC scores.
Requires
compute_gene_pairs()to have been called.- Parameters:
- mode
Literal['standard','cell_type'] "standard"for cell-type-agnostic analysis or"cell_type"for cell-type-stratified analysis.- model
str|None Expression normalization model.
- n_permutations
int Number of permutations for the non-parametric test.
- seed
int Random seed for reproducibility.
- test
Literal['parametric','non-parametric','both'] Statistical test to run.
- mean
Literal['algebraic','geometric'] Averaging method for multi-gene interactions.
- layer_key_p_test
str|None Layer to use for the parametric test. Defaults to the layer set at construction time (
layer_key).- layer_key_np_test
str|None Layer to use for the non-parametric test. Defaults to the layer set at construction time (
layer_key). Pass a different value fromlayer_key_p_testto use separate layers (e.g. raw counts vs log-norm).- device
str|None PyTorch device string.
Noneuses the underlying default.- verbose
bool Print progress.
- mode
- Return type:
- HarremanAnalysis.compute_gene_pairs(cell_type_pairs=None, ct_specific=True, fix_ct=None, verbose=False)[source]#
Compute local correlations for gene pairs in the metabolite database.
Requires
setup()to have been called.
- HarremanAnalysis.compute_interacting_cell_scores(mode='standard', test='both', restrict_significance='both', n_permutations=1000, seed=42, device=None, verbose=False)[source]#
Compute per-cell interaction scores.
Requires
compute_cell_communication()to have been called.- Parameters:
- mode
Literal['standard','cell_type'] "standard"or"cell_type"matching the CCC mode used.- test
Literal['parametric','non-parametric','both'] Which test scores to compute.
- restrict_significance
Literal['gene pairs','metabolites','both'] Which significant interactions to use from CCC results.
- n_permutations
int Permutations for non-parametric test.
- seed
int Random seed.
- device
str|None PyTorch device string.
- verbose
bool Print progress.
- mode
- Return type:
- HarremanAnalysis.filter_genes(model='danb', feature_elimination=False, threshold=0.2, autocorrelation_filt=False, expression_filt=False, de_filt=False, device=None, verbose=False)[source]#
Filter genes before gene pair computation.
- Parameters:
- model
Literal['danb','bernoulli','normal','none'] Expression model for autocorrelation-based filtering.
- feature_elimination
bool Filter genes expressed in fewer than
thresholdfraction of cells.- threshold
float Minimum fraction of cells expressing a gene.
- autocorrelation_filt
bool Keep only genes with significant local autocorrelation.
- expression_filt
bool Keep only genes expressed in each cell type.
- de_filt
bool Keep only genes differentially expressed between cell types.
- device
str|None PyTorch device string.
Noneuses auto-selection.- verbose
bool Print progress.
- model
- Return type:
- HarremanAnalysis.select_significant_interactions(fdr_threshold=0.05, test='parametric', use_fdr=True, ct_aware=None)[source]#
Filter to statistically significant interactions.
Requires
compute_cell_communication()to have been called.- Parameters:
- Return type:
- HarremanAnalysis.setup(compute_neighbors_on_key, species='human', database='both', n_neighbors=30, neighborhood_radius=None, cell_type_key=None, sample_key=None, spot_diameter=10, extracellular_only=True, use_gpu=None)[source]#
Register adata with HarremanDB and build the spatial proximity graph.
- Parameters:
- compute_neighbors_on_key
str Key in
adata.obsmto use for KNN computation (e.g."spatial").- species
Literal['human','mouse'] "human"or"mouse".- database
Literal['transporter','LR','both'] Which database to load:
"transporter","LR", or"both".- n_neighbors
int|None Number of nearest neighbors. Either this or
neighborhood_radiusrequired.- neighborhood_radius
float|None Radius for neighborhood graph. Alternative to
n_neighbors.- cell_type_key
str|None Key in
adata.obsfor cell types. Required formode="cell_type".- sample_key
str|None Key in
adata.obsfor sample/batch.- spot_diameter
int Spot diameter of the spatial technology.
- extracellular_only
bool Restrict HarremanDB to extracellular metabolites only.
- use_gpu
bool|None None(default) tries GPU via rapids_singlecell/cuML and falls back to CPU.Falseforces CPU.Trueraises if GPU is unavailable.
- compute_neighbors_on_key
- Return type: