samtools 的使用


主要介紹一下 SAMtools 的用法。它被譽為 NGS 里面的 瑞士軍刀,功能很是強大,所以值得好好學習一番。


文檔參考

總站

samtools-mannual

github-samtools

標准流程

推薦: blog SAMtools: Primer/Tutorial


安裝

由於 samtools 與 htslib , bcftools 經常結合使用,因此,最好一次就把這三個一起安裝好,屆時使用更方便。
下載,安裝

以 samtools 為例
下載,解壓到 samtools/ 目錄下, 里面有一個 INSTALL 文件,可以看看說明

	$ cd samtools-1.2        # and similarly for bcftools and htslib
	$ make

很有可能會出現如下的錯誤信息:

	bam_tview_curses.c:30:20: fatal error: curses.h: No such file or directory
	compilation terminated.
	make: *** [bam_tview_curses.o] Error 1

這說明缺少curses 文件,google 后,找到解決方法:
解決方法

	$ sudo apt-get update
	$ sudo apt-get install ncurses-dev

這樣,問題就解決啦

	$ make prefix=/home/user/samtools-1.2/ install

此時,可運行的軟件已經安裝到了 /home/user/samtools-1.2/bin/ 下,所以下一步把它加入到 PATH 中即可:

	$ export PATH=/home/user/samtools-1.2/bin:$PATH

這樣就基本算安裝,配置完了,可以測試一下:

	$ samtools 

應該會輸出各種信息,包括版本,語法,用法等等,這樣就算成功了。

剩下的 htslib 與 bcftools 的安裝與這個一樣。


這三個的安裝比較簡單,一切妥當后, 就可以進行使用了。

使用samtools

參考推薦: blog SAMtools: Primer/Tutorial

前提是有已經通過比對軟件 mapping 后的初始 sam 文件
方法在之前的博客中已經說過了

比對程序 BWA 的簡單用法
比對程序 Bowtie 的簡單使用
比對程序 Bowtie2 的簡單使用

將 sam 轉換成 bam 文件

	$ samtools view   # 查看 view 的用法
	$ samtools view -b -S -o /media/文檔/aln-pe.bam /media/文檔/aln-pe.sam
	# -b: indicates that the output is BAM.
	# -S: indicates that the input is SAM.
	# -o: specifies the name of the output file

這樣就把 aln-pe.sam 文件轉換成 aln-pe.bam 文件

sorting

	$ samtools sort   # 查看 sort 的用法
	$ samtools sort /media/文檔/aln-pe.bam /media/文檔/aln-pe.sorted

這樣就把 上一步的 aln-pe.bam 變為 sorted file : aln-pe.sorted.bam

index

	$ samtools index   # 查看 index 的用法		
	$ samtools index /media/文檔/aln-pe.sorted.bam	

This enables tools, including SAMtools itself, and other genomic viewers to perform efficient random access on the BAM file, resulting in greatly improved performance
This reads in the sorted BAM file, and creates a BAM index file with the .bai extension: aln-pe.sorted.bam.bai

至此,現在就可以利用軟件 IGV 去查看 mapping 結果了。


下面就可以鑒定基因組的變異位點了,也就是所謂的 SNP 以及 INDEL 等。

samtools mpileup

	$ samtools mpileup    # 查看 mpileup 的用法
	$ samtools mpileup -g -f /media/文檔/tigr7.fa  /media/文檔/samtools-test/aln-pe.sorted.bam  > /media/文檔/samtools-test/sim_variants.bcf
	-g: directs SAMtools to output genotype likelihoods in the binary call format (BCF). This is a compressed binary format.
	-f: directs SAMtools to use the specified reference genome

這一步會生成一個 sim_variants.bcf 文件,很大...

The mpileup command automatically scans every position supported by an aligned read, computes all the possible genotypes supported by these reads, and then computes the probability that each of these genotypes is truly present in our sample

bcftools call

	$ bcftools call      # 查看 call 的用法
	$ bcftools call -c -v /media/文檔/samtools-test/sim_variants.bcf > /media/文檔/samtools-test/sim_variants.vcf
	# -c: directs bcftools to call SNPs.
	# -v: directs bcftools to only output potential variants

這樣就生成了一個 sim_variants.vcf 文件。里面包含了鑒定出的 SNP 以及 INDEL 的詳細信息,可以用文本編輯器來查看

Visualizing Reads

除了用軟件如 IGV 來查看 mapping 的reads 的情況外,也可以在命令行下使用 samtools 去查看。

	$ samtools tview    # 查看 tview 的用法
	$ samtools tview /media/文檔/samtools-test/aln-pe.sorted.bam /media/文檔/tigr7.fa

終於算是把 samtools , bcftools 的最簡單的用法過了一遍,操作起來並不難,但是很多必要的原理知識還沒有去看,去閱讀體會,所以這僅僅算是一個入門而已。不過到這一步也算不錯的。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM