statalign.model.ext
Class ModelExtension

java.lang.Object
  extended by statalign.mcmc.McmcModule
      extended by statalign.model.ext.ModelExtension
Direct Known Subclasses:
PPFold, RNAAliFold, StructAlign

public abstract class ModelExtension
extends McmcModule

Ancestral class for model extension plugins.

Author:
novak, herman

Field Summary
 
Fields inherited from class statalign.mcmc.McmcModule
curLogLike, printExtraInfo
 
Constructor Summary
ModelExtension()
           
 
Method Summary
 void addToFilenameExtension(java.lang.String s)
           
 void afterAlignChange(Tree tree, Vertex selectRoot, boolean accepted)
          Called after an alignment change proposal (accepted or rejected).
 void afterEdgeLenChange(Tree tree, Vertex vertex, boolean accepted)
          Called after a proposed edge length change (accepted or rejected).
 void afterIndelParamChange(Tree tree, Hmm hmm, McmcMove m, boolean accepted)
          Called after a proposed indel parameter change (accepted or rejected).
 void afterModExtParamChange(Tree tree, ModelExtension ext, boolean accepted)
          Called after a proposed model extension parameter change (accepted or rejected).
 void afterSubstParamChange(Tree tree, SubstitutionModel model, int ind, boolean accepted)
          Called after a proposed indel parameter change (accepted or rejected).
 void afterTreeChange(Tree tree, Vertex nephew, boolean accepted)
          Called after a proposed topology change (accepted or rejected).
 void beforeAlignChange(Tree tree, Vertex selectRoot)
          Called before an alignment change is proposed, but after the affected subtree has been selected.
 void beforeEdgeLenChange(Tree tree, Vertex vertex)
          Called before an edge length change is proposed, but after the affected edge is selected.
 void beforeIndelParamChange(Tree tree, Hmm hmm, McmcMove m)
          Called before an indel parameter change is proposed, but after the affected parameter is selected.
 void beforeModExtParamChange(Tree tree, ModelExtension ext)
          Called when a model extension plugin is to propose a parameter change.
 void beforeSubstParamChange(Tree tree, SubstitutionModel model, int ind)
          Called before a substitution parameter change is proposed.
 void beforeTreeChange(Tree tree, Vertex nephew)
          Called before a topology change is proposed, but after the affected branches are selected.
 double calcLogEm(int[] aligned)
           
 void dataAdded(java.io.File file, DataType data)
           
 java.lang.String getFilenameExtension()
           
 int getParamChangeWeight()
          Returns the weight for choosing a parameter change for this model extension in the MCMC kernel.
 java.lang.String getPluginID()
           
 java.util.List<ModelExtension> getPluginList()
          Returns the (unmodifiable) list of recognised ModelExtension plugins.
 java.util.List<javax.swing.JComponent> getToolBarItems()
          Override this to return the list of toolbar items to be added.
 java.lang.String getUsageInfo()
          Prints the usage information for this plugin.
 void init()
          Called during StatAlign startup, after all ModelExtension plugins have been loaded and command line arguments have been processed (if present).
 void initRun(InputData inputData)
          Called during the initialisation of a run if plugin is active.
 boolean isActive()
           
 boolean isParamChangeAccepted(double logProposalRatio, McmcMove m)
          Should be called from McmcModule.proposeParamChange(Tree) to find out whether a proposed parameter change was accepted.
 boolean isSelectable()
           
 double logLikeAlignChange(Tree tree, Vertex selectRoot)
           
 double logLikeEdgeLenChange(Tree tree, Vertex vertex)
           
 double logLikeIndelParamChange(Tree tree, Hmm hmm, McmcMove m)
           
 double logLikeModExtParamChange(Tree tree, ModelExtension ext)
          Computes the change in likelihood to this ModelExtension, after a change to ext.
 double logLikeSubstParamChange(Tree tree, SubstitutionModel model, int ind)
           
 double logLikeTreeChange(Tree tree, Vertex nephew)
           
 void setActive(boolean active)
          Enables or disables this plugin.
 void setManager(ModelExtManager manager)
           
 void setParam(java.lang.String paramName, boolean paramValue)
           
 void setParam(java.lang.String paramName, java.lang.Number paramValue)
           
 void setParam(java.lang.String paramName, java.lang.String paramValue)
          This function is called when command line arguments are specified for a plugin.
 boolean useInAlignmentProposals()
          If true, then this plugin is able to compute a column-wise contribution to the likelihood, and can be used to influence the alignment proposals that are carried out by functions inside statalign.base.Vertex By default this is false.
 
