org.biojava3.alignment
Class SimpleSubstitutionMatrix<C extends Compound>

java.lang.Object
  extended by org.biojava3.alignment.SimpleSubstitutionMatrix<C>
Type Parameters:
C - each element of the matrix corresponds to a pair of Compounds of type C
All Implemented Interfaces:
SubstitutionMatrix<C>

public class SimpleSubstitutionMatrix<C extends Compound>
extends Object
implements SubstitutionMatrix<C>

Implements a data structure which holds the score (penalty or bonus) given during alignment for the exchange of one Compound in a sequence for another.

Author:
Mark Chapman

Constructor Summary
SimpleSubstitutionMatrix()
          Creates a substitution matrix using the defaults (BLOSUM 62).
SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, File fileInput)
          Creates a substitution matrix by reading in a file.
SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, Reader input, String name)
          Creates a substitution matrix by parsing some input.
SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, short match, short replace)
          Creates an identity substitution matrix from match and replace values.
SimpleSubstitutionMatrix(CompoundSet<C> compoundSet, String matrixInput, String name)
          Creates a substitution matrix by parsing a String.
 
Method Summary
 CompoundSet<C> getCompoundSet()
          Returns the CompoundSet on which the matrix is defined.
 String getDescription()
          Returns the description of this matrix.
 short[][] getMatrix()
          Returns entire matrix.
 String getMatrixAsString()
          Returns this matrix as a formatted String with Compound labels along the axes.
 short getMaxValue()
          Returns the maximum value in this matrix.
 short getMinValue()
          Returns the minimum value in this matrix.
 String getName()
          Returns the name (short description) of this matrix.
 short getValue(C from, C to)
          Returns value in matrix for conversion from first Compound to the second.
 SubstitutionMatrix<C> normalizeMatrix(short scale)
          Rescales the matrix so that to SubstitutionMatrix.getMaxValue() - SubstitutionMatrix.getMinValue() = scale.
 void setDescription(String description)
          Sets the description of this matrix.
 void setName(String name)
          Sets the name (short description) of this matrix.
 String toString()
          Returns in a format similar to the standard NCBI files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleSubstitutionMatrix

public SimpleSubstitutionMatrix()
Creates a substitution matrix using the defaults (BLOSUM 62).

Throws:
ClassCastException - if type parameter C is not AminoAcidCompound

SimpleSubstitutionMatrix

public SimpleSubstitutionMatrix(CompoundSet<C> compoundSet,
                                File fileInput)
                         throws FileNotFoundException
Creates a substitution matrix by reading in a file.

Parameters:
compoundSet - the CompoundSet on which the matrix is defined
fileInput - file parsed for a substitution matrix
Throws:
FileNotFoundException - if fileInput parameter cannot be read

SimpleSubstitutionMatrix

public SimpleSubstitutionMatrix(CompoundSet<C> compoundSet,
                                Reader input,
                                String name)
Creates a substitution matrix by parsing some input.

Parameters:
compoundSet - the CompoundSet on which the matrix is defined
input - input parsed for a substitution matrix
name - the name (short description) of this matrix

SimpleSubstitutionMatrix

public SimpleSubstitutionMatrix(CompoundSet<C> compoundSet,
                                String matrixInput,
                                String name)
Creates a substitution matrix by parsing a String.

Parameters:
compoundSet - the CompoundSet on which the matrix is defined
matrixInput - String parsed for a substitution matrix
name - the name (short description) of this matrix

SimpleSubstitutionMatrix

public SimpleSubstitutionMatrix(CompoundSet<C> compoundSet,
                                short match,
                                short replace)
Creates an identity substitution matrix from match and replace values.

Parameters:
compoundSet - the CompoundSet on which the matrix is defined
match - matrix value used for equivalent Compounds
replace - matrix value used for differing Compounds
Method Detail

getCompoundSet

public CompoundSet<C> getCompoundSet()
Description copied from interface: SubstitutionMatrix
Returns the CompoundSet on which the matrix is defined.

Specified by:
getCompoundSet in interface SubstitutionMatrix<C extends Compound>
Returns:
the CompoundSet on which the matrix is defined

getDescription

public String getDescription()
Description copied from interface: SubstitutionMatrix
Returns the description of this matrix.

Specified by:
getDescription in interface SubstitutionMatrix<C extends Compound>
Returns:
description

getMatrix

public short[][] getMatrix()
Description copied from interface: SubstitutionMatrix
Returns entire matrix.

Specified by:
getMatrix in interface SubstitutionMatrix<C extends Compound>
Returns:
matrix

getMatrixAsString

public String getMatrixAsString()
Description copied from interface: SubstitutionMatrix
Returns this matrix as a formatted String with Compound labels along the axes.

Specified by:
getMatrixAsString in interface SubstitutionMatrix<C extends Compound>
Returns:
this matrix as a formatted String

getMaxValue

public short getMaxValue()
Description copied from interface: SubstitutionMatrix
Returns the maximum value in this matrix.

Specified by:
getMaxValue in interface SubstitutionMatrix<C extends Compound>
Returns:
the maximum value in this matrix

getMinValue

public short getMinValue()
Description copied from interface: SubstitutionMatrix
Returns the minimum value in this matrix.

Specified by:
getMinValue in interface SubstitutionMatrix<C extends Compound>
Returns:
the minimum value in this matrix

getName

public String getName()
Description copied from interface: SubstitutionMatrix
Returns the name (short description) of this matrix.

Specified by:
getName in interface SubstitutionMatrix<C extends Compound>
Returns:
name

getValue

public short getValue(C from,
                      C to)
Description copied from interface: SubstitutionMatrix
Returns value in matrix for conversion from first Compound to the second. If an argument does not belong to the CompoundSet, this could either throw an IllegalArgumentException or it could return SubstitutionMatrix.getMinValue().

Specified by:
getValue in interface SubstitutionMatrix<C extends Compound>
Parameters:
from - original Compound
to - replacement Compound
Returns:
value in matrix for conversion from first Compound to the second

normalizeMatrix

public SubstitutionMatrix<C> normalizeMatrix(short scale)
Description copied from interface: SubstitutionMatrix
Rescales the matrix so that to SubstitutionMatrix.getMaxValue() - SubstitutionMatrix.getMinValue() = scale.

Specified by:
normalizeMatrix in interface SubstitutionMatrix<C extends Compound>
Parameters:
scale - new normalization scale of this matrix

setDescription

public void setDescription(String description)
Description copied from interface: SubstitutionMatrix
Sets the description of this matrix.

Specified by:
setDescription in interface SubstitutionMatrix<C extends Compound>
Parameters:
description - new description

setName

public void setName(String name)
Description copied from interface: SubstitutionMatrix
Sets the name (short description) of this matrix.

Specified by:
setName in interface SubstitutionMatrix<C extends Compound>
Parameters:
name - new name

toString

public String toString()
Returns in a format similar to the standard NCBI files.

Overrides:
toString in class Object