MuVI: A multi-view latent variable model with domain-informed structured sparsity for integrating noisy feature sets.
Project description
MuVI
A multi-view latent variable model with domain-informed structured sparsity, that integrates noisy domain expertise in terms of feature sets.
Basic usage
The MuVI class is the main entry point for loading the data and performing inference:
import numpy as np
import pandas as pd
import anndata as ad
import mudata as md
import muvi
# Load processed input data (missing values are allowed)
rna_df = pd.read_csv(...) # shape: n_samples x n_rna_features
prot_df = pd.read_csv(...) # shape: n_samples x n_prot_features
# Load prior feature sets, e.g. gene sets
gene_sets = muvi.fs.from_gmt(...)
gene_sets_mask = gene_sets.to_mask(rna_df.columns) # binary mask
# Create a MuVI object by passing both input data and prior information
model = muvi.MuVI(
observations={"rna": rna_df, "prot": prot_df},
prior_masks={"rna": gene_sets_mask},
...,
device=device,
)
# Alternatively, create a MuVI model from AnnData (single-view)
rna_adata = ad.AnnData(rna_df, dtype=np.float32)
rna_adata.varm["gene_sets_mask"] = gene_sets_mask.T
model = muvi.tl.from_adata(
rna_adata,
prior_mask_key="gene_sets_mask",
...,
device=device,
)
# Alternatively, create a MuVI model from MuData (multi-view)
mdata = md.MuData({"rna": rna_adata, "prot": prot_adata})
model = muvi.tl.from_mudata(
mdata,
prior_mask_key="gene_sets_mask",
...,
device=device,
)
# Fit the model
model.fit(batch_size, n_epochs, ...)
# Continue with the downstream analysis (see below)
Saving & loading models
MuVI provides a versioned, pickle-free, lightweight serialization format:
# Save the model
model.save("path/to/dir")
# Load the model later
loaded_model = muvi.MuVI.load("path/to/dir")
The directory contains:
- metadata.json – model metadata (JSON)
- params.npz – variational guide parameters
- structure.npz – observations, priors, covariates, factor order & signs
- factor.h5ad / cov.h5ad – optional cached AnnData objects (if present)
This mechanism is fully reproducible, stable across MuVI versions, and does not rely on Python pickle.
Submodules
The package consists of three additional submodules for analysing the results post-training:
muvi.tlprovides tools for downstream analysis, e.g.,- compute
muvi.tl.variance_explainedacross all factors and views muvi.tl.testthe significance between the prior feature sets and the inferred factors- apply clustering on the latent space such as
muvi.tl.leiden muvi.tl.savethe model in order tomuvi.tl.loadit at a later point in time
- compute
muvi.plworks in tandem withmuvi.tlby providing visualization methods such asmuvi.pl.variance_explained(see above)- plotting the latent space via
muvi.pl.tsne,muvi.pl.scatterormuvi.pl.stripplot - investigating factors in terms of their inferred loadings with
muvi.pl.inspect_factor
muvi.fsserves the data structure and methods for loading, processing and storing the prior information from feature sets
Tutorials
Check out our basic tutorial to get familiar with MuVI, or jump straight to a single-cell multiome analysis!
R users can readily export a trained MuVI model into R with a single line of code and resume the analysis with the MOFA2 package.
muvi.ext.save_as_hdf5(model, "muvi.hdf5", save_metadata=True)
See this vignette for more details!
Installation
We suggest using conda to manage your environments, and pip to install muvi as a python package. Follow these steps to get muvi up and running!
- Create a python environment in
conda:
conda create -n muvi python=3.12
- Activate freshly created environment:
source activate muvi
- Install
muviwithpip:
python3 -m pip install muvi
- Alternatively, install the latest version with
pip:
python3 -m pip install git+https://github.com/MLO-lab/MuVI.git
Make sure to install a GPU version of PyTorch to significantly speed up the inference.
Citation
If you use MuVI in your work, please use this BibTeX entry:
Encoding Domain Knowledge in Multi-view Latent Variable Models: A Bayesian Approach with Structured Sparsity
Arber Qoku and Florian Buettner
International Conference on Artificial Intelligence and Statistics (AISTATS) 2023
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file muvi-0.2.2.tar.gz.
File metadata
- Download URL: muvi-0.2.2.tar.gz
- Upload date:
- Size: 67.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-60-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6040e4698d76ccd3b49d3f77d1f3f8094aca313a5b3655d223436a956f0b71e4
|
|
| MD5 |
008199d750ea1ddf6684f02135db8856
|
|
| BLAKE2b-256 |
2fde9a61ea2d6d74655a854215f1c73e6ba7d74bd70529560f899f5e56c15804
|
File details
Details for the file muvi-0.2.2-py3-none-any.whl.
File metadata
- Download URL: muvi-0.2.2-py3-none-any.whl
- Upload date:
- Size: 71.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-60-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d3fd9f240430f03bfab88a066ed5a4fe234c141a467a2d4f5bceec33ad5e480
|
|
| MD5 |
c20563b47447bf68f4785f1f8a96bbf9
|
|
| BLAKE2b-256 |
d9fb7f4e4cdff625302eceded4f8168afbb05fab2795380b6c478f1d126e705c
|