Methods inherited from class statalign.mcmc.McmcModule
addMcmcMove, addMcmcMove, afterFirstHalfBurnin, afterSampling, beforeSampling, getLogLike, getMcmcInfo, getMcmcMove, getMcmcMoves, incrementWeights, isFirstHalfBurnin, logLikeFactor, logPrior, modifyProposalWidths, proposeParamChange, setAllMovesNotProposed, setLogLike, setMcmc, setWeight, zeroAllMoveCounts
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelExtension

public ModelExtension()
Method Detail

isSelectable

public boolean isSelectable()

addToFilenameExtension

public void addToFilenameExtension(java.lang.String s)

getFilenameExtension

public java.lang.String getFilenameExtension()

useInAlignmentProposals

public boolean useInAlignmentProposals()
If true, then this plugin is able to compute a column-wise contribution to the likelihood, and can be used to influence the alignment proposals that are carried out by functions inside statalign.base.Vertex By default this is false.


setParam

public void setParam(java.lang.String paramName,
                     java.lang.String paramValue)
This function is called when command line arguments are specified for a plugin. If the specific ModelExtension does not override these methods then it cannot handle any command line arguments, and so the default error is returned. The overriding method should call super.setParam(paramName,paramValue) in the case that paramName is unrecognised. An overriding method can also include a call such as addToFilenameExtension(paramName+"_"+paramValue); which will result in an informative string being appended to the names of any output files generated by the Postprocess plugins.

Parameters:
paramName - The name of a parameter that is to be set.
paramValue - The value to which it will be set.

setParam

public void setParam(java.lang.String paramName,
                     boolean paramValue)

setParam

public void setParam(java.lang.String paramName,
                     java.lang.Number paramValue)

setManager

public void setManager(ModelExtManager manager)

getUsageInfo

public java.lang.String getUsageInfo()
Prints the usage information for this plugin.


getPluginID

public java.lang.String getPluginID()
Returns:
The command line identifier string for the plugin.

isActive

public boolean isActive()
Returns:
true if this plugin is active

setActive

public void setActive(boolean active)
Enables or disables this plugin.

Parameters:
active - true if plugin should be enabled

getPluginList

public final java.util.List<ModelExtension> getPluginList()
Returns the (unmodifiable) list of recognised ModelExtension plugins.


getToolBarItems

public java.util.List<javax.swing.JComponent> getToolBarItems()
Override this to return the list of toolbar items to be added. By default returns null.


dataAdded

public void dataAdded(java.io.File file,
                      DataType data)

init

public void init()
Called during StatAlign startup, after all ModelExtension plugins have been loaded and command line arguments have been processed (if present).


initRun

public void initRun(InputData inputData)
             throws java.lang.IllegalArgumentException
Called during the initialisation of a run if plugin is active. Override to process input data.

Parameters:
input - the input data
Throws:
java.lang.IllegalArgumentException - if the run should be terminated as input data is illegal

getParamChangeWeight

public int getParamChangeWeight()
Returns the weight for choosing a parameter change for this model extension in the MCMC kernel. By default, returns 0, preventing McmcModule.proposeParamChange(Tree) from ever being called.

Overrides:
getParamChangeWeight in class McmcModule

beforeModExtParamChange

public void beforeModExtParamChange(Tree tree,
                                    ModelExtension ext)
Called when a model extension plugin is to propose a parameter change. Plugins must check whether they are selected for the parameter change and propose a change if necessary. Will be called for the selected plugin first. McmcModule.logLikeFactor(Tree) will be called afterwards to get the likelihood contribution after the change, and the move will be accepted or rejected by the framework. All plugins will be notified about its outcome by afterModExtParamChange(Tree, ModelExtension, boolean).

Parameters:
tree - the current tree
ext - the model extension plugin that is selected to propose a parameter change

isParamChangeAccepted

public final boolean isParamChangeAccepted(double logProposalRatio,
                                           McmcMove m)
Should be called from McmcModule.proposeParamChange(Tree) to find out whether a proposed parameter change was accepted.

