use of dr.evolution.util.Date in project beast-mcmc by beast-dev.
the class TipDatesPanel method setDates.
private void setDates() {
if (options.taxonList == null) {
// validation of check empty taxonList
return;
}
int result;
do {
if (dateValueDialog == null) {
dateValueDialog = new SetValueDialog(frame, "Set Date for Taxa");
}
int[] selRows = dataTable.getSelectedRows();
if (selRows.length == 1) {
precisionValueDialog.setDescription("Set date value for selected taxon");
} else if (selRows.length > 1) {
dateValueDialog.setDescription("Set date values for selected taxa");
} else {
dateValueDialog.setDescription("Set date values for all taxa");
}
result = dateValueDialog.showDialog();
if (result == -1 || result == JOptionPane.CANCEL_OPTION) {
return;
}
// currentTrait.guessTrait = true; // ?? no use?
String value = dateValueDialog.getValue();
java.util.Date origin = new java.util.Date(0);
double d = Double.parseDouble(value);
Date date = Date.createTimeSinceOrigin(d, Units.Type.YEARS, origin);
if (selRows.length > 0) {
for (int row : selRows) {
options.taxonList.getTaxon(row).setAttribute("date", date);
}
} else {
for (Taxon taxon : options.taxonList) {
taxon.setAttribute("date", date);
}
}
// adjust the dates to the current timescale...
timeScaleChanged();
dataTableModel.fireTableDataChanged();
} while (result < 0);
}
use of dr.evolution.util.Date 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.Date in project beast-mcmc by beast-dev.
the class SamplesPanel method timeScaleChanged.
public final void timeScaleChanged() {
Units.Type units = Units.Type.YEARS;
switch(unitsCombo.getSelectedIndex()) {
case 0:
units = Units.Type.YEARS;
break;
case 1:
units = Units.Type.MONTHS;
break;
case 2:
units = Units.Type.DAYS;
break;
}
boolean backwards = directionCombo.getSelectedIndex() == 1;
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Date date = taxonList.getTaxon(i).getDate();
double d = date.getTimeValue();
Date newDate = createDate(d, units, backwards, 0.0);
newDate.setUncertainty(date.getUncertainty());
taxonList.getTaxon(i).setDate(newDate);
}
calculateHeights();
dataTableModel.fireTableDataChanged();
frame.timeScaleChanged();
}
use of dr.evolution.util.Date in project beast-mcmc by beast-dev.
the class SamplesPanel method clearDates.
public void clearDates() {
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
java.util.Date origin = new java.util.Date(0);
double d = 0.0;
Date date = Date.createTimeSinceOrigin(d, Units.Type.YEARS, origin);
taxonList.getTaxon(i).setAttribute("date", date);
}
// adjust the dates to the current timescale...
timeScaleChanged();
dataTableModel.fireTableDataChanged();
}
use of dr.evolution.util.Date in project beast-mcmc by beast-dev.
the class TreeUtils method getTipDates.
/**
* Gets the tip dates from a tree.
*/
public static void getTipDates(Tree tree, Variate dates) {
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
Taxon taxon = tree.getNodeTaxon(tree.getExternalNode(i));
Object date = taxon.getAttribute("date");
if (date != null) {
if (date instanceof Date) {
dates.add(((Date) date).getTimeValue());
} else {
try {
dates.add(Double.parseDouble(date.toString()));
} catch (NumberFormatException nfe) {
dates.add(0.0);
}
}
} else {
dates.add(0.0);
}
}
}
Aggregations