thor.analy.SPARKX
- class thor.analy.SPARKX(rscript_path='R/run_SPARKX.R', **kwargs)[source]
Bases:
object
Class for running SPARK-X.
- Parameters:
rscript_path (
str
, default: “R/run_SPARKX.R”) – Path to the R script for running SPARKX.
Methods
Run SPARK-X with provided R script.
Compute the mean expression of each gene module.
Run hierarchical clustering with sklearn's AgglomerativeClustering on the residual matrix.
Run k-means clustering with sklearn's KMeans on the residual matrix.
Load the gene modules of SPARK-X.
Load the result of SPARK-X.
- RUN_SPARKX_R(adata_path=None, layer=None, out_path=None)[source]
Run SPARK-X with provided R script.
- static compute_pattern_mean(adata, data, pattern, obskey_prefix)[source]
Compute the mean expression of each gene module.
- Parameters:
adata (
anndata.AnnData
) – AnnData object.data (
pandas.DataFrame
(n_sig_genes x n_cells)) – Residual matrix of SPARK-X.pattern (
pandas.DataFrame
(n_sig_genes x 1), column is cluster, index is gene) –obskey_prefix (
str
) – Prefix of the observation key.
- Returns:
adata – AnnData object with the computed pattern mean.
- Return type:
- hierarchy_clustering(**hc_kwargs)[source]
Run hierarchical clustering with sklearn’s AgglomerativeClustering on the residual matrix.
- Parameters:
hc_kwargs (
dict
) – Keyword arguments for AgglomerativeClustering.- Returns:
labels – Cluster labels.
- Return type:
numpy.ndarray
(n_cells,)
- kmeans_clustering(n_patterns, **kmeans_kwargs)[source]
Run k-means clustering with sklearn’s KMeans on the residual matrix.
- Parameters:
- Returns:
labels – Cluster labels.
- Return type:
numpy.ndarray
(n_cells,)