use of dr.evolution.tree.UPGMATree in project beast-mcmc by beast-dev.
the class OldTreesPanel method createTree.
private void createTree() {
if (generateTreeDialog == null) {
generateTreeDialog = new GenerateTreeDialog(frame);
}
int result = generateTreeDialog.showDialog(options);
if (result != JOptionPane.CANCEL_OPTION) {
GenerateTreeDialog.MethodTypes methodType = generateTreeDialog.getMethodType();
PartitionData partition = generateTreeDialog.getDataPartition();
Patterns patterns = new Patterns(partition.getAlignment());
DistanceMatrix distances = new F84DistanceMatrix(patterns);
Tree tree;
TemporalRooting temporalRooting;
switch(methodType) {
case NJ:
tree = new NeighborJoiningTree(distances);
temporalRooting = new TemporalRooting(tree);
tree = temporalRooting.findRoot(tree, TemporalRooting.RootingFunction.CORRELATION);
break;
case UPGMA:
tree = new UPGMATree(distances);
temporalRooting = new TemporalRooting(tree);
break;
default:
throw new IllegalArgumentException("unknown method type");
}
tree.setId(generateTreeDialog.getName());
options.userTrees.add(tree);
treesTableModel.fireTableDataChanged();
int row = options.userTrees.size() - 1;
treesTable.getSelectionModel().setSelectionInterval(row, row);
}
fireTreePriorsChanged();
}
use of dr.evolution.tree.UPGMATree in project beast-mcmc by beast-dev.
the class UPGMATreeParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
boolean usingDatesSpecified = false;
boolean usingDates = true;
double rootHeight = xo.getAttribute(ROOT_HEIGHT, -1.0);
if (xo.hasAttribute(SimpleTreeParser.USING_DATES)) {
usingDatesSpecified = true;
usingDates = xo.getBooleanAttribute(SimpleTreeParser.USING_DATES);
}
DistanceMatrix distances = (DistanceMatrix) xo.getChild(DistanceMatrix.class);
UPGMATree tree = new UPGMATree(distances);
if (rootHeight > 0) {
double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
NodeRef node = tree.getInternalNode(i);
double height = tree.getNodeHeight(node);
tree.setNodeHeight(node, height * scaleFactor);
}
}
if (usingDates) {
dr.evolution.util.Date mostRecent = null;
for (int i = 0; i < tree.getTaxonCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
}
if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
mostRecent = date;
}
}
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
mostRecent = date;
}
}
if (mostRecent == null) {
if (usingDatesSpecified) {
throw new XMLParseException("no date elements in tree (and usingDates attribute set)");
}
} else {
TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
for (int i = 0; i < tree.getTaxonCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
}
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(tree.getExternalNode(i), height);
}
}
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(tree.getInternalNode(i), height);
}
}
MutableTree.Utils.correctHeightsForTips(tree);
}
}
if (rootHeight > 0) {
double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
for (int i = 0; i < tree.getInternalNodeCount(); i++) {
NodeRef node = tree.getInternalNode(i);
double height = tree.getNodeHeight(node);
tree.setNodeHeight(node, height * scaleFactor);
}
}
if (xo.getAttribute(RANDOMIZE, false)) {
shakeTree(tree);
}
return tree;
}
Aggregations