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 as adata.layers[cell_type].

  • RESOLVI: calls model.get_normalized_expression() and attaches as adata.layers[HARREMAN_DENOISED_LAYER].

  • SCVIVA: calls model.get_latent_representation() and attaches as adata.obsm[HARREMAN_LATENT_OBSM].

Model reference is dropped after extraction.

layer_key str | None

Layer to use for counts. None uses adata.X.

Notes

Lower-level functions are grouped under accessors that default to this object’s AnnData:

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

adata

The working AnnData object.

is_deconvolved

True if model-extracted cell-type proportion layers are present.

is_set_up

True if setup() has been called.

results

Typed view over the analysis results stored in adata.uns.

Methods table

compute_cell_communication([mode, model, ...])

Compute ligand-receptor / metabolite CCC scores.

compute_gene_pairs([cell_type_pairs, ...])

Compute local correlations for gene pairs in the metabolite database.

compute_interacting_cell_scores([mode, ...])

Compute per-cell interaction scores.

filter_genes([model, feature_elimination, ...])

Filter genes before gene pair computation.

select_significant_interactions([...])

Filter to statistically significant interactions.

setup(compute_neighbors_on_key[, species, ...])

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 from layer_key_p_test to use separate layers (e.g. raw counts vs log-norm).

device str | None

PyTorch device string. None uses the underlying default.

verbose bool

Print progress.

Return type:

None

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.

Parameters:
cell_type_pairs list | None

List of (ct_a, ct_b) tuples. If None, uses all pairs.

ct_specific bool

Restrict gene pairs to cell-type-relevant combinations.

fix_ct str | None

Fix one cell type across all pairs.

verbose bool

Print progress messages.

Return type:

None

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.

Return type:

None

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 threshold fraction 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. None uses auto-selection.

verbose bool

Print progress.

Return type:

None

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:
fdr_threshold float

Significance cutoff.

test Literal['parametric', 'non-parametric']

Which test results to filter on.

use_fdr bool

Use FDR or raw p-values.

ct_aware bool | None

Whether to filter cell-type-aware results. Defaults to True when a cell type key was registered.

Return type:

None

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.obsm to 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_radius required.

neighborhood_radius float | None

Radius for neighborhood graph. Alternative to n_neighbors.

cell_type_key str | None

Key in adata.obs for cell types. Required for mode="cell_type".

sample_key str | None

Key in adata.obs for 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. False forces CPU. True raises if GPU is unavailable.

Return type:

None