Skip to content

Latest commit

 

History

History
307 lines (272 loc) · 27.6 KB

3_Formats_of_SAM&VCF.md

File metadata and controls

307 lines (272 loc) · 27.6 KB

Sequence Alignment Map (SAM)


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. 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. 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) 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.

Format

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. 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.

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

Description

From the specification:

  1. QNAME: Query template NAME. Reads/segments having identical QNAME are regarded to come from the same template. A QNAME ‘*’ indicates the information is unavailable. In a SAM file, a read may occupy multiple alignment lines, when its alignment is chimeric or when multiple mappings are given.
  2. FLAG: Combination of bitwise FLAGs
  3. RNAME: Reference sequence NAME of the alignment. If @SQ header lines are present, RNAME (if not ‘’) must be present in one of the SQ-SN tag. An unmapped segment without coordinate has a ‘’ at this field. However, an unmapped segment may also have an ordinary coordinate such that it can be placed at a desired position after sorting. If RNAME is ‘*’, no assumptions can be made about POS and CIGAR.
  4. POS: 1-based leftmost mapping POSition of the first matching base. The first base in a reference sequence has coordinate 1. POS is set as 0 for an unmapped read without coordinate. If POS is 0, no assumptions can be made about RNAME and CIGAR.
  5. MAPQ: MAPping Quality. It equals −10 log10 Pr{mapping position is wrong}, rounded to the nearest integer. A value 255 indicates that the mapping quality is not available.
  6. CIGAR: Concise Idiosyncratic Gapped Alignment Report (CIGAR) string.
  7. RNEXT: Reference sequence name of the primary alignment of the NEXT read in the template. For the last read, the next read is the first read in the template. If @SQ header lines are present, RNEXT (if not ‘’ or ‘=’) must be present in one of the SQ-SN tag. This field is set as ‘’ when the information is unavailable, and set as ‘=’ if RNEXT is identical RNAME. If not ‘=’ and the next read in the template has one primary mapping (see also bit 0x100 in FLAG), this field is identical to RNAME at the primary line of the next read. If RNEXT is ‘*’, no assumptions can be made on PNEXT and bit 0x20.
  8. PNEXT: Position of the primary alignment of the NEXT read in the template. Set as 0 when the information is unavailable. This field equals POS at the primary line of the next read. If PNEXT is 0, no assumptions can be made on RNEXT and bit 0x20.
  9. TLEN: signed observed Template LENgth. If all segments are mapped to the same reference, the unsigned observed template length equals the number of bases from the leftmost mapped base to the rightmost mapped base. The leftmost segment has a plus sign and the rightmost has a minus sign. The sign of segments in the middle is undefined. It is set as 0 for single-segment template or when the information is unavailable.
  10. SEQ: segment SEQuence. This field can be a ‘’ when the sequence is not stored. If not a ‘’, the length of the sequence must equal the sum of lengths of M/I/S/=/X operations in CIGAR. An ‘=’ denotes the base is identical to the reference base. No assumptions can be made on the letter cases.
  11. QUAL: ASCII of base QUALity plus 33 (same as the quality string in the Sanger FASTQ format). A base quality is the phred-scaled base error probability which equals −10 log10 Pr{base is wrong}. This field can be a ‘’ when quality is not stored. If not a ‘’, SEQ must not be a ‘*’ and the length of the quality string ought to equal the length of SEQ.

Bitwise flags

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.

Integer Binary Description (Paired Read Interpretation)
1 1 template having multiple templates in sequencing (read is paired)
2 10 each segment properly aligned according to the aligner (read mapped in proper pair)
4 100 segment unmapped (read1 unmapped)
8 1000 next segment in the template unmapped (read2 unmapped)
16 10000 SEQ being reverse complemented (read1 reverse complemented)
32 100000 SEQ of the next segment in the template being reverse complemented (read2 reverse complemented)
64 1000000 the first segment in the template (is read1)
128 10000000 the last segment in the template (is read2)
256 100000000 not primary alignment
512 1000000000 alignment fails quality checks
1024 1E+10 PCR or optical duplicate
2048 1E+11 supplementary alignment (e.g. aligner specific, could be a portion of a split read or a tied region)

