use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NewickImporter method importNextTree.
/**
* import the next tree.
* return the tree or null if no more trees are available
*/
public Tree importNextTree() throws IOException, ImportException {
FlexibleTree tree = null;
try {
skipUntil("(");
unreadCharacter('(');
FlexibleNode root = readInternalNode(lastTree);
tree = new FlexibleTree(root, false, true);
} catch (EOFException e) {
//
}
lastTree = tree;
return tree;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NewickImporter method importTree.
/**
* importTree.
*/
public Tree importTree(TaxonList taxonList) throws IOException, ImportException {
setCommentDelimiters('[', ']', '\0', '\0', '&');
try {
skipUntil("(");
unreadCharacter('(');
final FlexibleNode root = readInternalNode(taxonList);
if (getLastMetaComment() != null) {
root.setAttribute(COMMENT, getLastMetaComment());
}
return new FlexibleTree(root, false, true);
} catch (EOFException e) {
throw new ImportException("incomplete tree");
}
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NewickImporter method readBranch.
/**
* Reads a branch in. This could be a node or a tip (calls readNode or readTip
* accordingly). It then reads the branch length and SimpleNode that will
* point at the new node or tip.
*/
private FlexibleNode readBranch(TaxonList taxonList) throws IOException, ImportException {
double length = 0.0;
FlexibleNode branch;
if (nextCharacter() == '(') {
// is an internal node
branch = readInternalNode(taxonList);
} else {
// is an external node
branch = readExternalNode(taxonList);
}
final String comment = getLastMetaComment();
if (comment != null) {
branch.setAttribute(COMMENT, comment);
clearLastMetaComment();
}
if (getLastDelimiter() == ':') {
length = readDouble(",():;");
}
branch.setLength(length);
return branch;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class TaxaOriginTrait method getIncomingJumpOrigins.
private HashMap<String, String> getIncomingJumpOrigins(FlexibleTree tree) {
HashMap<String, String> out = new HashMap<String, String>();
FlexibleNode[] tips = getTipsOfInterest(tree);
FlexibleNode mrca = findCommonAncestor(tree, tips);
HashSet<FlexibleNode> taxaSet = new HashSet<FlexibleNode>(Arrays.asList(tips));
HashSet<FlexibleNode> tipSet = getTipSet(tree, mrca);
if (!taxaSet.containsAll(tipSet)) {
System.out.println("WARNING: mixed traits in a clade");
}
if (!mrca.getAttribute(attributeName).equals(traitName)) {
out.put(traitName, "Multiple");
System.out.println("Multiple origin found.");
} else {
boolean sameTrait = true;
FlexibleNode currentParent = mrca;
while (sameTrait) {
currentParent = (FlexibleNode) tree.getParent(currentParent);
if (currentParent == null) {
out.put(traitName, "root");
break;
} else {
String parentTrait = (String) currentParent.getAttribute(attributeName);
if (!parentTrait.equals(traitName)) {
sameTrait = false;
out.put(traitName, parentTrait);
}
}
}
}
return out;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class TaxaOriginTrait method findCommonAncestor.
private FlexibleNode findCommonAncestor(FlexibleTree tree, FlexibleNode[] nodes) {
HashSet<FlexibleNode> doneNodes = new HashSet<FlexibleNode>();
FlexibleNode currentParent = nodes[0];
for (FlexibleNode node : nodes) {
doneNodes.add(node);
boolean ancestorOfAllDoneNodes = false;
currentParent = node;
if (getTipSet(tree, currentParent).containsAll(doneNodes)) {
ancestorOfAllDoneNodes = true;
}
while (!ancestorOfAllDoneNodes) {
currentParent = (FlexibleNode) tree.getParent(currentParent);
if (getTipSet(tree, currentParent).containsAll(doneNodes)) {
ancestorOfAllDoneNodes = true;
}
}
}
return currentParent;
}
Aggregations