use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class MigrateTreeImporter 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.
*/
FlexibleNode readBranch(HashMap<String, Taxon> translationList) throws IOException, ImportException {
double length = 0.0;
FlexibleNode branch;
clearLastMetaComment();
if (nextCharacter() == '(') {
// is an internal node
branch = readInternalNode(translationList);
} else {
// is an external node
branch = readExternalNode(translationList);
}
if (getLastDelimiter() != ':' && getLastDelimiter() != ',' && getLastDelimiter() != ')') {
String label = readToken(",():;");
if (label.length() > 0) {
branch.setAttribute("label", label);
}
}
if (getLastDelimiter() == ':') {
length = readDouble(" ,():;");
if (getLastMetaComment() != null) {
parseMigrationString(getLastMetaComment(), branch);
clearLastMetaComment();
}
}
branch.setLength(length);
return branch;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NexusImporter method readExternalNode.
// private void labelNode(FlexibleNode node, String label, String value) {
// // Attempt to format the value as a number
// Number number = null;
// try {
// number = Integer.valueOf(value);
// } catch (NumberFormatException nfe1) {
// try {
// number = Double.valueOf(value);
// } catch (NumberFormatException nfe2) {
// //
// }
// }
// if (number != null) {
// node.setAttribute(label, number);
// } else {
// node.setAttribute(label, value);
// }
// }
/**
* Reads an external node in.
*/
FlexibleNode readExternalNode(HashMap<String, Taxon> translationList) throws ImportException, IOException {
FlexibleNode node = new FlexibleNode();
String label = readToken(":(),;");
Taxon taxon;
if (translationList.size() > 0) {
taxon = translationList.get(label);
if (taxon == null) {
// taxon not found in taxon list...
throw new UnknownTaxonException("Taxon in tree, '" + label + "' is unknown");
}
} else {
taxon = new Taxon(label);
}
if (getLastMetaComment() != null) {
if (!ignoreMetaComments) {
// \[&label[=value][,label[=value]>[,/..]]\]
try {
parseMetaCommentPairs(getLastMetaComment(), node);
} catch (BadFormatException bfe) {
// ignore it
}
}
clearLastMetaComment();
}
node.setTaxon(taxon);
return node;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NexusImporter 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.
*/
FlexibleNode readBranch(HashMap<String, Taxon> translationList) throws IOException, ImportException {
double length = 0.0;
FlexibleNode branch;
clearLastMetaComment();
if (nextCharacter() == '(') {
// is an internal node
branch = readInternalNode(translationList);
} else {
// is an external node
branch = readExternalNode(translationList);
}
if (getLastDelimiter() != ':' && getLastDelimiter() != ',' && getLastDelimiter() != ')') {
String label = readToken(",():;");
if (label.length() > 0) {
branch.setAttribute("label", label);
}
}
if (getLastDelimiter() == ':') {
length = readDouble(",():;");
if (getLastMetaComment() != null) {
if (!ignoreMetaComments) {
// \[&label[=value][,label[=value]>[,/..]]\]
try {
parseMetaCommentPairs(getLastMetaComment(), branch);
} catch (BadFormatException bfe) {
// ignore it
}
}
clearLastMetaComment();
}
}
branch.setLength(length);
return branch;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class MigrateTreeImporter method readExternalNode.
/**
* Reads an external node in.
*/
FlexibleNode readExternalNode(HashMap<String, Taxon> translationList) throws ImportException, IOException {
FlexibleNode node = new FlexibleNode();
String label = readToken(":(),;");
Taxon taxon;
if (translationList.size() > 0) {
taxon = translationList.get(label);
if (taxon == null) {
// taxon not found in taxon list...
throw new UnknownTaxonException("Taxon in tree, '" + label + "' is unknown");
}
} else {
taxon = new Taxon(label);
}
if (getLastMetaComment() != null) {
parseMigrationString(getLastMetaComment(), node);
clearLastMetaComment();
}
node.setTaxon(taxon);
int pop = Integer.parseInt(label.split("\\.")[0]);
node.setAttribute(POP, (pop - 1));
return node;
}
use of dr.evolution.tree.FlexibleNode in project beast-mcmc by beast-dev.
the class NewickImporter method importTrees.
/**
* importTrees.
*/
public Tree[] importTrees(TaxonList taxonList) throws IOException, ImportException {
boolean done = false;
ArrayList<FlexibleTree> array = new ArrayList<FlexibleTree>();
do {
try {
skipUntil("(");
unreadCharacter('(');
FlexibleNode root = readInternalNode(taxonList);
FlexibleTree tree = new FlexibleTree(root, false, true);
array.add(tree);
if (taxonList == null) {
taxonList = tree;
}
if (readCharacter() != ';') {
throw new BadFormatException("Expecting ';' after tree");
}
} catch (EOFException e) {
done = true;
}
} while (!done);
Tree[] trees = new Tree[array.size()];
array.toArray(trees);
return trees;
}
Aggregations