Search in sources :

Example 46 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class OperatorListInputEditor method getLabel.

String getLabel(Operator operator) {
    String name = operator.getClass().getName();
    name = name.substring(name.lastIndexOf('.') + 1);
    name = name.replaceAll("Operator", "");
    if (name.matches(".*[A-Z].*")) {
        name = name.replaceAll("(.)([A-Z])", "$1 $2");
    }
    name += ": ";
    try {
        for (BEASTInterface beastObject2 : operator.listActiveBEASTObjects()) {
            if (beastObject2 instanceof StateNode && ((StateNode) beastObject2).isEstimatedInput.get()) {
                name += beastObject2.getID() + " ";
            }
            // issue https://github.com/CompEvol/beast2/issues/661
            if (name.length() > 100) {
                name += "... ";
                break;
            }
        }
    } catch (Exception e) {
    // ignore
    }
    String tipText = getDoc().tipTextMap.get(operator.getID());
    if (tipText != null) {
        name += " " + tipText;
    }
    return name;
}
Also used : StateNode(beast.core.StateNode) BEASTInterface(beast.core.BEASTInterface)

Example 47 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class PriorListInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    List<?> list = (List<?>) input.get();
    Collections.sort(list, (Object o1, Object o2) -> {
        if (o1 instanceof BEASTInterface && o2 instanceof BEASTInterface) {
            String d1 = ((BEASTInterface) o1).getID();
            String id2 = ((BEASTInterface) o2).getID();
            // first the tree priors
            if (o1 instanceof TreeDistribution) {
                if (o2 instanceof TreeDistribution) {
                    TreeInterface tree1 = ((TreeDistribution) o1).treeInput.get();
                    if (tree1 == null) {
                        tree1 = ((TreeDistribution) o1).treeIntervalsInput.get().treeInput.get();
                    }
                    TreeInterface tree2 = ((TreeDistribution) o2).treeInput.get();
                    if (tree2 == null) {
                        tree2 = ((TreeDistribution) o2).treeIntervalsInput.get().treeInput.get();
                    }
                    return d1.compareTo(id2);
                } else {
                    return -1;
                }
            } else if (o1 instanceof MRCAPrior) {
                // last MRCA priors
                if (o2 instanceof MRCAPrior) {
                    return d1.compareTo(id2);
                } else {
                    return 1;
                }
            } else {
                if (o2 instanceof TreeDistribution) {
                    return 1;
                }
                if (o2 instanceof MRCAPrior) {
                    return -1;
                }
                if (o1 instanceof Prior) {
                    d1 = ((Prior) o1).getParameterName();
                }
                if (o2 instanceof Prior) {
                    id2 = ((Prior) o2).getParameterName();
                }
                return d1.compareTo(id2);
            }
        }
        return 0;
    });
    rangeButtons = new ArrayList<>();
    taxonButtons = new ArrayList<>();
    // m_buttonStatus = ButtonStatus.NONE;
    super.init(input, beastObject, itemNr, isExpandOption, addButtons);
    if (beastObject instanceof BeautiPanelConfig) {
        BeautiPanelConfig config = (BeautiPanelConfig) beastObject;
        if (config.parentBEASTObjects != null && config.parentBEASTObjects.size() > 0 && config.parentBEASTObjects.get(0).getID().equals("speciescoalescent")) {
            m_buttonStatus = ButtonStatus.NONE;
        }
    }
    if (m_buttonStatus == ButtonStatus.ALL || m_buttonStatus == ButtonStatus.ADD_ONLY) {
        addButton = new SmallButton("+ Add Prior", true);
        addButton.setName("addItem");
        addButton.setToolTipText("Add new prior (like an MRCA-prior) to the list of priors");
        addButton.addActionListener(e -> {
            addItem();
        });
        buttonBox.add(addButton);
        buttonBox.add(Box.createHorizontalGlue());
    }
}
Also used : TreeDistribution(beast.evolution.tree.TreeDistribution) Prior(beast.math.distributions.Prior) MRCAPrior(beast.math.distributions.MRCAPrior) MRCAPrior(beast.math.distributions.MRCAPrior) SmallButton(beast.app.draw.SmallButton) ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface) TreeInterface(beast.evolution.tree.TreeInterface)

