Search in sources :

Example 6 with Input

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

the class DocumentationTest method testInputTipText.

// testDescriptions
/**
 * Check all inputs of plug-ins have a proper tip text, again
 * to facilitate proper documentation. *
 */
@Test
public void testInputTipText() {
    final List<String> pluginNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
    final List<String> undocumentedInputs = new ArrayList<String>();
    for (final String beastObjectName : pluginNames) {
        try {
            final BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
            final List<Input<?>> inputs = beastObject.listInputs();
            for (final Input<?> input : inputs) {
                boolean hasSatisfactoryDescription = false;
                final String tipText = input.getTipText();
                if (isProperDocString(tipText)) {
                    hasSatisfactoryDescription = true;
                }
                if (!hasSatisfactoryDescription) {
                    undocumentedInputs.add(beastObjectName + ":" + input.getName());
                }
            }
        } catch (Exception e) {
        }
    }
    assertTrue("No proper input tip text (at least " + N_WORDS + " words and " + N_CHARS + " characters) for: " + undocumentedInputs.toString(), undocumentedInputs.size() == 0);
}
Also used : Input(beast.core.Input) ArrayList(java.util.ArrayList) BEASTObject(beast.core.BEASTObject) Test(org.junit.Test)

Example 7 with Input

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

the class XMLElementNameTest method test_NameUniqueness.

/**
 * test that Inputs have a unique name
 * It can happen that a derived class uses the same Input name as one of its ancestors
 */
@Test
public void test_NameUniqueness() {
    List<String> pluginNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
    List<String> improperInputs = new ArrayList<String>();
    for (String beastObjectName : pluginNames) {
        try {
            BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
            List<Input<?>> inputs = beastObject.listInputs();
            Set<String> names = new HashSet<String>();
            for (Input<?> input : inputs) {
                String name = input.getName();
                if (names.contains(name)) {
                    improperInputs.add(beastObjectName + "." + name);
                    break;
                }
                names.add(name);
            }
        } catch (InstantiationException e) {
        // ignore
        } catch (Exception e) {
        // ignore
        }
    }
    if (improperInputs.size() > 0) {
        String str = improperInputs.toString();
        str = str.replaceAll(",", "\n");
        System.err.println("Input names are not unique:\n" + str);
    }
    // not activated till problem with naming is solved
    assertTrue("Input names are not unique: " + improperInputs.toString(), improperInputs.size() == 0);
}
Also used : Input(beast.core.Input) ArrayList(java.util.ArrayList) BEASTObject(beast.core.BEASTObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Input

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

the class Document method process.

void process(BEASTObjectShape shape, int depth) throws IllegalArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException {
    BEASTInterface beastObject = shape.m_beastObject;
    List<Input<?>> inputs = beastObject.listInputs();
    for (Input<?> input_ : inputs) {
        Object o = input_.get();
        if (o != null) {
            if (o instanceof List<?>) {
                for (Object o2 : (List<?>) o) {
                    addInput(shape, o2, depth + 1, input_.getName());
                }
            } else if (o instanceof BEASTInterface) {
                addInput(shape, o, depth + 1, input_.getName());
            // } else {
            // it is a primitive type
            }
        }
    }
}
Also used : Input(beast.core.Input) BEASTInterface(beast.core.BEASTInterface) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with Input

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

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

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