org.biojava.bio.program.phred
Class PhredTools

java.lang.Object
  extended by org.biojava.bio.program.phred.PhredTools

public final class PhredTools
extends Object

PhredTools contains static methods for working with phred quality data.

Copyright (c) 2001

Company: AgResearch

Since:
1.1 Note that Phred is a copyright of CodonCode Corporation.
Author:
Mark Schreiber, Matthew Pocock

Constructor Summary
PhredTools()
           
 
Method Summary
static SymbolList createPhred(SymbolList dna, SymbolList quality)
          Merges a Symbol List from the DNA alphabet with a SymbolList from the [0..99] subset of the IntegerAlphabet into a SymbolList from the PHRED alphabet.
static Symbol dnaSymbolFromPhred(Symbol phredSym)
          Retrives the DNA symbol component of the Phred BasisSymbol from the PHRED alphabet.
static FiniteAlphabet getPhredAlphabet()
          Retrieves the PHRED alphabet from the AlphabetManager.
static Symbol getPhredSymbol(Symbol dna, Symbol integer)
          Creates a symbol from the PHRED alphabet by combining a Symbol from the DNA alphabet and a Symbol from the IntegerAlphabet (or one of its subsets).
static IntegerAlphabet.IntegerSymbol integerSymbolFromPhred(Symbol phredSym)
          Retrives the IntegerSymbol component of the Phred BasisSymbol from the PHRED alphabet.
static double pFromQuality(double quality)
          Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)
static double pFromQuality(int quality)
          Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)
static double pFromQuality(IntegerAlphabet.IntegerSymbol quality)
          Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)
static Distribution[] phredAlignmentToDistArray(Alignment a)
          converts an Alignment of PhredSequences to a Distribution[] where each position is the average distribution of the underlying column of the alignment.
static Distribution[] phredToDistArray(PhredSequence s)
          Converts a Phred sequence to an array of distributions.
static double qualityFromP(double probOfError)
          The quality value is related to the base call error probability by the formula QV = - 10 * log_10( P_e ) where P_e is the probability that the base call is an error.
static StreamReader readPhredQuality(BufferedReader br)
          Constructs a StreamReader to read in Phred quality data in FASTA format.
static StreamReader readPhredSequence(BufferedReader br)
          Calls SeqIOTools.readFastaDNA(br), added here for convinience.
static void writePhredQuality(OutputStream qual, OutputStream seq, SequenceDB db)
          Writes Phred quality data in a Fasta type format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhredTools

public PhredTools()
Method Detail

getPhredAlphabet

public static final FiniteAlphabet getPhredAlphabet()
Retrieves the PHRED alphabet from the AlphabetManager. The Phred alphabet is a cross product of a subset of the IntegerAlphabet from 0...99 and the DNA alphabet. The Phred alphabet is finite. The Phred Alphabet contains 400 BasisSymbols named, for example, (guanine 47). The BasisSymbols can be fragmented into their component AtomicSymbols using the getSymbols() method of BasisSymbol.


dnaSymbolFromPhred

public static final Symbol dnaSymbolFromPhred(Symbol phredSym)
                                       throws IllegalSymbolException
Retrives the DNA symbol component of the Phred BasisSymbol from the PHRED alphabet.

Throws:
IllegalSymbolException - if the provided symbol is not from the PHRED alphabet.

integerSymbolFromPhred

public static final IntegerAlphabet.IntegerSymbol integerSymbolFromPhred(Symbol phredSym)
                                                                  throws IllegalSymbolException
Retrives the IntegerSymbol component of the Phred BasisSymbol from the PHRED alphabet.

Throws:
IllegalSymbolException - if the provided symbol is not from the PHRED alphabet.

createPhred

public static SymbolList createPhred(SymbolList dna,
                                     SymbolList quality)
                              throws IllegalArgumentException,
                                     IllegalAlphabetException,
                                     IllegalSymbolException
Merges a Symbol List from the DNA alphabet with a SymbolList from the [0..99] subset of the IntegerAlphabet into a SymbolList from the PHRED alphabet.

Throws:
IllegalAlphabetException - if the alphabets are not of the required alphabets
IllegalArgumentException - if the two SymbolLists are not of equal length.
IllegalSymbolException - if a combination of Symbols cannot be represented by the PHRED alphabet.

getPhredSymbol

public static final Symbol getPhredSymbol(Symbol dna,
                                          Symbol integer)
                                   throws IllegalSymbolException
Creates a symbol from the PHRED alphabet by combining a Symbol from the DNA alphabet and a Symbol from the IntegerAlphabet (or one of its subsets).

Throws:
IllegalSymbolException - if there is no Symbol in the PHRED alphabet that represents the two arguments.

writePhredQuality

public static void writePhredQuality(OutputStream qual,
                                     OutputStream seq,
                                     SequenceDB db)
                              throws IOException,
                                     BioException
Writes Phred quality data in a Fasta type format.

Parameters:
db - a bunch of PhredSequence objects
qual - the OutputStream to write the quality data to.
seq - the OutputStream to write the sequence data to.
Throws:
IOException
BioException
Since:
1.2

readPhredQuality

public static StreamReader readPhredQuality(BufferedReader br)
Constructs a StreamReader to read in Phred quality data in FASTA format. The data is converted into sequences consisting of Symbols from the IntegerAlphabet.


readPhredSequence

public static StreamReader readPhredSequence(BufferedReader br)
Calls SeqIOTools.readFastaDNA(br), added here for convinience.


qualityFromP

public static double qualityFromP(double probOfError)
The quality value is related to the base call error probability by the formula QV = - 10 * log_10( P_e ) where P_e is the probability that the base call is an error.

Returns:
a double value, note that for most Phred scores this will be rounded to the nearest int

pFromQuality

public static double pFromQuality(double quality)
Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)


pFromQuality

public static double pFromQuality(int quality)
Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)


pFromQuality

public static double pFromQuality(IntegerAlphabet.IntegerSymbol quality)
Calculates the probability of an error from the quality score via the formula P_e = 10**(QV/-10)


phredToDistArray

public static Distribution[] phredToDistArray(PhredSequence s)
Converts a Phred sequence to an array of distributions. Essentially a fuzzy sequence Assumes that all of the non called bases are equiprobable


phredAlignmentToDistArray

public static Distribution[] phredAlignmentToDistArray(Alignment a)
converts an Alignment of PhredSequences to a Distribution[] where each position is the average distribution of the underlying column of the alignment.

Throws:
ClassCastException - if the sequences in the alignment are not instances of PhredSequence