statalign.model.ext.plugins
Class StructAlign

java.lang.Object
  extended by statalign.mcmc.McmcModule
      extended by statalign.model.ext.ModelExtension
          extended by statalign.model.ext.plugins.StructAlign
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class StructAlign
extends ModelExtension
implements java.awt.event.ActionListener


Field Summary
 double angleP
          Starting value for rotation proposal tuning parameter.
 double[] angles
          Rotation angle for each protein along the rotation axis
 double[][] axes
          Axis of rotation for each sequence
 double[][] bFactors
          Crystallographic temperature factors, for weighting epsilon.
 double[][][] coords
          Alpha-C atomic coordinate for each sequence and each residue
 java.lang.String[] curAlign
          Current alignment between all leaf sequences
 double[][] distanceMatrix
          Pairwise distances implied by current tree topology
 double epsilon
           
 PriorDistribution<java.lang.Double> epsilonPrior
           
 boolean fixedEpsilon
           
 double fixedEpsilonValue
          Value to fix epsilon at if we're not estimating it.
 boolean fixedSigma2
           
 double fixedSigma2Value
          Value to fix sigma at if we're not estimating it.
 double[][] fullCovar
          Covariance matrix implied by current tree topology
 boolean globalSigma
           
 boolean globalSigmaSpike
          If globalSigma = false then this switches on a spike prior at sigma2Hier.
 java.lang.String linkType
           
 boolean localEpsilon
           
 double MIN_EPSILON
          Minimum value for epsilon, to prevent numerical errors.
 java.util.HashMap<java.lang.Integer,MultiNormCholesky> multiNorms
           
 java.util.HashMap<statalign.model.ext.plugins.StructAlign.Column,MultiNormCholesky> multiNormsLocal
           
 double nu
           
 GammaPrior nuPrior
           
 java.lang.String[] oldAlign
           
 double[][] oldCovar
           
 double[][] oldDist
           
 double oldLogLi
           
 java.util.HashMap<statalign.model.ext.plugins.StructAlign.Column,MultiNormCholesky> oldMultiNormsLocal
           
 double[][][] rotCoords
          Alpha-C atomic coordinates under the current set of rotations/translations
 RotationProposal rotProp
          independence rotation proposal distribution
 double[] sigma2
          Parameters of structural drift
 double sigma2Hier
           
 GammaPrior sigma2HPrior
           
 PriorDistribution<java.lang.Double> sigma2Prior
           
 double tau
           
 InverseGammaPrior tauPrior
           
 boolean useLibrary
           
 double xlatP
          Starting value for translation proposal tuning parameter.
 double[][] xlats
          Translation vector for each protein
 
Fields inherited from class statalign.mcmc.McmcModule
curLogLike, printExtraInfo
 
