epigen/unsupervised_analysis

A general purpose Snakemake workflow and MrBiomics module to perform unsupervised analyses (dimensionality reduction & cluster analysis) and visualizations of high-dimensional data.

Overview

Topics: data-science high-dimensional-data snakemake workflow unsupervised-learning principal-component-analysis umap pca visualization clustering data-visualization dimensionality-reduction heatmap densmap cluster-analysis cluster-validation clustering-algorithm clustree leiden-algorithm

Latest release: v3.0.1, Last update: 2025-03-04

Linting: linting: failed, Formatting:formatting: failed

Deployment

Step 1: Install Snakemake and Snakedeploy

Snakemake and Snakedeploy are best installed via the Mamba package manager (a drop-in replacement for conda). If you have neither Conda nor Mamba, it is recommended to install Miniforge. More details regarding Mamba can be found here.

When using Mamba, run

mamba create -c conda-forge -c bioconda --name snakemake snakemake snakedeploy

to install both Snakemake and Snakedeploy in an isolated environment. For all following commands ensure that this environment is activated via

conda activate snakemake

Step 2: Deploy workflow

With Snakemake and Snakedeploy installed, the workflow can be deployed as follows. First, create an appropriate project working directory on your system and enter it:

mkdir -p path/to/project-workdir
cd path/to/project-workdir

In all following steps, we will assume that you are inside of that directory. Then run

snakedeploy deploy-workflow https://github.com/epigen/unsupervised_analysis . --tag v3.0.1

Snakedeploy will create two folders, workflow and config. The former contains the deployment of the chosen workflow as a Snakemake module, the latter contains configuration files which will be modified in the next step in order to configure the workflow to your needs.

Step 3: Configure workflow

To configure the workflow, adapt config/config.yml to your needs following the instructions below.

Step 4: Run workflow

The deployment method is controlled using the --software-deployment-method (short --sdm) argument.

To run the workflow with automatic deployment of all required software via conda/mamba, use

snakemake --cores all --sdm conda

Snakemake will automatically detect the main Snakefile in the workflow subfolder and execute the workflow module that has been defined by the deployment in step 2.

For further options such as cluster and cloud execution, see the docs.

Step 5: Generate report

After finalizing your data analysis, you can automatically generate an interactive visual HTML report for inspection of results together with parameters and code inside of the browser using

snakemake --report report.zip

Configuration

The following section is imported from the workflow’s config/README.md.

Configuration

You need one configuration file to configure the analyses and one annotation file describing the data to run the complete workflow. If in doubt read the comments in the config and/or try the default values. We provide a full example including data and configuration in test/ as a starting point.

  • project configuration (config/config.yaml): Different for every project and configures the analyses to be performed.
  • sample annotation (annotation): CSV file consisting of four mandatory columns.
    • name: A unique name for the dataset (tip: keep it short but descriptive).
    • data: Path to the tabular data as a comma-separated table (CSV).
    • metadata: Path to the metadata as a comma-separated table (CSV) with the first column being the index/identifier of each observation/sample and every other column metadata for the respective observation (either numeric or categorical, not mixed). No NaN or empty values allowed.
    • samples_by_features: Boolean indicator if the data matrix is observations/samples (rows) x features (columns): 0==no, 1==yes.

Set workflow-specific resources or command line arguments (CLI) in the workflow profile workflow/profiles/default.config.yaml, which supersedes global Snakemake profiles.

Linting and formatting

Linting results

Using workflow specific profile workflow/profiles/default for setting default command line arguments.
Lints for rule aggregate_clustering_results (line 43, /tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/clustering.smk):
    * Migrate long run directives into scripts or notebooks:
      Long run directives hamper workflow readability. Use the script or
      notebook directive instead. Note that the script or notebook directive
      does not involve boilerplate. Similar to run, you will have direct access
      to params, input, output, and wildcards.Only use the run directive for a
      handful of lines.
      Also see:
      https://snakemake.readthedocs.io/en/latest/snakefiles/rules.html#external-scripts
      https://snakemake.readthedocs.io/en/latest/snakefiles/rules.html#jupyter-notebook-integration

Lints for rule annot_export (line 39, /tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/envs_export.smk):
    * Specify a conda environment or container for each rule.:
      This way, the used software for each specific step is documented, and the
      workflow can be executed on any machine without prerequisites.
      Also see:
      https://snakemake.readthedocs.io/en/latest/snakefiles/deployment.html#integrated-package-management
      https://snakemake.readthedocs.io/en/latest/snakefiles/deployment.html#running-jobs-in-containers


... (truncated)

Formatting results

[DEBUG] 
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/envs_export.smk":  Formatted content is different from original
[DEBUG] 
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/clustering.smk":  Formatted content is different from original
[DEBUG] 
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/common.smk":  Formatted content is different from original
[DEBUG] 
[ERROR] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/Snakefile":  InvalidPython: Black error:

Cannot parse for target version Python 3.12: 2:0: EOF in multi-line statement

(Note reported line number may be incorrect, as snakefmt could not determine the true line number)


[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/Snakefile":  
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/dimred.smk":  Formatted content is different from original
[DEBUG] 
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/visualization.smk":  Formatted content is different from original
[DEBUG] 
[DEBUG] In file "/tmp/tmps7b_4ku2/epigen-unsupervised_analysis-a360814/workflow/rules/cluster_validation.smk":  Formatted content is different from original

... (truncated)