Using Conda Environments
Conda Set Up
Anaconda has “channels” that are community maintained packages. You will need to add these “channels” to your setup so you Anaconda knows where to look for the packages you are trying to install.
- Bioinformatics packages
- Depends on conda-forge dependencies
- Common dependencies (gcc, g++, etc)
- Languages (python)
- Data science type packages (numpy, scipy, machine learning packages)
conda config --add channels bioconda
conda config --add channels conda-forge
If you don’t add channels then you can also pass the -c
argument whenever installing, but who wants to remember that? As an example it would look like this.
conda create -c conda-forge -c bioconda -n smake snakemake
Creating Conda Environment
Once we have Anaconda installed we can create an environment to install Snakemake into. You can name the environment whatever you want, but here I used the name smake. If you are going to install different versions of the software its probably best to add a the version to the name.
You can do this in one line:
conda create --name smake snakemake
Or two:
conda create --name smake
conda install --name smake snakemake
Or you can activate the environment and install inside it:
conda create --name smake
source activate smake
conda install snakemake
Version Control
If you want a particular version you can search to see what is available:
conda search snakemake
Then install that version:
conda create --name smake snakemake==5.32.0
Activating the Environment
When you want to run snakemake you can activate your environment with:
source activate smake
When you are done using the environment exit the environment with:
conda deactivate
If you forgot what your named your environment(s).
conda env list
If you messed up just delete and start over.
conda remove --name smake --all
Or
conda env remove --name smake
Changing the path to your environments
You can change where conda looks for your environments running the following line.
conda config --add envs_dirs /$PATH/bin/anaconda3/envs/
Exporting Your Environment
Now that you have made your own custom environement you can export the details to a .yml file that can be used to install the exact same dependencies into an environment on a different computer.
First export the details of the packages and their versions.
conda env export > environment.yml
Then on a new computer or instance recreate it.
conda env create -f environment.yml
Cheat Sheet
There is a handy Cheat Sheet for conda commands.
Mamba
If anyone has installed anything with conda they will come to realize the pain of the phrase resolving environment
. More recently, there has been a reimplementation of the conda package manager in C++ called Mamba. This was suppose to help speed up the process as the conda solver is a “bit slow” and sometimes has issues with selecting the latest package releases.
You can install mamba with conda into the base environment! :smiley: :tada:
conda install mamba -n base -c conda-forge
You can then install snakemake like this:
mamba create --name smake snakemake