Constructor Summary
StructAlign()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void addEdgeLength(double[][] distMat, int[] subTree, double edgeLength)
           
 void afterAlignChange(Tree tree, Vertex selectRoot, boolean accepted)
          Called after an alignment change proposal (accepted or rejected).
 void afterContinuousParamChange(Tree tree, boolean accepted)
           
 void afterEdgeLenChange(Tree tree, Vertex vertex, boolean accepted)
          Called after a proposed edge length change (accepted or rejected).
 void afterFirstHalfBurnin()
           
 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 beforeContinuousParamChange(Tree tree)
           
 void beforeEdgeLenChange(Tree tree, Vertex vertex)
          Called before an edge length change is proposed, but after the affected edge is selected.
 void beforeSampling(Tree tree)
          Called before the start of MCMC sampling, but after the initial tree, alignment etc. have been generated.
 void beforeTreeChange(Tree tree, Vertex nephew)
          Called before a topology change is proposed, but after the affected branches are selected.
 double calcAllColumnContrib()
           
 int[] calcDistanceMatrix(Vertex vertex, double[][] distMat)
           
 int[] calcDistanceMatrix(Vertex vertex, double[][] distMat, boolean unweighted)
          recursive algorithm to traverse tree and calculate distance matrix between leaves
 double[][] calcFullCovar(Tree tree)
          return the full covariance matrix for the tree topology and branch lengths
 double calcLogEm(int[] aligned)
           
 void calcRotation(int ind)
           
 int[] calcUnweightedDistanceMatrix(Vertex vertex, double[][] distMat)
           
 double columnContrib(int[] col)
          Calculates the structural likelihood contribution of a single alignment column
 double computeLogLikeFactor(Tree tree)
           
 void connectRmsdTrace(RmsdTrace _rmsdTrace)
           
 void connectStructTrace(StructTrace structTrace)
           
 void dataAdded(java.io.File file, DataType data)
           
 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<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.
 double logLikeAlignChange(Tree tree, Vertex selectRoot)
           
 double logLikeContinuousParamChange(Tree tree)
           
 double logLikeEdgeLenChange(Tree tree, Vertex vertex)
           
 double logLikeFactor(Tree tree)
          This should return the log of the model's contribution to the likelihood, it will be added on to the log-likelihood of the current point in the MCMC state space.
 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 printTree(Vertex v, java.lang.String vname)
           
 void setActive(boolean active)
          Enables or disables this plugin.
 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.model.ext.ModelExtension
addToFilenameExtension, afterIndelParamChange, afterModExtParamChange, afterSubstParamChange, beforeIndelParamChange, beforeModExtParamChange, beforeSubstParamChange, getFilenameExtension, getPluginList, isActive, isParamChangeAccepted, isSelectable, setManager
 
Methods inherited from class statalign.mcmc.McmcModule
addMcmcMove, addMcmcMove, afterSampling, getLogLike, getMcmcInfo, getMcmcMove, getMcmcMoves, incrementWeights, isFirstHalfBurnin, logPrior, modifyProposalWidths, proposeParamChange, setAllMovesNotProposed, setLogLike, setMcmc, setWeight, zeroAllMoveCounts
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalSigma

public boolean globalSigma

useLibrary

public boolean useLibrary

fixedEpsilon

public boolean fixedEpsilon

fixedSigma2

public boolean fixedSigma2

globalSigmaSpike

public boolean globalSigmaSpike
If globalSigma = false then this switches on a spike prior at sigma2Hier.


localEpsilon

public boolean localEpsilon

coords

public double[][][] coords
Alpha-C atomic coordinate for each sequence and each residue


bFactors

public double[][] bFactors
Crystallographic temperature factors, for weighting epsilon.


rotCoords

public double[][][] rotCoords
Alpha-C atomic coordinates under the current set of rotations/translations


axes

public double[][] axes
Axis of rotation for each sequence


angles

public double[] angles
Rotation angle for each protein along the rotation axis


xlats

public double[][] xlats
Translation vector for each protein


sigma2

public double[] sigma2
Parameters of structural drift


sigma2Hier

public double sigma2Hier

nu

public double nu

tau

public double tau

epsilon

public double epsilon

distanceMatrix

public double[][] distanceMatrix
Pairwise distances implied by current tree topology


fullCovar

public double[][] fullCovar
Covariance matrix implied by current tree topology


curAlign

public java.lang.String[] curAlign
Current alignment between all leaf sequences


rotProp

public RotationProposal rotProp
independence rotation proposal distribution


oldCovar

public double[][] oldCovar

oldDist

public double[][] oldDist

oldAlign

public java.lang.String[] oldAlign

oldLogLi

public double oldLogLi

linkType

public java.lang.String linkType

sigma2Prior

public PriorDistribution<java.lang.Double> sigma2Prior

epsilonPrior

public PriorDistribution<java.lang.Double> epsilonPrior

tauPrior

public InverseGammaPrior tauPrior

sigma2HPrior

public GammaPrior sigma2HPrior

nuPrior

public GammaPrior nuPrior

angleP

public final double angleP
Starting value for rotation proposal tuning parameter.

