Skip to content

Instantly share code, notes, and snippets.

@ckandoth
Last active March 22, 2024 06:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ckandoth/982ce140b4dd9d6bf72a780c05a549a3 to your computer and use it in GitHub Desktop.
Save ckandoth/982ce140b4dd9d6bf72a780c05a549a3 to your computer and use it in GitHub Desktop.
Install conda and use it to install nextflow and singularity

This guide will show you how to install conda and then use it to install nextflow and singularity for executing popular bioinformatics workflows. Unfortunately, singularity is not available on Windows or macOS. So, this guide will only target Linux environments. If you have to use Windows 10, then try WSL2. If you have to use macOS, then try a Virtual Machine.

Download the Miniconda3 installer for Linux environments:

curl -L https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh

Install into a folder named miniconda3 under your home directory, and delete the installer:

bash miniconda.sh -bup $HOME/miniconda3 && rm -f miniconda.sh

Add the following lines to your ~/.bashrc so that conda is available across sessions:

# Add conda to PATH if found
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
    . $HOME/miniconda3/etc/profile.d/conda.sh
fi

Logout and login to add conda to your $PATH, update it, and then configure it to use a faster solver:

conda update -n base -c defaults conda
conda install -n base conda-libmamba-solver
conda config --set solver libmamba

Create a conda environment with the necessary packages, and cleanup cached packages:

conda create -y -n nf -c conda-forge -c bioconda openjdk==11.0.20 singularity nextflow git
conda clean -y -a

Test nextflow and singularity by running the Sarek workflow on its included test data:

conda activate nf
nextflow run -ansi-log false -profile test,singularity -work-dir nf_work nf-core/sarek --tools freebayes --outdir test_results

Notice how the name of the workflow nf-core/sarek refers to the GitHub repo (github.com/nf-core/sarek) from where nextflow will download the workflow definition and configuration. You can specify a repo tag, branch, or even a commit ID to use with parameter -revision. Command-line parameters that start with one dash - are for nextflow itself, while parameters that start with two dashes -- are passed into the workflow. The test workflow above should finish in <5 minutes, but typical workflows will take longer, and you'd want to run the command in a screen or tmux session. You can also use the parameter -bg to run a workflow in the background. Monitor status of ongoing or completed workflows using nextflow log and clean up intermediate output files using nextflow clean. Read the documentation for each subcommand using parameter -help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment