SIGnature.models.scvi#
- class SIGnature.models.scvi.SCVIWrapper(*args, **kwargs)[source]#
Bases:
ModuleA class to load and use a pre-trained scVI (https://doi.org/10.1038/s41592-018-0229-2) model for embedding and attribution.
- Parameters:
model_path (str)
use_gpu (bool)
cat_value (int)
- calculate_attributions(adata, method='ig', batch_size=100, multiply_by_inputs=True, disable_tqdm=False, target_sum=1000.0, npz_path=None)[source]#
Calculates gene attributions for the scVI model using a specified method.
- Parameters:
adata (anndata.AnnData) – A preprocessed AnnData object (must be prepared with self.preprocess_adata).
method (str) – The attribution method to use. Options are “ig” (Integrated Gradients), “dl” (DeepLift), or “ixg” (Saliency).
batch_size (int) – The number of samples to process in each batch.
multiply_by_inputs (bool) – Whether to multiply attributions by input values. Note: for Integrated Gradients and DeepLift, this is passed to the Captum constructor. For Saliency, the multiplication is done manually after calculation.
disable_tqdm (bool) – Whether to disable the progress bar.
target_sum (float) – The desired sum for each row after normalization.
npz_path (str | None) – Path to save the resulting sparse attribution matrix.
- Returns:
A scipy.sparse.csr_matrix containing the calculated attributions.
- Return type:
csr_matrix
- preprocess_adata(adata, ensembl_gene_file=None, gene_overlap_threshold=500)[source]#
Preprocesses an AnnData object for use with the scVI model.
This method must be called before calculate_attributions().
- Parameters:
adata (anndata.AnnData)
ensembl_gene_file (str | None)
gene_overlap_threshold (int)
- Return type:
anndata.AnnData