序列比對(将測序reads與已知序列資訊的基因或基因組進行比對)是高通量測序資料分析中最重要的一環,無論是轉錄組還是重測序都是基于比對結果來進行後續各項分析的,比對結果格式比較常見的是sam和bam檔案,例如轉錄組Tophat分析軟體輸出的比對結果為.bam檔案,而重測序中BWA、bowtie等比對軟體則主要輸出為.sam檔案。
samtools是一個用于操作sam和bam檔案的工具軟體,能夠對比對檔案進行二進制檢視、格式轉換、排序及合并等,結合sam格式中的flag、tag等資訊,還可以完成比對結果的統計彙總,是處理sam和bam檔案不可或缺的神器!
1.下載下傳安裝包
http://www.htslib.org/download/2. 安裝依賴
yum install bzip2-devel ncurses-libs ncurses-devel xz-devel zlib-devel
3.編譯安裝
tar xvf samtools-1.9.tar.bz2
cd samtools-1.9
./configure --prefix=/opt/samtools1.9
make
make install
4.配置環境變量
gedit ~/.bashrc
#Samtools1.9
export PATH=/opt/samtools1.9/bin:$PATH
source ~/.bashrc
5.運作:samtools
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5yY0cjNzkjZjZDNmBTNyQWYwcjZ0EmY0QmZmZ2MjJzNm9CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
samtools常用指令詳解
1. view
view指令的主要功能是:将sam檔案轉換成bam檔案;然後對bam檔案進行各種操作,比如資料的排序(不屬于本指令的功能)和提取(這些操作是對bam檔案進行的,因而當輸入為sam檔案的時候,不能進行該操作);最後将排序或提取得到的資料輸出為bam或sam(預設的)格式。
bam檔案優點:bam檔案為二進制檔案,占用的磁盤空間比sam文本檔案小;利用bam二進制檔案的運算速度快。
view指令中,對sam檔案頭部的輸入(-t或-T)和輸出(-h)是單獨的一些參數來控制的。
Usage: samtools view [options] | [region1 [...]]
預設情況下不加 region,則是輸出所有的 region.
Options: -b output BAM
預設下輸出是 SAM 格式檔案,該參數設定輸出 BAM 格式
-h print header for the SAM output
預設下輸出的 sam 格式檔案不帶 header,該參數設定輸出sam檔案時帶 header 資訊
-H print header only (no alignments)
-S input is SAM
預設下輸入是 BAM 檔案,若是輸入是 SAM 檔案,則最好加該參數,否則有時候會報錯。
-u uncompressed BAM output (force -b)
該參數的使用需要有-b參數,能節約時間,但是需要更多磁盤空間。
-c Instead of printing the alignments, only count them and print the
total number. All filter options, such as ‘-f’, ‘-F’ and ‘-q’ ,
are taken into account.
-1 fast compression (force -b)
-x output FLAG in HEX (samtools-C specific)
-X output FLAG in string (samtools-C specific)
-c print only the count of matching records
-L FILE output alignments overlapping the input BED FILE [null]
-t FILE list of reference names and lengths (force -S) [null]
使用一個list檔案來作為header的輸入
-T FILE reference sequence file (force -S) [null]
使用序列fasta檔案作為header的輸入
-o FILE output file name [stdout]
-R FILE list of read groups to be outputted [null]
-f INT required flag, 0 for unset [0]
-F INT filtering flag, 0 for unset [0]
Skip alignments with bits present in INT [0]
數字4代表該序列沒有比對到參考序列上
數字8代表該序列的mate序列沒有比對到參考序列上
-q INT minimum mapping quality [0]
-l STR only output reads in library STR [null]
-r STR only output reads in read group STR [null]
-s FLOAT fraction of templates to subsample; integer part as seed [-1]
-? longer help