statalign.base
Class Vertex

java.lang.Object
  extended by statalign.base.Vertex

public class Vertex
extends java.lang.Object

This is a vertex of the tree. The 'hardcore' functions are implemented in this class, developers are suggested not change functions in it. The implemented functions are quite unreadable, since we opted for efficiency and not readability. You should be able to develop novel functionality of the software package (postprocessing, substitution models, etc.) without touching this class.

Author:
miklos, novak, herman

Field Summary
 double edgeLength
          The length of the edge that connects this vertex with its parent.
 AlignColumn first
           
 double indelLogLike
          The log-sum of the cumulative insertion-deletion loglikelihoods up to this vertex (ie. summed over the subtree below this vertex.).
 int index
          Index of this vertex in the Tree.vertex array
 int leafCount
           
 Vertex left
          This reference points to the left child of the vertex.
 java.lang.String name
          The name of the sequence associated to the vertex.
 int nSilentIndels
           
 double orphanLogLike
          The log-sum of the Felsenstein's likelihoods of characters that are inserted into the sequence of this vertex.
 Vertex parent
          This reference points to the parent of the vertex
 Vertex right
          This reference points to the right child of the vertex.
 boolean selected
           
 
Constructor Summary
Vertex(Tree tree)
           
Vertex(Vertex parent)
           
 
Method Summary
 void alignRestore()
          Restores all the changes an alignment resampling on the currently selected subtree has produced.
 Vertex brother()
           
 void calcAllUp()
          Calculates Felsenstein and indel likelihoods up to root, starting from `parent'
 void calcFelsen()
           
 void calcFelsenRecursively()
          This function calculates the Felsenstein likelihood for the subtree below this.
 void calcIndelLogLike()
           
 void calcIndelLogLikeRecursively()
           
 void calcOrphan()
           
 void calcOrphanRecursively()
           
 void calcUpperFromRoot()
           
 void calcUpperRecursively()
          This function calculates the upper probability vectors, which contain the partial likelihoods for everything except this subtree.
 void calcUpperRecursivelyWithCheck()
           
 double calcSumOfEdges()
          Calculate the sum of branch lengths below on this vertex.
 void checkPointers()
          this function checks if the pointers are all right...
 void computeWeights(statalign.base.Vertex.Neighbours curr, double[] logProbs)
          Computes the probability of all the possible imputations for parent and grandpa given the neighbouring AlignColumn objects.
 void edgeChangeUpdate()
           
 void exciseAllSilentIndels()
           
 double exciseSilentIndel()
           
 double exciseSilentIndel(AlignColumn c)
           
 double exciseSilentIndel(AlignColumn c, boolean remove)
           
 double exciseSilentIndelBlock(AlignColumn insert, boolean remove)
           
 void fastSwapBackUncle()
          Restores the exact state just before the call of fastSwapWithUncle().
 double fastSwapWithUncle()
          Swaps this with its uncle, but keeps alignment columns where this, its parent, the uncle node and its parent are all aligned unchanged with a given probability, and only proposes new alignments between these selected alignment anchors columns.
 int favouredDestination(int state)
           
 int getLength()
           
 double hmm2AlignWithSave()
          Samples a new alignment between `this' & `this.parent', taking window sizes into account.
 double hmm2AlignWithSave(double heat)
           
 double insertSilentIndel()
           
 double insertSilentIndel(AlignColumn c)
           
 double insertSilentIndelBlock(AlignColumn c)
           
 double maxDepth()
          Calculate the maximum depth below on this vertex.
 double modifySilentIndel(boolean insert)
           
 double nephewUncleSwapFixedColumns()
           
 double nephewUncleSwapFixedColumns2()
           
 double nephewUncleSwapFixedColumns3()
           
 java.lang.String print(int digits)
           
 void print(java.lang.StringBuffer b)
           
 void print(java.lang.StringBuffer b, boolean withNumbers)
           
static void printChildren(Vertex v)
           
 java.lang.String[] printedAlignment()
           
 java.lang.String[] printedAlignment(boolean inWindow)
           
