Models
Class RateCategory

java.lang.Object
  extended by Models.RateCategory
All Implemented Interfaces:
java.io.Serializable

public class RateCategory
extends java.lang.Object
implements java.io.Serializable

Represents a rate category of a phylogenetic model.

Version:
1.0
See Also:
Serialized Form

Nested Class Summary
static class RateCategory.FrequencyType
          Enumeration of the different ways of defining the root frequency
 class RateCategory.RateException
          Exception thrown if there is a problem within a RateClass
 
Constructor Summary
RateCategory(java.lang.String[][] rates, RateCategory.FrequencyType freqType, java.util.HashMap<java.lang.String,java.lang.Integer> map)
          Constrcutor for when the root distribution is defined as the stationary or quasi-staionary distribution.
RateCategory(java.lang.String[][] rates, java.lang.String[] freq, java.util.HashMap<java.lang.String,java.lang.Integer> map)
          Constructor for when the root distribution is defined.
 
Method Summary
static RateCategory fromFile(java.io.File mfile)
          Creates an instance from the information in a file.
 double[] getFreq()
          Gets the root frequencies
 java.util.HashMap<java.lang.String,java.lang.Integer> getMap()
          Gets the map that maps state to position in matrix
 java.lang.String getName()
          Get the name of the rate category
 int getNumberStates()
          Gets the number of states in the rate class
 SquareMatrix getP(double length)
          Gets the P-matrix for a given length
 double getTotalRate()
          Gets the total rate of the rate class.
 void setName(java.lang.String name)
          Sets the name of the rate category.
 void setParameters(Parameters p)
          Updates the parameters in the RateCategory.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RateCategory

public RateCategory(java.lang.String[][] rates,
                    RateCategory.FrequencyType freqType,
                    java.util.HashMap<java.lang.String,java.lang.Integer> map)
             throws RateCategory.RateException
Constrcutor for when the root distribution is defined as the stationary or quasi-staionary distribution.

Parameters:
rates - Array representing the rate matrix
freqType - How the root frequency is calculated
map - Map from State to position in matrix (0-index). For example map would contain A -> 0 if state A was in the first position (column and row of the matrix.
Throws:
RateCategory.RateException - If the rate matrix is not square

RateCategory

public RateCategory(java.lang.String[][] rates,
                    java.lang.String[] freq,
                    java.util.HashMap<java.lang.String,java.lang.Integer> map)
             throws RateCategory.RateException
Constructor for when the root distribution is defined.

Parameters:
rates - Array representing the rate matrix
freq - Root frequency.
map - Map from State to position in matrix (0-index) or root frequency. For example map would contain A -> 0 if state A was in the first position (column and row) of the matrix and in the first position of the root frequency array.
Throws:
RateCategory.RateException - If the rate matrix is not square or the frequncy array is not the same length as the rate matrix.
Method Detail

setParameters

public void setParameters(Parameters p)
                   throws RateCategory.RateException
Updates the parameters in the RateCategory. Should only be called if a parameter in the matrix / frequency defintion has chnaged.

Parameters:
p - The new parameters
Throws:
RateCategory.RateException - If the parameters passed does not include all the parameters in the model.

getTotalRate

public double getTotalRate()
Gets the total rate of the rate class.

Returns:
The total rate

getFreq

public double[] getFreq()
Gets the root frequencies

Returns:
An array containing the root frequencies. Order is that given by the map returned by getMap() and which was passed to the constuctor.

getNumberStates

public int getNumberStates()
Gets the number of states in the rate class

Returns:
The number of states

getMap

public java.util.HashMap<java.lang.String,java.lang.Integer> getMap()
Gets the map that maps state to position in matrix

Returns:
Map from state to position in matrix

getP

public SquareMatrix getP(double length)
                  throws RateCategory.RateException
Gets the P-matrix for a given length

Parameters:
length - The length
Returns:
The probability matrix. Order is that given by the map returned by getMap() and which was passed to the constuctor.
Throws:
RateCategory.RateException - Thrown if the matrix cannot be calculated.

setName

public void setName(java.lang.String name)
Sets the name of the rate category. Used so there is something meaningful to return to the user'

Parameters:
name - The rate category's name

getName

public java.lang.String getName()
Get the name of the rate category

Returns:
The rate category's name.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromFile

public static RateCategory fromFile(java.io.File mfile)
                             throws InputException,
                                    RateCategory.RateException
Creates an instance from the information in a file. See MathsParse for a description of the format of the equations that can be in the rate matrix and root distribution. File format is as follows:

Parameters:
mfile - The input file
Returns:
An instance of this class
Throws:
InputException - If there is a problem with the input file
RateCategory.RateException - If the RateCategory can not be created