The FLAG attributes are summed to get the final value, e.g. a SAM row resulting from an Illumina paired-end FASTQ record having the FLAG value 2145 would indicate:

Flag Value Meaning Flag Sum
1 read is paired 1
32 read2 was reverse complemented 33
64 read1 97
2048 Supplementary alignment 2145

Optional fields

From the specification:

The type may be one of A (character), B (general array), f (real number), H (hexadecimal array), i (integer), or Z ( string).

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
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

Example

# Header section
@HD    VN:1.3    SO:coordinate
@SQ    SN:conticA    LN:443
@SQ    SN:contigB    LN:1493
@SQ    SN:contigC    LN:328
# Tab-delimited read alignment information lines
readID43GYAX15:7:1:1202:19894/1    256    contig43    613960    1    65M    *    0    0    CCAGCGCGAACGAAATCCGCATGCGTCTGGTCGTTGCACGGAACGGCGGCGGTGTGATGCACGGC    EDDEEDEE=EE?DE??DDDBADEBEFFFDBEFFEBCBC=?BEEEE@=:?::?7?:8-6?7?@??#    AS:i:0    XS:i:0  XN:i:0  XM:i:0  XO:i:0  XG:i:0  NM:i:0  MD:Z:65  YT:Z:UU
readID43GYAX15:7:1:1202:19894/1    272    contig32    21001    1    65M    *    0    0    GCCGGACGTCACACGGCCGCCGGGCCGGTCTACGACCAGACGCATGCGGATTTCGTTAGAGCCGG    #??@?7?6-8:?7?::?:=@EEEEB?=CBCBEFFEBDFFFEBEDABDDD??ED?EE=EEDEEDDE    AS:i:-5    XS:i:0   XN:i:0  XM:i:1   XO:i:0   XG:i:0   NM:i:1   MD:Z:42T22   YT:Z:UU
readID43GYAX15:7:1:1202:19894/1    256    contig87    540849    1    65M    *    0    0    CCTGCACGAACGAAATCCGCATGCGTCTGGTCGTTGTACGGAACGGCGGTTGTGTGACGAACGGC    EDDEEDEE=EE?DE??DDDBADEBEFFFDBEFFEBCBC=?BEEEE@=:?::?7?:8-6?7?@??# AS:i:0  XS:i:0 XN:i:0  XM:i:0 XO:i:0  XG:i:0  NM:i:0    MD:Z:65    YT:Z:UU

Variant Call Format (VCF)


The Variant Call Format (VCF) specifies the format of a text file used in bioinformatics for storing gene sequence variations. The format has been developed with the advent of large-scale genotyping and DNA sequencing projects, such as the 1000 Genomes Project. Existing formats for genetic data such as General feature format (GFF) stored all of the genetic data, much of which is redundant because it will be shared across the genomes. By using the variant call format only the variations need to be stored along with a reference genome.

The standard is currently in version 4.3, although the 1000 Genomes Project has developed its own specification for structural variations such as duplications, which are not easily accommodated into the existing schema. There is also a Genomic VCF (gVCF) extended format, which includes additional information about "blocks" that match the reference and their qualities. A set of tools is also available for editing and manipulating the files.

The VCF header

The header begins the file and provides metadata describing the body of the file. Header lines are denoted as starting with #. Special keywords in the header are denoted with ##. Recommended keywords include fileformat, fileDate and reference.

The header contains keywords that optionally semantically and syntactically describe the fields used in the body of the file, notably INFO, FILTER, and FORMAT (see below).

The columns of a VCF

The body of VCF follows the header, and is tab separated into 8 mandatory columns and an unlimited number of optional columns that may be used to record other information about the sample(s). When additional columns are used, the first optional column is used to describe the format of the data in the columns that follow.

Name Brief description (see the specification for details).
1 CHROM The name of the sequence (typically a chromosome) on which the variation is being called. This sequence is usually known as 'the reference sequence', i.e. the sequence against which the given sample varies.
2 POS The 1-based position of the variation on the given sequence.
3 ID The identifier of the variation, e.g. a dbSNP rs identifier, or if unknown a ".". Multiple identifiers should be separated by semi-colons without white-space.
4 REF The reference base (or bases in the case of an indel) at the given position on the given reference sequence.
5 ALT The list of alternative alleles at this position.
6 QUAL A quality score associated with the inference of the given alleles.
7 FILTER A flag indicating which of a given set of filters the variation has passed.
8 INFO An extensible list of key-value pairs (fields) describing the variation. See below for some common fields. Multiple fields are separated by semicolons with optional values in the format: <key>=<data>[,data].
9 FORMAT An (optional) extensible list of fields for describing the samples. See below for some common fields.
+ SAMPLEs For each (optional) sample described in the file, values are given for the fields listed in FORMAT