See Also:
Constant Field Values

xlatP

public final double xlatP
Starting value for translation proposal tuning parameter.

See Also:
Constant Field Values

fixedSigma2Value

public double fixedSigma2Value
Value to fix sigma at if we're not estimating it.


MIN_EPSILON

public double MIN_EPSILON
Minimum value for epsilon, to prevent numerical errors.


fixedEpsilonValue

public double fixedEpsilonValue
Value to fix epsilon at if we're not estimating it.


multiNorms

public java.util.HashMap<java.lang.Integer,MultiNormCholesky> multiNorms

multiNormsLocal

public java.util.HashMap<statalign.model.ext.plugins.StructAlign.Column,MultiNormCholesky> multiNormsLocal

oldMultiNormsLocal

public java.util.HashMap<statalign.model.ext.plugins.StructAlign.Column,MultiNormCholesky> oldMultiNormsLocal
Constructor Detail

StructAlign

public StructAlign()
Method Detail

getPluginID

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

useInAlignmentProposals

public boolean useInAlignmentProposals()
Description copied from class: ModelExtension
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.

Overrides:
useInAlignmentProposals in class ModelExtension

getToolBarItems

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

Overrides:
getToolBarItems in class ModelExtension

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

getUsageInfo

public java.lang.String getUsageInfo()
Description copied from class: ModelExtension
Prints the usage information for this plugin.

Overrides:
getUsageInfo in class ModelExtension

setActive

public void setActive(boolean active)
Description copied from class: ModelExtension
Enables or disables this plugin.

Overrides:
setActive in class ModelExtension
Parameters:
active - true if plugin should be enabled

setParam

public void setParam(java.lang.String paramName,
                     java.lang.String paramValue)
Description copied from class: ModelExtension
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.

Overrides:
setParam in class ModelExtension
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,
                     java.lang.Number paramValue)
Overrides:
setParam in class ModelExtension

setParam

public void setParam(java.lang.String paramName,
                     boolean paramValue)
Overrides:
setParam in class ModelExtension

init

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

Overrides:
init in class ModelExtension

initRun

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

Overrides:
initRun in class ModelExtension
Throws:
java.lang.IllegalArgumentException - if the run should be terminated as input data is illegal

beforeSampling

public void beforeSampling(Tree tree)
Description copied from class: McmcModule
Called before the start of MCMC sampling, but after the initial tree, alignment etc. have been generated. Override to initialise data structures etc.

Overrides:
beforeSampling in class McmcModule
Parameters:
tree - the starting tree

afterFirstHalfBurnin

public void afterFirstHalfBurnin()
Overrides:
afterFirstHalfBurnin in class McmcModule

computeLogLikeFactor

public double computeLogLikeFactor(Tree tree)

logLikeFactor

public double logLikeFactor(Tree tree)
Description copied from class: McmcModule
This should return the log of the model's contribution to the likelihood, it will be added on to the log-likelihood of the current point in the MCMC state space. Normally it will be called once at the initialisation of the MCMC process and from then on once in each MCMC step, when proposing any change. In debug mode, will be called more often (including after proposed changes) to ensure consistency.

Specified by:
logLikeFactor in class McmcModule
Parameters:
tree - current tree
Returns:
log of model extension likelihood, conditional on current tree, alignment and params

calcAllColumnContrib

public double calcAllColumnContrib()

columnContrib

public double columnContrib(int[] col)
Calculates the structural likelihood contribution of a single alignment column

Parameters:
col - the column, id of the residue for each sequence (or -1 if gapped in column)
Returns:
the likelihood contribution

calcRotation

public void calcRotation(int ind)

calcFullCovar

public double[][] calcFullCovar(Tree tree)
return the full covariance matrix for the tree topology and branch lengths


printTree

public void printTree(Vertex v,
                      java.lang.String vname)

calcUnweightedDistanceMatrix

public int[] calcUnweightedDistanceMatrix(Vertex vertex,
                                          double[][] distMat)

