Search in sources :

Example 56 with BEASTInterface

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

the class ModelBuilder method setDrawingFlag.

public void setDrawingFlag() {
    for (int i = 0; i < m_doc.m_objects.size(); i++) {
        Shape shape = m_doc.m_objects.get(i);
        shape.m_bNeedsDrawing = false;
        if (shape.m_bNeedsDrawing) {
            shape.m_bNeedsDrawing = true;
        }
        if (shape instanceof BEASTObjectShape) {
            BEASTInterface beastObject = ((BEASTObjectShape) shape).m_beastObject;
            if (needsDrawing(beastObject)) {
                shape.m_bNeedsDrawing = true;
            }
        } else if (shape instanceof InputShape) {
            BEASTObjectShape beastObjectShape = ((InputShape) shape).m_beastObjectShape;
            if (beastObjectShape != null) {
                if (needsDrawing(beastObjectShape.m_beastObject)) {
                    shape.m_bNeedsDrawing = true;
                }
            } else {
                shape.m_bNeedsDrawing = true;
            }
        } else if (shape instanceof Arrow) {
            Shape tail = ((Arrow) shape).m_tailShape;
            boolean needsDrawing = true;
            if (tail instanceof BEASTObjectShape) {
                needsDrawing = needsDrawing(((BEASTObjectShape) tail).m_beastObject);
            }
            if (needsDrawing) {
                Shape head = ((Arrow) shape).m_headShape;
                if (head instanceof InputShape) {
                    BEASTObjectShape beastObjectShape = ((InputShape) head).m_beastObjectShape;
                    if (beastObjectShape != null) {
                        needsDrawing = needsDrawing(beastObjectShape.m_beastObject);
                    }
                }
                if (needsDrawing) {
                    shape.m_bNeedsDrawing = true;
                }
            }
        } else {
            shape.m_bNeedsDrawing = true;
        }
    }
}
Also used : BEASTInterface(beast.core.BEASTInterface)

Example 57 with BEASTInterface

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

the class ParameterInputEditor method addComboBox.

