Short Read Mapping
Sam, Bam File Formats
SCP
Can I use Blast or Diamond?
Short Read Mappers
ACGTTGCTAGCGGTCAGTAATCGGCCCGTATCGATATATGGCG
Reference Genome
Read 1 Read 2
CAATCGCCCC ACGTTCTA
? ?
Heinz 1706
Cherokee purple
Where in the genome did each of the short reads originate?
ACGTTGCTAGCGGTCAGTAATCGGCCCGTATCGATATATGGCG
Reference Genome
Read 2 Read 1
ACGTT CTA CAATCGCCCC
||||| ||| ||||| |||
Short Read Mappers
Bwa-mem2
Ambystoma mexicanum Paris japonica Pinus taeda
32Gb 150Gb 22Gb
Indexing Strategies
Algorithms
BWA mem
Unique Read Mapping
? ? ?
The read matches to each location equally well.
Clever Ways to find “Best” Alignments
How BWA-MEM2 Processes Multi-Mapping Reads
Scenario 1. The full read maps to one or more locations.
SECONDARY
Alignments
Scenario 2. Part of the read maps to one location, part of the read maps to another.
SUPPLEMENTARY
Alignments
Ref genome
Ref genome
read
read
How BWA-MEM2 Processes Multi-Mapping Reads
Scenario 1. The full read maps to one or more locations.
SECONDARY Alignments
Bwa-mem2 outputs NO secondary alignments by default; you only get flag-256 records with -a.
Scenario 2. Part of the read maps to one location, part of the read maps to another.
SUPPLEMENTARY Alignments
Did It Actually Work? Mapping QC
samtools flagstat aln.bam # % mapped, % properly paired,
duplicates
samtools stats aln.bam # insert size, error rate, coverage
(plot-bamstats)
Red flags:
Read Groups: the @RG Line You Need for GATK and Picard Tools
-R '@RG\tID:run1\tSM:sample1\tPL:ILLUMINA\tLB:lib1'
When to use bwa-mem2
Choosing a mapper:
Caution: Reference Mismatches
PAUSE
Go get fastqc started….
III. SAM, BAM AND CRAM FORMAT
SAM Format
Formats we’ve already learned:
SAM Format
Strengths
SAM
Example sam with one read:
@SQ SN:gi|254160123|ref|NC_012967.1| LN:4629812
@PG ID:bwa PN:bwa VN:0.7.12-r1039 CL:/lustre/projects/rnaseq_ws/apps/bwa-0.7.12/bwa sampe ../raw_data/NC_012967.1.fasta aln_SRR030257_1.sai aln_SRR030257_2.sai ../raw_data/SRR030257_1.fastq ../raw_data/SRR030257_2.fastq
SRR030257.1 99 gi|254160123|ref|NC_012967.1| 950180 60 36M = 950295 151 TTACACTCCTGTTAATCCATACAGCAACAGTATTGG AAA;A;AA?A?AAAAA?;?A?1A;;????566)=*1 XT:A:U NM:i:1 SM:i:37 AM:i:25 X0:i:1 X1:i:0 XM:i:1 XO:i:0 XG:i:0 MD:Z:32C3
SAM - Header
@
@
@
@
Read Info
Read Info
Read Info
SAM - Header
Simple Header
@HD = first line
VN = version of SAM format
SO = sort order (this is sorted by coordinates)
@HD VN:1.5 SO:coordinate
@SQ SN:ref LN:45
@SQ = reference sequence
SN = Sequence reference Name
LN = seqeunce reference length
Decipher header information: https://samtools.github.io/hts-specs/SAMv1.pdf
Alignment Line
Below the headers are the alignment records
Tab-delimited fields
1 QNAME Query template/pair NAME
2 FLAG bitwise FLAG
3 RNAME Reference sequence NAME
4 POS 1-based leftmost POSition/coordinate of clipped sequence
5 MAPQ MAPping Quality (Phred-scaled)
6 CIGAR extended CIGAR string
7 MRNM Mate Reference sequence NaMe (`=' if same as RNAME)
8 MPOS 1-based Mate POSistion
9 TLEN inferred Template LENgth (insert size)
10 SEQ query SEQuence on the same strand as the reference
11 QUAL query QUALity (ASCII-33 gives the Phred base quality)
12+ OPT variable OPTional fields in the format TAG:VTYPE:VALUE
Lets unpack this alignment line, taken from a SAM file. Tab delimited:
SRR030257.2000020 83 gi|254160123|ref|NC_012967.1| 3295752 60 36M = 3295706 -82 TGCTGGCGGCGATATCGTCCGTGGTTCCGATCTGGT ?%<91<?>>??AAAAAAAAAAAAAAAAAAAAAAAAA XT:A: NM:i:0 SM:i:37 AM:i:37 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:36
SAM Field 1
Query name = Read name
SRR030257.2000020
Field 2:
Flag
83
64 + 16 + 2 + 1
1 = Read is paired
2 = Read mapped in proper pair
16 = Read mapped to reverse strand
64 = First in pair
Look up a SAM flag: https://broadinstitute.github.io/picard/explain-flags.html
Online tools can help decipher the flag:
SAM Field 3
Reference sequence name (useful especially if you have multiple chromosomes)
gi|254160123|ref|NC_012967.1|
SAM Field 4
Position- 1-based leftmost mapping position of the first matching base
3295752
SAM Field 5
Mapping Quality, Phred-scaled. bwa caps at 60; the SAM spec allows 0–254 (255 = unavailable)
60 0.0001% probability wrong (1 in 1,000,000)
SAM Field 6
CIGAR String
36M 36 bases consume query AND reference
8S28M 8 bases soft-clipped, 28 aligned
bwa mem only ever emits M — never = or X — so mismatches hide inside M
M does NOT mean "perfect match" — it means alignment match and INCLUDES mismatches.
More CIGAR
Position: 5
CIGAR: 3M1I3M1D5M
The Full CIGAR Operation Table
Op Meaning Consumes
M alignment match (match OR mismatch) query + ref
I insertion relative to the reference query
D deletion from the reference ref
N skipped region (intron in RNA-seq) ref
S soft clip — bases REMAIN in SEQ query
H hard clip — bases REMOVED from SEQ neither
P padding
= true match
X mismatch
SAM Field 7
Reference sequence for the next read in the template
= reverse read maps on the same reference
SAM Field 8
Position where the next read maps
3295706
SAM Field 9
Observed template length
From leftmost base to rightmost base
Negative if this read is the rightmost read
-82
R1
R2
Template length
SAM Field 10
Sequence of the read
TGCTGGCGGCGATATCGTCCGTGGTTCCGATCTGGT
SAM Field 11
Quality of the read
?%<91<?>>??AAAAAAAAAAAAAAAAAAAAAAAAA
SAM Field 12
Optional MORE information
TAG:TYPE:VALUE format
XT:A:U NM:i:0 SM:i:37 AM:i:37 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:36
Anything with an X is specified by the user or by the mapping software, and is not part of the SAM spec.
Tags from bwa-mem2
NM:i: edit distance to the reference (mismatches + indel bases)
MD:Z: which reference bases mismatched — reconstruct ref without loading it
AS:i: alignment score of THIS alignment
XS:i: score of the best OTHER alignment
XA:Z: up to 5 alternative hits, as chr,pos,CIGAR,NM;
SA:Z: pointer to supplementary alignments (the split reads, flag 2048)
MC:Z / MQ:i mate’s CIGAR and MAPQ RG:Z read group
BAM Format
CRAM
Fritz, Markus Hsi-Yang, et al. "Efficient storage of high throughput DNA sequencing data using reference-based compression." Genome research 21.5 (2011): 734-740.
Moving Data
SCP
Remember our previous cp command:
cp <location of what we want> <location where it should go>
cp from to
SCP
From a local directory to Sphinx:
scp file.txt mstaton1@sphinx.ag.utk.edu:~
From Sphinx to your local directory:
scp mstaton1@sphinx.ag.utk.edu:~/file.txt .
Local file
Username
Remote Machine
Remote location to place file
Username
Remote Machine
Remote Location
Local Location