VIVS#
VIVS [Boyeau et al., 2024] (Variational Inference for Variable Selection; Python class VIVS) identifies which genes in a count matrix X are conditionally dependent on an external response Y — protein expression, niche composition, or any other obsm feature — using a conditional randomization test (CRT).
VIVS fits two components: a generative VAE over X (reusing scvi-tools’ standard VAE module, or an already-trained model passed via x_model — see “Compatible knockoff-sampler models” below), used only to sample conditional “knockoff” replacements of each gene; and an importance-score network predicting Y from X, whose per-cell negative log-likelihood is the CRT test statistic. For each gene (or, in the hierarchical variant, each cluster of correlated genes), the statistic is recomputed after substituting in a knockoff sample, yielding a calibrated, BH-corrected p-value for that gene’s/cluster’s conditional importance to Y.
The advantages of VIVS are:
Conditional (not marginal) dependence testing — controls for the rest of the transcriptome when assessing each gene’s relevance to
Y.Calibrated false-discovery-rate control via the CRT + Benjamini-Hochberg correction.
A hierarchical variant (
get_hier_importance) that tests at multiple resolutions of correlated gene clusters, improving power for co-regulated genes.Can reuse an already-trained model (e.g. a niche-aware
SCVIVAmodel) as the knockoff sampler — see the compatibility table below for which models qualify.
The limitations of VIVS include:
The knockoff sampler’s quality (how well the generative VAE models gene expression
p(X)) is necessary for the p-values returned by VIVS to be calibrated. A poorly fit VAE can inflate false-discovery rates.Runtime scales with the number of genes tested; filtering to a smaller gene set (
select_genes) is recommended above a few thousand genes.Ported from VIVS’s original JAX implementation; large-scale runtime is not guaranteed to match the original’s
vmap/jit-optimized performance (seeuse_vmaponget_importance/get_hier_importance).fastcluster(forget_gene_groupings/get_hier_importance) andplotnine(forplot_hier_importance) are optional dependencies.fastclusterships withpip install scvi-tools[optional];plotninehas no dedicated lightweight extra — install it directly (pip install plotnine) or viapip install scvi-tools[tutorials].
Preliminaries#
VIVS takes as input a raw-count gene expression matrix X and a response matrix Y (registered via y_obsm_key in setup_anndata()). Training proceeds in two sequential phases: first the generative VAE over X is fit to convergence (or supplied pretrained via x_model), then it is frozen and the importance-score network is fit to predict Y from X. This order is required for CRT validity — the knockoff sampler must not be contaminated by information about Y.
Compatible knockoff-sampler models#
VIVS(..., x_model=...) requires x_model.module to be an instance of scvi.module.VAE (or a subclass), because the knockoff sampler calls module.inference(x=x, batch_index=batch_index) expecting a dict with z/library, then module.generative(z=z, library=library, batch_index=batch_index) expecting a dict with a px distribution supporting .sample(). Most non-VAE scvi-tools modules diverge from this signature (extra required arguments, or a different output-dict shape), so they fail either the isinstance check up front or the first knockoff-sampling call. Verified directly against module source (src/scvi/module/, src/scvi/external/*/):
Model |
|
Works as |
Notes |
|---|---|---|---|
|
✅ Yes |
Reference case; |
|
|
✅ Yes |
Only overrides |
|
|
✅ Yes |
|
|
|
✅ Yes |
|
|
|
✅ Yes |
Same as |
|
|
⚠️ Blocked only by the |
Not a |
|
|
❌ No |
|
|
|
❌ No |
Pyro-based, no |
|
|
❌ No |
|
|
|
❌ No |
|
|
|
❌ No |
|
|
|
❌ No |
|
|
|
❌ No |
Pyro-based, no VAE-style |
Practical takeaway: today, the safest x_model choices are a plain SCVI, an SCVIVA model, or (with less real-world precedent) LinearSCVI/AUTOZI/SCANVI. Deconvolution (DestVI), Pyro-based (RESOLVI, AmortizedLDA), and paired/multimodal (TOTALVI, MULTIVI, PEAKVI, CondSCVI) models need either a model-specific adapter or a relaxed compatibility check before they can serve as VIVS’s knockoff sampler.