Tutorial: Low Pass Sequence Analysis: Difference between revisions

From Genome Analysis Wiki
Jump to navigationJump to search
Csidore (talk | contribs)
Csidore (talk | contribs)
No edit summary
Line 40: Line 40:
* Q2: Which is the base quality of the fifth nucleotide of this read?
* Q2: Which is the base quality of the fifth nucleotide of this read?


== Mapping reads to the genome ==


There are many different tools for mapping DNA sequence reads. One of the most commonly used tools is BWA, developed by Heng Li and Richard Durbin at the Sanger Center. As with other read mappers, BWA first builds an index of the reference genome and then uses this index to quickly assign each sequence read to a genomic location.  
There are many different tools for mapping DNA sequence reads. One of the most commonly used tools is BWA, developed by Heng Li and Richard Durbin at the Sanger Center. As with other read mappers, BWA first builds an index of the reference genome and then uses this index to quickly assign each sequence read to a genomic location.  
Line 45: Line 46:
To learn more about BWA, you should visit the BWA website at http://bio-bwa.sourceforge.net
To learn more about BWA, you should visit the BWA website at http://bio-bwa.sourceforge.net


Here, we will use GotCloud to run BWA to find the most likely sequence location for each read using the <code>align</code> command. For time reasons we will map only 3 samples and you will find the remaining 2
Here, we will use GotCloud to run BWA to find the most likely sequence location for each read using the <code>align</code> command. For time reasons we will map only 3 samples and you will find the remaining 7 samples in the folder bams/


   
   
This command requires the configuration file, which contains the index file and the files to be used as reference.  
The <code>align</code> command requires the configuration file, which contains the index file and the files to be used as reference.  


  ${GC}/gotcloud/gotcloud align --conf ${GC}/examples/index/chr7.CFTR.align.conf --outDir align --baseprefix ${GC}/examples
cat configuration file
INDEX_FILE = index/chr20.smallregion.fastq.index
###################
# References
REF_DIR = ref
AS = NCBI37
REF = $(REF_DIR)/human_g1k_v37_chr20.fa
DBSNP_VCF =  $(REF_DIR)/dbsnp_135.b37.chr20.smallregion.vcf.gz
HM3_VCF = $(REF_DIR)/hapmap_3.3.b37.chr20.smallregion.sites.vcf.gz


So let's recap: we have mapped reads to genome, converted them from a BWA specific format to a more
You can find the index file containing the samples to be used in the index folder
commonly used format used by many different programs, sorted and indexed the results.


In most cases, the next step would be to remove duplicate reads and to ensure that base quality scores are properly calibrated. To save time, we'll skip those steps now.
cat index/chr20.smallregion.fastq.index


MERGE_NAME      FASTQ1  FASTQ2  RGID
HG00108 fastq/HG00108.lowcoverage.chr20.smallregion.fastq      .      .
HG00108 fastq/HG00108.lowcoverage.chr20.smallregion_1.fastq      fastq/HG00108.lowcoverage.chr20.smallregion_2.fastq    .
HG00111 fastq/HG00111.lowcoverage.chr20.smallregion.fastq      .      .
HG00111 fastq/HG00111.lowcoverage.chr20.smallregion_1.fastq    fastq/HG00111.lowcoverage.chr20.smallregion_2.fastq    .
HG00120 fastq/HG00120.lowcoverage.chr20.smallregion.fastq      .      .
HG00120 fastq/HG00120.lowcoverage.chr20.smallregion_1.fastq      fastq/HG00120.lowcoverage.chr20.smallregion_2.fastq    .
We are now ready to align our fastq files




=== SKIP THIS Converting Alignments to BAM format ===
  ${GC}/gotcloud/gotcloud align --conf ${GC}/examples/index/chr7.CFTR.align.conf --outDir align --baseprefix ${GC}/examples
 
The .sai alignment format is specific to BWA, so the first thing to do is to convert the alignment to a more standard format that will be compatible with downstream analysis tools. We can do this with a combination of the <code>bwa samse</code> command and <code>samtools view</code> and <code>samtoosl sort</code> commands.
 
  bwa samse ref/human_g1k_v37_chr20.fa bwa.sai/NA20589.sai fastq/NA20589.fastq.gz | \
      samtools view -uhS - | samtools sort -m 2000000000 - bams/NA20589
 
