ANGSD: Analysis of next generation Sequencing Data

Latest tar.gz version is (0.938/0.939 on github), see Change_log for changes, and download it here.

Error estimation

From angsd
Revision as of 14:18, 7 December 2013 by Thorfinn (talk | contribs) (→‎Options)
Jump to navigation Jump to search

ANGSD currently has 2 different methods for estimating error rates.

  1. A method that will estimate the joint typespecific errorrates for multiple samples. This method is using the minor allele frequency as prior, and therefore this method can not be used for single samples.
  1. A method that that uses an outgroup and an 'errorfree' individual. Useful for single samples.

The typespecific errorrates is an matrix, with the errorates of observing base A but in reality it was base C etc.

Error estimation from polymorphic sites

The method for estimating typespecific errors is described in Kim2011, and is based on the counts of the 4 different nucleotides. This method should be applied to the sites that are variable and the measure for variability is the simple MAF estimator that is described in Li2010.

Brief Overview

./angsd -doError 
        -> angsd version: 0.564  build(Dec  6 2013 12:52:55)
        -> Analysis helpbox/synopsis information:
---------------------
analysisEstError.cpp:
-doError        0
        1: SYK method, joint typespecific errors (Multisample)
        -minSites       10000
        -errors         (null)  (Filename for starterrors)
        -emIter         100
        -minPhat        0.005000        (Minimum phat)
        -eps            0.001000        (Estimate of errorrate)
        NB this method requires -doMajorMinor 2

Options

-numSites [int]

default 10000. This is the number of sites we want to use for this analysis.

-cutoff [float]

default 0.005. This means we only run the error estimation on sites with a MAF>0.005. This should be modified according to the number of samples in the dataset.

-eps [float]

default 0.001.This is a guess of the errorrate in the sample, this is used for the simple MAF estimator

-errors [filename]

This file should contain a guess of the typespecific errors.


To further refine what data should be used please see alleles counts.

Example

The simplest example is:

./angsd -bam smallBam.filelist -doCounts 1 -out test  -doError 1 -doMajorMinor 2 -nThreads 2 -minSites 1000 

Or a more elaborate example where we only want to estimate the typespecific errors for the "good" data:

./angsd -bam smallBam.filelist -doCounts 1 -out test2  -doError 1 -doMajorMinor 2 -nThreads 2 -minSites 1000 -minQ 20 -minMapQ 30

Output

#test
0.000000	0.005488	0.003847	0.003137\
0.006807	0.000000	0.001972	0.002396\
0.002190	0.001855	0.000000	0.008068\
0.002491	0.004268	0.005812	0.000000
#test2
0.000000	0.000071	0.003381	0.001254\
0.003989	0.000000	0.000000	0.002568\
0.002270	0.000000	0.000000	0.003650\
0.001451	0.004327	0.000974	0.000000

Notice that we for the more stringent test2 dataset have somewhat lower error rates. But we should really choose a much larger number of sites to do this analysis. Each line has 16 entries corresponding to the type specific errors for a region of -numsites.

NB Currently the ordering of each line, can not be interpreted as the error rates along the genome, due to the threading. This will likely change in future versions.

We can visualise this easily in R, see figures on right side (These are not the values from the above)

a <- as.numeric(read.table("test.error.chunkunordered",nrow=1))
b <- as.numeric(read.table("test2.error.chunkunordered",nrow=1))
DNA<-c("A","C","G","T")
names(a) <- as.vector((sapply(1:4,function(x) paste(DNA[x],DNA,sep="->"))))
barplot(a)
barplot(b)

Error estimation using an outgroup and an error free individual

The estimated rates can roughly be interpreted as relative error rates. That is excess of derived alleles in your sample compare to the derived alleles in the an error free indviduals The idea is the your sample and the error free individuals should have the same expected number of derived alleles and the extra observed derived alleles in you sample are due to the excess error. For each individual we sample a single base from the reads at each position. We use only positions were there are coverage for both the outgroup, the sample and the error free individual. See theory section below for more details.

Brief Overview

./angsd -doAnsError 
	-> angsd version: 0.564	 build(Dec  7 2013 13:58:19)
	-> Analysis helpbox/synopsis information:
--------------
analysisAnsError.cpp:
	-doAnsError	0
	1: EM v1 
	2: EM v2 (Under development, don't use)
	-sample	1	(Sampling strategies, for EM v1)
	 0:	 (Use all bases)
	 1:	 (Sample single base)
	 2:	 (Sample first base)
Required:
	-ref	(null)	(fastafile containg 'perfect' sample)
	-anc	(null)	(fastafile containg outgroup)

To make matters explicit: For this analysis, the -ref should not be your reference, but a fasta file containing the consensus of a 'perfect' sample. The method will calculate the difference between the -ref and -anc, and the difference between the supplied BAM files, and interpret the excess of difference as an error. You can generate a consensus fasta with -doFasta.

Options

-doAnsError 1

Use -doAnsError to use this analysis

-anc [filename]

fasta file with the ancestral alleles

-ref [filename]

fasta file of an error free individual.

-sample [int]

0: Use all reads

1: Sample only one base per site (default)

2: Use first base per site

To further refine what data should be used please see alleles counts.

Example

- angsd -doAnsError 1 -anc chimpHg19.fa -ref hg19perfect.fa -out results -bam bam.filelist
- Rscript R/estError.R file=results.ancError

typing Rscript R/estError.R will give you additional options for plotting the results

Output

  1. The output from the angsd cprogram is in a horrible format.
  2. The Rscript will output the type specific errors and the overall errors. It will also produce two figures. One will the type specific errors and one with the overall errors. If a lot of individuals are included in the analysis the figure will need to be modified.

Theory

Method 1

Method 2

The estimated rates can roughly be intrepreted as relative error rates. That is excess of errors in your sample compare to the error in the perfect indviduals. The idea is the your sample and the perfect individuals should have the same expected number of derived alleles and the extra derived alleles in you sample are due to the excess errorr. For each individual we sample a single base from the reads at each position. We use only positions were there are coverage for both the chimp, the sample and the perfect man. The overall error rate is obtained from


were

  • is the error rate
  • is the observed number of derived alleles in the sample
  • is the expected number of derived alleles which is obtained from the observed derived alleles from the perfect man
  • is the expected number of ancestral alleles which is obtained from the perfect man

For the type specific error rates are obtained from maximizing the likehood

where

  • is the allele of you sample
  • is the allele of the chimp
  • is the error rate for base a to base b
  • are obtained from the perfect man assuming that the perfect man has no errors.