static void printEdges(Vertex v)
           
 void printPointers()
           
 void printToScreenAlignment(int windowStart, int windowEnd)
           
 void printToScreenAlignment(int windowStart, int windowEnd, boolean printAll)
           
 void printWithNumbers(java.lang.StringBuffer b)
           
 double realignToParent()
           
 double realignToParent(boolean useCurrentWin)
           
 double realignToParent(boolean useCurrentWin, double heat)
          Samples a new alignment between the subtree rooted at this vertex and the rest of the sequences.
 double realignToParent(double heat)
           
 void recomputeCheckLogLike()
           
 void recomputeLogLike()
           
 void recomputeLogLikeSelected()
           
 void recursivelyUpdateHmm2Matrices()
           
 void recursivelyUpdateHmm3Matrices()
           
 void recursivelyUpdateHmmMatrices()
           
 void restoreData()
           
 void restoreFiveWay()
           
 void restoreFiveWay(boolean swapNephewUncle)
           
 void saveData()
           
 double selectAndResampleAlignment()
          This function cuts out a window and realigns in the selected subtree.
 void selectSubtree(double[] weights, int level)
          Selects a subtree
 void setEdgeLength(double x)
           
 void swapBackUncleAlignToParent()
          Restores the exact state just before the call to swapWithUncleAlignToParent().
 double swapWithUncleAlignToParent()
          Swaps this with its uncle, but proposes new alignments only between this node and its parent, and the uncle node and its parent, every other alignment is kept fixed.
 void undoExciseSilentIndel()
           
 void undoInsertSilentIndel()
           
 void updateAligned()
           
 void updateAlignedInWindow()
           
 void updateAlignedParent()
           
 void updateAlignedParentInWindow()
           
 void updateAlignedRecursively()
           
 void updateAlignedRecursivelyInWindow()
           
 void updateAlignedRecursivelyInWindowWithCheck()
           
 void updateAlignedRecursivelyWithCheck()
           
 void updateHmm2Matrices()
           
 void updateHmm2Matrix(double[] params)
           
 void updateHmmMatrices()
           
 void updateTransitionMatrix()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The name of the sequence associated to the vertex. Used only if the vertex is a leaf of the tree.


index

public int index
Index of this vertex in the Tree.vertex array


parent

public Vertex parent
This reference points to the parent of the vertex


left

public Vertex left
This reference points to the left child of the vertex. If the vertex is a leaf, it is set to null.


right

public Vertex right
This reference points to the right child of the vertex. If the vertex is a leaf, it is set to null.


nSilentIndels

public int nSilentIndels

first

public AlignColumn first

selected

public boolean selected

edgeLength

public double edgeLength
The length of the edge that connects this vertex with its parent.


orphanLogLike

public double orphanLogLike
The log-sum of the Felsenstein's likelihoods of characters that are inserted into the sequence of this vertex.


indelLogLike

public double indelLogLike
The log-sum of the cumulative insertion-deletion loglikelihoods up to this vertex (ie. summed over the subtree below this vertex.).


leafCount

public int leafCount
Constructor Detail

Vertex

public Vertex(Tree tree)

Vertex

public Vertex(Vertex parent)
Method Detail

brother

public Vertex brother()
Returns:
the "brother" of this node, i.e. the other descendant of its parent

updateTransitionMatrix

public void updateTransitionMatrix()

updateHmm2Matrix

public void updateHmm2Matrix(double[] params)

updateHmmMatrices

public void updateHmmMatrices()

recursivelyUpdateHmmMatrices

public void recursivelyUpdateHmmMatrices()

updateHmm2Matrices

public void updateHmm2Matrices()

recursivelyUpdateHmm2Matrices

public void recursivelyUpdateHmm2Matrices()

recursivelyUpdateHmm3Matrices

public void recursivelyUpdateHmm3Matrices()

setEdgeLength

public void setEdgeLength(double x)

printChildren

public static void printChildren(Vertex v)

printEdges

public static void printEdges(Vertex v)

edgeChangeUpdate

public void edgeChangeUpdate()

printWithNumbers

public void printWithNumbers(java.lang.StringBuffer b)

print

public void print(java.lang.StringBuffer b)

print

public void print(java.lang.StringBuffer b,
                  boolean withNumbers)

print

public java.lang.String print(int digits)

recomputeLogLike

public void recomputeLogLike()

recomputeLogLikeSelected

public void recomputeLogLikeSelected()

recomputeCheckLogLike

public void recomputeCheckLogLike()

calcUpperFromRoot

public void calcUpperFromRoot()

calcUpperRecursively

public void calcUpperRecursively()
This function calculates the upper probability vectors, which contain the partial likelihoods for everything except this subtree. Requires the felsenstein partial likelihoods to have already been computed for everything below.


calcUpperRecursivelyWithCheck

public void calcUpperRecursivelyWithCheck()

calcFelsenRecursively

public void calcFelsenRecursively()
This function calculates the Felsenstein likelihood for the subtree below this. When called from the root, the result is stored in orphanLogLike at the root.


calcFelsen

public void calcFelsen()

calcOrphan

public void calcOrphan()

calcOrphanRecursively

public void calcOrphanRecursively()

calcIndelLogLikeRecursively

public void calcIndelLogLikeRecursively()

calcIndelLogLike

public void calcIndelLogLike()

hmm2AlignWithSave

public double hmm2AlignWithSave()
Samples a new alignment between `this' & `this.parent', taking window sizes into account. Updates all Vertex-stored suppl. data, saving old data for restoration into oldVertex.

Returns:
log of 1/proposal

hmm2AlignWithSave

public double hmm2AlignWithSave(double heat)

selectSubtree

public void selectSubtree(double[] weights,
                          int level)
Selects a subtree


selectAndResampleAlignment

public double selectAndResampleAlignment()
This function cuts out a window and realigns in the selected subtree.


realignToParent

public double realignToParent(double heat)

realignToParent

public double realignToParent()

