Tutorial: How to Install SamTools, HTSLib, and BCFTools on Ubuntu 18.04
gravatar for otwtgin2010
2.5 years ago by
otwtgin2010310 wrote:

Just thought I would contribute this since figuring it all out was a super confusing process consisting of a few hundred google searches. It's likely it was just me, but maybe there are a few other people like me who will benefit from being able to avoid the process. This was a clean Ubuntu 18.04 install. Probably most people do not have that luxury.

Install Updates and Required Packages

sudo apt-get update
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install libbz2-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libncurses5-dev 
sudo apt-get install libncursesw5-dev
sudo apt-get install liblzma-dev

Install HTSLIB

cd /usr/bin
wget https://github.com/samtools/htslib/releases/download/1.9/htslib-1.9.tar.bz2
tar -vxjf htslib-1.9.tar.bz2
cd htslib-1.9


cd ..
wget https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2
tar -vxjf samtools-1.9.tar.bz2
cd samtools-1.9

Install BCFTools

cd ..
wget https://github.com/samtools/bcftools/releases/download/1.9/bcftools-1.9.tar.bz2
tar -vxjf bcftools-1.9.tar.bz2
cd bcftools-1.9

Export To Path And Refresh

export PATH="$PATH:/usr/bin/bcftools-1.9"
export PATH="$PATH:/usr/bin/samtools-1.9"
export PATH="$PATH:/usr/bin/htslib-1.9"
source ~/.profile
ADD COMMENTlink written 2.5 years ago by otwtgin2010310

Thank you otwtgin2010 for the work. Others may benefit from it, if they want to compile these softwares from source. Another option would be to use the Anaconda package manager. With conda, things are as easy as conda install -c bioconda samtools, taking care of the dependencies internally.

ADD REPLYlink written 2.5 years ago by ATpoint44k

This is the best way to go about it, IMO. Neither apt-get nor brew allow creating environments.

ADD REPLYlink written 2.5 years ago by _r_am32k

Good direction to find an installer package for Samtools. As an FYI based on the original poster, here is the full instructions for Noobs:

Note that the installer for Conda is for the Python2.7, 64-bit version. Select the appropriate path for something else. The Conda installer takes care of other dependencies including Python itself. It could be even simpler if they registered an install package for Miniconda in APT :)

sudo apt-get update
wget https://repo.anaconda.com/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
rm Miniconda2-latest-Linux-x86_64.sh
source ~/.bashrc
conda install -c bioconda samtools bcftools
ADD REPLYlink modified 14 months ago by _r_am32k • written 14 months ago by Randy H0

+1 for sharing your experiences with other users. Keep on contributing!

As Ram said, in this case one should follow the instruction given by the authors of the program.

fin swimmer

ADD REPLYlink written 2.5 years ago by finswimmer14k

this was super helpful for my attempt to get HTSlib working

ADD REPLYlink written 22 months ago by MaxF80

That was an extremely helpful walk-through. I've been trying to install BCFtools following their guidelines, but failing miserably (the operation would stop due to not finding curl:curl.h directory). Now, it has worked just fine.

And sorry for the lay question - I am still taking slow steps in learning Unix - but what is the meaning of the last step, "export to path and refresh"? I tried looking on the export --help, but I am still quite not sure what it does.

Many thanks, @otwtgin2010 !

ADD REPLYlink written 18 months ago by dodausp140

It means that you have to put the folder where the executable is in into your .bashrc or .bash_profile like

export PATH=$PATH:/path/to/folder/with/executable

Still, it would be easier to use a package manager such as conda.

ADD REPLYlink modified 18 months ago • written 18 months ago by ATpoint44k

The reason why you got an error when building bcftools was that there is one missing dependency. Adding one more following then you will be fine:

apt-get install -y libcurl4-openssl-dev
ADD REPLYlink written 9 months ago by hsiaoyi050460
gravatar for _r_am
2.5 years ago by
Baylor College of Medicine, Houston, TX
_r_am32k wrote:


Wait, you're using apt-get to install prerequisites but not the actual software you need? Why is that? Pretty sure samtools is available on apt-get.

source ~/.profile might override your $PATH settings if there is a statement in the profile file that overwrites (not appends to) the $PATH variable. You're better off with, say:

mkdir ~/myBinaries/
cd ~/myBinaries/
find /usr/bin/bcftools-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
find /usr/bin/samtools-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
find /usr/bin/htslib-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
cd -
echo 'export PATH=$PATH:~/myBinaries' >>~/.profile
source ~/.profile

Or, use a package manager and not worry about adding stuff to $PATH :-)

ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by _r_am32k

Got it - thank-you for the clarification! i tried apt-get but it was installing old versions. And the old versions were super buggy and didn't work with a lot of my sample files.

ADD REPLYlink written 2.5 years ago by otwtgin2010310

I see. Also, this information is available directly on the htslib site: http://www.htslib.org/download/

Plus the post contains less information than what's available on that site. Why create this post?

ADD REPLYlink written 2.5 years ago by _r_am32k

Thanks. Yeah, for someone who knows as much as they should, that would no doubt be plenty. But i guess for those who knows as little as i do :) - the things like how you download the file, how you extract it (or even that you need to extract it), that you need "make" installed are not self-evident.

ADD REPLYlink written 2.5 years ago by otwtgin2010310

You're right, but that's a rabbit hole. We have to stick to some pre-requisites that we can assume people that come here know. Command line basics is one of them. How to download a file (not necessarily using the command line), un-archive it (tar options, computer science stuff), cd into directories, know sudo stuff, etc. People who do not know that should be working with bioinformaticians who do and learning in the process, not searching online.

ADD REPLYlink modified 2.5 years ago • written 2.5 years ago by _r_am32k

Thanks and true! i guess i have a tendency to create my roof before my foundation, and the assumption that most others are the same way is an invalid one. And i don't mean this to be my personal beef about documentation that is not sufficient enough to make up for my lack of basic knowledge. Just hoping it will help someone else.

ADD REPLYlink written 2.5 years ago by otwtgin2010310

Not every beginner has access to bioinformaticians who come from CS. And some of us who've spent decades in biology are still beginners in bioinformatics. I learned a lot from this thread - both the original post and the comments that followed. I can see the perspective of a basal level of required knowledge, but not every bioinformatics expert is a good teacher, and even if they are good teachers, they are busy people. People who invest time in online forums like biostars are sharing people and make the world of science a better place. Thanks to everyone who contributed to this thread.

ADD REPLYlink written 15 months ago by rdphair0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1657 users visited in the last hour