macでインフォマティクス

macでインフォマティクス

HTS (NGS) 関連のインフォマティクス情報についてまとめています。

samtoolsのインストール

2019 2/26 インストール追記

2019 12/8 追記

2020 3/25 conda追記

2020 10/13 1.11追記2021 2/17  新しい論文を引用、ツイート追加

2021 dockerについて追記

2022/05/12 追記 v1.15

 

 

あけましておめでとうございます。今年もよろしくお願い致します。 

samtoolsがどんどんアップデートしているので、久しぶりに更新します。ここではパッケージマネージャに頼らず、ソースからビルドします。自分の環境に合わせてビルドした方がチューニングが効きますし、ビルドのオプション次第で速くなる可能性もあります。

 

追記 1.10更新アナウンス 

2021 2/17

 

 

新しいバージョンを入れる場合は他のツールとの互換性に注意してください。特にいきなり本環境に入れるのは良くないです。

 

http://www.htslib.org/

f:id:kazumaxneo:20190104214218p:plain

 

インストール

OSは素のubuntuを想定(失念していたものを追記)

#必要なコマンド、ライブラリを導入
sudo apt update #追記 
sudo apt install -y wget
sudo apt install -y libncurses5-dev
sudo apt install -y zlib1g-dev
sudo apt install -y libbz2-dev
sudo apt install -y liblzma-dev
sudo apt install -y gcc #追記 
sudo apt install -y make #追記 
sudo apt install libcurl4-openssl-dev
#追記
sudo apt install bgzip2 #追記

samtoolsのダウンロードとインストール

#v1.9
#wget
wget https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2
#curl (macos)
curl -L https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2 > samtools-1.9.tar.bz2

tar -jxvf samtools-1.9.tar.bz2
cd samtools-1.9/
./configure --prefix=/usr/local/
make -j 8
make install

#2020 10/13追記 v1.11
wget https://github.com/samtools/samtools/releases/download/1.11/samtools-1.11.tar.bz2
#curl (macos)
curl -L
https://github.com/samtools/samtools/releases/download/1.10/samtools-1.10.tar.bz2
tar -xvf samtools-1.11.tar.bz2
cd samtools-1.11/
./configure --prefix=/usr/local/
make -j 8
make install

#2024/03/31 v1.19.2
wget https://github.com/samtools/samtools/releases/download/1.19.2/samtools-1.19.2.tar.bz2
tar -xvf samtools-1.19.2.tar.bz2
cd samtools-1.19.2/
./configure --prefix=/usr/local/
make -j12
make install

追記; apple silicon macでもhomebrew(M1 native版の方) でgccなど導入しておけば、オプションの指定なく、make出来ることを確認(gcc --version;Apple clang version 14.0.0 (clang-1400.0.29.102))。

 

追記

もちろんconda|mambaを使って導入することもできます。

#bioconda (link)
mamba install -c bioconda -y samtools==1.12

#updateする
conda update samtools

追記

bgzipとtabixも使えるようにしておく。

cd samtools-1.10/htslib-1.10/
make -j
make install

   

ヘルプ (v1.11)

> samtools 

Program: samtools (Tools for alignments in the SAM format)

Version: 1.11 (using htslib 1.11)

 

Usage:   samtools <command> [options]

 

Commands:

  -- Indexing

     dict           create a sequence dictionary file

     faidx          index/extract FASTA

     fqidx          index/extract FASTQ

     index          index alignment

 

  -- Editing

     calmd          recalculate MD/NM tags and '=' bases

     fixmate        fix mate information

     reheader       replace BAM header

     targetcut      cut fosmid regions (for fosmid pool only)

     addreplacerg   adds or replaces RG tags

     markdup        mark duplicates

     ampliconclip   clip oligos from the end of reads

 

  -- File operations

     collate        shuffle and group alignments by name

     cat            concatenate BAMs

     merge          merge sorted alignments

     mpileup        multi-way pileup

     sort           sort alignment file

     split          splits a file by read group

     quickcheck     quickly check if SAM/BAM/CRAM file appears intact

     fastq          converts a BAM to a FASTQ

     fasta          converts a BAM to a FASTA

 

  -- Statistics

     bedcov         read depth per BED region

     coverage       alignment depth and percent coverage

     depth          compute the depth

     flagstat       simple stats

     idxstats       BAM index stats

     phase          phase heterozygotes

     stats          generate stats (former bamcheck)

     ampliconstats  generate amplicon specific stats

 

  -- Viewing

     flags          explain BAM flags

     tview          text alignment viewer

     view           SAM<->BAM<->CRAM conversion

     depad          convert padded BAM to unpadded BAM

 

 

1.4を消して1.9を入れ直したのですが、samtools sortコマンドは5%ほど速くなっていました。メモリ使用量もかなり減っているようです。

 

引用

The Sequence Alignment/Map format and SAMtools.

Li H, Handsaker B, Wysoker A, Fennell T, Ruan J, Homer N, Marth G, Abecasis G, Durbin R; 1000 Genome Project Data Processing Subgroup.

Bioinformatics. 2009 Aug 15;25(16):2078-9

 

2020 12/21

HTSlib - C library for reading/writing high-throughput sequencing data

James K. Bonfield, John Marshall, Petr Danecek, Heng Li, Valeriu Ohan, Andrew Whitwham, Thomas Keane

bioRxiv, Posted December 16, 2020

 

2021 2/17

Twelve years of SAMtools and BCFtools
Petr Danecek, James K Bonfield, Jennifer Liddle, John Marshall, Valeriu Ohan, Martin O Pollard, Andrew Whitwham, Thomas Keane, Shane A McCarthy, Robert M Davies, Heng Li
GigaScience, Volume 10, Issue 2, February 2021

 

2021 4/21 

dockerでsamtoolsを動かすなら、biocontainersのイメージが利用できます。具体的には、

biocontainers/satoolsのdockerfileは、biocontainersのubuntuのベースイメージ(Dockerfile)をpullし、condaコマンドだけランすることでsamtoolsをインストールしています(Dockerfile)。

docker pull biocontainers/samtools:v1.9-4-deb_cv1

 ただ、biocontainersのubuntuのベースイメージは色々なツールを導入するために肥大しています。samtoolsを動かすだけなら、自分でビルドするか、軽量なイメージをpullした方が良いと思います。