realignToParent

public double realignToParent(boolean useCurrentWin)

realignToParent

public double realignToParent(boolean useCurrentWin,
                              double heat)
Samples a new alignment between the subtree rooted at this vertex and the rest of the sequences. Only the alignment between this vertex and its parent is changed.

Parameters:
useCurrentWin - if true then keeps the current window selection for this node (backproposal and proposal for window selection must be computed by the caller)
Returns:
the ratio between backproposal and proposal probabilities

updateAligned

public void updateAligned()

updateAlignedInWindow

public void updateAlignedInWindow()

updateAlignedParentInWindow

public void updateAlignedParentInWindow()

updateAlignedParent

public void updateAlignedParent()

updateAlignedRecursively

public void updateAlignedRecursively()

updateAlignedRecursivelyInWindow

public void updateAlignedRecursivelyInWindow()

updateAlignedRecursivelyInWindowWithCheck

public void updateAlignedRecursivelyInWindowWithCheck()

updateAlignedRecursivelyWithCheck

public void updateAlignedRecursivelyWithCheck()

alignRestore

public void alignRestore()
Restores all the changes an alignment resampling on the currently selected subtree has produced. Must be called on selected subtree root.


restoreFiveWay

public void restoreFiveWay()

restoreFiveWay

public void restoreFiveWay(boolean swapNephewUncle)

computeWeights

public void computeWeights(statalign.base.Vertex.Neighbours curr,
                           double[] logProbs)
Computes the probability of all the possible imputations for parent and grandpa given the neighbouring AlignColumn objects.

Parameters:
curr - Neighbours struct corresponding to current state
old - Neighbours struct corresponding to original state

favouredDestination

public int favouredDestination(int state)

saveData

public void saveData()

restoreData

public void restoreData()

insertSilentIndel

public double insertSilentIndel()

insertSilentIndel

public double insertSilentIndel(AlignColumn c)

insertSilentIndelBlock

public double insertSilentIndelBlock(AlignColumn c)

undoInsertSilentIndel

public void undoInsertSilentIndel()

undoExciseSilentIndel

public void undoExciseSilentIndel()

exciseSilentIndel

public double exciseSilentIndel()

exciseSilentIndel

public double exciseSilentIndel(AlignColumn c)

exciseSilentIndel

public double exciseSilentIndel(AlignColumn c,
                                boolean remove)

exciseAllSilentIndels

public void exciseAllSilentIndels()

modifySilentIndel

public double modifySilentIndel(boolean insert)

exciseSilentIndelBlock

public double exciseSilentIndelBlock(AlignColumn insert,
                                     boolean remove)

nephewUncleSwapFixedColumns3

public double nephewUncleSwapFixedColumns3()

nephewUncleSwapFixedColumns2

public double nephewUncleSwapFixedColumns2()

nephewUncleSwapFixedColumns

public double nephewUncleSwapFixedColumns()

swapWithUncleAlignToParent

public double swapWithUncleAlignToParent()
Swaps this with its uncle, but proposes new alignments only between this node and its parent, and the uncle node and its parent, every other alignment is kept fixed. Slow because full sequence alignment is done. Assumes this has a non-null grandparent.

Returns:
log-quotient of backproposal and proposal

swapBackUncleAlignToParent

public void swapBackUncleAlignToParent()
Restores the exact state just before the call to swapWithUncleAlignToParent(). Must be called on ex-uncle node. Assumes this has a non-null grandparent.


fastSwapWithUncle

public double fastSwapWithUncle()
Swaps this with its uncle, but keeps alignment columns where this, its parent, the uncle node and its parent are all aligned unchanged with a given probability, and only proposes new alignments between these selected alignment anchors columns. Alignments between other sequences than the above mentioned four are kept unchanged. Assumes this has a non-null grandparent.

Returns:
log-quotient of backproposal and proposal

fastSwapBackUncle

public void fastSwapBackUncle()
Restores the exact state just before the call of fastSwapWithUncle(). Must be called on ex-uncle node. Assumes this has a non-null grandparent.


calcAllUp

public void calcAllUp()
Calculates Felsenstein and indel likelihoods up to root, starting from `parent'


printedAlignment

public java.lang.String[] printedAlignment(boolean inWindow)

printedAlignment

public java.lang.String[] printedAlignment()

printPointers

public void printPointers()

printToScreenAlignment

public void printToScreenAlignment(int windowStart,
                                   int windowEnd)

printToScreenAlignment

public void printToScreenAlignment(int windowStart,
                                   int windowEnd,
                                   boolean printAll)

calcSumOfEdges

public double calcSumOfEdges()
Calculate the sum of branch lengths below on this vertex. Used to generate the prior for the whole state.

Returns:
sum of branchlengths below this node.

maxDepth

public double maxDepth()
Calculate the maximum depth below on this vertex. Used in tree visualisation.

Returns:
maximum depth below this vertex.

checkPointers

public void checkPointers()
this function checks if the pointers are all right...


getLength

public int getLength()