The result BAM file uses a compact binary format to represent the
alignment of each short read to the genome. You can view the contents
of the file using the <code>samtools view</code> command, like so:
 
  samtools view bams/NA20589.bam | more
 
The text representation of the alignemt produced by <code>samtools view</code> describes
the alignment of one read per line. The most interesting fields are column 1 (the read
name), columns 3 and 4 (the alignment position), column 5 (the CIGAR string, describing
any gaps in the alignment), and columns 10 and 11 (with the sequence and quality score). In this representation, all alignments are automatically converted to the forward strand.
 
=== Indexing the BAM file ===


<!--
GotCloud <code>align</code> command map the reads to the genome, mark duplicate reads and calibrates quality score to allow better error estimation in genotypes evaluation.
Although the current file contains all necessary information about reads and their
GotCloud also provide some statistics on the identity verification and contamination evaluation by using veryfyBamID and some useful quality statistics by using qplot
genomic locations, it is missing some auxiliary information that BAM files typically
contain to help describe their contents (for example, to specify that this file contains
DNA sequence reads for sample NA20589). So, the very next step is to add this information
to the file:


  samtools reheader bams/NA20589.header bams/noheader.NA20589.bam > bams/NA20589.bam
open the file .stats


!-->
Q4. Which is the depth of the sample HG00108? which is the Mapping Rate?


If you reached this far, rejoice! The mapping process is almost done. We will now create
and index for the file, which makes it convenient to quickly extract reads from any
genome location. We do this with the <code>samtools index</code> command, like so:
  samtools index bams/NA20589.bam


=== Browsing Alignment Results ===
=== Browsing Alignment Results ===
Line 106: Line 97:


Then, type "g 20:33350971" and press "." to hide the nucleotide equal to the reference to see the variant site at position 33350987
Then, type "g 20:33350971" and press "." to hide the nucleotide equal to the reference to see the variant site at position 33350987
You can play with the visualization help to set different way to visualize nucleotides, base qualities, mapping qualities and so on.
Press "?" in the tview screen to show the help and the available options


Another way to check the reads covering a position is to use <code>samtools mpileup</code>
Another way to check the reads covering a position is to use <code>samtools mpileup</code>
    
 
   samtools view  -uh  bams/HG00108.recal.bam 20:33350987 | samtools mpileup - | grep 33350987
The header of the mpileup format is "CHR    POS            REF    DEPTH  BASES   QUALITIES" 
 
   samtools view  -uh  bams/HG00108.recal.bam 20:33350987 | samtools mpileup - | grep 33350987
 


* Q3: Which is the depth of the position 33350987 ? Which would be the most likely genotype looking at the reads?
* Q3: Which is the depth of the position 33350987 ? Which would be the most likely genotype looking at the reads?
You can play with the visualization help to set different way to visualize nucleotides, base qualities, mapping qualities and so on.
Press "?" in the tview screen to show the help and the available options


== Initial set of variant calls ==
== Initial set of variant calls ==


The first thing we'll do is use samtools to generate an initial list of variant sites, using the <code>mpileup</code> command. This command looks at the bases aligned to each location and flags locations taht are likely to vary. By default, the results are stored in BCF file, which can be converted into the more widely used VCF format using bcftools (a companion set of tools distributed with samtools).
We can also use GotCloud to identify the SNPs present in our bam files and generating a VCF file containing the variant calls.
We will start by calling the variants of a single individual low pass


  samtools mpileup -r 20:42000000-44000000 -Iuf ref/human_g1k_v37_chr20.fa bams/NA*bam | bcftools view -bvcg - > mpileup/chr20.bcf
The variant calling pipeline has multiple built-in steps to generate BAMs:


  bcftools view mpileup/chr20.bcf  | sed s/AF1/AF/g | grep -v AF=1 > mpileup/chr20.vcf
    Filter out reads with low mapping quality
    Per Base Alignment Quality Adjustment (BAQ)
    Resolve overlapping paired end reads
    Generate genotype likelihood files
    Perform variant calling
    Extract features from variant sites
    Perform variant filtering


Again, GotCloud will take care of all these steps, we will focus on the interpretation of results.
Here are some questions for you to investigate:


The VCF format is a simple text format. It starts with several header lines, which all start with the two '##' characters, and is followed by a single line per marker that provides both summary information about the marker and genotypes for each individual. You can review the contents of the VCF file using the 'more' command:
The first section of the vcf is the header, every line in the header starts with "#".
You can find some useful information about the data that we are going to analyse.


  more mpileup/chr20.vcf
