scmagnify.MAGNI#

class scmagnify.MAGNI(data, modal='RNA', layer=None, time_key='palantir_pseudotime', gene_selected=None, basal_grn=None, use_rep='X_pca', func=<class 'scmagnify.models._modules.MSNGC'>, hidden=[50], lag=5, max_iter=1000, batch_size=32, lr=0.001, weight_decay=0.0, lmbd=3, gamma=0.02, alpha=0.5, seed=42, early_stopping=True, patience=20, device='cuda')#

Class implementing Multi-Scale Gene Regulation Inference (MAGNI).

This model integrates single-cell multi-omic data and pseudotemporal information through a nonlinear Granger causality model to infer multi-scale GRNs.

  • See :doc:`` on how to

    compute the

Parameters:
  • data (AnnData | MuData) – Single cell data object. Can be an anndata.AnnData, mudata.MuData, scmagnify.GRNMuData

  • modal (str (default: 'RNA')) – Modality key (e.g., ‘RNA’, ‘ATAC’) when using multi-modal data. mudata.MuData or scmagnify.GRNMuData must be provided.

  • layer (Optional[str] (default: None)) – Layer in layers. If None, defaults to X.

  • time_key (str (default: 'palantir_pseudotime')) – Key in obs that stores pseudotime values.

  • func (nn.Module, optional) – Neural network model to use, by default MSNGC.

  • chrom_constraint – Prior network matrix, by default None.

  • hidden (list[int] (default: [50])) – Number of hidden units per layer, by default [50].

  • lag (int (default: 5)) – Number of time lags, by default 5.

  • max_iter (int (default: 1000)) – Maximum number of iterations, by default 1000.

  • batch_size (int (default: 32)) – Batch size for training, by default 32.

  • lr (float (default: 0.001)) – Learning rate, by default 1e-3.

  • weight_decay (float (default: 0.0)) – Weight decay for optimizer, by default 0.0.

  • lmbd (float (default: 3)) – Regularization parameter, by default 3.

  • gamma (float (default: 0.02)) – Smoothness penalty parameter, by default 0.02.

  • alpha (float (default: 0.5)) – Sparsity-inducing penalty parameter, by default 0.5.

  • patience (int (default: 20)) – Patience for early stopping, by default 20.

  • seed (int (default: 42)) – Random seed for reproducibility.

  • device (str (default: 'cuda')) – Device to run the computation on. Can be a string like ‘cpu’, ‘cuda’, ‘cuda:0’, or an integer specifying the CUDA device index (e.g., 0). If a CUDA device is requested but is not available, it will automatically fall back to ‘cpu’.

  • gene_selected (list[str] | None)

  • basal_grn (NDArray | None)

  • use_rep (str)

  • early_stopping (bool)

Methods table#

estimate_lags(multiscale_network)

Estimate optimal lags.

load(filename)

Load a trained model's state dictionary from a file.

regulation_inference([cv_thres, filter, ...])

Estimate causal structure.

save(filename)

Save the trained model's state dictionary.

train()

Train the model.

Methods#

MAGNI.estimate_lags(multiscale_network)#

Estimate optimal lags.

Parameters:
  • GC_est – Causal matrix.

  • multiscale_network (ndarray[Any, dtype[_ScalarType_co]])

Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

Returns:

NDArray Normalized lags.

MAGNI.load(filename)#

Load a trained model’s state dictionary from a file.

You must initialize the MAGNI class with the same parameters as the saved model before calling this method.

Parameters:

filename (str) – Path to the file where the model state is saved.

MAGNI.regulation_inference(cv_thres=0.2, filter=['quantile', 0.9, True], acts_method='mlm', save_atten=True)#

Estimate causal structure.

Parameters:
  • signed – Whether to use signed coefficients, by default True.

  • Q – Number of quantiles, by default 20.

  • batch_size – Batch size for inference, by default 32.

  • cv_thres (float (default: 0.2)) – Coefficient of variation threshold, by default 0.2.

  • filter (list)

  • acts_method (str)

  • save_atten (bool)

Return type:

GRNMuData

Returns:

GRNMuData Gene regulatory network object.

MAGNI.save(filename)#

Save the trained model’s state dictionary.

Parameters:

filename (str) – Path to the file where the model state will be saved.

MAGNI.train()#

Train the model.

Return type:

Module

Returns:

nn.Module Trained neural network model.