【bioinfo】samtools stats 输出结果解读

参考:samtools stats

# sam or bam input
$ samtools stats test.sam > test_sam_stat.txt 

下图为示例统计的SN关键字部分:
在这里插入图片描述

统计结果中包含的信息有:

关键字官方解释说明
CHKChecksum校验和
SNSummary numbers摘要编号
FFQFirst fragment qualitiesRead1片段质量
LFQLast fragment qualitiesRead2片段质量
GCFGC content of first fragmentsRead1的GC含量
GCLGC content of last fragmentsRead2的GC含量
GCCACGT content per cycle每个cycle的ACGT含量
FBCACGT content per cycle for first fragments onlyRead1片段每个cycle的ACGT含量
FTCACGT raw counters for first fragmentsRead1片段, ACGT的原始计数
LBCACGT content per cycle for last fragments onlyRead2片段每个cycle的ACGT含量
LTCACGT raw counters for last fragmentsRead2片段, ACGT的原始计数
BCCACGT content per cycle for BC barcodeBC Barcode每个周期的ACGT含量
CRCACGT content per cycle for CR barcodeCR Barcode每个周期的ACGT含量
OXCACGT content per cycle for OX barcodeOX Barcode每个周期的ACGT含量
RXCACGT content per cycle for RX barcodeRX Barcode每个周期的ACGT内容
QTQQuality distribution for BC barcodeBC Barcod的质量分布
CYQQuality distribution for CR barcodeCR Barcod的质量分布
BZQQuality distribution for OX barcodeOX Barcod的质量分布
QXQQuality distribution for RX barcodeRX Barcod的质量分布
ISInsert sizes插入片段大小
RLRead lengthsread长度
FRLRead lengths for first fragments only只有Read1的长度
LRLRead lengths for last fragments only只有Read2的长度
IDIndel size distributionIndel大小分布
ICIndels per cycle每个周期的Indels
COVCoverage (depth) distribution覆盖范围(深度)分布
GCDGC-depthGC深度

SN关键字信息说明(使用 grep ^SN | cut -f 2- 提取信息): samtools版本v1.6

KeyValueNOTEidx说明
raw total sequences:7693458(1)原始序列数
filtered sequences:0(2)过滤掉的序列数
sequences:7693458(3)序列数, 同(1)
is sorted:1(4)是否排序, 1是,0否
1st fragments:3876581(5)R1片段数
last fragments:3816877(6)R2片段数
reads mapped:6590466(7)比对上的reads数
reads mapped and paired:5329118# paired-end technology bit set + both mates mapped(8)比对上,且是成对的reads数
reads unmapped:1102992(9)未比对上的reads数
reads properly paired:4719116# proper-pair bit set(10)成对比上也位置合适的序列(比对的位置是接近的?)
reads paired:7693458# paired-end technology bit set(11)成对的read数(技术上)
reads duplicated:0# PCR or optical duplicate bit set(12)PCR或光学重复reads数
reads MQ0:63803# mapped and MQ=0(13)比对质量是0的reads数
reads QC failed:0(14)质量失败的reads数
non-primary alignments:266109(15)非首次比对的reads数
total length:1111705142# ignores clipping(16)总长度(忽略截断)
bases mapped:952346426# ignores clipping(17)比对上的碱基数(忽略截断)
bases mapped (cigar):921111215# more accurate(18)来自Cigar的比对上的碱基数(更精确)
bases trimmed:0(19)去掉的碱基数
bases duplicated:0(20)重复的碱基数
mismatches:1822453# from NM fields(21)错配数(来自NM)
error rate:1.98E-03# mismatches / bases mapped (cigar)(22)错误率(错配数/比对上的总碱基数)
average length:144(23)平均长度
maximum length:150(24)最大长度
average quality:36.1(25)平均碱基质量
insert size average:845.9(26)插入片段长度
insert size standard deviation:1597.6(27)插入片段长度标准差
inward oriented pairs:2014285(28)?向内成对
outward oriented pairs:72676(29)?向外成对
pairs with other orientation:178825(30)其他方向
pairs on different chromosomes:2562(31)成对,比对在不同染色体上

上述示例信息是使用samtools v1.6 统计,发现与samtools v1.2结果有差异。

samtools flagstat统计使用v1.6和v1.2没有差异:
在这里插入图片描述 在这里插入图片描述

key对应SN
0 in total (QC-passed reads + QC-failed reads)v1.2 (1)
0 secondaryv1.2/v1.6 (15)
0 supplementary补充比对reads数
0 duplicatesv1.2/v1.6 (12)
0 mapped (86.14% : N/A)v1.2 (7)
0 paired in sequencingv1.6 (1)
0 read1v1.6 (5)
0 read2v1.6 (6)
0 properly paired (61.34% : N/A)v1.6 (10)
0 with itself and mate mappedv1.6 (8)
0 singletons (16.40% : N/A)?
0 with mate mapped to a different chrv1.6 (31) * 2
0 with mate mapped to a different chr (mapQ>=5)比对到不同染色体且比对质量值>5

一些问题:

【1】输入的bam/sam文件是PE,SN中的raw total sequences为什么是奇数,R1和R2的总和应该是偶数?

【2】官网samtools stats中对raw total sequences解释是:
在这里插入图片描述
就是说,统计的是:输入文件中 除了supplementarysecondary比对的reads,其他read数目。并且和samtools这个命令输出的是相同的:samtools view -c -F 0x900

但是,在用samtools v1.2测试时,输出的raw total sequences的值和这个命令输出的reads数不同。且经过使用脚本自己统计read数,使用这个命令(samtools view -c -F 0x900)的结果是一致的。

import pysam

def cntbam(bam):
    total_cnt = 0  # total read
    bmrd = pysam.AlignmentFile(bam)
    for rec in bmrd:
        if rec.is_unmapped:
            total_cnt += 1
            continue
            
        if 'H' in rec.cigarstring:
            continue
        if rec.is_secondary:
            continue
        if rec.is_supplementary:
            print('#sup\t%s' % rec.query_name)
            continue

        total_cnt += 1
    return total_cnt

print(cntbam(inbam))

pysam常用属性可参考笔者的另一篇博客:使用pysam读取sam/vcf/fasta文件时的常用属性


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值