@Override
protected void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
    Box paramBox = Box.createHorizontalBox();
    Parameter.Base<?> parameter = null;
    if (itemNr >= 0) {
        parameter = (Parameter.Base<?>) ((List<?>) input.get()).get(itemNr);
    } else {
        parameter = (Parameter.Base<?>) input.get();
    }
    if (parameter == null) {
        super.addComboBox(box, input, beastObject);
    } else {
        setUpEntry();
        paramBox.add(m_entry);
        if (doc.allowLinking) {
            boolean isLinked = doc.isLinked(m_input);
            if (isLinked || doc.suggestedLinks((BEASTInterface) m_input.get()).size() > 0) {
                JButton linkbutton = new JButton(Utils.getIcon(BeautiPanel.ICONPATH + (isLinked ? "link.png" : "unlink.png")));
                linkbutton.setBorder(BorderFactory.createEmptyBorder());
                linkbutton.setToolTipText("link/unlink this parameter with another compatible parameter");
                linkbutton.addActionListener(e -> {
                    if (doc.isLinked(m_input)) {
                        // unlink
                        try {
                            BEASTInterface candidate = doc.getUnlinkCandidate(m_input, m_beastObject);
                            m_input.setValue(candidate, m_beastObject);
                            doc.deLink(m_input);
                        } catch (RuntimeException e2) {
                            e2.printStackTrace();
                            JOptionPane.showMessageDialog(this, "Could not unlink: " + e2.getMessage());
                        }
                    } else {
                        // create a link
                        List<BEASTInterface> candidates = doc.suggestedLinks((BEASTInterface) m_input.get());
                        JComboBox<BEASTInterface> jcb = new JComboBox<>(candidates.toArray(new BEASTInterface[] {}));
                        JOptionPane.showMessageDialog(null, jcb, "select parameter to link with", JOptionPane.QUESTION_MESSAGE);
                        BEASTInterface candidate = (BEASTInterface) jcb.getSelectedItem();
                        if (candidate != null) {
                            try {
                                m_input.setValue(candidate, m_beastObject);
                                doc.addLink(m_input);
                            } catch (Exception e2) {
                                e2.printStackTrace();
                            }
                        }
                    }
                    refreshPanel();
                });
                paramBox.add(linkbutton);
            }
        }
        paramBox.add(Box.createHorizontalGlue());
        m_isEstimatedBox = new JCheckBox(doc.beautiConfig.getInputLabel(parameter, parameter.isEstimatedInput.getName()));
        m_isEstimatedBox.setName(input.getName() + ".isEstimated");
        if (input.get() != null) {
            m_isEstimatedBox.setSelected(parameter.isEstimatedInput.get());
        }
        m_isEstimatedBox.setToolTipText(parameter.isEstimatedInput.getHTMLTipText());
        boolean isClockRate = false;
        for (Object output : parameter.getOutputs()) {
            if (output instanceof BranchRateModel.Base) {
                isClockRate |= ((BranchRateModel.Base) output).meanRateInput.get() == parameter;
            }
        }
        m_isEstimatedBox.setEnabled(!isClockRate || !getDoc().autoSetClockRate);
        m_isEstimatedBox.addActionListener(e -> {
            try {
                Parameter.Base<?> parameter2 = (Parameter.Base<?>) m_input.get();
                parameter2.isEstimatedInput.setValue(m_isEstimatedBox.isSelected(), parameter2);
                if (isParametricDistributionParameter) {
                    String id = parameter2.getID();
                    if (id.startsWith("RealParameter")) {
                        ParametricDistribution parent = null;
                        for (Object beastObject2 : parameter2.getOutputs()) {
                            if (beastObject2 instanceof ParametricDistribution) {
                                parent = (ParametricDistribution) beastObject2;
                                break;
                            }
                        }
                        Distribution grandparent = null;
                        for (Object beastObject2 : parent.getOutputs()) {
                            if (beastObject2 instanceof Distribution) {
                                grandparent = (Distribution) beastObject2;
                                break;
                            }
                        }
                        id = "parameter.hyper" + parent.getClass().getSimpleName() + "-" + m_input.getName() + "-" + grandparent.getID();
                        doc.pluginmap.remove(parameter2.getID());
                        parameter2.setID(id);
                        doc.addPlugin(parameter2);
                    }
                    PartitionContext context = new PartitionContext(id.substring("parameter.".length()));
                    Log.warning.println(context + " " + id);
                    doc.beautiConfig.hyperPriorTemplate.createSubNet(context, true);
                }
                refreshPanel();
            } catch (Exception ex) {
                Log.err.println("ParameterInputEditor " + ex.getMessage());
            }
        });
        paramBox.add(m_isEstimatedBox);
        // only show the estimate flag if there is an operator that works on this parameter
        m_isEstimatedBox.setVisible(doc.isExpertMode());
        m_isEstimatedBox.setToolTipText("Estimate value of this parameter in the MCMC chain");
        // m_bAddButtons = false;
        if (itemNr < 0) {
            for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
                if (beastObject2 instanceof ParametricDistribution) {
                    m_isEstimatedBox.setVisible(true);
                    isParametricDistributionParameter = true;
                    break;
                }
            }
            for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
                if (beastObject2 instanceof Operator) {
                    m_isEstimatedBox.setVisible(true);
                    // m_editPluginButton.setVisible(true);
                    break;
                }
            }
        } else {
            for (Object beastObject2 : ((BEASTInterface) ((List<?>) m_input.get()).get(itemNr)).getOutputs()) {
                if (beastObject2 instanceof Operator) {
                    m_isEstimatedBox.setVisible(true);
                    // m_editPluginButton.setVisible(true);
                    break;
                }
            }
        }
        box.add(paramBox);
    }
}
Also used : Operator(beast.core.Operator) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) JComboBox(javax.swing.JComboBox) JCheckBox(javax.swing.JCheckBox) PartitionContext(beast.app.beauti.PartitionContext) ParametricDistribution(beast.math.distributions.ParametricDistribution) BranchRateModel(beast.evolution.branchratemodel.BranchRateModel) ParametricDistribution(beast.math.distributions.ParametricDistribution) Distribution(beast.core.Distribution) Parameter(beast.core.parameter.Parameter) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 58 with BEASTInterface

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