Example 48 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class StateNodeInitialiserListInputEditor method addPluginItem.

@Override
protected InputEditor addPluginItem(Box itemBox, BEASTInterface beastObject) {
    final StateNodeInitialiser currentInitialiser = (StateNodeInitialiser) beastObject;
    Input initialInput = beastObject.getInput("initial");
    List<BeautiSubTemplate> sAvailablePlugins = doc.getInputEditorFactory().getAvailableTemplates(initialInput, (BEASTInterface) beastObject, null, doc);
    JComboBox<?> comboBox = null;
    if (sAvailablePlugins.size() > 0) {
        sAvailablePlugins.remove(sAvailablePlugins.size() - 1);
        comboBox = new JComboBox<>(sAvailablePlugins.toArray());
        String sID = beastObject.getID();
        try {
            sID = sID.substring(0, sID.indexOf('.'));
        } catch (Exception e) {
            throw new RuntimeException("Improperly formatted ID: " + sID);
        }
        for (BeautiSubTemplate template : sAvailablePlugins) {
            if (template.matchesName(sID)) {
                comboBox.setSelectedItem(template);
            }
        }
        comboBox.setName("Initialiser");
        comboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        JComboBox<?> currentComboBox = (JComboBox<?>) e.getSource();
                        BeautiSubTemplate template = (BeautiSubTemplate) currentComboBox.getSelectedItem();
                        PartitionContext partitionContext;
                        partitionContext = doc.getContextFor(beastObject);
                        try {
                            Object o = template.createSubNet(partitionContext, true);
                            StateNodeInitialiser newInitialiser = (StateNodeInitialiser) o;
                            List<StateNodeInitialiser> inits = (List<StateNodeInitialiser>) m_input.get();
                            int i = inits.indexOf(currentInitialiser);
                            inits.set(i, newInitialiser);
                            System.out.println(inits.size());
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        sync();
                        refreshPanel();
                    }
                });
            }
        });
    }
    String name = beastObject.getID();
    Object o = beastObject.getInput("initial").get();
    if (o instanceof BEASTInterface) {
        name = ((BEASTInterface) o).getID();
    }
    if (name == null || name.length() == 0) {
        name = beastObject.getClass().getName();
        name = name.substring(name.lastIndexOf('.') + 1);
    }
    JLabel label = new JLabel("Initial " + name + ":");
    itemBox.add(Box.createRigidArea(new Dimension(5, 1)));
    itemBox.add(label);
    if (comboBox != null) {
        itemBox.add(comboBox);
    }
    itemBox.add(Box.createHorizontalGlue());
    return this;
}
Also used : JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) StateNodeInitialiser(beast.core.StateNodeInitialiser) Input(beast.core.Input) ActionListener(java.awt.event.ActionListener) ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 49 with BEASTInterface

use of beast.core.BEASTInterface 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 50 with BEASTInterface

use of beast.core.BEASTInterface 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)

Aggregations

BEASTInterface (beast.core.BEASTInterface)111 ArrayList (java.util.ArrayList)43 List (java.util.List)27 IOException (java.io.IOException)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)18 SAXException (org.xml.sax.SAXException)18 NodeList (org.w3c.dom.NodeList)13 Input (beast.core.Input)12 MRCAPrior (beast.math.distributions.MRCAPrior)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 XMLParser (beast.util.XMLParser)11 TransformerException (javax.xml.transform.TransformerException)11 Alignment (beast.evolution.alignment.Alignment)10 XMLParserException (beast.util.XMLParserException)10 BEASTObject (beast.core.BEASTObject)9 Distribution (beast.core.Distribution)9 XMLProducer (beast.util.XMLProducer)9 CompoundDistribution (beast.core.util.CompoundDistribution)8 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)8