Search in sources :

Example 1 with Date

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();
}
Also used : Date(dr.evolution.util.Date)

Example 2 with Date

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;
    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];
            }
        }
    }
}
Also used : TimeScale(dr.evolution.util.TimeScale) Date(dr.evolution.util.Date)

Example 3 with Date

use of dr.evolution.util.Date in project beast-mcmc by beast-dev.

the class TipDatesPanel method clearDates.

private void clearDates() {
    for (int i = 0; i < options.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);
        options.taxonList.getTaxon(i).setAttribute("date", date);
    }
    // adjust the dates to the current timescale...
    timeScaleChanged();
    dataTableModel.fireTableDataChanged();
}
Also used : java.util(java.util) dr.evolution.util(dr.evolution.util) Date(dr.evolution.util.Date)

Example 4 with Date

use of dr.evolution.util.Date in project beast-mcmc by beast-dev.

the class TipDatesPanel method timeScaleChanged.

public final void timeScaleChanged() {
    Units.Type units = Units.Type.YEARS;
    switch((DateUnitsType) unitsCombo.getSelectedItem()) {
        case YEARS:
            units = Units.Type.YEARS;
            break;
        case MONTHS:
            units = Units.Type.MONTHS;
            break;
        case DAYS:
            units = Units.Type.DAYS;
            break;
    }
    boolean backwards = directionCombo.getSelectedItem() == DateUnitsType.BACKWARDS;
    for (int i = 0; i < options.taxonList.getTaxonCount(); i++) {
        Date date = options.taxonList.getTaxon(i).getDate();
        double d = date.getTimeValue();
        Date newDate = createDate(d, units, backwards, 0.0);
        newDate.setUncertainty(date.getUncertainty());
        options.taxonList.getTaxon(i).setDate(newDate);
    }
    if (specifyOriginDate.isSelected()) {
        String text = originDateText.getText();
        DateGuesser guesser = options.dateGuesser;
        guessDatesDialog.setupGuesser(guesser);
        try {
            options.originDate = guesser.parseDate(text);
        } catch (GuessDatesException e) {
            options.originDate = null;
        }
    } else {
        options.originDate = null;
    }
    if (options.originDate != null) {
        originDateLabel.setText(" date value: " + Double.toString(options.originDate.getTimeValue()));
    } else {
        originDateLabel.setText(" unable to parse date");
    }
    calculateHeights();
    if (options.useTipDates) {
        for (PartitionTreeModel treeModel : options.getPartitionTreeModels()) {
            treeModel.setTipCalibrations(true);
        }
    }
    dataTableModel.fireTableDataChanged();
    frame.setDirty();
}
Also used : DateUnitsType(dr.evoxml.util.DateUnitsType) Date(dr.evolution.util.Date)

Example 5 with Date

use of dr.evolution.util.Date in project beast-mcmc by beast-dev.

the class TipDatesPanel method calculateHeights.

private void calculateHeights() {
    options.maximumTipHeight = 0.0;
    if (options.taxonList == null || options.taxonList.getTaxonCount() == 0)
        return;
    heights = null;
    dr.evolution.util.Date mostRecent = options.originDate;
    for (int i = 0; i < options.taxonList.getTaxonCount(); i++) {
        Date date = options.taxonList.getTaxon(i).getDate();
        if ((date != null) && (mostRecent == null || date.after(mostRecent))) {
            mostRecent = date;
        }
    }
    if (mostRecent != null) {
        heights = new double[options.taxonList.getTaxonCount()];
        TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
        double time0 = timeScale.convertTime(mostRecent.getTimeValue(), mostRecent);
        for (int i = 0; i < options.taxonList.getTaxonCount(); i++) {
            Taxon taxon = options.taxonList.getTaxon(i);
            Date date = taxon.getDate();
            if (date != null) {
                heights[i] = timeScale.convertTime(date.getTimeValue(), date) - time0;
                taxon.setAttribute("height", heights[i]);
                if (heights[i] > options.maximumTipHeight)
                    options.maximumTipHeight = heights[i];
            }
        }
    }
    frame.setStatusMessage();
}
Also used : java.util(java.util) dr.evolution.util(dr.evolution.util) Date(dr.evolution.util.Date) Date(dr.evolution.util.Date)

Aggregations

Date (dr.evolution.util.Date)39 Taxon (dr.evolution.util.Taxon)19 Taxa (dr.evolution.util.Taxa)5 TimeScale (dr.evolution.util.TimeScale)5 Parameter (dr.inference.model.Parameter)5 java.util (java.util)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 Sequence (dr.evolution.sequence.Sequence)4 NodeRef (dr.evolution.tree.NodeRef)4 dr.evolution.util (dr.evolution.util)4 Units (dr.evolution.util.Units)3 CompoundParameter (dr.inference.model.CompoundParameter)3 ArrayList (java.util.ArrayList)3 Tree (dr.evolution.tree.Tree)2 TaxonList (dr.evolution.util.TaxonList)2 Attribute (dr.util.Attribute)2 NexusExporter (dr.app.tools.NexusExporter)1 CoalescentSimulator (dr.evolution.coalescent.CoalescentSimulator)1 PiecewiseLinearPopulation (dr.evolution.coalescent.PiecewiseLinearPopulation)1 SimpleNode (dr.evolution.tree.SimpleNode)1