Search in sources :

Example 11 with Input

use of beast.core.Input 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 12 with Input

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

the class PriorInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
    m_bAddButtons = addButtons;
    m_input = input;
    m_beastObject = beastObject;
    this.itemNr = listItemNr;
    Box itemBox = Box.createHorizontalBox();
    Prior prior = (Prior) beastObject;
    String text = prior.getParameterName();
    JLabel label = new JLabel(text);
    Font font = label.getFont();
    Dimension size = new Dimension(font.getSize() * 200 / 13, font.getSize() * 25 / 13);
    label.setMinimumSize(size);
    label.setPreferredSize(size);
    itemBox.add(label);
    List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(prior.distInput, prior, null, doc);
    JComboBox<BeautiSubTemplate> comboBox = new JComboBox<BeautiSubTemplate>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
    comboBox.setName(text + ".distr");
    String id = prior.distInput.get().getID();
    // Log.warning.println("id=" + id);
    id = id.substring(0, id.indexOf('.'));
    for (BeautiSubTemplate template : availableBEASTObjects) {
        if (template.classInput.get() != null && template.shortClassName.equals(id)) {
            comboBox.setSelectedItem(template);
        }
    }
    comboBox.addActionListener(e -> {
        @SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> comboBox1 = (JComboBox<BeautiSubTemplate>) e.getSource();
        List<?> list = (List<?>) m_input.get();
        BeautiSubTemplate template = (BeautiSubTemplate) comboBox1.getSelectedItem();
        // String id = ((BEASTObject) list.get(item)).getID();
        // String partition = BeautiDoc.parsePartition(id);
        PartitionContext context = doc.getContextFor((BEASTInterface) list.get(itemNr));
        Prior prior1 = (Prior) list.get(itemNr);
        try {
            template.createSubNet(context, prior1, prior1.distInput, true);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        sync();
        refreshPanel();
    });
    JPanel panel = new JPanel();
    panel.add(comboBox);
    panel.setMaximumSize(size);
    itemBox.add(panel);
    if (prior.m_x.get() instanceof RealParameter) {
        // add range button for real parameters
        RealParameter p = (RealParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            RealParameter p1 = (RealParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    } else if (prior.m_x.get() instanceof IntegerParameter) {
        // add range button for real parameters
        IntegerParameter p = (IntegerParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            IntegerParameter p1 = (IntegerParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntegerParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    }
    int fontsize = comboBox.getFont().getSize();
    comboBox.setMaximumSize(new Dimension(1024 * fontsize / 13, 24 * fontsize / 13));
    String tipText = getDoc().tipTextMap.get(beastObject.getID());
    // System.out.println(beastObject.getID());
    if (tipText != null) {
        JLabel tipTextLabel = new JLabel(" " + tipText);
        itemBox.add(tipTextLabel);
    }
    itemBox.add(Box.createGlue());
    add(itemBox);
}
Also used : Arrays(java.util.Arrays) JButton(javax.swing.JButton) Input(beast.core.Input) Prior(beast.math.distributions.Prior) Font(java.awt.Font) FontSizeAction(javax.swing.text.StyledEditorKit.FontSizeAction) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) Box(javax.swing.Box) IntegerParameter(beast.core.parameter.IntegerParameter) Dimension(java.awt.Dimension) List(java.util.List) InputEditor(beast.app.draw.InputEditor) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) BEASTInterface(beast.core.BEASTInterface) JComboBox(javax.swing.JComboBox) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) IntegerParameter(beast.core.parameter.IntegerParameter) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) Dimension(java.awt.Dimension) Font(java.awt.Font) Prior(beast.math.distributions.Prior) List(java.util.List)

Example 13 with Input

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

