Search in sources :

Example 1 with Taxa

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

the class AncestralStatesOptionsPanel method setupPanel.

/**
     * Lays out the appropriate components in the panel for this partition
     * model.
     */
void setupPanel() {
    isUpdating = true;
    String selectedItem = (String) mrcaReconstructionCombo.getSelectedItem();
    if (mrcaReconstructionCombo.getItemCount() > 0) {
        mrcaReconstructionCombo.removeAllItems();
    }
    mrcaReconstructionCombo.addItem("Tree Root");
    if (options.taxonSets.size() > 0) {
        for (Taxa taxonSet : options.taxonSets) {
            mrcaReconstructionCombo.addItem("MRCA(" + taxonSet.getId() + ")");
        }
        if (selectedItem != null) {
            mrcaReconstructionCombo.setSelectedItem(selectedItem);
        }
    }
    mrcaReconstructionCombo.setEnabled(mrcaReconstructionCheck.isSelected());
    boolean ancestralReconstructionAvailable = true;
    boolean countingAvailable = true;
    boolean dNdSRobustCountingAvailable = false;
    boolean errorModelAvailable = false;
    switch(partition.getDataType().getType()) {
        case DataType.NUCLEOTIDES:
            errorModelAvailable = true;
            // but will be disabled if not codon partitioned
            dNdSRobustCountingAvailable = true;
            break;
        case DataType.AMINO_ACIDS:
        case DataType.GENERAL:
        case DataType.TWO_STATES:
            break;
        case DataType.CONTINUOUS:
            countingAvailable = false;
            break;
        case DataType.MICRO_SAT:
            ancestralReconstructionAvailable = false;
            countingAvailable = false;
            break;
        default:
            throw new IllegalArgumentException("Unsupported data type");
    }
    removeAll();
    if (ancestralReconstructionAvailable) {
        if (partition.getPartitionSubstitutionModel().getCodonPartitionCount() == 2) {
            // mergedPatterns for codon positions 1&2 will always be compressed...
            // so cannot do any of this stuff. Disable it and provide an explanation.
            addSpanningComponent(new JLabel("<html>Unable to provide these options with the 1+2,3 codon<br>" + "position model. Use a 1,2,3 codon position model instead.<br><html>"));
        }
        JLabel label1 = new JLabel("Ancestral State Reconstruction:");
        addSpanningComponent(label1);
        addComponent(ancestralReconstructionCheck);
        FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
        layout.setHgap(0);
        JPanel panel = new JPanel(layout);
        panel.setOpaque(false);
        panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        panel.add(mrcaReconstructionCheck);
        panel.add(mrcaReconstructionCombo);
        addComponent(panel);
        boolean enabled = true;
        if (partition.getPartitionSubstitutionModel().getCodonPartitionCount() == 2) {
            // mergedPatterns for codon positions 1&2 will always be compressed...
            // so cannot do any of this stuff. Disable it and provide an explanation.
            ancestralReconstructionCheck.setEnabled(false);
            enabled = false;
        }
        label1.setEnabled(enabled);
        panel.setEnabled(enabled);
        ancestralReconstructionCheck.setEnabled(enabled);
        mrcaReconstructionCheck.setEnabled(enabled);
        mrcaReconstructionCombo.setEnabled(enabled);
    }
    if (countingAvailable) {
        if (ancestralReconstructionAvailable) {
            addSeparator();
        }
        JLabel label2 = new JLabel("State Change Count Reconstruction:");
        addSpanningComponent(label2);
        JTextArea text1 = new JTextArea("Select this option to reconstruct counts of state changes using " + "Markov Jumps. This approach is described in Minin & Suchard (2008).");
        text1.setColumns(40);
        PanelUtils.setupComponent(text1);
        addComponent(text1);
        addComponent(countingCheck);
        boolean enableSimpleCounting = true;
        // TODO Simple counting is currently not available for codon partitioned models due to BEAUti limitation
        if (ancestralStatesComponent.dNdSRobustCountingAvailable(partition) || partition.getPartitionSubstitutionModel().getCodonPartitionCount() == 2) {
            enableSimpleCounting = false;
            countingCheck.setSelected(false);
        }
        countingCheck.setEnabled(enableSimpleCounting);
        label2.setEnabled(enableSimpleCounting);
        text1.setEnabled(enableSimpleCounting);
        JTextArea text2 = null;
        if (dNdSRobustCountingAvailable) {
            //                addSeparator();
            text2 = new JTextArea("Renaissance counting: select this option to reconstruct counts of synonymous and nonsynonymous " + "changes using Robust Counting. This approach is described in O'Brien, Minin " + "& Suchard (2009) and Lemey, Minin, Bielejec, Kosakovsky-Pond & Suchard " + "(2012):");
            text2.setColumns(40);
            PanelUtils.setupComponent(text2);
            addComponent(text2);
            addComponent(dNdSRobustCountingCheck);
            dNnSText.setColumns(40);
            dNnSText.setBorder(BorderFactory.createEmptyBorder(0, 32, 0, 0));
            PanelUtils.setupComponent(dNnSText);
            addComponent(dNnSText);
            boolean enableRC = ancestralStatesComponent.dNdSRobustCountingAvailable(partition);
            // && !ancestralStatesComponent.isCountingStates(partition);
            dNdSRobustCountingCheck.setEnabled(enableRC);
            ancestralStatesComponent.setDNdSRobustCounting(partition, enableRC && dNdSRobustCountingCheck.isSelected());
            text2.setEnabled(enableRC);
            dNnSText.setEnabled(enableRC);
            if (!enableRC) {
                dNdSRobustCountingCheck.setSelected(false);
            }
        }
        addComponent(completeHistoryLoggingCheck);
        completeHistoryLoggingCheck.setEnabled(countingCheck.isSelected() || dNdSRobustCountingCheck.isSelected());
    }
    if (errorModelAvailable) {
        if (ancestralReconstructionAvailable || countingAvailable) {
            addSeparator();
        }
        JLabel label3 = new JLabel("Sequence error model:");
        addSpanningComponent(label3);
        JLabel label4 = addComponentWithLabel("Error Model:", errorModelCombo);
        boolean enabled = (partition.getPartitionSubstitutionModel().getCodonPartitionCount() != 2);
        label3.setEnabled(enabled);
        label4.setEnabled(enabled);
        errorModelCombo.setEnabled(enabled);
    }
    isUpdating = false;
}
Also used : Taxa(dr.evolution.util.Taxa)