For a complete description of the vcf format, you can take a look at
http://www.1000genomes.org/wiki/Analysis/Variant%20Call%20Format/vcf-variant-call-format-version-41


Here are some questions for you to investigate:


* How many variant sites were detected in this dataset? Try a command like this one:
* How many variant sites were detected in this dataset? Try a command like this one:
Line 137: Line 140:


(The grep command line excludes all lines beginning with # and then the wc command counts the number of lines in the file).
(The grep command line excludes all lines beginning with # and then the wc command counts the number of lines in the file).


<!--  
<!--  

Revision as of 08:49, 3 September 2013

Sequence Analysis Workshop

In this workshop, we will illustrate some of the essential steps in the analysis of next generation sequence data. As part of the process, you will learn about many of the file formats commonly used to store next generation sequence data.

We will start with a set of short sequence reads and associated base quality scores (stored in a fastq file), find the most likely genomic location for each read (producing a BAM file), generate an initial list of polymorphic sites and genotypes (stored in a VCF file) and use haplotype information to refine these genotypes (resulting in an updated VCF file).

Example Dataset

Our dataset consists of 10 individuals sequenced by the 1000 Genomes Project. As with other 1000 Genomes Project samples, these individuals have been sequenced to an average depth of about 4x.

To conserve time and disk-space, our analysis will focus on a small region of chromosome 20, from 33,500,000 to 33,600,000 bp. We will first map reads for 3 individuals, test the variant caller on a single individual and then combine the results with mapped reads from the other 30 individuals to generate a list of polymorphic sites and estimate accurate genotypes at each of these sites. We will compare the results of the variant calling on the low pass dataset with results from the exome sequencing of the same individual. Finally we will use the LD refinement to increase the accuracy of our genotypes.

The example dataset we'll be using is included in this tar-ball FIX THIS!lowPassWorkshop-2012-01-23.tar.gz.

Required Software

In order to run this exercise, we already installed the package GotCloud in the workshop machines, which contains most of the softwares commonly used for next generation sequencing data.

Building an Index for Short Read Alignment

To quickly place short reads along the genome, BWA and other read mappers typically build a word index for the genome. This index lists the location of particular short words along the genome and can be used to seed and then extend particular matches.

The sequence index is typically not compatible across different BWA versions. To rebuild the sequence index, issue the following commands:

 rm ref/human_g1k_v37_chr20.fa.*
 bwa index -a is ref/human_g1k_v37_chr20.fa


A quick look to the fastq files

The sequencers provides unmapped reads which are stored in fastq file. For this workshop, you will find DNA sequence reads for 3 samples in fastq format. To conserve disk space, the files have been compressed with gzip but, since fastq is a simple text format, you can easily view the contents of the files using a command like:

 zcat HG00111.fastq_1.gz | more

A fastq file consists of a series of multi-line records. Each record starts with a read name, followed by a DNA sequencing, a separator line, and a set of per base quality scores. Base quality scores estimate the probability of error at each sequenced base (a base quality of 10 denotes an error probability of 10%, base quality 20 denotes 1% error probability and base quality 30 denotes 0.1% error probability). These error probabilities are each encoded in a single character (for compactness) and can be decoded using an [1] - you should look up the ascii code for each base and subtract 33 to get base quality. By inspecting the FastQ file you should be able to learn about the length of reads being mapped and their base qualities (is base quality typically higher at the start or end of each read). For each sample you will find two fastq file, since the 1000G samples are sequenced in pair end, thus each DNA fragment has been sequenced twice, in the forward and reverse direction

  • Q1: How long is the first read in the file HG00111_1.fastq.gz
  • Q2: Which is the base quality of the fifth nucleotide of this read?

Mapping reads to the genome

There are many different tools for mapping DNA sequence reads. One of the most commonly used tools is BWA, developed by Heng Li and Richard Durbin at the Sanger Center. As with other read mappers, BWA first builds an index of the reference genome and then uses this index to quickly assign each sequence read to a genomic location.

To learn more about BWA, you should visit the BWA website at http://bio-bwa.sourceforge.net

Here, we will use GotCloud to run BWA to find the most likely sequence location for each read using the align command. For time reasons we will map only 3 samples and you will find the remaining 7 samples in the folder bams/


The align command requires the configuration file, which contains the index file and the files to be used as reference.

cat configuration file

INDEX_FILE = index/chr20.smallregion.fastq.index
###################
# References
REF_DIR = ref
AS = NCBI37
REF = $(REF_DIR)/human_g1k_v37_chr20.fa
DBSNP_VCF =  $(REF_DIR)/dbsnp_135.b37.chr20.smallregion.vcf.gz
HM3_VCF = $(REF_DIR)/hapmap_3.3.b37.chr20.smallregion.sites.vcf.gz

You can find the index file containing the samples to be used in the index folder

cat index/chr20.smallregion.fastq.index
MERGE_NAME      FASTQ1  FASTQ2  RGID
HG00108 fastq/HG00108.lowcoverage.chr20.smallregion.fastq       .       .
HG00108 fastq/HG00108.lowcoverage.chr20.smallregion_1.fastq      fastq/HG00108.lowcoverage.chr20.smallregion_2.fastq     .
HG00111 fastq/HG00111.lowcoverage.chr20.smallregion.fastq       .       .
HG00111 fastq/HG00111.lowcoverage.chr20.smallregion_1.fastq     fastq/HG00111.lowcoverage.chr20.smallregion_2.fastq     .
HG00120 fastq/HG00120.lowcoverage.chr20.smallregion.fastq       .       .
HG00120 fastq/HG00120.lowcoverage.chr20.smallregion_1.fastq      fastq/HG00120.lowcoverage.chr20.smallregion_2.fastq     .

We are now ready to align our fastq files


 ${GC}/gotcloud/gotcloud align --conf ${GC}/examples/index/chr7.CFTR.align.conf --outDir align --baseprefix ${GC}/examples

GotCloud align command map the reads to the genome, mark duplicate reads and calibrates quality score to allow better error estimation in genotypes evaluation. GotCloud also provide some statistics on the identity verification and contamination evaluation by using veryfyBamID and some useful quality statistics by using qplot

open the file .stats

Q4. Which is the depth of the sample HG00108? which is the Mapping Rate?


Browsing Alignment Results

You can view the contents of the alignment at any location using the samtools view and samtools tview commands. While the tview generates prettier output, it is not compatible with all screens. For example, to view reads overlapping starting at position 43,000,000 on chromosome 20, we could run:

  samtools tview bams/NA20589.bam ref/human_g1k_v37_chr20.fa

Then, type "g 20:33350971" and press "." to hide the nucleotide equal to the reference to see the variant site at position 33350987

You can play with the visualization help to set different way to visualize nucleotides, base qualities, mapping qualities and so on. Press "?" in the tview screen to show the help and the available options


Another way to check the reads covering a position is to use samtools mpileup

The header of the mpileup format is "CHR POS REF DEPTH BASES QUALITIES"

 samtools view  -uh  bams/HG00108.recal.bam 20:33350987 | samtools mpileup - | grep 33350987


  • Q3: Which is the depth of the position 33350987 ? Which would be the most likely genotype looking at the reads?

Initial set of variant calls

We can also use GotCloud to identify the SNPs present in our bam files and generating a VCF file containing the variant calls.

The variant calling pipeline has multiple built-in steps to generate BAMs:

   Filter out reads with low mapping quality
   Per Base Alignment Quality Adjustment (BAQ)
   Resolve overlapping paired end reads
   Generate genotype likelihood files
   Perform variant calling
   Extract features from variant sites
   Perform variant filtering 

Again, GotCloud will take care of all these steps, we will focus on the interpretation of results. Here are some questions for you to investigate:

The first section of the vcf is the header, every line in the header starts with "#". You can find some useful information about the data that we are going to analyse.

For a complete description of the vcf format, you can take a look at http://www.1000genomes.org/wiki/Analysis/Variant%20Call%20Format/vcf-variant-call-format-version-41


  • How many variant sites were detected in this dataset? Try a command like this one:
 grep -vE ^# chr20.vcf | wc -l

(The grep command line excludes all lines beginning with # and then the wc command counts the number of lines in the file).


Genotype Refinement Using Linkage Disequilibrium Information

The initial set of genotype calls is generated examining a single individual at a time. These calls are typically quite good for deep sequencing data, but much less accurate for low pass sequence data. In either case, they can be greatly improved by models that combine information across sites and individuals.

Here is how that might work:

  thunderVCF --shotgun mpileup/chr20.vcf --phase --dosage -r 10 --prefix thunder/chr20.thunder

Again, you can review the contents of the updated VCF file using the more command:

  more thunder/chr20.vcf