samtools 的常用命令
001、生成统计文件
[root@PC1 test01]# ls ## 测试bam文件 SRR21814498.sorted.bam [root@PC1 test01]# samtools flagstat SRR21814498.sorted.bam > stat.txt ## 生成统计文件 [root@PC1 test01]# ls SRR21814498.sorted.bam stat.txt
002、结果文件
[root@PC1 test01]# cat stat.txt 24350195 + 0 in total (QC-passed reads + QC-failed reads) ## ?? 23343284 + 0 primary ## 总共的reads数目 1006911 + 0 secondary ## ??? 0 + 0 supplementary 0 + 0 duplicates 0 + 0 primary duplicates 21647554 + 0 mapped (88.90% : N/A) ## ???? 20640643 + 0 primary mapped (88.42% : N/A) ## 初级匹配率 23343284 + 0 paired in sequencing ##有多少reads属于pairedreads 11671642 + 0 read1 ## read1中的read数目 11671642 + 0 read2 ## read2中的read数目 20123714 + 0 properly paired (86.21% : N/A) ## 完美匹配率,比对到同一条参考序列,并且两条reads之间的距离符合设置的阈值 20553332 + 0 with itself and mate mapped ##paired reads中两条都比对到参考序列上的reads数 87311 + 0 singletons (0.37% : N/A) ## 单独一条匹配到参考序列上的reads数,和上一个相加,则是总的匹配上的reads数 232868 + 0 with mate mapped to a different chr ##paired reads中两条分别比对到两条不同的参考序列的reads数 76469 + 0 with mate mapped to a different chr (mapQ>=5)
。
003、验证;总的reads数目
[root@PC1 002_result]# ls SRR21814498_1.fastq.gz SRR21814498_2.fastq.gz SRR21814498.sorted.bam stat.txt [root@PC1 002_result]# zcat SRR21814498_1.fastq.gz | wc -l | awk '{print $0/4}' ## 统计read1的reads数目 11671642 [root@PC1 002_result]# zcat SRR21814498_2.fastq.gz | wc -l | awk '{print $0/4}' ## read2的reads数目 11671642
004、 samtools idxstats 统计结果
[root@PC1 002_result]# samtools idxstats SRR21814498.sorted.bam | column -t ## 统计命令 NC_003070.9 30427671 3908352 19878 ## 第一列scaffold名称, 第二列长度,第三列,比对上的reand数目 NC_003071.7 19698289 3063170 13234 ## 第四列 未比对上的read数目 NC_003074.8 23459830 3294763 13086 NC_003075.7 18585056 2691582 9587 NC_003076.8 26975502 3788593 24044 NC_037304.1 367808 214049 373 NC_000932.1 154478 4687045 7109 * 0 0 2615330
。
005、bam转sam
[root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai [root@PC1 002_result]# samtools view -h SRR21814498.sorted.bam -o test.sam ## bam转换未sam
[root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai test.sam [root@PC1 002_result]# head test.sam -n 3 test.sam ## 查看sam ==> test.sam <== @HD VN:1.6 SO:coordinate @SQ SN:NC_003070.9 LN:30427671 @SQ SN:NC_003071.7 LN:19698289 ==> test.sam <== @HD VN:1.6 SO:coordinate @SQ SN:NC_003070.9 LN:30427671 @SQ SN:NC_003071.7 LN:19698289
006、提取比对到参考基因组上的结果
[root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai [root@PC1 002_result]# samtools view -bF 4 SRR21814498.sorted.bam > test.F4.bam ## [root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai test.F4.bam [root@PC1 002_result]# ll -h total 3.2G -rw-r--r--. 1 root root 1.7G Jul 6 20:47 SRR21814498.sorted.bam -rw-r--r--. 1 root root 340K Jul 6 21:16 SRR21814498.sorted.bam.bai -rw-r--r--. 1 root root 1.6G Jul 6 21:42 test.F4.bam
007、
[root@PC1 003_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai [root@PC1 003_result]# samtools view -bF 12 SRR21814498.sorted.bam > test.F12.bam ## [root@PC1 003_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai test.F12.bam [root@PC1 003_result]# ll -h total 3.2G -rw-r--r--. 1 root root 1.7G Jul 6 21:41 SRR21814498.sorted.bam -rw-r--r--. 1 root root 340K Jul 6 21:41 SRR21814498.sorted.bam.bai -rw-r--r--. 1 root root 1.5G Jul 6 21:46 test.F12.bam
008、
[root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai ## 小写f [root@PC1 002_result]# samtools view -bf 4 SRR21814498.sorted.bam > test.f4.bam ##提取没有比对到参考序列上的比对结果 [root@PC1 002_result]# ls SRR21814498.sorted.bam SRR21814498.sorted.bam.bai test.f4.bam [root@PC1 002_result]# ll -h total 1.9G -rw-r--r--. 1 root root 1.7G Jul 6 20:47 SRR21814498.sorted.bam -rw-r--r--. 1 root root 340K Jul 6 21:16 SRR21814498.sorted.bam.bai -rw-r--r--. 1 root root 156M Jul 6 21:45 test.f4.bam
。
参考:https://mp.weixin.qq.com/s?__biz=Mzk0MzM5NzQ3Mw==&mid=2247485374&idx=1&sn=f4c113c19c4743f6e9e0c0bffda1af5c&chksm=c335c8b0f44241a6ce03198d51381d94b940956c440f03d100ca4253e8ac4fec072a5b349f27&cur_album_id=2548290874787807234&scene=189#wechat_redirect
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-07-06 硬盘接口、协议、总线
2021-07-06 plink格式中如何提取map文件重复的位点
2021-07-06 R语言中order函数,数值型和字符型的差异