Example 2 with Taxa

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

the class STARBEASTGenerator method writeStartingTreeForCalibration.

public void writeStartingTreeForCalibration(XMLWriter writer) {
    writer.writeComment("species starting tree for calibration");
    writer.writeText("");
    writer.writeOpenTag(OldCoalescentSimulatorParser.COALESCENT_TREE, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SP_START_TREE) });
    Attribute[] taxaAttribute = { new Attribute.Default<String>(XMLParser.IDREF, ALL_SPECIES) };
    writer.writeOpenTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
    writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
    for (Taxa taxa : options.speciesSets) {
        Parameter statistic = options.getStatistic(taxa);
        Attribute mono = new Attribute.Default<Boolean>(OldCoalescentSimulatorParser.IS_MONOPHYLETIC, options.speciesSetsMono.get(taxa));
        writer.writeOpenTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT, mono);
        writer.writeIDref(TaxaParser.TAXA, taxa.getId());
        if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE_CALIBRATION && statistic.priorType == PriorType.UNIFORM_PRIOR) {
            writeDistribution(statistic, false, writer);
        }
        writer.writeCloseTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT);
    }
    writer.writeCloseTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
    writer.writeOpenTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "spInitDemo"), new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units)) });
    writer.writeOpenTag(ConstantPopulationModelParser.POPULATION_SIZE);
    // "initial" is "value"
    double popSizeValue = options.getPartitionTreePriors().get(0).getParameter("constant.popSize").getInitial();
    writer.writeTag(ParameterParser.PARAMETER, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "sp.popSize"), new Attribute.Default<Double>(ParameterParser.VALUE, popSizeValue) }, true);
    writer.writeCloseTag(ConstantPopulationModelParser.POPULATION_SIZE);
    writer.writeCloseTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL);
    writer.writeCloseTag(OldCoalescentSimulatorParser.COALESCENT_TREE);
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute) Parameter(dr.app.beauti.options.Parameter)

Example 3 with Taxa

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

the class BeautiOptions method selectTaxonSetsStatistics.