Parameter logProposalRatio must be the log of P(x|x')/P(x'|x) * Pr(x')/Pr(x) where x is the old value of the model parameter, x' is new value, P(x'|x) is the probability of the proposed change (proposal probability), P(x|x') is the backproposal probability, Pr(x') is the prior probability of the new parameter value (new prior), Pr(x) is the old prior. The remaining factor Pi(new state)/Pi(old state) of the Metropolis-Hastings ratio will be calculated by calls to logLikeModExtParamChange(Tree, ModelExtension).

Overrides:
isParamChangeAccepted in class McmcModule
Parameters:
logProposalRatio - Ratio of proposal and prior densities as explained above
Returns:
true if the change was accepted

logLikeModExtParamChange

public double logLikeModExtParamChange(Tree tree,
                                       ModelExtension ext)
Computes the change in likelihood to this ModelExtension, after a change to ext.

Parameters:
tree -
ext - The ModelExtension that just changed.
Returns:

afterModExtParamChange

public void afterModExtParamChange(Tree tree,
                                   ModelExtension ext,
                                   boolean accepted)
Called after a proposed model extension parameter change (accepted or rejected).

Parameters:
tree - the current tree
ext - the model extension plugin that was selected to propose a parameter change
accepted - true if the change was accepted

beforeAlignChange

public void beforeAlignChange(Tree tree,
                              Vertex selectRoot)
Called before an alignment change is proposed, but after the affected subtree has been selected. May change later to be called after subalignment (window) has also been selected.

Parameters:
tree - the current tree
selectRoot - root of the selected subtree

logLikeAlignChange

public double logLikeAlignChange(Tree tree,
                                 Vertex selectRoot)
Parameters:
tree -
selectRoot -
Returns:

afterAlignChange

public void afterAlignChange(Tree tree,
                             Vertex selectRoot,
                             boolean accepted)
Called after an alignment change proposal (accepted or rejected).

Parameters:
tree - the current tree
selectRoot - root of the selected subtree
accepted - true if the change was accepted

beforeTreeChange

public void beforeTreeChange(Tree tree,
                             Vertex nephew)
Called before a topology change is proposed, but after the affected branches are selected.

Parameters:
tree - the current tree
nephew - node that is proposed to be swapped with its "uncle"

logLikeTreeChange

public double logLikeTreeChange(Tree tree,
                                Vertex nephew)

afterTreeChange

public void afterTreeChange(Tree tree,
                            Vertex nephew,
                            boolean accepted)
Called after a proposed topology change (accepted or rejected).

Parameters:
tree - the tree after the change
nephew - the new nephew (this is the deepest lying node that was affected by the change if there was one)
accepted - true if the change was accepted

beforeEdgeLenChange

public void beforeEdgeLenChange(Tree tree,
                                Vertex vertex)
Called before an edge length change is proposed, but after the affected edge is selected.

Parameters:
tree - the current tree
vertex - the node whose edge to its parent is selected to be changed

logLikeEdgeLenChange

public double logLikeEdgeLenChange(Tree tree,
                                   Vertex vertex)

afterEdgeLenChange

public void afterEdgeLenChange(Tree tree,
                               Vertex vertex,
                               boolean accepted)
Called after a proposed edge length change (accepted or rejected).

Parameters:
tree - the current tree
vertex - the node whose edge to its parent was selected
accepted - true if the change was accepted

beforeIndelParamChange

public void beforeIndelParamChange(Tree tree,
                                   Hmm hmm,
                                   McmcMove m)
Called before an indel parameter change is proposed, but after the affected parameter is selected.

Parameters:
tree - the current tree
hmm - the TKF92 HMM containing its parameters
ind - the index of the selected parameter

logLikeIndelParamChange

public double logLikeIndelParamChange(Tree tree,
                                      Hmm hmm,
                                      McmcMove m)

afterIndelParamChange

public void afterIndelParamChange(Tree tree,
                                  Hmm hmm,
                                  McmcMove m,
                                  boolean accepted)
Called after a proposed indel parameter change (accepted or rejected).

Parameters:
tree - the current tree
hmm - the TKF92 HMM containing its parameters
ind - the index of the selected parameter
accepted - true if the change was accepted

beforeSubstParamChange

public void beforeSubstParamChange(Tree tree,
                                   SubstitutionModel model,
                                   int ind)
Called before a substitution parameter change is proposed.

Parameters:
tree - the current tree
model - the active substitution model
ind - the index of the substitution parameter selected to be changed or -1 if unknown

logLikeSubstParamChange

public double logLikeSubstParamChange(Tree tree,
                                      SubstitutionModel model,
                                      int ind)

afterSubstParamChange

public void afterSubstParamChange(Tree tree,
                                  SubstitutionModel model,
                                  int ind,
                                  boolean accepted)
Called after a proposed indel parameter change (accepted or rejected).

Parameters:
tree - the current tree
model - the active substitution model
ind - the index of the substitution parameter selected to be changed or -1 if unknown
accepted - true if the change was accepted

calcLogEm

public double calcLogEm(int[] aligned)
Parameters:
aligned - Vector indicating which characters are aligned to the current column in the subtrees below.
Returns:
Logarithm of emission probability for subtrees