the class IntegerListInputEditor method setValue.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setValue(Object o) {
    if (itemNr < 0) {
        m_input.setValue(o, m_beastObject);
    } else {
        // set value of an item in a list
        List list = (List) m_input.get();
        Object other = list.get(itemNr);
        if (other != o) {
            if (other instanceof BEASTInterface) {
                BEASTInterface.getOutputs(other).remove(m_beastObject);
            }
            list.set(itemNr, o);
            if (o instanceof BEASTInterface) {
                BEASTInterface.getOutputs(o).add(m_beastObject);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 59 with BEASTInterface

use of beast.core.BEASTInterface in project MultiTypeTree by tgvaughan.

the class InitMigrationModelConnector method customConnector.

public static boolean customConnector(BeautiDoc doc) {
    for (BEASTInterface p : doc.getPartitions("Tree")) {
        TreeLikelihood treeLikelihood = (TreeLikelihood) p;
        StructuredCoalescentMultiTypeTree tree = (StructuredCoalescentMultiTypeTree) treeLikelihood.treeInput.get();
        String pID = BeautiDoc.parsePartition(tree.getID());
        SCMigrationModel migModel = (SCMigrationModel) doc.pluginmap.get("migModel.t:" + pID);
        SCMigrationModel migModelInit = (SCMigrationModel) doc.pluginmap.get("migModelInit.t:" + pID);
        String rateMatrixStr = getParameterString((RealParameter) migModel.rateMatrixInput.get());
        String popSizesStr = getParameterString((RealParameter) migModel.popSizesInput.get());
        // Ensure model has appropriate number of demes
        int uniqueTraitCount = uniqueTraitsInData(tree).size();
        StringBuilder rateMatrixStrBuilder = new StringBuilder();
        StringBuilder popSizesStrBuilder = new StringBuilder();
        migModel.getTypeSet().initAndValidate();
        if (migModel.popSizesInput.get().getDimension() != migModel.getNTypes()) {
            for (int i = 0; i < migModel.getNTypes(); i++) {
                popSizesStrBuilder.append(" 1.0");
                for (int j = 0; j < migModel.getNTypes(); j++) {
                    if (j == i)
                        continue;
                    rateMatrixStrBuilder.append(" 1.0");
                }
            }
            popSizesStr = popSizesStrBuilder.toString();
            rateMatrixStr = rateMatrixStrBuilder.toString();
            ((RealParameter) migModel.popSizesInput.get()).setDimension(migModel.getNTypes());
            ((RealParameter) migModel.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModel.popSizesInput.get());
            ((RealParameter) migModel.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
            ((RealParameter) migModel.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModel.rateMatrixInput.get());
            ((RealParameter) migModel.popSizesInput.get()).initAndValidate();
            ((RealParameter) migModel.rateMatrixInput.get()).initAndValidate();
            migModel.initAndValidate();
        }
        ((RealParameter) migModelInit.popSizesInput.get()).setDimension(migModel.getNTypes());
        ((RealParameter) migModelInit.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModelInit.popSizesInput.get());
        ((RealParameter) migModelInit.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
        ((RealParameter) migModelInit.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModelInit.rateMatrixInput.get());
        try {
            ((RealParameter) migModelInit.popSizesInput.get()).initAndValidate();
            ((RealParameter) migModelInit.rateMatrixInput.get()).initAndValidate();
            migModelInit.initAndValidate();
        } catch (Exception ex) {
            System.err.println("Error configuring initial migration model.");
        }
    }
    return false;
}
Also used : TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) RealParameter(beast.core.parameter.RealParameter) BEASTInterface(beast.core.BEASTInterface) SCMigrationModel(beast.evolution.tree.SCMigrationModel) StructuredCoalescentMultiTypeTree(beast.evolution.tree.StructuredCoalescentMultiTypeTree)

Example 60 with BEASTInterface

use of beast.core.BEASTInterface in project bacter by tgvaughan.

the class CustomConnectors method applyRestrictions.

public static void applyRestrictions(BeautiDoc doc) {
    for (BEASTInterface p : doc.getPartitions("Tree")) {
        ACGLikelihood acgLikelihood = (ACGLikelihood) p;
        SimulatedACG acg = (SimulatedACG) ((ACGLikelihood) p).treeInput.get();
        ACGCoalescent coalescent = null;
        for (BEASTInterface output : acg.getOutputs()) {
            if (output instanceof ACGCoalescent) {
                coalescent = (ACGCoalescent) output;
                break;
            }
        }
        if (coalescent == null)
            continue;
        acg.setWholeLocusMode(coalescent.wholeLocusConversionsInput.get());
    }
}
Also used : ACGLikelihood(bacter.model.ACGLikelihood) ACGCoalescent(bacter.model.ACGCoalescent) SimulatedACG(bacter.model.SimulatedACG) 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