Common INFO fields

Arbitrary keys are permitted, although the following sub-fields are reserved (albeit optional):

Name Brief description
AA ancestral allele
AC allele count in genotypes, for each ALT allele, in the same order as listed
AF allele frequency for each ALT allele in the same order as listed (use this when estimated from primary data, not called genotypes)
AN total number of alleles in called genotypes
BQ RMS base quality at this position
CIGAR cigar string describing how to align an alternate allele to the reference allele
DB dbSNP membership
DP combined depth across samples, e.g. DP=154
END end position of the variant described in this record (for use with symbolic alleles)
H2 membership in hapmap2
H3 membership in hapmap3
MQ RMS mapping quality, e.g. MQ=52
MQ0 Number of MAPQ == 0 reads covering this record
NS Number of samples with data
SB strand bias at this position
SOMATIC indicates that the record is a somatic mutation, for cancer genomics
VALIDATED validated by follow-up experiment
1000G membership in 1000 Genomes

Common FORMAT fields

Name Brief description
AD Read depth for each allele
ADF Read depth for each allele on the forward strand
ADR Read depth for each allele on the reverse strand
DP Read depth
EC Expected alternate allele counts
FT Filter indicating if this genotype was “called”
GL Genotype likelihoods
GP Genotype posterior probabilities
GQ Conditional genotype quality
GT Genotype
HQ Haplotype quality
MQ RMS mapping quality
PL Phred-scaled genotype likelihoods rounded to the closest integer
PQ Phasing quality
PS Phase set

Example

##fileformat=VCFv4.3
##fileDate=20090805
##source=myImputationProgramV3.1
##reference=file:///seq/references/1000GenomesPilot-NCBI36.fasta
##contig=<ID=20,length=62435964,assembly=B36,md5=f126cdf8a6e0c7f379d618ff66beb2da,species="Homo sapiens",taxonomy=x>
##phasing=partial
##INFO=<ID=NS,Number=1,Type=Integer,Description="Number of Samples With Data">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total Depth">
##INFO=<ID=AF,Number=A,Type=Float,Description="Allele Frequency">
##INFO=<ID=AA,Number=1,Type=String,Description="Ancestral Allele">
##INFO=<ID=DB,Number=0,Type=Flag,Description="dbSNP membership, build 129">
##INFO=<ID=H2,Number=0,Type=Flag,Description="HapMap2 membership">
##FILTER=<ID=q10,Description="Quality below 10">
##FILTER=<ID=s50,Description="Less than 50% of samples have data">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
#CHROM POS      ID         REF   ALT    QUAL  FILTER   INFO                             FORMAT       NA00001         NA00002          NA00003
20     14370    rs6054257  G     A      29    PASS    NS=3;DP=14;AF=0.5;DB;H2           GT:GQ:DP:HQ  0|0:48:1:51,51  1|0:48:8:51,51   1/1:43:5:.,.
20     17330    .          T     A      3     q10     NS=3;DP=11;AF=0.017               GT:GQ:DP:HQ  0|0:49:3:58,50  0|1:3:5:65,3     0/0:41:3
20     1110696  rs6040355  A     G,T    67    PASS    NS=2;DP=10;AF=0.333,0.667;AA=T;DB GT:GQ:DP:HQ  1|2:21:6:23,27  2|1:2:0:18,2     2/2:35:4
20     1230237  .          T     .      47    PASS    NS=3;DP=13;AA=T                   GT:GQ:DP:HQ  0|0:54:7:56,60  0|0:48:4:51,51   0/0:61:2
20     1234567  microsat1  GTC   G,GTCT 50    PASS    NS=3;DP=9;AA=G                    GT:GQ:DP     0/1:35:4        0/2:17:2         1/1:40:3