SAMtools

SAMtools is a quite of commands for dealing with databases of mapped reads. You'll be using it quite a bit throughout the course.

Right now, we'll be using it to call variants (find mutations) in the re-sequenced E. coli genome from the Introduction to mapping (bowtie, BWA). You will need the output SAM files from that tutorial to continue here.

Create a new output directory:

mkdir samtools_bowtie

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

cp bowtie/SRR030257.sam samtools_bowtie/ 
cp bowtie/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.)

samtools faidx samtools_bowtie/NC_012967.1.fasta

Take a look at the new file that was created by this command.

SAM is a text file, so it is slow to access information about a read. SAMtools and many of the commands that we will run later work on BAM files (essentially 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 -bS -o samtools_bowtie/SRR030257.bam bowtie/SRR030257.sam |borderStyle=solid}

Sort the BAM file.

samtools sort samtools_bowtie/SRR030257.bam samtools_bowtie/SRR030257.sorted

Output VCF file.

samtools mpileup -uf samtools_bowtie/NC_012967.1.fasta samtools_bowtie/SRR030257.sorted.bam \|bcftools view -vcg - \> samtools_bowtie/output.vcf 

Output - Samtools

Exercise 1

VCF format has Allele Frequency tags denoted by AF1. Try the following command to see what values we have in our files.

cat input.vcf | grep AF1

For the data we are dealing with, predictions with an allele frequency not equal to 1 are not really applicable. How can we remove these lines from the file and continue on?

What does the -v flag do in grep?

grep -v *something*

Solutions

Output - Filtering Allele Frequencies

Determining Differences Between Mappers.

Setup output directory and then change into it.

mkdir output
cp samtools_bowtie/output.vcf output/bowtie.vcf
cp samtools_bwa/output.vcf output/bwa.vcf
cd output

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.

Load Bedtools.

module load bedtools

Finding alike mutations.

intersectBed -a bowtie.vcf -b bwa.vcf > intersect.vcf

Finding unique mutations for each mapper.

subtractBed -a bowtie.vcf -b intersect.vcf > unique_bowtie.vcf
subtractBed -a bwa.vcf -b intersect.vcf > unique_bwa.vcf

Output - Determining Differences Between Mappers