public void selectTaxonSetsStatistics(List<Parameter> params) {
    if (useStarBEAST) {
        if (speciesSets != null) {
            for (Taxa taxa : speciesSets) {
                Parameter statistic = statistics.get(taxa);
                if (statistic == null) {
                    statistic = new Parameter.Builder(taxa.getId(), "tmrca statistic for species set " + taxa.getId()).taxaId(taxa.getId()).isStatistic(true).isNodeHeight(true).initial(Double.NaN).isNonNegative(true).build();
                    statistics.put(taxa, statistic);
                } else {
                    statistic.isCalibratedYule = getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE_CALIBRATION && speciesSetsMono.get(taxa);
                }
                params.add(statistic);
            }
        } else {
            System.err.println("SpeciesSets are null");
        }
    } else {
        if (taxonSets != null) {
            for (Taxa taxa : taxonSets) {
                Parameter statistic = statistics.get(taxa);
                PartitionTreeModel treeModel = taxonSetsTreeModel.get(taxa);
                if (statistic == null) {
                    // default scaleType = PriorScaleType.NONE; priorType = PriorType.NONE_TREE_PRIOR
                    statistic = new Parameter.Builder(taxa.getId(), "tmrca statistic for taxon set " + taxa.getId()).taxaId(taxa.getId()).isStatistic(true).isNodeHeight(true).partitionOptions(treeModel).initial(Double.NaN).isNonNegative(true).build();
                    statistic.setPrefix(treeModel.getPrefix());
                    statistics.put(taxa, statistic);
                } else {
                    // keep consistent to taxonSetsTreeModel
                    statistic.setOptions(treeModel);
                    // keep prefix consistent after link/unlink tree
                    statistic.setPrefix(treeModel.getPrefix());
                    PartitionTreePrior treePrior = treeModel.getPartitionTreePrior();
                    statistic.isCalibratedYule = treePrior.getNodeHeightPrior() == TreePriorType.YULE_CALIBRATION && taxonSetsMono.get(taxa);
                }
                params.add(statistic);
            }
        } else {
            System.err.println("TaxonSets are null");
        }
    }
}
Also used : Taxa(dr.evolution.util.Taxa)

Example 4 with Taxa

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

the class StatisticsPanel method createStatistic.

