scanpex.tl package
Module contents
- scanpex.tl.curate_phase(adata, thresh=0)[source]
Manually curate the threshold for cell cycle phase assignment.
This function re-assigns phases (G1, S, G2/M) based on existing “S_score” and “G2M_score” using a user-defined threshold.
- Parameters:
adata (ad.AnnData) – Annotated data matrix with pre-assigned cell cycle scores (e.g., via scanpex.tl.score_genes_cell_cycle).
thresh (float, optional (default: 0)) – The threshold value for determination. Scores below this value are considered G1 phase.
- Returns:
adata.obs[“phase”] is overwritten with the new assignments.
- Return type:
None
- scanpex.tl.get_degs(data, cluster_name, pvals_adj=0.05, max_logfc=inf, min_logfc=-inf)[source]
- Parameters:
data (anndata.AnnData)
cluster_name (str)
pvals_adj (float)
max_logfc (float)
min_logfc (float)
- Return type:
ndarray
- scanpex.tl.prob_genes(adata, gene_list, **kwargs)[source]
Calculate gene signature scores and transform them to [0, 1] probability using the sigmoid-Z-score transformation. This is a wrapper of scanpy.tl.score_genes. It adds a {score_name}_prob column to adata.obs.
- Parameters:
adata (ad.AnnData) – Annotated data matrix.
gene_list (list) – The list of genes to be scored.
**kwargs – Additional arguments passed to scanpy.tl.score_genes. (e.g., score_name, ctrl_size, random_state)
- Returns:
Returns None if copy=False (default), otherwise returns a copy of adata. The result is stored in adata.obs[‘{score_name}_prob’].
- Return type:
Union[None, ad.AnnData]
- scanpex.tl.score_genes_cell_cycle(adata, s_genes, g2m_genes, **kwargs)[source]
Assign cell cycle phases based on “S_score” and “G2M_score”.
This is a wrapper of scanpex.tl.prob_genes and scanpy.tl.score_genes_cell_cycle. It calculates raw scores, probability scores (0-1), and assigns phases.
- Parameters:
adata (ad.AnnData) – Annotated data matrix.
s_genes (list) – The list of S-phase related genes to be scored.
g2m_genes (list) – The list of G2/M-phase related genes to be scored.
**kwargs – Additional arguments passed to scanpy.tl.score_genes and scanpy.tl.score_genes_cell_cycle.
- Returns:
The following columns are added to adata.obs: - “S_score”, “S_score_prob” - “G2M_score”, “G2M_score_prob” - “phase” (with “G2M” label prettified to “G2/M”)
- Return type:
None
- scanpex.tl.seacells(adata, seacell_size=50, n_SEACells=None, n_waypoint_eigs=10, min_iter=10, max_iter=50, seacell_key='SEACells')[source]
Compute SEACells (metacells) aggregation.
This function is a wrapper for the SEACells algorithm. It identifies archetypes (metacells) based on the PCA space (X_pca).
- Parameters:
adata (ad.AnnData) – Annotated data matrix. Must contain “X_pca” in obsm.
seacell_size (int, optional (default: 50)) – Approximate number of cells per SEACell (metacell). Used to calculate n_SEACells automatically: n_SEACells = n_obs / seacell_size. If provided, this takes precedence over n_SEACells argument.
n_SEACells (int, optional (default: None)) – The exact number of SEACells to identify. Ignored if seacell_size is provided.
n_waypoint_eigs (int, optional (default: 10)) – Number of eigenvalues to use for waypoint initialization.
min_iter (int, optional (default: 10)) – Minimum number of iterations for the model fitting.
max_iter (int, optional (default: 50)) – Maximum number of iterations for the model fitting.
seacell_key (str, optional (default: "SEACells")) – The key under which the hard assignments are stored in adata.obs.
- Returns:
The result is stored in adata.obs[seacell_key], containing the assigned SEACell ID for each single cell.
- Return type:
None
- Raises:
ImportError – If the SEACells library is not installed.
ValueError – If neither seacell_size nor n_SEACells is provided.