the class BeautiAlignmentProvider method replaceItem.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void replaceItem(BeautiDoc doc, BEASTInterface oldData, BEASTInterface newData) {
    doc.pluginmap.remove(newData.getID());
    Set<BEASTInterface> outputs = new LinkedHashSet<>();
    outputs.addAll(oldData.getOutputs());
    for (BEASTInterface o : outputs) {
        for (Input i : o.listInputs()) {
            if (i.get() == oldData) {
                i.setValue(newData, o);
            } else if (i.get() != null && i.get() instanceof List) {
                List list = (List) i.get();
                int index = list.indexOf(oldData);
                if (index >= 0) {
                    list.set(index, newData);
                    newData.getOutputs().add(o);
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Input(beast.core.Input) BEASTInterface(beast.core.BEASTInterface) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 14 with Input

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

the class BeautiPanel method cloneFrom.

/**
 * Clones partition identified by sourceID to targetID and type (Site/Clock/Tree model)
 * as stored in config.
 * @param sourceID
 * @param targetID
 */
public void cloneFrom(String sourceID, String targetID) {
    if (sourceID.equals(targetID)) {
        return;
    }
    String type = config.hasPartitionsInput.get().toString();
    java.util.List<BEASTInterface> list = doc.getPartitions(type);
    int source = -1, target = -1;
    for (int i = 0; i < list.size(); i++) {
        BEASTInterface partition = list.get(i);
        if (type.equals("SiteModel")) {
            partition = (BEASTInterface) ((GenericTreeLikelihood) partition).siteModelInput.get();
        } else if (type.equals("ClockModel")) {
            partition = ((GenericTreeLikelihood) partition).branchRateModelInput.get();
        } else if (type.equals("Tree")) {
            partition = (BEASTInterface) ((GenericTreeLikelihood) partition).treeInput.get();
        }
        String partitionID = partition.getID();
        partitionID = partitionID.substring(partitionID.lastIndexOf('.') + 1);
        if (partitionID.length() > 1 && partitionID.charAt(1) == ':') {
            partitionID = partitionID.substring(2);
        }
        if (partitionID.equals(sourceID)) {
            source = i;
        }
        if (partitionID.equals(targetID)) {
            target = i;
        }
    }
    if (target == -1) {
        throw new RuntimeException("Programmer error: sourceID and targetID should be in list");
    }
    CompoundDistribution likelihoods = (CompoundDistribution) doc.pluginmap.get("likelihood");
    GenericTreeLikelihood likelihoodSource = (GenericTreeLikelihood) likelihoods.pDistributions.get().get(source);
    GenericTreeLikelihood likelihood = (GenericTreeLikelihood) likelihoods.pDistributions.get().get(target);
    PartitionContext oldContext = doc.getContextFor(likelihoodSource);
    PartitionContext newContext = doc.getContextFor(likelihood);
    // this ensures the config.sync does not set any input value
    config._input.setValue(null, config);
    if (type.equals("SiteModel")) {
        SiteModelInterface siteModelSource = likelihoodSource.siteModelInput.get();
        SiteModelInterface siteModel = null;
        try {
            siteModel = (SiteModel.Base) BeautiDoc.deepCopyPlugin((BEASTInterface) siteModelSource, likelihood, (MCMC) doc.mcmc.get(), oldContext, newContext, doc, null);
        } catch (RuntimeException e) {
            JOptionPane.showMessageDialog(this, "Could not clone " + sourceID + " to " + targetID + " " + e.getMessage());
            return;
        }
        likelihood.siteModelInput.setValue(siteModel, likelihood);
        return;
    } else if (type.equals("ClockModel")) {
        BranchRateModel clockModelSource = likelihoodSource.branchRateModelInput.get();
        BranchRateModel clockModel = null;
        try {
            clockModel = (BranchRateModel) BeautiDoc.deepCopyPlugin((BEASTInterface) clockModelSource, likelihood, (MCMC) doc.mcmc.get(), oldContext, newContext, doc, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Could not clone " + sourceID + " to " + targetID + " " + e.getMessage());
            return;
        }
        // make sure that *if* the clock model has a tree as input, it is
        // the same as for the likelihood
        TreeInterface tree = null;
        try {
            for (Input<?> input : ((BEASTInterface) clockModel).listInputs()) {
                if (input.getName().equals("tree")) {
                    tree = (TreeInterface) input.get();
                }
            }
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (tree != null && tree != likelihood.treeInput.get()) {
            // likelihood.treeInput.setValue(tree, likelihood);
            JOptionPane.showMessageDialog(null, "Cannot clone clock model with different trees");
            return;
        }
        likelihood.branchRateModelInput.setValue(clockModel, likelihood);
        return;
    } else if (type.equals("Tree")) {
        TreeInterface tree = null;
        TreeInterface treeSource = likelihoodSource.treeInput.get();
        try {
            tree = (TreeInterface) BeautiDoc.deepCopyPlugin((BEASTInterface) treeSource, likelihood, (MCMC) doc.mcmc.get(), oldContext, newContext, doc, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Could not clone " + sourceID + " to " + targetID + " " + e.getMessage());
            return;
        }
        // sanity check: make sure taxon sets are compatible
        Taxon.assertSameTaxa(tree.getID(), tree.getTaxonset().getTaxaNames(), likelihood.dataInput.get().getID(), likelihood.dataInput.get().getTaxaNames());
        likelihood.treeInput.setValue(tree, likelihood);
        return;
    } else {
        throw new RuntimeException("Programmer error calling cloneFrom: Should only clone Site/Clock/Tree model");
    }
}
Also used : GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) MCMC(beast.core.MCMC) SiteModel(beast.evolution.sitemodel.SiteModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) TreeInterface(beast.evolution.tree.TreeInterface) CompoundDistribution(beast.core.util.CompoundDistribution) Input(beast.core.Input) BranchRateModel(beast.evolution.branchratemodel.BranchRateModel) BEASTInterface(beast.core.BEASTInterface) SiteModelInterface(beast.evolution.sitemodel.SiteModelInterface)

Example 15 with Input

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

the class DocMaker method getHTML.

// createBEASTObjectPage
public String getHTML(String beastObjectName, boolean useExternalStyleSheet) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    StringBuffer buf = new StringBuffer();
    buf.append("<html>\n<head>\n<title>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</title>\n");
    if (useExternalStyleSheet) {
        buf.append("<link rel='StyleSheet' href='/tmp/styles.css' type='text/css'>\n");
    } else {
        buf.append("<style type='text/css'>\n");
        buf.append(getCSS());
        buf.append("</style>\n");
    }
    buf.append("</head>\n");
    buf.append("<body>\n");
    buf.append("<h1>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</h1>\n");
    BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
    // show all implementation of this plug-in
    String[] implementations = m_isa.get(beastObjectName);
    if (implementations == null) {
        // this class is not documented, perhaps outside ClassDiscover path?
        buf.append("No documentation available for " + beastObjectName + ". Perhaps it is not in the ClassDiscovery path\n");
        buf.append("</body>\n");
        buf.append("</html>\n");
        return buf.toString();
    }
    if (implementations.length > 0) {
        buf.append("<table border='1px'>\n");
        buf.append("<thead><tr><td>implemented by the following</td></tr></thead>\n");
        for (String imp : implementations) {
            buf.append("<tr><td><a href='" + imp + ".html'>" + imp + "</a></td></tr>\n");
        }
        buf.append("</table>\n");
    }
    // show descriptions of all plug-ins implemented by this plug in...
    buf.append("<p>" + m_descriptions.get(beastObjectName) + "</p>\n");
    // show citation (if any)
    for (Citation citation : beastObject.getCitationList()) {
        buf.append("<h2>Reference:</h2><p>" + citation.value() + "</p>\n");
        if (citation.DOI().length() > 0) {
            buf.append("<p><a href=\"http://dx.doi.org/" + citation.DOI() + "\">doi:" + citation.DOI() + "</a></p>\n");
        }
    }
    // show if this is Loggable
    if (m_sLoggables.contains(beastObjectName)) {
        buf.append("<p>Logable:");
        buf.append(" yes, this can be used in a log.");
        buf.append("</p>\n");
    // } else {
    // buf.append(" no, this cannot be used in a log.");
    }
    // show short list its inputs
    buf.append("<h2>Inputs:</h2>\n");
    buf.append("<p>");
    List<Input<?>> inputs = beastObject.listInputs();
    for (Input<?> input : inputs) {
        buf.append("<a href='#" + input.getName() + "'>" + input.getName() + "</a>, ");
    }
    buf.delete(buf.length() - 3, buf.length() - 1);
    buf.append("</p>\n");
    // list its inputs
    if (inputs.size() == 0) {
        buf.append("&lt;none&gt;");
    }
    for (Input<?> input : inputs) {
        buf.append("<p>&nbsp</p>");
        buf.append("<table id='" + input.getName() + "' border='1px' width='90%'>\n");
        buf.append("<caption>" + input.getName() + "</caption>\n");
        buf.append("<thead><tr bgcolor='#AAAAAA'><td>type: " + getType(beastObject, input.getName()) + "</td></tr></thead>\n");
        buf.append("<tr><td>" + input.getTipText() + "</td></tr>\n");
        buf.append("<tr><td>\n");
        switch(input.getRule()) {
            case OPTIONAL:
                buf.append("Optional input");
                if (input.defaultValue != null) {
                    if (input.defaultValue instanceof Integer || input.defaultValue instanceof Double || input.defaultValue instanceof Boolean || input.defaultValue instanceof String) {
                        buf.append(". Default: " + input.defaultValue.toString());
                    }
                }
                break;
            case REQUIRED:
                buf.append("Required input");
                break;
            case XOR:
                buf.append("Either this, or " + input.getOther().getName() + " needs to be specified");
                break;
            case FORBIDDEN:
                buf.append("Forbidden: must not be specified");
                break;
        }
        buf.append("</td></tr>\n");
        buf.append("</table>\n");
    }
    buf.append("</body>\n");
    buf.append("</html>\n");
    return buf.toString();
}
Also used : Input(beast.core.Input) BEASTObject(beast.core.BEASTObject) Citation(beast.core.Citation)

Aggregations

Input (beast.core.Input)20 BEASTInterface (beast.core.BEASTInterface)12 ArrayList (java.util.ArrayList)11 List (java.util.List)7 BEASTObject (beast.core.BEASTObject)6 Test (org.junit.Test)4 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)3 SiteModel (beast.evolution.sitemodel.SiteModel)3 InputEditor (beast.app.draw.InputEditor)2 MCMC (beast.core.MCMC)2 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)2 SiteModelInterface (beast.evolution.sitemodel.SiteModelInterface)2 TreeInterface (beast.evolution.tree.TreeInterface)2 MRCAPrior (beast.math.distributions.MRCAPrior)2 XMLParser (beast.util.XMLParser)2 Dimension (java.awt.Dimension)2 FileNotFoundException (java.io.FileNotFoundException)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 JComboBox (javax.swing.JComboBox)2