Linux for Bioinformatics

Lesson 12 of 14 · 11 min

Installing Bioinformatics Tools with Conda

Bioinformatics tools like samtools and bwa are separate programs written by different labs, and each one needs its own set of supporting libraries to run. Installing them by hand often breaks, because two tools may demand different versions of the same library. Conda is a tool that installs these programs for you and keeps their libraries from colliding.

What Conda Does

Conda is both a package manager and an environment manager. A package manager is a program that downloads software along with everything that software depends on, then installs it all with one command. An environment is a private, isolated folder of installed tools, so the programs inside one environment cannot disturb the programs in another.

Installing Miniconda

bash
# Miniconda is the small installer that gives you the conda command.
# Download the installer for 64-bit Linux with wget (a file downloader).
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

# Run the installer with bash, then answer 'yes' at each prompt.
bash Miniconda3-latest-Linux-x86_64.sh

# Close and reopen your terminal, then check that conda is working.
conda --version
conda 24.11.0

Channels and Environments

A channel is an online repository that conda downloads packages from. Bioinformatics tools live on the bioconda channel, and the shared libraries they rely on come from the conda-forge channel. Keeping one environment per project makes each analysis reproducible, because the tool versions in that environment stay fixed and cannot be broken by unrelated work in other projects.

bash
# Register the channels conda should search. Each --add puts the new
# channel at the top, so conda-forge ends up highest priority.
conda config --add channels bioconda
conda config --add channels conda-forge

# 'strict' priority tells conda to prefer higher channels firmly,
# which avoids mixing mismatched libraries from different channels.
conda config --set channel_priority strict
bash
# conda create makes a new environment; -n gives it the name 'rnaseq'.
conda create -n rnaseq

# conda activate switches into it; your prompt now begins with (rnaseq).
conda activate rnaseq

# -c bioconda installs these two real tools from the bioconda channel.
conda install -c bioconda samtools bwa

# Confirm samtools is installed inside the environment.
samtools --version

# conda deactivate leaves the environment and returns to the base shell.
conda deactivate
samtools 1.21
Using htslib 1.21
Copyright (C) 2024 Genome Research Ltd.

Try it yourself: Create a second environment with conda create -n variants, activate it, and run conda install -c bioconda bcftools to install a different tool. Now switch back and forth with conda activate rnaseq and conda activate variants, and notice that samtools works only inside rnaseq while bcftools works only inside variants. That separation is environment isolation in action.