Search in sources :

Example 11 with MRCAPrior

use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.

the class MRCAPriorInputEditor method disableTipSampling.

// remove TipDatesRandomWalker from list of operators
private static void disableTipSampling(BEASTInterface m_beastObject, BeautiDoc doc) {
    // First, find the operator
    TipDatesRandomWalker operator = null;
    MRCAPrior prior = (MRCAPrior) m_beastObject;
    TaxonSet taxonset = prior.taxonsetInput.get();
    // However, if there is an TipDatesRandomWalker with taxonset as input, we want to remove it.
    for (BEASTInterface o : taxonset.getOutputs()) {
        if (o instanceof TipDatesRandomWalker) {
            operator = (TipDatesRandomWalker) o;
        }
    }
    if (operator == null) {
        // should never happen
        return;
    }
    // remove from list of operators
    Object o = doc.mcmc.get().getInput("operator");
    if (o instanceof Input<?>) {
        Input<List<Operator>> operatorInput = (Input<List<Operator>>) o;
        List<Operator> operators = operatorInput.get();
        operators.remove(operator);
    }
}
Also used : Operator(beast.core.Operator) Input(beast.core.Input) MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) ArrayList(java.util.ArrayList) List(java.util.List) TaxonSet(beast.evolution.alignment.TaxonSet) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Example 12 with MRCAPrior

use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.

the class MRCAPriorInputEditor method customConnector.

public static void customConnector(BeautiDoc doc) {
    Object o0 = doc.pluginmap.get("prior");
    if (o0 != null && o0 instanceof CompoundDistribution) {
        CompoundDistribution p = (CompoundDistribution) o0;
        for (Distribution p0 : p.pDistributions.get()) {
            if (p0 instanceof MRCAPrior) {
                MRCAPrior prior = (MRCAPrior) p0;
                if (prior.treeInput.get() != null) {
                    boolean isInState = false;
                    for (BEASTInterface o : prior.treeInput.get().getOutputs()) {
                        if (o instanceof State) {
                            isInState = true;
                            break;
                        }
                    }
                    if (!isInState) {
                        doc.disconnect(prior, "prior", "distribution");
                        doc.disconnect(prior, "tracelog", "log");
                        if (prior.onlyUseTipsInput.get()) {
                            disableTipSampling(prior, doc);
                        }
                        doc.unregisterPlugin(prior);
                        return;
                    }
                }
            }
        }
    }
}
Also used : CompoundDistribution(beast.core.util.CompoundDistribution) State(beast.core.State) CompoundDistribution(beast.core.util.CompoundDistribution) Distribution(beast.core.Distribution) MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface)

Example 13 with MRCAPrior

use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.

the class MRCAPriorInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, final int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
    m_bAddButtons = addButtons;
    m_input = input;
    m_beastObject = beastObject;
    this.itemNr = listItemNr;
    Box itemBox = Box.createHorizontalBox();
    MRCAPrior prior = (MRCAPrior) beastObject;
    String text = prior.getID();
    JButton taxonButton = new JButton(text);
    // taxonButton.setMinimumSize(Base.PREFERRED_SIZE);
    // taxonButton.setPreferredSize(Base.PREFERRED_SIZE);
    itemBox.add(taxonButton);
    taxonButton.addActionListener(e -> {
        List<?> list = (List<?>) m_input.get();
        MRCAPrior prior2 = (MRCAPrior) list.get(itemNr);
        try {
            TaxonSet taxonset = prior2.taxonsetInput.get();
            List<Taxon> originalTaxa = new ArrayList<>();
            originalTaxa.addAll(taxonset.taxonsetInput.get());
            Set<Taxon> candidates = getTaxonCandidates(prior2);
            TaxonSetDialog dlg = new TaxonSetDialog(taxonset, candidates, doc);
            if (dlg.showDialog()) {
                if (dlg.taxonSet.taxonsetInput.get().size() == 0) {
                    JOptionPane.showMessageDialog(doc.beauti, "At least one taxon should be included in the taxon set", "Error specifying taxon set", JOptionPane.ERROR_MESSAGE);
                    taxonset.taxonsetInput.get().addAll(originalTaxa);
                    return;
                }
                prior2.taxonsetInput.setValue(dlg.taxonSet, prior2);
                int i = 1;
                String id = dlg.taxonSet.getID();
                while (doc.pluginmap.containsKey(dlg.taxonSet.getID()) && doc.pluginmap.get(dlg.taxonSet.getID()) != dlg.taxonSet) {
                    dlg.taxonSet.setID(id + i);
                    i++;
                }
                BEASTObjectPanel.addPluginToMap(dlg.taxonSet, doc);
                prior2.setID(dlg.taxonSet.getID() + ".prior");
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        refreshPanel();
    });
    if (prior.distInput.getType() == null) {
        try {
            prior.distInput.setValue(new OneOnX(), prior);
            prior.distInput.setValue(null, prior);
        } catch (Exception e) {
        // TODO: handle exception
        }
    }
    List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(prior.distInput, prior, null, doc);
    JComboBox<BeautiSubTemplate> comboBox = new JComboBox<>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
    comboBox.setName(text + ".distr");
    if (prior.distInput.get() != null) {
        String id = prior.distInput.get().getID();
        // id = BeautiDoc.parsePartition(id);
        id = id.substring(0, id.indexOf('.'));
        for (BeautiSubTemplate template : availableBEASTObjects) {
            if (template.classInput.get() != null && template.shortClassName.equals(id)) {
                comboBox.setSelectedItem(template);
            }
        }
    } else {
        comboBox.setSelectedItem(BeautiConfig.NULL_TEMPLATE);
    }
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            @SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> comboBox = (JComboBox<BeautiSubTemplate>) e.getSource();
            BeautiSubTemplate template = (BeautiSubTemplate) comboBox.getSelectedItem();
            List<?> list = (List<?>) m_input.get();
            MRCAPrior prior = (MRCAPrior) list.get(itemNr);
            // }
            try {
                // BEASTObject beastObject2 =
                template.createSubNet(new PartitionContext(""), prior, prior.distInput, true);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            refreshPanel();
        }
    });
    itemBox.add(comboBox);
    JCheckBox isMonophyleticdBox = new JCheckBox(doc.beautiConfig.getInputLabel(prior, prior.isMonophyleticInput.getName()));
    isMonophyleticdBox.setName(text + ".isMonophyletic");
    isMonophyleticdBox.setSelected(prior.isMonophyleticInput.get());
    isMonophyleticdBox.setToolTipText(prior.isMonophyleticInput.getHTMLTipText());
    isMonophyleticdBox.addActionListener(new MRCAPriorActionListener(prior));
    itemBox.add(isMonophyleticdBox);
    JButton deleteButton = new SmallButton("-", true);
    deleteButton.setToolTipText("Delete this calibration");
    deleteButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Log.warning.println("Trying to delete a calibration");
            List<?> list = (List<?>) m_input.get();
            MRCAPrior prior = (MRCAPrior) list.get(itemNr);
            doc.disconnect(prior, "prior", "distribution");
            doc.disconnect(prior, "tracelog", "log");
            if (prior.onlyUseTipsInput.get()) {
                disableTipSampling(m_beastObject, doc);
            }
            doc.unregisterPlugin(prior);
            refreshPanel();
        }
    });
    itemBox.add(Box.createGlue());
    itemBox.add(deleteButton);
    add(itemBox);
}
Also used : ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) JComboBox(javax.swing.JComboBox) Taxon(beast.evolution.alignment.Taxon) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) TaxonSet(beast.evolution.alignment.TaxonSet) InvocationTargetException(java.lang.reflect.InvocationTargetException) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) MRCAPrior(beast.math.distributions.MRCAPrior) SmallButton(beast.app.draw.SmallButton) OneOnX(beast.math.distributions.OneOnX)