calcDistanceMatrix

public int[] calcDistanceMatrix(Vertex vertex,
                                double[][] distMat)

calcDistanceMatrix

public int[] calcDistanceMatrix(Vertex vertex,
                                double[][] distMat,
                                boolean unweighted)
recursive algorithm to traverse tree and calculate distance matrix between leaves


addEdgeLength

public void addEdgeLength(double[][] distMat,
                          int[] subTree,
                          double edgeLength)

getParamChangeWeight

public int getParamChangeWeight()
Description copied from class: ModelExtension
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 ModelExtension

logLikeModExtParamChange

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

Overrides:
logLikeModExtParamChange in class ModelExtension
ext - The ModelExtension that just changed.
Returns:

beforeAlignChange

public void beforeAlignChange(Tree tree,
                              Vertex selectRoot)
Description copied from class: ModelExtension
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.

Overrides:
beforeAlignChange in class ModelExtension
Parameters:
tree - the current tree
selectRoot - root of the selected subtree

logLikeAlignChange

public double logLikeAlignChange(Tree tree,
                                 Vertex selectRoot)
Overrides:
logLikeAlignChange in class ModelExtension
Returns:

afterAlignChange

public void afterAlignChange(Tree tree,
                             Vertex selectRoot,
                             boolean accepted)
Description copied from class: ModelExtension
Called after an alignment change proposal (accepted or rejected).

Overrides:
afterAlignChange in class ModelExtension
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)
Description copied from class: ModelExtension
Called before a topology change is proposed, but after the affected branches are selected.

Overrides:
beforeTreeChange in class ModelExtension
Parameters:
tree - the current tree
nephew - node that is proposed to be swapped with its "uncle"

logLikeTreeChange

public double logLikeTreeChange(Tree tree,
                                Vertex nephew)
Overrides:
logLikeTreeChange in class ModelExtension

afterTreeChange

public void afterTreeChange(Tree tree,
                            Vertex nephew,
                            boolean accepted)
Description copied from class: ModelExtension
Called after a proposed topology change (accepted or rejected).

Overrides:
afterTreeChange in class ModelExtension
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

beforeContinuousParamChange

public void beforeContinuousParamChange(Tree tree)

logLikeContinuousParamChange

public double logLikeContinuousParamChange(Tree tree)

afterContinuousParamChange

public void afterContinuousParamChange(Tree tree,
                                       boolean accepted)

logLikeEdgeLenChange

public double logLikeEdgeLenChange(Tree tree,
                                   Vertex vertex)
Overrides:
logLikeEdgeLenChange in class ModelExtension

beforeEdgeLenChange

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

Overrides:
beforeEdgeLenChange in class ModelExtension
Parameters:
tree - the current tree
vertex - the node whose edge to its parent is selected to be changed

afterEdgeLenChange

public void afterEdgeLenChange(Tree tree,
                               Vertex vertex,
                               boolean accepted)
Description copied from class: ModelExtension
Called after a proposed edge length change (accepted or rejected).

Overrides:
afterEdgeLenChange in class ModelExtension
Parameters:
tree - the current tree
vertex - the node whose edge to its parent was selected
accepted - true if the change was accepted

logLikeIndelParamChange

public double logLikeIndelParamChange(Tree tree,
                                      Hmm hmm,
                                      McmcMove m)
Overrides:
logLikeIndelParamChange in class ModelExtension

logLikeSubstParamChange

public double logLikeSubstParamChange(Tree tree,
                                      SubstitutionModel model,
                                      int ind)
Overrides:
logLikeSubstParamChange in class ModelExtension

calcLogEm

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

connectStructTrace

public void connectStructTrace(StructTrace structTrace)

connectRmsdTrace

public void connectRmsdTrace(RmsdTrace _rmsdTrace)

dataAdded

public void dataAdded(java.io.File file,
                      DataType data)
Overrides:
dataAdded in class ModelExtension