Search in sources :

Example 16 with Distribution

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

the class BeautiDoc method collectClockModels.

private void collectClockModels() {
    // collect branch rate models from model
    CompoundDistribution likelihood = (CompoundDistribution) pluginmap.get("likelihood");
    while (clockModels.size() < partitionNames.size()) {
        try {
            GenericTreeLikelihood treelikelihood = new GenericTreeLikelihood();
            treelikelihood.branchRateModelInput.setValue(new StrictClockModel(), treelikelihood);
            List<BeautiSubTemplate> availableBEASTObjects = inputEditorFactory.getAvailableTemplates(treelikelihood.branchRateModelInput, treelikelihood, null, this);
            BEASTInterface beastObject = availableBEASTObjects.get(0).createSubNet(partitionNames.get(clockModels.size()), true);
            clockModels.add((BranchRateModel.Base) beastObject);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    int k = 0;
    for (Distribution d : likelihood.pDistributions.get()) {
        BranchRateModel clockModel = ((GenericTreeLikelihood) d).branchRateModelInput.get();
        // sanity check
        Tree tree = null;
        try {
            for (Input<?> input : ((BEASTInterface) clockModel).listInputs()) {
                if (input.getName().equals("tree")) {
                    tree = (Tree) input.get();
                }
            }
            if (tree != null && tree != ((GenericTreeLikelihood) d).treeInput.get()) {
                clockModel = clockModels.get(k);
                Log.warning.println("WARNING: unlinking clock model for " + d.getID());
                // TODO #557: this should move to the event of clock model drop box
                // JOptionPane.showMessageDialog(beauti.getSelectedComponent(),
                // "Cannot link all clock model(s) except strict clock with different trees !");
                ((GenericTreeLikelihood) d).branchRateModelInput.setValue(clockModel, d);
            }
        } catch (Exception e) {
        // ignore
        }
        if (clockModel != null) {
            String id = ((BEASTInterface) clockModel).getID();
            id = parsePartition(id);
            String partition = alignments.get(k).getID();
            if (id.equals(partition)) {
                clockModels.set(k, clockModel);
            }
            k++;
        }
    }
}
Also used : GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) XMLParserException(beast.util.XMLParserException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CompoundDistribution(beast.core.util.CompoundDistribution) StrictClockModel(beast.evolution.branchratemodel.StrictClockModel) BranchRateModel(beast.evolution.branchratemodel.BranchRateModel) CompoundDistribution(beast.core.util.CompoundDistribution) ParametricDistribution(beast.math.distributions.ParametricDistribution) Distribution(beast.core.Distribution) Tree(beast.evolution.tree.Tree) BEASTInterface(beast.core.BEASTInterface)

Example 17 with Distribution

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

the class PriorListInputEditor method pluginSelector.

@Override
protected List<BEASTInterface> pluginSelector(Input<?> input, BEASTInterface parent, List<String> tabooList) {
    if (priorProviders == null) {
        initProviders();
    }
    PriorProvider priorProvider = priorProviders.get(0);
    if (priorProviders.size() > 1) {
        // let user choose a PriorProvider
        List<String> descriptions = new ArrayList<>();
        List<PriorProvider> availableProviders = new ArrayList<>();
        for (PriorProvider i : priorProviders) {
            if (i.canProvidePrior(doc)) {
                descriptions.add(i.getDescription());
                availableProviders.add(i);
            }
        }
        String option = (String) JOptionPane.showInputDialog(null, "Which prior do you want to add", "Option", JOptionPane.WARNING_MESSAGE, null, descriptions.toArray(), descriptions.get(0));
        if (option == null) {
            return null;
        }
        int i = descriptions.indexOf(option);
        priorProvider = availableProviders.get(i);
    }
    List<BEASTInterface> selectedPlugins = new ArrayList<>();
    List<Distribution> distrs = priorProvider.createDistribution(doc);
    if (distrs == null) {
        return null;
    }
    for (Distribution distr : distrs) {
        selectedPlugins.add(distr);
    }
    return selectedPlugins;
}
Also used : Distribution(beast.core.Distribution) TreeDistribution(beast.evolution.tree.TreeDistribution) ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface)

Aggregations

Distribution (beast.core.Distribution)17 CompoundDistribution (beast.core.util.CompoundDistribution)12 BEASTInterface (beast.core.BEASTInterface)9 ParametricDistribution (beast.math.distributions.ParametricDistribution)8 ArrayList (java.util.ArrayList)7 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)5 MRCAPrior (beast.math.distributions.MRCAPrior)5 XMLParserException (beast.util.XMLParserException)5 IOException (java.io.IOException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 SAXException (org.xml.sax.SAXException)5 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)4 Tree (beast.evolution.tree.Tree)4 List (java.util.List)4 BEASTObject (beast.core.BEASTObject)3 Parameter (beast.core.parameter.Parameter)3 TaxonSet (beast.evolution.alignment.TaxonSet)3 StateNode (beast.core.StateNode)2 RealParameter (beast.core.parameter.RealParameter)2