Example 14 with MRCAPrior

use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.

the class MRCAPriorInputEditor method createTipsonlyEditor.

public InputEditor createTipsonlyEditor() throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    BooleanInputEditor e = new BooleanInputEditor(doc) {

        private static final long serialVersionUID = 1L;

        @Override
        public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
            super.init(input, beastObject, itemNr, isExpandOption, addButtons);
            // hack to get to JCheckBox
            Component[] components = getComponents();
            ((JCheckBox) components[0]).addActionListener(e -> {
                JCheckBox src = (JCheckBox) e.getSource();
                if (src.isSelected()) {
                    enableTipSampling();
                } else {
                    disableTipSampling(m_beastObject, doc);
                }
            });
        }
    };
    MRCAPrior prior = (MRCAPrior) m_beastObject;
    Input<?> input = prior.onlyUseTipsInput;
    e.init(input, prior, -1, ExpandOption.FALSE, false);
    return e;
}
Also used : JCheckBox(javax.swing.JCheckBox) Input(beast.core.Input) MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) Component(java.awt.Component) BooleanInputEditor(beast.app.draw.BooleanInputEditor)

Example 15 with MRCAPrior

use of beast.math.distributions.MRCAPrior in project beast2 by CompEvol.

the class MRCAPriorInputEditor method enableTipSampling.

// add TipDatesRandomWalker (if not present) and add to list of operators
private void enableTipSampling() {
    // First, create/find the operator
    TipDatesRandomWalker operator = null;
    MRCAPrior prior = (MRCAPrior) m_beastObject;
    TaxonSet taxonset = prior.taxonsetInput.get();
    taxonset.initAndValidate();
    // see if an old operator still hangs around -- happens when toggling the TipsOnly checkbox a few times
    for (BEASTInterface o : taxonset.getOutputs()) {
        if (o instanceof TipDatesRandomWalker) {
            operator = (TipDatesRandomWalker) o;
        }
    }
    if (operator == null) {
        operator = new TipDatesRandomWalker();
        operator.initByName("tree", prior.treeInput.get(), "taxonset", taxonset, "windowSize", 1.0, "weight", 1.0);
    }
    operator.setID("tipDatesSampler." + taxonset.getID());
    doc.mcmc.get().setInputValue("operator", operator);
}
Also used : MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) TaxonSet(beast.evolution.alignment.TaxonSet) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Aggregations

MRCAPrior (beast.math.distributions.MRCAPrior)19 BEASTInterface (beast.core.BEASTInterface)12 TaxonSet (beast.evolution.alignment.TaxonSet)9 ArrayList (java.util.ArrayList)9 List (java.util.List)6 Distribution (beast.core.Distribution)5 CompoundDistribution (beast.core.util.CompoundDistribution)5 Alignment (beast.evolution.alignment.Alignment)5 RealParameter (beast.core.parameter.RealParameter)4 Tree (beast.evolution.tree.Tree)4 TreeInterface (beast.evolution.tree.TreeInterface)4 ParametricDistribution (beast.math.distributions.ParametricDistribution)4 Taxon (beast.evolution.alignment.Taxon)3 IOException (java.io.IOException)3 SmallButton (beast.app.draw.SmallButton)2 BEASTObject (beast.core.BEASTObject)2 Input (beast.core.Input)2 StateNode (beast.core.StateNode)2 TipDatesRandomWalker (beast.evolution.operators.TipDatesRandomWalker)2 Node (beast.evolution.tree.Node)2