Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| /* PDAP:PDTREE package for Mesquite copyright 2001-2009 P. Midford & W. MaddisonPDAP:PDTREE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.The web site for PDAP:PDTREE is http://mesquiteproject.org/pdap_mesquite/This source code and its compiled class files are free and modifiable under the terms of GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)*/package mesquite.pdap.PagelTransform;/*~~ */import mesquite.lib.*;import mesquite.lib.duties.*;/** ======================================================================== */public class PagelTransform extends BranchLengthsAlterer { private int [] depth; /*.................................................................................................................*/ public boolean startJob(String arguments, Object condition, boolean hiredByName) { return true; } /*.................................................................................................................*/ /** * * @param tree * @param resultString * @return true if calling code is responsible for notifying listeners of tree */ public boolean transformTree(AdjustableTree tree, MesquiteString resultString){ doTransform(tree); return true; } /** * This procedure sets all the branch lengths to those dictated by * Pagel's (1992, J. of Theoretical Biol 156:431-442) arbitrary method. * The depth of a node is equal to the maximum of the number of * bifurcation levels of the left child and the right child plus one. * If a node is a polytomy, its depth is set to the maximum of the * bifurcation levels of the offspring, but one is not added. This * results in polytomies being assigned the least depth possible. This * was a (PDAP) internal decision, as Pagel(1992, p. 441 paragraph 7) does * not discuss how to assign a depth to a polytomy node. * * @param tree what to transform */ private void doTransform(AdjustableTree tree) { final int root = tree.getRoot(); depth = new int[tree.getNumNodeSpaces()]; pagelMe1(tree,root); pagelMe2(tree,root); } /** * * This method computes the depths recursively. The original * Pagelme procedure was split into 2 pieces to support PDAP's implementation of polytomy. * Comment from DOS PDAP PEM 9-May-95. * @param tree * @param nd * @return */ private int pagelMe1(AdjustableTree tree, int nd) { int maxBif = 0; if (!tree.nodeIsInternal(nd)) { depth[nd] =0; //set depth to 0} return 0; } else { // node is either unbranched or branched - don't add depth for unbranched internal nodes int daughterCount = tree.numberOfDaughtersOfNode(nd); if (daughterCount == 1){ depth[nd] = pagelMe1(tree,tree.firstDaughterOfNode(nd)); return depth[nd]; } else{ // it branches, so add one to the depth for (int daughter=tree.firstDaughterOfNode(nd); tree.nodeExists(daughter); daughter = tree.nextSisterOfNode(daughter) ) { int d = pagelMe1(tree,daughter); if (d > maxBif) maxBif = d; } depth[nd] = maxBif+1; // this should be compatible with DOS PDAP - a polytomy does add exactly one to the depth (nothing for implied internal ZLB's) return depth[nd]; } } } /** * This method finishes the transformation (taking * polytomies into account. Note that it does its work while going * back down the tree (toward the root), while pagelme1 does its work * going up the tree (toward the tips). Original 9-May-95, Java translation 23-Feb-2001 PEM * @param tree * @param nd */ private void pagelMe2(AdjustableTree tree, int nd) { if (tree.nodeIsInternal(nd)) { for (int daughter=tree.firstDaughterOfNode(nd); tree.nodeExists(daughter); daughter = tree.nextSisterOfNode(daughter) ) { tree.setBranchLength(daughter,depth[nd]-depth[daughter],false); pagelMe2(tree,daughter); } } } /*.................................................................................................................*/ public String getName() { return "Branch Lengths Transformation of Pagel (1992)"; } /*.................................................................................................................*/ public String getVersion() { return "1.15"; } /*.................................................................................................................*/ public boolean isPrerelease() { return false; } /*................................................................................................................*/ public boolean isSubstantive(){ return true; } /*.................................................................................................................*/ public String getAuthors() { return "Peter E. Midford, Ted Garland Jr., and Wayne P. Maddison"; } /*.................................................................................................................*/ /** returns an explanation of what the module does.*/ public String getExplanation() { return ("Adjusts a tree's branch lengths according the method of Pagel (1992): " + "The depth of a node is equal to the maximum of the number of " + "bifurcation levels of the left child and the right child plus one. "); }} |