use of dr.evolution.tree.FlexibleTree in project beast-mcmc by beast-dev.
the class TiterImporter 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;
}
use of dr.evolution.tree.FlexibleTree in project beast-mcmc by beast-dev.
the class TaxaOriginTrait method tabulateOrigins.
private void tabulateOrigins() {
HashMap<String, Integer> countsMap = new HashMap<String, Integer>();
int count = 0;
for (FlexibleTree currentTree : trees) {
if (count % 1 == 0) {
System.out.println("Doing tree " + count);
}
HashMap<String, String> results = getIncomingJumpOrigins(currentTree);
for (String key : results.keySet()) {
int oldCount = countsMap.containsKey(results.get(key)) ? countsMap.get(results.get(key)) : 0;
countsMap.put(results.get(key), oldCount + 1);
}
count++;
}
try {
BufferedWriter outWriter = new BufferedWriter(new FileWriter(fileNameRoot + ".csv"));
for (String key : countsMap.keySet()) {
outWriter.write(key + "," + countsMap.get(key) + "\n");
}
outWriter.flush();
} catch (IOException e) {
System.out.println("Failed to write to file");
}
}
use of dr.evolution.tree.FlexibleTree in project beast-mcmc by beast-dev.
the class TaxaOriginTrait method getTraitName.
private String getTraitName() {
FlexibleTree tree = trees[0];
String traitName = null;
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
NodeRef node = tree.getExternalNode(i);
for (String taxaName : taxaNames) {
if (tree.getNodeTaxon(node).getId().equals(taxaName)) {
String attributeValue = (String) tree.getNodeAttribute(node, attributeName);
if (traitName != null && !traitName.equals(attributeValue)) {
throw new RuntimeException("Not all taxa given have the same trait value");
} else {
traitName = attributeValue;
}
}
}
}
return traitName;
}
use of dr.evolution.tree.FlexibleTree in project beast-mcmc by beast-dev.
the class SimulateTrait method simulate.
/**
* simulates a trait ona tree.
* @param clone if true, use copy of the tree, otherwise use given tree
* @return the simulated tree.
*/
public Tree simulate(Tree tree, double value, boolean clone) {
Tree binaryTree = null;
if (clone) {
binaryTree = new FlexibleTree(tree);
((FlexibleTree) binaryTree).resolveTree();
} else {
binaryTree = tree;
}
simulate((MutableTree) binaryTree, binaryTree.getRoot(), value);
return binaryTree;
}
use of dr.evolution.tree.FlexibleTree 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