Changes

From Genome Analysis Wiki
Jump to navigationJump to search
3,537 bytes added ,  16:10, 11 September 2015
m
Line 8: Line 8:  
The current definition of the format is at [[http://samtools.sourceforge.net/SAM1.pdf BAM/SAM Specification]].
 
The current definition of the format is at [[http://samtools.sourceforge.net/SAM1.pdf BAM/SAM Specification]].
   −
If you are writing software to read SAM or BAM data, our C++ [[C++ Library: libbam|BamFile]] is a good resource to use.
+
If you are writing software to read SAM or BAM data, our C++ [[C++ Library: libStatGen|libStatGen]] is a good resource to use.
      Line 14: Line 14:  
SAM files and BAM files contain the same information, but in a different format.  Refer to the specs to see a format description.
 
SAM files and BAM files contain the same information, but in a different format.  Refer to the specs to see a format description.
   −
Both SAM & BAM files contain a header section and an alignment section.
+
Both SAM & BAM files contain an optional header section followed by the alignment section.
 +
 
 
The header section may contain information about the entire file and additional information for alignments.  The alignments then associate themselves with specific header information.
 
The header section may contain information about the entire file and additional information for alignments.  The alignments then associate themselves with specific header information.
    
The alignment section contains the information for each sequence about where/how it aligns to the reference genome.
 
The alignment section contains the information for each sequence about where/how it aligns to the reference genome.
      
=== What Information Does SAM/BAM Have for an Alignment ===
 
=== What Information Does SAM/BAM Have for an Alignment ===
Line 39: Line 39:  
* reference sequence name, RNAME, often contains the Chromosome name.   
 
* reference sequence name, RNAME, often contains the Chromosome name.   
 
* leftmost position of where this alignment maps to the reference, POS.  For SAM, the reference starts at 1, so this value is 1-based, while for BAM the reference starts at 0,so this value is 0-based.  Beware to always use the correct base when referencing positions.
 
* leftmost position of where this alignment maps to the reference, POS.  For SAM, the reference starts at 1, so this value is 1-based, while for BAM the reference starts at 0,so this value is 0-based.  Beware to always use the correct base when referencing positions.
* mapping quality, MAPQ, which contains the "phred-scaled posterior probability that the mapping position" is wrong. (from SAM-1.pdf)
+
* mapping quality, MAPQ, which contains the "phred-scaled posterior probability that the mapping position" is wrong. (see [[http://samtools.sourceforge.net/SAM1.pdf]])
 
* string indicating alignment information that allows the storing of clipped, [[SAM#What is a CIGAR?|CIGAR]]
 
* string indicating alignment information that allows the storing of clipped, [[SAM#What is a CIGAR?|CIGAR]]
 
* the reference sequence name of the next alignment in this group, MRNM or RNEXT.  In paired alignments, it is the mate's reference sequence name. (A group is alignments with the same query name.)
 
* the reference sequence name of the next alignment in this group, MRNM or RNEXT.  In paired alignments, it is the mate's reference sequence name. (A group is alignments with the same query name.)
Line 111: Line 111:  
|}
 
|}
   −
There are a set of predefined tags that are general used in Alignments.
     −
A user can also use any additional tags to store any information they want.
+
There are a set of predefined tags that are general used in Alignments.  They are documented in the SAM Specification.
 +
Predefined tags have been specified for storing information about the read or alignment.
 +
Examples of things stored in predefined tags:
 +
* Previous settings for various fields if they have been updated due to additional processing
 +
* Mappings from the alignment to Header values, used to match to a read group or program.
 +
* Additional information which may already be in the header like library and platform.
 +
 
 +
A user can also use any additional tags to store any information they want.  TAGs starting with X, Y, or Z are reserved to be user defined.
 +
 
 +
Examples:
 +
XT:A:U  - user defined tag called XT.  It holds a character.  The value associated with this tag is 'U'.
 +
NM:i:2  - predefined tag NM means: Edit distance to the reference (number of changes necessary to make this equal the reference, excluding clipping)
 +
 
 +
=== What Information is in the SAM/BAM Header ===
 +
 
 +
The SAM/BAM header is not required, but if it is there, it contains generic information for the SAM/BAM file. 
 +
 
 +
The header may contain the version information for the SAM/BAM file and information regarding whether or not and how the file is sorted.
 +
 
 +
It also contains supplemental information for alignment records like information about the reference sequences, the processing that was used to generate the various reads in the file, and the programs that have been used to process the different reads.  The alignment records may then point to this supplemental information identifying which ones the specific alignment is associated with.
 +
 
 +
For example, a group of reads in the SAM/BAM file may all be assigned to the same reference sequence.  Rather than every alignment containing information about the reference sequence, this information is put in the header, and the alignment "points" to the appropriate reference sequence in the header via the RNAME field.  The header contains generic information about this reference like its length.
 +
 
 +
The SAM/BAM Header also may contain comments which are free-form text lines that can contain any information.
    +
Header lines start with an '@'.
    
== Example SAM ==
 
== Example SAM ==
 +
=== Example Header Lines ===
 +
@HD VN:1.0 SO:coordinate
 +
@SQ SN:1 LN:249250621 AS:NCBI37 UR:file:/data/local/ref/GATK/human_g1k_v37.fasta M5:1b22b98cdeb4a9304cb5d48026a85128
 +
@SQ SN:2 LN:243199373 AS:NCBI37 UR:file:/data/local/ref/GATK/human_g1k_v37.fasta M5:a0d9851da00400dec1098a9255ac712e
 +
@SQ SN:3 LN:198022430 AS:NCBI37 UR:file:/data/local/ref/GATK/human_g1k_v37.fasta M5:fdfd811849cc2fadebc929bb925902e5
 +
@RG ID:UM0098:1 PL:ILLUMINA PU:HWUSI-EAS1707-615LHAAXX-L001 LB:80 DT:2010-05-05T20:00:00-0400 SM:SD37743 CN:UMCORE
 +
@RG ID:UM0098:2 PL:ILLUMINA PU:HWUSI-EAS1707-615LHAAXX-L002 LB:80 DT:2010-05-05T20:00:00-0400 SM:SD37743 CN:UMCORE
 +
@PG ID:bwa VN:0.5.4
 +
@PG ID:GATK TableRecalibration VN:1.0.3471 CL:Covariates=[ReadGroupCovariate, QualityScoreCovariate, CycleCovariate, DinucCovariate, TileCovariate], default_read_group=null, default_platform=null, force_read_group=null, force_platform=null, solid_recal_mode=SET_Q_ZERO, window_size_nqs=5, homopolymer_nback=7, exception_if_no_tile=false, ignore_nocall_colorspace=false, pQ=5, maxQ=40, smoothing=1
 +
 +
In the alignment examples below, you will see that the 2nd alignment maps back to the RG line with ID UM0098.1, and all of the alignments point back to the SQ line with SN:1 because their RNAME is 1.
 +
 +
 
=== Example Alignments ===
 
=== Example Alignments ===
 
This is what the alignment section of a SAM file looks like:
 
This is what the alignment section of a SAM file looks like:
    
  1:497:R:-272+13M17D24M 113 1 497 37 37M 15 100338662 0 CGGGTCTGACCTGAGGAGAACTGTGCTCCGCCTTCAG 0;==-==9;>>>>>=>>>>>>>>>>>=>>>>>>>>>> XT:A:U NM:i:0 SM:i:37 AM:i:0 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
 
  1:497:R:-272+13M17D24M 113 1 497 37 37M 15 100338662 0 CGGGTCTGACCTGAGGAGAACTGTGCTCCGCCTTCAG 0;==-==9;>>>>>=>>>>>>>>>>>=>>>>>>>>>> XT:A:U NM:i:0 SM:i:37 AM:i:0 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
  19:20389:F:275+18M2D19M 99 1 17644 0 37M = 17919 314 TATGACTGCTAATAATACCTACACATGTTAGAACCAT >>>>>>>>>>>>>>>>>>>><<>>><<>>4::>>:<9 XT:A:R NM:i:0 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
+
  19:20389:F:275+18M2D19M 99 1 17644 0 37M = 17919 314 TATGACTGCTAATAATACCTACACATGTTAGAACCAT >>>>>>>>>>>>>>>>>>>><<>>><<>>4::>>:<9 RG:Z:UM0098:1 XT:A:R NM:i:0 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
 
  19:20389:F:275+18M2D19M 147 1 17919 0 18M2D19M = 17644 -314 GTAGTACCAACTGTAAGTCCTTATCTTCATACTTTGT ;44999;499<8<8<<<8<<><<<<><7<;<<<>><< XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:18^CA19
 
  19:20389:F:275+18M2D19M 147 1 17919 0 18M2D19M = 17644 -314 GTAGTACCAACTGTAAGTCCTTATCTTCATACTTTGT ;44999;499<8<8<<<8<<><<<<><7<;<<<>><< XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:18^CA19
 
  9:21597+10M2I25M:R:-209 83 1 21678 0 8M2I27M = 21469 -244 CACCACATCACATATACCAAGCCTGGCTGTGTCTTCT <;9<<5><<<<><<<>><<><>><9>><>>>9>>><> XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:5 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:35
 
  9:21597+10M2I25M:R:-209 83 1 21678 0 8M2I27M = 21469 -244 CACCACATCACATATACCAAGCCTGGCTGTGTCTTCT <;9<<5><<<<><<<>><<><>><9>><>>>9>>><> XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:5 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:35
Line 198: Line 234:  
|TAGs
 
|TAGs
 
|XT:A:U NM:i:0 SM:i:37 AM:i:0 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
 
|XT:A:U NM:i:0 SM:i:37 AM:i:0 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
|XT:A:R NM:i:0 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
+
|RG:Z:UM0098:1 XT:A:R NM:i:0 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:37
 
|XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:18^CA19
 
|XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:4 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:18^CA19
 
|XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:5 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:35
 
|XT:A:R NM:i:2 SM:i:0 AM:i:0 X0:i:5 X1:i:0 XM:i:0 XO:i:1 XG:i:2 MD:Z:35
 
|}
 
|}
   −
You should now be a SAM expert ;-)
+
== Tips/Tricks ==
 +
*Calculating BAM Block Size
 +
** Block Size = 8*4 + ReadNameLength(including null) + CigarLength*4 + (ReadLength+1)/2 + ReadLength + TagLength
 +
 
 +
 
 +
 
 +
You should now be a SAM expert :-)
61

edits

Navigation menu