参考链接:https://www.jianshu.com/p/6b7a442d293f
中文使用手册:http://cncbi.github.io/Samtools-Manual-CN/
技巧一、使用samtools view筛选具有特殊flag/质量值/scaffold的比对结果组成bam文件(一定要注意使用view的筛选功能!!)
sam中的flag的详细解释:https://www.cnblogs.com/xudongliang/p/5437850.html
1 : 代表这个序列采用的是PE双端测序
2: 代表这个序列和参考序列完全匹配,没有插入缺失
4: 代表这个序列没有mapping到参考序列上
8: 代表这个序列的另一端序列没有比对到参考序列上,比如这条序列是R1,它对应的R2端序列没有比对到参考序列上
16:代表这个序列比对到参考序列的负链上
32 :代表这个序列对应的另一端序列比对到参考序列的负链上
64 : 代表这个序列是R1端序列, read1;
128 : 代表这个序列是R2端序列,read2;
256: 代表这个序列不是主要的比对,一条序列可能比对到参考序列的多个位置,只有一个是首要的比对位置,其他都是次要的
512: 代表这个序列在QC时失败了,被过滤不掉了(# 这个标签不常用)
1024: 代表这个序列是PCR重复序列(#这个标签不常用)
2048: 代表这个序列是补充的比对(#这个标签具体什么意思,没搞清楚,但是不常用)
比如我们可以通过samtools view中的-f参数,找到flag值包括2的比对结果
samtools view -f 2 -q 30 test.bam chr2:1-74455083
如果有未知含义的flag,可以通过samtools flags查询
samtools flags 49
# 0x31 49 PAIRED,REVERSE,MREVERSE
![](https://img.haomeiwen.com/i7983008/36186ee893341f12.png)
技巧二、使用samtools faidx构建不同染色体的fasta
首先一定要先对fasta文件构建index
samtools faidx test.fasta
使用samtools faidx
samtools faidx chr1 test.fasta>chr1.fasta
或者提取指定未知
samtools faidx chr1:1-1000000 test.fasta>test.sub.fasta
技巧三、使用samtools depth 统计bam文件每个位置的测序深度
samtools depth test.bam
samtools depth -r chr1 test.bam #统计一号染色体上的比对的各位点覆盖深度
-r <chr:from-to> region
# 后面跟染色体号(region)
-a output all positions (including zero depth)
# 输入所有位置的序列,包括测序深度为0的
-q <int> base quality threshold [0]
# 碱基质量阈值
-Q <int> mapping quality threshold [0]
# 比对的质量阈值
一个大小为2G左右的bam文件(提前sort+index)统计所用时间为
real 7m54.912s
user 4m52.029s
sys 0m26.610s
![](https://img.haomeiwen.com/i7983008/23c5c935e8fe1277.png)
技巧四、使用samtools flagstat统计bam的比对相关信息
samtools flagstat -@ 10 test.bam
结果:
500 + 0 in total (QC-passed reads + QC-failed reads)
0 + 0 secondary
0 + 0 supplementary
0 + 0 duplicates
498 + 0 mapped (99.60% : N/A)
500 + 0 paired in sequencing
250 + 0 read1
250 + 0 read2
494 + 0 properly paired (98.80% : N/A)
498 + 0 with itself and mate mapped
0 + 0 singletons (0.00% : N/A)
4 + 0 with mate mapped to a different chr
4 + 0 with mate mapped to a different chr (mapQ>=5)
技巧五、质量值为30、测序深度大于10的一号染色体上的比对信息
samtools view -q 30 -@ 10 test.bam chr1 |samtools index|samtools depth -r chr1 |awk '$3>10{print $0}' ->q30depth10chr1.depth
![](https://img.haomeiwen.com/i7983008/96f4ca9c15fbdc19.png)
网友评论