statalign.model.subst
Class SubstitutionModel

java.lang.Object
  extended by statalign.model.subst.SubstitutionModel
Direct Known Subclasses:
AminoAcidModel, NucleotideModel

public abstract class SubstitutionModel
extends java.lang.Object

Superclass of the substitution models.

Author:
miklos, novak

Field Summary
 char[] alphabet
          This array contains the potential characters of the alphabet.
 SubstitutionScore attachedScoringScheme
          This scoring scheme is used for constructing an initial tree.
 double[] d
          The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix.
 double[] e
          This array tells the equilibrium distribution
static java.lang.String menuName
          Sets the name of the model plugin that will appear in the menu when declared with the same name and type.
 double[] params
          Model parameters.
static java.lang.String type
          Tells whether your plugin is a nucleotide or protein model (or something else) when declared with the same name and type.
 double[][] v
          The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix
 double[][] w
          The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix
 
Constructor Summary
SubstitutionModel()
           
 
Method Summary
abstract  double acceptable(RawSequences r)
          If a model cannot accept the currently loaded sequences (for example, because the sequences contains a character that is not part of the model) then it returns a negative number.
abstract  java.awt.Color getColor(char c)
          Returns the colour associated with the character.
 java.lang.String getMenuName()
          Retrieves the static field menuName of the class of the object the method is called on.
static java.lang.String getMenuName(java.lang.Class<? extends SubstitutionModel> cl)
          Retrieves menuName static field of a SubstitutionModel plug-in class.
 double getPrior()
          Returns the prior for the substitution parameters.
 java.lang.String getType()
          Retrieves the static field type of the class of the object the method is called on.
static java.lang.String getType(java.lang.Class<? extends SubstitutionModel> cl)
          Retrieves the static field type of a SubstitutionModel plug-in class.
abstract  char mostLikely(double[] seq)
           
abstract  java.lang.String print()
          Represents model state as a String (usually parameter values concatenated)
abstract  void restoreParameter()
          Restores state just before the call of sampleParameter
abstract  double sampleParameter()
          Abstract method to sample a new model parameter and update v,w,d,e accordingly.
 void updateSpan(double newSpan)
           
 double[][] updateTransitionMatrix(double[][] transitionMatrix, double edgeLength)
          Updates externally stored transition matrix using current values of v, w, d, e and current edge length.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

v

public double[][] v
The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix


w

public double[][] w
The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix


d

public double[] d
The rate matrix must be diagonalized and represented in a v d w product, where d is a diagonal matrix. Only the diagonal elements must be put into the one dimensional array d.


e

public double[] e
This array tells the equilibrium distribution


alphabet

public char[] alphabet
This array contains the potential characters of the alphabet.


params

public double[] params
Model parameters.


type

public static java.lang.String type
Tells whether your plugin is a nucleotide or protein model (or something else) when declared with the same name and type. Affects grouping of models in the menu.


menuName

public static java.lang.String menuName
Sets the name of the model plugin that will appear in the menu when declared with the same name and type.


attachedScoringScheme

public SubstitutionScore attachedScoringScheme
This scoring scheme is used for constructing an initial tree.

Constructor Detail

SubstitutionModel

public SubstitutionModel()
Method Detail

updateSpan

public void updateSpan(double newSpan)

acceptable

public abstract double acceptable(RawSequences r)
If a model cannot accept the currently loaded sequences (for example, because the sequences contains a character that is not part of the model) then it returns a negative number. Otherwise it returns a double value between 0 and 1, the better likes the model the sequences the greater the return number is.

Parameters:
r - raw sequences
Returns:
the value telling how well the substitution model likes the sequences.

updateTransitionMatrix

public double[][] updateTransitionMatrix(double[][] transitionMatrix,
                                         double edgeLength)
Updates externally stored transition matrix using current values of v, w, d, e and current edge length. Must always be called in the form m = updateTransitionMatrix(m, len) where m can be null as well.

Parameters:
transitionMatrix - reference to matrix to store results, null to create new
edgeLength - evolutionary time
Returns:
updated (or newly created) transition matrix

sampleParameter

public abstract double sampleParameter()
Abstract method to sample a new model parameter and update v,w,d,e accordingly.

Returns:
log(fwd proposal probability/bwd proposal probability) [i.e. inverse Hastings ratio]

restoreParameter

public abstract void restoreParameter()
Restores state just before the call of sampleParameter


print

public abstract java.lang.String print()
Represents model state as a String (usually parameter values concatenated)

Returns:
the resulting String

getColor

public abstract java.awt.Color getColor(char c)
Returns the colour associated with the character. This colour will be the background colour of the character in the printed alignments.

Parameters:
c - character whose background colour is to be returned

mostLikely

public abstract char mostLikely(double[] seq)

getType

public java.lang.String getType()
Retrieves the static field type of the class of the object the method is called on. See getType(Class cl) for details.


getType

public static java.lang.String getType(java.lang.Class<? extends SubstitutionModel> cl)
Retrieves the static field type of a SubstitutionModel plug-in class. In the class it must be declared public static String. Searches the class hierarchy upwards until a class with the field declared is found.

Parameters:
cl - class extending SubstitutionModel
Returns:
value of the static field type or "unknown" if the field is null or empty

getMenuName

public java.lang.String getMenuName()
Retrieves the static field menuName of the class of the object the method is called on. See getMenuName(Class cl) for details.


getMenuName

public static java.lang.String getMenuName(java.lang.Class<? extends SubstitutionModel> cl)
Retrieves menuName static field of a SubstitutionModel plug-in class. In the class it must be declared public static String.

Parameters:
cl - class extending SubstitutionModel
Returns:
value of the static field menuName or the simple name of cl if the field doesn't exist or is null

getPrior

public double getPrior()
Returns the prior for the substitution parameters. By default the prior is uniform and this function returns 1.

Returns:
prior for the parameters of the substitution model.