General utils

Calculate max number of modules with leiden clustering

utils.get_max_modules()

Lightning module task to train Pyro scvi-tools modules.

Parameters:

adata – AnnData object containing single-cell RNA sequencing data.

Returns:

The maximal number of modules determined through Leiden clustering.

Return type:

Int

Robust optimization of cell2fate model

utils.robust_optimization(save_dir, max_epochs=[200, 400], lr=[0.01, 0.01], use_gpu=True)

Perform robust optimization of the model.

Parameters:
  • mod – Model to optimize.

  • save_dir – The directory to save the optimized model.

  • max_epochs – List of maximum epochs for the first and second optimization runs. Default is [200, 400].

  • lr – List of learning rates for the first and second optimization runs. Default is [0.01, 0.01].

Returns:

The optimized model.

Return type:

PyroBaseModuleClass

Other methods for cell2fate model definition

utils.G_a(sd)

Converts mean and standard deviation for a Gamma distribution into the shape parameter.

Parameters:
  • mu – The mean of the Gamma distribution.

  • sd – The standard deviation of the Gamma distribution.

Returns:

The shape parameter of the Gamma distribution.

Return type:

Float

utils.G_b(sd)

Converts mean and standard deviation for a Gamma distribution into the scale parameter.

Parameters:
  • mu – The mean of the Gamma distribution.

  • sd – The standard deviation of the Gamma distribution.

Returns:

The scale parameter of the Gamma distribution.

Return type:

Float

utils.mu_alpha(alpha_old, tau, lam)

Calculates transcription rate as a function of new target transcription rate, old transcription rate at changepoint, time since changepoint, and rate of exponential change process.

Parameters:
  • alpha_new – The new target transcription rate.

  • alpha_old – The old transcription rate at the changepoint.

  • tau – Time since the changepoint.

  • lam – Rate of the exponential change process.

Returns:

The calculated transcription rate.

Return type:

Float

utils.mu_mRNA_continuousAlpha(beta, gamma, tau, u0, s0, delta_alpha, lam)

Calculates the expected value of spliced and unspliced counts as a function of rates, latent time, initial states, difference to transcription rate in the previous state, and rate of exponential change process between states.

Parameters:
  • alpha – Transcription rate.

  • beta – Splicing rate.

  • gamma – Degradation rate.

  • tau – Latent time.

  • u0 – Initial unspliced count.

  • s0 – Initial spliced count.

  • delta_alpha – Difference to transcription rate in the previous state.

  • lam – Rate of exponential change process between states.

Returns:

A tensor containing the expected value of unspliced and spliced counts.

Return type:

Torch.Tensor

utils.mu_mRNA_continousAlpha_globalTime_twoStates(alpha_OFF, beta, gamma, lam_gi, T_c, T_gON, T_gOFF, Zeros)

Calculates the expected value of spliced and unspliced counts as a function of rates, global latent time, initial states, and global switch times between two states.

Parameters:
  • alpha_ON – Transcription rate when the gene is turned ON.

  • alpha_OFF – Transcription rate when the gene is turned OFF.

  • beta – Splicing rate.

  • gamma – Degradation rate.

  • lam_gi – Parameters for the rate of exponential change process between states.

  • T_c – Global latent time.

  • T_gON – Global switch time when the gene is turned ON.

  • T_gOFF – Global switch time when the gene is turned OFF.

  • Zeros – Tensor with zeros used for initialization.

Returns:

The expected value of unspliced and spliced counts.

Return type:

Torch.Tensor