use of dr.evolution.util.TimeScale in project beast-mcmc by beast-dev.
the class SamplesPanel method calculateHeights.
private void calculateHeights() {
maximumTipHeight = 0.0;
if (taxonList == null || taxonList.getTaxonCount() == 0)
return;
heights = null;
dr.evolution.util.Date mostRecent = null;
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Date date = taxonList.getTaxon(i).getDate();
if ((date != null) && (mostRecent == null || date.after(mostRecent))) {
mostRecent = date;
}
}
if (mostRecent != null) {
heights = new double[taxonList.getTaxonCount()];
TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
double time0 = timeScale.convertTime(mostRecent.getTimeValue(), mostRecent);
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Date date = taxonList.getTaxon(i).getDate();
if (date != null) {
heights[i] = timeScale.convertTime(date.getTimeValue(), date) - time0;
if (heights[i] > maximumTipHeight)
maximumTipHeight = heights[i];
}
}
}
}
use of dr.evolution.util.TimeScale in project beast-mcmc by beast-dev.
the class TreeUtils method setHeightsFromDates.
/**
* Sets the tip heights from the tip dates
*/
public static void setHeightsFromDates(MutableTree tree) {
Date mostRecent = null;
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
Taxon taxon = tree.getNodeTaxon(tree.getExternalNode(i));
Date date = (Date) taxon.getAttribute("date");
if (date != null) {
if ((mostRecent == null) || date.after(mostRecent)) {
mostRecent = date;
}
}
}
TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
NodeRef node = tree.getExternalNode(i);
Taxon taxon = tree.getNodeTaxon(node);
Date date = (Date) taxon.getAttribute("date");
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(node, height);
} else {
tree.setNodeHeight(node, 0.0);
}
}
adjustInternalHeights(tree, tree.getRoot());
if (mostRecent != null) {
tree.setUnits(mostRecent.getUnits());
}
}
use of dr.evolution.util.TimeScale in project beast-mcmc by beast-dev.
the class SamplesPanel method calculateHeights.
private void calculateHeights() {
maximumTipHeight = 0.0;
if (taxonList == null || taxonList.getTaxonCount() == 0)
return;
heights = null;
Date mostRecent = null;
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Date date = taxonList.getTaxon(i).getDate();
if ((date != null) && (mostRecent == null || date.after(mostRecent))) {
mostRecent = date;
}
}
if (mostRecent != null) {
heights = new double[taxonList.getTaxonCount()];
TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
double time0 = timeScale.convertTime(mostRecent.getTimeValue(), mostRecent);
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Date date = taxonList.getTaxon(i).getDate();
if (date != null) {
heights[i] = timeScale.convertTime(date.getTimeValue(), date) - time0;
if (heights[i] > maximumTipHeight)
maximumTipHeight = heights[i];
}
}
}
}
use of dr.evolution.util.TimeScale 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;
}
use of dr.evolution.util.TimeScale in project beast-mcmc by beast-dev.
the class SimpleTreeParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
boolean usingDates = xo.getAttribute(USING_DATES, false);
SimpleNode root = (SimpleNode) xo.getChild(SimpleNode.class);
if (root == null) {
throw new XMLParseException("node element missing from tree");
}
SimpleTree tree = new SimpleTree(root);
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, DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), 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), DATE);
if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
mostRecent = date;
}
}
if (mostRecent == null) {
throw new XMLParseException("no date elements in tree (and usingDates attribute set)");
}
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, DATE);
if (date == null) {
date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), 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), DATE);
if (date != null) {
double height = timeScale.convertTime(date.getTimeValue(), date);
tree.setNodeHeight(tree.getInternalNode(i), height);
}
}
MutableTree.Utils.correctHeightsForTips(tree);
}
tree.setUnits(units);
return tree;
}
Aggregations