Search in sources :

Example 6 with Date

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

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

Example 8 with Date

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

Example 9 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 10 with Date

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