SAM file format | |
Extension: | .sam |
Genre: | Bioinformatics |
Extended From: | Tab-separated values |
Standards: | --> |
Sequence Alignment Map (SAM) is a text-based format originally for storing biological sequences aligned to a reference sequence developed by Heng Li and Bob Handsaker et al.[1] It was developed when the 1000 Genomes Project wanted to move away from the MAQ mapper format and decided to design a new format. The overall TAB-delimited flavour of the format came from an earlier format inspired by BLAT’s PSL. The name of SAM came from Gabor Marth from University of Utah, who originally had a format under the same name but with a different syntax more similar to a BLAST output.[2] It is widely used for storing data, such as nucleotide sequences, generated by next generation sequencing technologies, and the standard has been broadened to include unmapped sequences. The format supports short and long reads (up to 128 Mbp[3]) produced by different sequencing platforms and is used to hold mapped data within the Genome Analysis Toolkit (GATK) and across the Broad Institute, the Wellcome Sanger Institute, and throughout the 1000 Genomes Project.
The SAM format consists of a header and an alignment section. The binary equivalent of a SAM file is a Binary Alignment Map (BAM) file, which stores the same data in a compressed binary representation.[4] SAM files can be analysed and edited with the software SAMtools. The header section must be prior to the alignment section if it is present. Headings begin with the '@' symbol, which distinguishes them from the alignment section. Alignment sections have 11 mandatory fields, as well as a variable number of optional fields.[1]
Col | Field | Type | Brief description | |
---|---|---|---|---|
1 | QNAME | String | Query template NAME | |
2 | FLAG | Int | bitwise FLAG | |
3 | RNAME | String | References sequence NAME | |
4 | POS | Int | 1- based leftmost mapping POSition | |
5 | MAPQ | Int | MAPping Quality | |
6 | CIGAR | String | CIGAR string | |
7 | RNEXT | String | Ref. name of the mate/next read | |
8 | PNEXT | Int | Position of the mate/next read | |
9 | TLEN | Int | observed Template LENgth | |
10 | SEQ | String | segment SEQuence | |
11 | QUAL | String | ASCII of Phred-scaled base QUALity+33 |
From the specification:[4]
The FLAG field is displayed as a single integer, but is the sum of bitwise flags to denote multiple attributes of a read alignment. Each attribute denotes one bit in the binary representation of the integer.
1 | 000000000001 | template having multiple templates in sequencing (read is paired) | |
2 | 000000000010 | each segment properly aligned according to the aligner (read mapped in proper pair) | |
4 | 000000000100 | segment unmapped (read1 unmapped) | |
8 | 000000001000 | next segment in the template unmapped (read2 unmapped) | |
16 | 000000010000 | SEQ being reverse complemented (read1 reverse complemented) | |
32 | 000000100000 | SEQ of the next segment in the template being reverse complemented (read2 reverse complemented) | |
64 | 000001000000 | the first segment in the template (is read1) | |
128 | 000010000000 | the last segment in the template (is read2) | |
256 | 000100000000 | not primary alignment | |
512 | 001000000000 | alignment fails quality checks | |
1024 | 010000000000 | PCR or optical duplicate | |
2048 | 100000000000 | supplementary alignment (e.g. aligner specific, could be a portion of a split read or a tied region) |
Flag Value | Meaning | Flag Sum | |
---|---|---|---|
1 | read is paired | 1 | |
32 | read2 was reverse complemented | 33 | |
64 | read1 | 97 | |
2048 | Supplementary alignment | 2145 |
From the specification for Sequence Alignment/Map Optional Fields Specification (SAMtags):[6]
The type may be one of A (character), C (integer 0-255), f (real number), H (hexadecimal array), i (integer), or Z (string). It may be a single value or B (general array).
Tag | Type | Description | |
---|---|---|---|
AM | i | The smallest template-independent mapping quality in the template | |
AS | i | Alignment score generated by aligner | |
BC | Z | Barcode sequence identifying the sample | |
BQ | Z | Offset to base alignment quality (BAQ) | |
BZ | Z | Phred quality of the unique molecular barcode bases in the OX tag | |
CB | Z | Cell identifier | |
CC | Z | Reference name of the next hit | |
CG | B,I | BAM only: CIGAR in BAM's binary encoding if (and only if) it consists of >65535 operators | |
CM | i | Edit distance between the color sequence and the color reference (see also NM) | |
CO | Z | Free-text comments | |
CP | i | Leftmost coordinate of the next hit | |
CQ | Z | Color read base qualities | |
CR | Z | Cellular barcode sequence bases (uncorrected) | |
CS | Z | Color read sequence | |
CT | Z | Complete read annotation tag, used for consensus annotation dummy features | |
CY | Z | Phred quality of the cellular barcode sequence in the CR tag | |
E2 | Z | The 2nd most likely base calls | |
FI | i | The index of segment in the template | |
FS | Z | Segment suffix | |
FZ | B,S | Flow signal intensities | |
GC | ? | Reserved for backwards compatibility reasons | |
GQ | ? | Reserved for backwards compatibility reasons | |
GS | ? | Reserved for backwards compatibility reasons | |
H0 | i | Number of perfect hits | |
H1 | i | Number of 1-difference hits (see also NM) | |
H2 | i | Number of 2-difference hits | |
HI | i | Query hit index | |
IH | i | Query hit total count | |
LB | Z | Library | |
MC | Z | CIGAR string for mate/next segment | |
MD | Z | String for mismatching positions | |
MF | ? | Reserved for backwards compatibility reasons | |
MI | Z | Molecular identifier; a string that uniquely identifies the molecule from which the record was derived | |
ML | B, C | Base modification probabilities | |
MM | Z | Base modifications / methylation | |
MQ | i | Mapping quality of the mate/next segment | |
NH | i | Number of reported alignments that contain the query in the current record | |
NM | i | Edit distance to the reference | |
OA | Z | Original alignment | |
OC | Z | Original CIGAR (deprecated; use OA instead) | |
OP | i | Original mapping position (deprecated; use OA instead) | |
OQ | Z | Original base quality | |
OX | Z | Original unique molecular barcode bases | |
PG | Z | Program | |
PQ | i | Phred likelihood of the template | |
PT | Z | Read annotations for parts of the padded read sequence | |
PU | Z | Platform unit | |
Q2 | Z | Phred quality of the mate/next segment sequence in the R2 tag | |
QT | Z | Phred quality of the sample barcode sequence in the BC tag | |
QX | Z | Quality score of the unique molecular identifier in the RX tag | |
R2 | Z | Sequence of the mate/next segment in the template | |
RG | Z | Read group | |
RT | ? | Reserved for backwards compatibility reasons | |
RX | Z | Sequence bases of the (possibly corrected) unique molecular identifier | |
S2 | ? | Reserved for backwards compatibility reasons | |
SA | Z | Other canonical alignments in a chimeric alignment | |
SM | i | Template-independent mapping quality | |
SQ | ? | Reserved for backwards compatibility reasons | |
TC | i | The number of segments in the template | |
U2 | Z | Phred probability of the 2nd call being wrong conditional on the best being wrong | |
UQ | i | Phred likelihood of the segment, conditional on the mapping being correct | |
X? | ? | Reserved for end users | |
Y? | ? | Reserved for end users | |
Z? | ? | Reserved for end users |