public TreeSummaryStatistic createStatistic(TreeSummaryStatistic.Factory factory) {
    if (!factory.allowsTaxonList() && !factory.allowsDouble() && !factory.allowsInteger() && !factory.allowsString()) {
        return factory.createStatistic();
    }
    OptionsPanel optionPanel = new OptionsPanel();
    optionPanel.addSpanningComponent(new JLabel(factory.getSummaryStatisticDescription()));
    final JRadioButton wholeTreeRadio = new JRadioButton("For the whole tree", false);
    final JRadioButton taxonSetRadio = new JRadioButton("Using a given taxon set", false);
    final JComboBox taxonSetCombo = new JComboBox();
    final JTextField valueField;
    if (factory.allowsTaxonList()) {
        for (Object taxonSet : treeStatData.taxonSets) {
            taxonSetCombo.addItem(taxonSet);
        }
        ButtonGroup group = new ButtonGroup();
        ItemListener listener = new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                taxonSetCombo.setEnabled(taxonSetRadio.isSelected());
            }
        };
        if (factory.allowsWholeTree()) {
            group.add(wholeTreeRadio);
            wholeTreeRadio.addItemListener(listener);
            optionPanel.addSpanningComponent(wholeTreeRadio);
            optionPanel.addSeparator();
        }
        if (factory.allowsTaxonList()) {
            group.add(taxonSetRadio);
            taxonSetRadio.addItemListener(listener);
            optionPanel.addSpanningComponent(taxonSetRadio);
            optionPanel.addComponentWithLabel("Taxon Set: ", taxonSetCombo);
            optionPanel.addSeparator();
        }
        if (factory.allowsTaxonList()) {
            taxonSetRadio.setSelected(true);
        }
        if (factory.allowsWholeTree()) {
            wholeTreeRadio.setSelected(true);
        }
    }
    if (factory.allowsDouble() || factory.allowsInteger() || factory.allowsString()) {
        if (factory.allowsDouble()) {
            valueField = new RealNumberField();
            valueField.setColumns(12);
            optionPanel.addComponentWithLabel(factory.getValueName(), valueField);
        } else if (factory.allowsInteger()) {
            valueField = new WholeNumberField();
            valueField.setColumns(12);
            optionPanel.addComponentWithLabel(factory.getValueName(), valueField);
        } else {
            // allowsString
            valueField = new JTextField();
            valueField.setColumns(24);
            optionPanel.addComponentWithLabel(factory.getValueName(), valueField);
        }
    } else {
        valueField = null;
    }
    JOptionPane optionPane = new JOptionPane(optionPanel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
    optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    JDialog dialog = optionPane.createDialog(frame, factory.getSummaryStatisticName());
    // dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.pack();
    dialog.setVisible(true);
    if (optionPane.getValue() == null) {
        return null;
    }
    int result = (Integer) optionPane.getValue();
    if (result == -1 || result == JOptionPane.CANCEL_OPTION) {
        return null;
    }
    TreeSummaryStatistic statistic = factory.createStatistic();
    if (wholeTreeRadio.isSelected()) {
        statistic = factory.createStatistic();
    } else if (taxonSetRadio.isSelected()) {
        TreeStatData.TaxonSet t = (TreeStatData.TaxonSet) taxonSetCombo.getSelectedItem();
        Taxa taxa = new Taxa();
        taxa.setId(t.name);
        // Iterator iter = t.taxa.iterator();
        for (Object aTaxa : t.taxa) {
            String id = (String) aTaxa;
            Taxon taxon = new Taxon(id);
            taxa.addTaxon(taxon);
        }
        statistic.setTaxonList(taxa);
    } else {
        return null;
    }
    if (factory.allowsDouble()) {
        assert valueField instanceof RealNumberField;
        Double value = ((RealNumberField) valueField).getValue();
        statistic.setDouble(value);
    } else if (factory.allowsInteger()) {
        assert valueField instanceof WholeNumberField;
        Integer value = ((WholeNumberField) valueField).getValue();
        statistic.setInteger(value);
    } else if (factory.allowsString()) {
        String value = valueField.getText();
        statistic.setString(value);
    }
    return statistic;
}
Also used : ItemEvent(java.awt.event.ItemEvent) WholeNumberField(dr.app.gui.components.WholeNumberField) Taxon(dr.evolution.util.Taxon) RealNumberField(dr.app.gui.components.RealNumberField) Taxa(dr.evolution.util.Taxa) ItemListener(java.awt.event.ItemListener) EmptyBorder(javax.swing.border.EmptyBorder) OptionsPanel(jam.panels.OptionsPanel)

Example 5 with Taxa

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

the class BetaTreeDiversityStatistic method main.

public static void main(String[] arg) throws IOException, Importer.ImportException {
    Tree tree = (new NewickImporter("((A:1,B:1):1,(C:1, D:1):1);")).importNextTree();
    BetaTreeDiversityStatistic statistic = (BetaTreeDiversityStatistic) BetaTreeDiversityStatistic.FACTORY.createStatistic();
    Taxa taxa = new Taxa();
    taxa.addTaxon(new Taxon("A"));
    taxa.addTaxon(new Taxon("C"));
    statistic.setTaxonList(taxa);
    System.out.println(statistic.getSummaryStatistic(tree)[0]);
}
Also used : Taxa(dr.evolution.util.Taxa) NewickImporter(dr.evolution.io.NewickImporter) Taxon(dr.evolution.util.Taxon) Tree(dr.evolution.tree.Tree)

Aggregations

Taxa (dr.evolution.util.Taxa)75 Taxon (dr.evolution.util.Taxon)34 ArrayList (java.util.ArrayList)23 Tree (dr.evolution.tree.Tree)19 TaxonList (dr.evolution.util.TaxonList)15 Attribute (dr.util.Attribute)13 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)10 TreeModel (dr.evomodel.tree.TreeModel)10 Patterns (dr.evolution.alignment.Patterns)9 Microsatellite (dr.evolution.datatype.Microsatellite)9 IOException (java.io.IOException)8 NewickImporter (dr.evolution.io.NewickImporter)7 Parameter (dr.inference.model.Parameter)6 Date (dr.evolution.util.Date)5 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 ImportException (dr.evolution.io.Importer.ImportException)4 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)3