SAMtools is a suite of commands for dealing with databases of mapped reads. You'll be using it quite a bit throughout the course. It includes programs for performing variant calling (mpileup-bcftools).
Right now, we'll be using it to call variants (find mutations) in the re-sequenced E. coli genome from the Mapping tutorial. You will need the output SAM files from that tutorial to continue here. We assume that you are still in the main directory of
intro_to_mapping data that you copied to
Load the SAMtools module (if not already loaded):
module load samtools
What version of samtools is loaded on TACC?
Create a new output directory:
Let's copy over the read alignment file in the SAM format and the reference genome in FASTA format to the new directory, so that we don't have so many files cluttering our space.
cp bowtie/SRR030257.sam samtools_bowtie cp NC_012967.1.fasta samtools_bowtie
Index the reference file. (This isn't indexing it for mapping. It's indexing it so that SAMtools can quickly jump to a certain base in the reference.)
samtools faidx samtools_bowtie/NC_012967.1.fasta
Take a look at the new *.fai file that was created by this command. Any idea what some of the numbers mean?
SAM is a text file, so it is slow to access information about how any given read was mapped. SAMtools and many of the commands that we will run later work on BAM files (essentially GZIP compressed binary forms of the text SAM files). These can be loaded much more quickly. Typically, they also need to be sorted, so that when the program wants to look at all reads overlapping position 4,129,888, it can easily find them all at once without having to search through the entire BAM file.
Convert from SAM to BAM format.
samtools view -b -S -o samtools_bowtie/SRR030257.bam samtools_bowtie/SRR030257.sam
Sort and index the BAM file.
samtools sort samtools_bowtie/SRR030257.bam samtools_bowtie/SRR030257.sorted samtools index samtools_bowtie/SRR030257.sorted.bam
What new files were created by these commands? Why didn't we name the output
SRR030257.sorted.bam? Can you guess what a *.bai file is?
Hint: You might be tempted to
gzip BAM files when copying them from one computer to another. Don't bother! They are already internally compressed, so you won't be able to shrink the file. On the other hand, compressing SAM files will save a fair bit of space.
Output BCF file. This is a binary form of the text Variant Call Format (VCF).
samtools mpileup -u -f samtools_bowtie/NC_012967.1.fasta samtools_bowtie/SRR030257.sorted.bam > samtools_bowtie/SRR030257.bcf
Convert BCF to VCF:
bcftools view -v -c -g samtools_bowtie/SRR030257.bcf > samtools_bowtie/SRR030257.vcf
Take a look at this file. It has a nice header explaining what the columns mean.
VCF format has Allele Frequency tags denoted by AF1. Try the following command to see what values we have in our files.
grep AF1 samtools_bowtie/SRR030257.vcf
For the data we are dealing with, predictions with an allele frequency not equal to 1 are not really applicable here. (The reference genome is haploid. There aren't any heterozygotes.) How can we remove these lines from the file and continue on?
What does the -v flag do in grep?
Is not practical, since we will lose vital VCF formatting and may not be able to use this file in the future.
Will preserve all lines that don't have a AF1=0 value and is one way of doing this.
Is a way of doing it in-line and not requiring you to make another file.
Follow the same directions to call variants in the BWA-mapped reads.
Just be sure you don't write over your old files. Maybe create another new directory:
You could also try running all of the commands from inside of the
samtools_bwa directory, just for a change of pace.
Set up a new output directory and copy the respective VCF files to it.
mkdir comparison cp samtools_bowtie/SRR030257.vcf comparison/bowtie.vcf cp samtools_bwa/SRR030257.vcf comparison/bwa.vcf cd comparison
Bedtools is a suite of utility programs that work on a variety of file formats, one of which is conveniently VCF format. Using intersectBed and subtractBed we can find equal and different predictions between mappers.
module load bedtools
Finding common mutations.
intersectBed -a bowtie.vcf -b bwa.vcf > common_bowtie_bwa.vcf
Finding mutations that are unique for each mapper.
subtractBed -a bowtie.vcf -b common_bowtie_bwa.vcf > unique_bowtie.vcf subtractBed -a bwa.vcf -b common_bowtie_bwa.vcf > unique_bwa.vcf
Look at how the reads supporting these variants were aligned to the reference genome by continuing the Integrative Genomics Viewer (IGV) tutorial.