Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

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

Table of Contents

Calling variants in reads mapped by bowtie

...

Create a new output directory called samtools_bowtie or whatever makes sense to you.

Let's copy over just the read alignment file in the SAM format and the reference genome in FASTA format to the this new directory, so that we don't have so many files cluttering our space.

Expand
Commands for doing this if you've been following the tutorials...
Commands for doing this if you've been following the tutorials...
Code Block
mdkdirmkdir samtools_bowtie
cp bowtie/SRR030257.sam samtools_bowtie
cp bowtie/NC_012967.1.fasta samtools_bowtie

...

First, you need to index the reference file. (This isn't indexing it for read mapping. It's indexing it so that SAMtools can quickly jump to a certain base in the reference.)

Then run this command to index the reference file.

Code Block
samtools faidx samtools_bowtie/NC_012967.1.fasta

...

  • What new files were created by these commands?
    Expand
    Check that
    Check that
    Code Block
    titleList the contents of the output directory
    
    ls samtools_bowtie
    
    Code Block
    titleExpected output
    
    NC_012967.1.fasta      SRR030257.sorted.bam.bai
    NC_012967.1.fasta.fai  SRR030257.sam
    SRR030257.bam          SRR030257.sorted.bam
    
  • Why didn't we name the output SRR030257.sorted.bam in the samtools sort command?
    Expand
    Answer...
    Answer...

    Samtools appends an extra .bam to whatever we put here, so it would have created SRR030257.sorted.bam.bam, and we would have had to make a joke about the Flintstones.

  • Can you guess what a *.bai file is?
    Expand
    Answer...
    Answer...

    Sure enough, it's the index file for the BAM file.

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

Code Block
titleThis is *one* command. Put it all on one line.
samtools mpileup -u -f samtools_bowtie/NC_012967.1.fasta  samtools_bowtie/SRR030257.sorted.bam > samtools_bowtie/SRR030257.bcf

...

Convert BCF to human-readable VCF:

Code Block
titleThis is *one* command. Put it all on one line.
bcftools view -v -c -g samtools_bowtie/SRR030257.bcf > samtools_bowtie/SRR030257.vcf

...

Take a look at the samtools_bowtie/SRR030257.vcf file using less. It has a nice header explaining what the columns mean.

...

Below this are the rows of data describing potential genetic variants.

Optional Exercises

Calling variants in reads mapped by BWA or Bowtie2

Anchor
Calling variants in reads mapped by BWA or Bowtie2
Calling variants in reads mapped by BWA or Bowtie2

Follow the same directions to call variants in the BWA or Bowtie2 mapped reads.

Just be sure you don't write over your old files. Maybe create new directories like samtools_bwa and samtools_bowtie2 for the output in each case.

You could also try running all of the commands from inside of the samtools_bwa directory, just for a change of pace.

Filtering VCF files with grep

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

...

Expand
Solution...
Solution...
Code Block
cat input.vcf | grep AF1=1 > output.vcf

Is not practical, since we will lose vital VCF formatting and may not be able to use this file in the future.

Code Block
cat input.vcf | grep -v AF1=0 > output.vcf

Will preserve all lines that don't have a AF1=0 value and is one way of doing this.

Code Block
sed -i '/AF1=0/ d' input.vcf

Is a way of doing it in-line and not requiring you to make another file. (But it writes over your existing file!)

...

Comparing the results of different mappers using bedtools

You will need the output from #Calling variants in reads mapped by BWA or Bowtie2

...

Follow the same directions to call variants in the BWA or Bowtie2 mapped reads.

Just be sure you don't write over your old files. Maybe create new directories like samtools_bwa and samtools_bowtie2.

You could also try running all of the commands from inside of the samtools_bwa directory, just for a change of pace.

Comparing the results of different mappers

to complete this exercise.

Often you want to compare the results of variant calling on different samples or using different pipelines. Bedtools is a suite of utility programs that work on a variety of file formats, one of which is conveniently VCF format. It provides many ways of slicing, dicing, and comparing the information in VCF files. For example, we can use it to find out what predictions are the same and which are different from the variant calling on reads mapped with different programs.

...

Expand
I'm stuck? Show me the commands...
I'm stuck? Show me the commands...

Load Bedtools.

Code Block
module load bedtools

Finding common mutations.

Code Block
bedtools intersect -a bowtie.vcf -b bwa.vcf > common_bowtie_bwa.vcf

Finding mutations that are unique for each mapper.

Code Block
bedtools subtract -a bowtie.vcf -b common_bowtie_bwa.vcf > unique_bowtie.vcf
bedtools subtract -a bwa.vcf -b common_bowtie_bwa.vcf > unique_bwa.vcf

Further Optional Exercises

  • Which mapper finds more variants?
  • Can you figure out how to filter the VCF files on various criteria, like coverage, quality, ... ?
  • How many high quality mutations are there in these E. coli samples relative to the reference genome?

From here...

*Look at how the reads supporting these variants were aligned to the reference genome in the Integrative Genomics Viewer (IGV) tutorial.
*Look into more sophisticated Variant+calling+with+GATK.