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_SPARKX_R

Run SPARK-X with provided R script.

compute_pattern_mean

Compute the mean expression of each gene module.

hierarchy_clustering

Run hierarchical clustering with sklearn's AgglomerativeClustering on the residual matrix.

kmeans_clustering

Run k-means clustering with sklearn's KMeans on the residual matrix.

load_gene_modules

Load the gene modules of SPARK-X.

load_result

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.

Parameters:
  • adata_path (str) – Path to the AnnData object.

  • layer (str, default: None) – Layer of the AnnData object to use.

  • out_path (str, default: None) – Path to the output directory.

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:

anndata.AnnData

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:
  • n_patterns (int) – Number of clusters.

  • kmeans_kwargs (dict) – Keyword arguments for KMeans.

Returns:

labels – Cluster labels.

Return type:

numpy.ndarray (n_cells,)

load_gene_modules(pattern_prefix='SP')[source]

Load the gene modules of SPARK-X.

Parameters:

pattern_prefix (str, default: “SP”) – Prefix of the gene modules.

load_result()[source]

Load the result of SPARK-X.