SAM文件HEADER: SAM Format Header
SAM文件每一列的信息:

image.png

image.png

image.png
理解FLAG值含义的关键在于将FLAG转换为二进制,再对照下方的表,哪一位上是1,就代表这个比对符合后面的描述。
计算机处理时,可通过对FLAG值和每种FLAG进行与运算,若为True,则包含此FLAG,反之不包含。
| FLAG(十进制) | 二进制 | 描述 | 英文描述 | 
|---|---|---|---|
| 1 | 1 | Pair end(PE)测序,否则是Single end(SE)测序。 | Read paired | 
| 2 | 10 | 代表正常比对,如果是PE测序,还代表PE的两条read之间的比对距离没有明显偏离插入片段长度。 | Read mapped in proper pair | 
| 4 | 100 | 该read没有比对到参考序列。 | Read unmapped | 
| 8 | 1000 | PE测序的另一个配对read没有比对到参考序列。 | Mate unmapped | 
| 16 | 10000 | 比对到负链(反向互补后比对到参考序列)。 | Read reverse strand | 
| 32 | 100000 | PE测序的另一条read反向互补后比对到参考序列。 | Mate reverse strand | 
| 64 | 1000000 | PE测序read1。 | First in pair | 
| 128 | 10000000 | PE测序read2。 | Second in pair | 
| 256 | 100000000 | 二次比对(secondary alignment),该read在基因组上比对到了多个位置,当前比对位置是次佳比对位置,通常需要过滤掉,但有些分析场景中很有用。 | Not primary alignment | 
| 512 | 1000000000 | 低于(测序平台等)过滤阈值。 | Read fails platform/vendor quality checks | 
| 1024 | 10000000000 | PCR重复序列(来自测序文库构建过程)或光学重复(来自测序过程)。 | Read is PCR or optical duplicate | 
| 2048 | 100000000000 | 该read可能存在嵌合,这个比对部分只是来自其中的一部分序列(supplementary alignment)。 | Supplementary alignment | 
SAM文件中CIGAR字符串详细记录了read比对到参考序列上的细节:
| 标记 | 描述 | Description | Consumes query | Consumes reference | 
|---|---|---|---|---|
| M | 匹配(包含完全匹配和单碱基错配) | alignment match (can be a sequence match or mismatch) | yes | yes | 
| I | 序列插入(包含潜在Insertion变异) | insertion to the reference | yes | no | 
| D | 序列删除(包含潜在Deletion变异) | deletion from the reference | no | yes | 
| N | 跳过参考序列 | skipped region from the reference | no | yes | 
| S | 软跳过(soft clip),跳过read中的部分序列,不会改变read长度 | soft clipping (clipped sequences present inSEQ) | yes | no | 
| H | 硬跳过(hard clip),直接剪切掉read中部分序列,会改变read长度 | hard clipping (clipped sequences NOT present inSEQ) | no | no | 
| P | padding,类似N,跳过参考序列的部分区域 | padding (silent deletion from padded reference) | no | no | 
| = | 完全匹配 | sequence match | yes | yes | 
| X | 序列错配 | sequence mismatch | yes | yes | 
“Consumes query” and “consumes reference” indicate whether the CIGAR operation causes the alignment to step along the query sequence and the reference sequence respectively.
BAM文件中除了必须的前11列信息之外,不同的BAM文件中后面记录metadata的列是不固定的,在不同的处理软件中输出时也会有所不同,meatdata含义:SAM (Sequence Alignment/Map) Format Alignment Tags (samformat.info)
参考:
从零开始完整学习全基因组测序数据分析:第5节 理解并操作BAM文件 
SAM Format Flag
https://samtools.github.io/hts-specs/SAMv1.pdf