2 Environment Management System

2.1 Install conda

Conda is a package manager obtained via Miniconda or Anaconda.

2.2 Install mamba

Mamba is a CLI tool to manage conda environments

  • Mamba can be obtained via Mambaforge.
  • For a complete installation guide, click here.
  • For documentation, click here.

2.2.1 Demo installing Miniconda3 for Mac OS

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

2.2.2 Demo installing Mambaforge for Mac OS

curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-MacOSX-x86_64.sh -o Mambaforge-MacOSX-x86_64.sh
bash Mambaforge-MacOSX-x86_64.sh

2.3 Setting up common channels

We will be using lots of bioinformatics and analysis tools.

  • Note that most bioinformatics tools are via the bioconda channel.
  • Most analysis tools are installed via the conda-forge channel.
  • Some metagenomics analysis tools described in this guide are installed via the biobakery channel.
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge
conda config --add channels biobakery
conda config --add channels qiime2
conda config --add channels "qiime2/label/r2023.2"
conda config --set auto_activate_base False

2.4 Creating a conda environment

2.4.1 Using conda

conda activate base
conda create --name imap
conda create --name imap python==10
conda create --name imap python==10 pandas numpy seaborn

Note: Each command line creates the environment imap in the base environment, so choose a line that suits you best.

2.4.2 Using mamba

mamba create -c bioconda --name imap
mamba create --name imap python==10
mamba create --name imap python==10 pandas numpy seaborn

2.5 Activating and deactivating the environment

conda activate imap

conda deactivate imap
  • After setting up the channels and creating an environment, we can install more software.
  • For installation, we will use Mamba package manager instead of Conda package manager because it is much faster.

2.6 Updating conda

conda update conda

mamba update conda

2.7 Checking the conda version

conda -V

mamba -V

2.8 Reproducing existing environment

Requires an environment spec file or a yml file

2.8.1 Creating an env spec file

conda list --explicit > env_spec_file.txt

2.8.2 Creating a new environment from a spec file

conda create --name new_env --file env_spec_file.txt

2.8.3 Updating existing environment

To update the packages in the existing environment e.g. named my_environment, you can run:

conda env update -n my_environment -f environment.yml

2.8.4 Installing packages from a spec file

conda install --name existing_env --file env_spec_file.txt

2.8.5 Creating new env from a YAML file

  • First, create the YAML or YML file:
    • environment.yml
    • environment.yaml
    • Here, we save the environment.yml file in the workflow/envs folder, and it is configured to contain the following:
name: imap
channels:
  - conda-forge
  - bioconda
  - defaults
  - r
dependencies:
  - snakemake =7.19.1
  - snakemake-minimal =7.19.1
  - snakemake-wrapper-utils =0.5.0
  - snakedeploy =0.8.6
  - python =3.8.0
  - r-base =4.1.3
  - r-tidyverse =1.3.2 
  - r-bookdown =0.32
  - r-htmltools =0.5.4 
  - r-htmlwidgets =1.6.1
  - r-leaflet =2.1.1
  - r-leaflet.providers =1.9.0 
  - r-rmarkdown =2.20
  - r-schtools =0.4.0
  - graphviz =6.0.1
  - qiime2 =2023.2.0
  - mothur =1.48.0
  - vsearch =2.22.1
  - q2-vsearch =2023.2.0
conda activate base
mamba env create --name imap --file environment.yaml

2.9 Checking available environments

If everything goes smoothly, you should see the newly created environment. It will be ready to be activated. Great!

conda env list

conda info --envs

mamba env list

mamba info --envs
conda activate imap

2.10 Removing an environment

Must deactivate the environment before removing it.

conda env list
conda deactivate

conda env remove --name imap

conda remove --name imap --all

conda env list

2.11 Miscellaneous queries with repoquery

2.11.1 Search all package version

 mamba repoquery search snakemake --channel bioconda 

 mamba repoquery search python --channel conda-forge 

2.11.2 List package dependencies

mamba repoquery depends snakemake --channel bioconda

mamba repoquery depends python --channel conda-forge

2.11.3 List which packages depend on

mamba repoquery whoneeds snakemake --channel bioconda

mamba repoquery whoneeds python --channel conda-forge