use of dr.evomodel.bigfasttree.ghosttree.GhostTreeModel in project beast-mcmc by beast-dev.
the class CladeAwareSubtreePruneRegraft method getRelevantClade.
private CladeRef getRelevantClade(NodeRef nodeRef) {
if (isGhostTree) {
// TODO test this branch
GhostTreeModel ghostTreeModel = ((GhostTreeModel) tree);
CorporealTreeModel corporealTreeModel = ghostTreeModel.getCorporealTreeModel();
if (((GhostTreeModel) tree).hasCorporealCounterPart(nodeRef)) {
NodeRef corporealNode = ghostTreeModel.getCorporealCounterPart(nodeRef);
if (corporealTreeModel.isRoot(corporealNode)) {
return cladeModel.getClade(corporealNode);
} else {
return cladeModel.getClade(corporealTreeModel.getParent(corporealNode));
}
} else if (ghostTreeModel.getNextCorporealDescendent(nodeRef) != null) {
NodeRef corporealNode = ghostTreeModel.getNextCorporealDescendent(nodeRef);
if (corporealTreeModel.isRoot(corporealNode)) {
return cladeModel.getClade(corporealNode);
} else {
return cladeModel.getClade(corporealTreeModel.getParent(corporealNode));
}
} else {
if (tree.isRoot(nodeRef)) {
return cladeModel.getClade(corporealTreeModel.getRoot());
}
return getRelevantClade(tree.getParent(nodeRef));
}
} else {
return cladeModel.getClade(tree.getParent(nodeRef));
}
}
use of dr.evomodel.bigfasttree.ghosttree.GhostTreeModel in project beast-mcmc by beast-dev.
the class CladeAwareSubtreePruneRegraft method getDistances.
private void getDistances(double height, NodeRef node, CladeRef clade, List<Double> nodeDistances, List<Double> effectiveNodeHeights, List<NodeRef> nodes) {
double effectiveHeight = Math.max(tree.getNodeHeight(node), height);
if (tree.getParent(node) == null) {
totalDistanceTraversed += 0;
} else {
double effectiveBranchLength = tree.getNodeHeight(tree.getParent(node)) - effectiveHeight;
totalDistanceTraversed += effectiveBranchLength;
}
nodeDistances.add(totalDistanceTraversed);
nodes.add(node);
effectiveNodeHeights.add(effectiveHeight);
boolean goOn;
if (isGhostTree) {
if (((GhostTreeModel) tree).hasCorporealCounterPart(node)) {
NodeRef corpNode = ((GhostTreeModel) tree).getCorporealCounterPart(node);
goOn = cladeModel.getClade(corpNode) == clade && tree.getNodeHeight(node) > height;
} else {
// if just a ghost node keep going
goOn = true;
}
} else {
goOn = cladeModel.getClade(node) == clade && tree.getNodeHeight(node) > height;
}
if (goOn) {
for (int i = 0; i < tree.getChildCount(node); i++) {
NodeRef child = tree.getChild(node, i);
getDistances(height, child, clade, nodeDistances, effectiveNodeHeights, nodes);
}
}
}
use of dr.evomodel.bigfasttree.ghosttree.GhostTreeModel in project beast-mcmc by beast-dev.
the class GhostTreeModelParser method parseXMLObject.
/**
* @return a tree object based on the XML element it was passed.
*/
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Tree tree = (Tree) xo.getChild(Tree.class);
TaxonList ghostTaxa = (TaxonList) xo.getElementFirstChild(GHOST_TAXA);
GhostTreeModel treeModel = new GhostTreeModel(xo.getId(), tree, ghostTaxa);
Logger.getLogger("dr.evomodel").info("\nCreating the tree model, '" + xo.getId() + "'" + "\n\nwith " + ghostTaxa.getTaxonCount() + " ghost lineages.");
Logger.getLogger("dr.evomodel").info(" taxon count = " + treeModel.getExternalNodeCount());
Logger.getLogger("dr.evomodel").info(" tree height = " + treeModel.getNodeHeight(treeModel.getRoot()));
return treeModel;
}
use of dr.evomodel.bigfasttree.ghosttree.GhostTreeModel in project beast-mcmc by beast-dev.
the class GhostTreeModelTest method setUp.
public void setUp() throws Exception {
super.setUp();
Taxa ghostTaxa = new Taxa("ghost");
ghostTaxa.addTaxon(new Taxon("g1"));
ghostTaxa.addTaxon(new Taxon("g2"));
Taxa corporealTaxa = new Taxa("corporeal");
corporealTaxa.addTaxon(new Taxon("0"));
corporealTaxa.addTaxon(new Taxon("1"));
corporealTaxa.addTaxon(new Taxon("2"));
Taxa allTaxa = new Taxa(ghostTaxa);
allTaxa.addTaxa(corporealTaxa);
NewickImporter importer = new NewickImporter("(((g1:0.5,0:1):0.5,1:1):1,(g2:1,2:1):0.5)");
Tree superTree = importer.importTree(allTaxa);
ghostTree = new GhostTreeModel(superTree, ghostTaxa);
corporealTree = ghostTree.getCorporealTreeModel();
}
Aggregations