SIGnature.models.ssl#

class SIGnature.models.ssl.SSLWrapper(*args, **kwargs)[source]#

Bases: Module

A class to load and use self-supervised learning (SSL) models from Richter et al (DOI: https://doi.org/10.1038/s42256-024-00934-3) for embedding and attribution.

Parameters:
  • model_path (str)

  • model_filename (str)

  • n_layers (int)

  • use_gpu (bool)

calculate_attributions(X, 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 SSL model using a specified method.

Parameters:
  • X (torch.Tensor | numpy.ndarray | scipy.sparse.csr_matrix) – The input data matrix.

  • 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.

  • 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