Tutorial:How to Install SamTools, HTSLib, and BCFTools on Ubuntu 18.04
2
59
Entering edit mode
6.3 years ago
otwtgin2010 ▴ 630

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
make

Install SAMTOOLS

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
make

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
make

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
bcftools samtools htslib • 105k views
ADD COMMENT
11
Entering edit mode

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 REPLY
3
Entering edit mode

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 REPLY
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode

+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 REPLY
1
Entering edit mode

THANKS SO MUCH! Also, since a lot of people also use BWA with Samtools, here's what I did to also download that through the command line:

cd /usr/bin
wget https://sourceforge.net/projects/bio-bwa/files/bwa-0.7.17.tar.bz2
tar -vxjf bwa-0.7.17.tar.bz2
cd bwa-0.7.17.tar.bz2
make
ADD REPLY
0
Entering edit mode

Thanks for the method list very helpful. I have set this up using windows 10 - WSL and Ubuntu 22.04 which is working. There were a couple of additional things I found along he way - install apt-get install bzip2 before htslib / samtools etc.. it wasn't there for the Ubuntu Install. My setup required sudo from fresh for each install. The above bwa release has a bug when running make - apparently linked to gcc 10. I used sudo chmod 777 usr/bin/bwa-0.7.17 to allow modification of file rle.h. Once the folder permission in my case was granted, I used vi and modified the file following make file failed on gcc 10 then added to PATH as above.

ADD REPLY
0
Entering edit mode

this was super helpful for my attempt to get HTSlib working

ADD REPLY
0
Entering edit mode

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 REPLY
2
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

I just wanted to thank you! This still works as of 12/21/21 and version 1.14 for all software

ADD REPLY
0
Entering edit mode

Thank you, Biostar always have something useful.

ADD REPLY
0
Entering edit mode

Thank you so much for this very clear guide that actually works!

ADD REPLY
4
Entering edit mode
6.3 years ago
Ram 44k

EDIT

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 COMMENT
1
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
4
Entering edit mode
24 months ago
cmdcolin ★ 4.0k

you should be able to install straight from apt in the year 2022. it gets a reasonably up to date version (1.13 as of writing)

sudo apt install samtools
sudo apt install tabix
sudo apt install bcftools
ADD COMMENT
2
Entering edit mode

As mentioned in the previous, similar comment, you get old versions of htslib / samtools / bcftools this way. The apt repository only ports the bioionformatics tools just before the release of that Ubuntu software version. And they are never updated after that. So apt get update does not help either. The original script is to get the latest version (at that time) to install and operate. For the most part, newer versions of htslib / samtools / bcftools can be "backported" to the older OS releases.

For example, using your instructions on these platforms gets you:

  • Ubuntu LTS 18.04 htslib / samtools / bcftools v1.7
  • Ubuntu LTS 20.04 htslib / samtools / bcftools v1.10
  • Ubuntu LTS 22.04 htslib / samtools / bcftools v1.13

Many stick with Ubuntu LTS releases. And even then, may not update to the latest LTS. The next LTS is not scheduled until April 2024. If you do not care about LTS, I believe 23.04 due out shortly has the latest htslib 1.16.1 . Our pipeline requires 1.15.1 due to bug fixes and feature enhancements we depend on that are not in earlier versions. Upgrading Ubuntu is beyond the scope of this site.

Maybe the above should be edited into the original post to make it clearer why the tutorial is needed.

ADD REPLY
1
Entering edit mode

That is a reasonable. I like to suggest easy ways if possible because I think complicated install instructions can challenge newcomers. Also, the tutorial here suggests manually downloading files to /usr/bin. That's just a weird thing to do in my opinion. Samtools has a make install. The more idiomatic the install, the better :) Another alternative to apt is homebrew/linuxbrew, they keep the latest samtools generally (they have the latest at the time of writing)

ADD REPLY

Login before adding your answer.

Traffic: 1737 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6