stLENS.stLENS

Module Contents

class stLENS.stLENS.stLENS(sparsity='auto', sparsity_step=0.001, sparsity_threshold=0.9, perturbed_n_scale=2, n_rand_matrix=20, threshold=np.cos(np.deg2rad(60)))[source]
sparsity = 'auto'[source]
sparsity_threshold = 0.9[source]
sparsity_step = 0.001[source]
n_rand_matrix = 20[source]
threshold = np.cos(np.deg2rad(60))[source]
filter_cells_and_genes(data, min_tp_c=0, min_tp_g=0, max_tp_c=np.inf, max_tp_g=np.inf, min_genes_per_cell=200, max_genes_per_cell=0, min_cells_per_gene=15, mito_percent=5.0, ribo_percent=0.0, inplace=True, use_raw=True)[source]

Filter cells and genes in the AnnData object using the scLENS approach.

Parameters:
  • data (anndata.AnnData) – Input AnnData object containing the data to be filtered.

  • min_tp_c (int, optional) – Minimum total counts per cell. Default is 0.

  • min_tp_g (int, optional) – Minimum total counts per gene. Default is 0.

  • max_tp_c (int, optional) – Maximum total counts per cell. Default is np.inf.

  • max_tp_g (int, optional) – Maximum total counts per gene. Default is np.inf.

  • min_genes_per_cell (int, optional) – Minimum number of genes per cell. Default is 200.

  • max_genes_per_cell (int, optional) – Maximum number of genes per cell. Default is 0.

  • min_cells_per_gene (int, optional) – Minimum number of cells expressing each gene. Default is 15.

  • mito_percent (float, optional) – Upper threshold for mitochondrial gene expression as a percentage of total cell expression. Default is 5.0.

  • ribo_percent (float, optional) – Upper threshold for ribosomal gene expression as a percentage of total cell expression. Default is 0.0.

  • inplace (bool, optional) – If True, modifies the input AnnData object directly. If False, returns a new AnnData object.

  • use_raw (bool, optional) – If True, uses the raw attribute of the AnnData object. Default is True.

Returns:

data_filtered – If inplace is True, returns None. If False, returns the filtered AnnData object.

Return type:

anndata.AnnData or None

pca(adata, inplace=True, device='gpu')[source]

Perform PCA on the given AnnData object.

Parameters:
  • adata (anndata.AnnData) – Input AnnData object containing the data to be transformed.

  • inplace (bool, optional) – If True, modifies the input AnnData object directly. If False, returns a new AnnData object.

  • device (str, optional) – Device to use for computations, either ‘cpu’ or ‘gpu’. Default is ‘gpu’.

Returns:

adata – If inplace is True, returns None. If False, returns the AnnData object with PCA results stored in obsm[‘X_pca_stlens’].

Return type:

anndata.AnnData or None

find_optimal_pc(data, inplace=True, plot_mp=False, tmp_directory=None, device='gpu')[source]

Find the optimal number of principal components.

Parameters:
  • data (pd.DataFrame or anndata.AnnData) – Input data, either a pandas DataFrame or an AnnData object.

  • inplace (bool, optional) – If True, modifies the input data directly. If False, returns a new AnnData object.

  • plot_mp (bool, optional) – If True, plots the results of the PCA and SRT steps.

  • tmp_directory (str, optional) – Temporary directory for storing intermediate results. If None, uses the system’s temporary directory.

  • device (str, optional) – Device to use for computations, either ‘cpu’ or ‘gpu’. Default is ‘gpu’.

Returns:

adata – If inplace is True, returns None. If False, returns the normalized AnnData object.

Return type:

anndata.AnnData or None

plot_robust_score(adata)[source]

Plot the robust scores and their stability.

Parameters:

adata (anndata.AnnData) – AnnData object containing the results of the stLENS analysis.

Return type:

scatter plot

clean_tempfiles()[source]
Clean up temporary files created during the analysis.
Return type:

None