Search in sources :

Example 11 with GenericTreeLikelihood

use of beast.evolution.likelihood.GenericTreeLikelihood 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 12 with GenericTreeLikelihood

use of beast.evolution.likelihood.GenericTreeLikelihood in project beast2 by CompEvol.

the class SiteModelInputEditor method setUpOperator.

/**
 * set up relative weights and parameter input *
 */
public void setUpOperator() {
    boolean isAllClocksAreEqual = true;
    try {
        boolean hasOneEstimatedRate = customConnector(doc);
        if (doc.autoUpdateFixMeanSubstRate) {
            fixMeanRatesCheckBox.setSelected(hasOneEstimatedRate);
            doFixMeanRates(hasOneEstimatedRate);
        }
        try {
            double commonClockRate = -1;
            CompoundDistribution likelihood = (CompoundDistribution) doc.pluginmap.get("likelihood");
            for (Distribution d : likelihood.pDistributions.get()) {
                GenericTreeLikelihood treelikelihood = (GenericTreeLikelihood) d;
                if (treelikelihood.siteModelInput.get() instanceof SiteModel) {
                    SiteModel siteModel = (SiteModel) treelikelihood.siteModelInput.get();
                    RealParameter mutationRate = siteModel.muParameterInput.get();
                    // clockRate.m_bIsEstimated.setValue(true, clockRate);
                    if (mutationRate.isEstimatedInput.get()) {
                        if (commonClockRate < 0) {
                            commonClockRate = mutationRate.valuesInput.get().get(0);
                        } else {
                            if (Math.abs(commonClockRate - mutationRate.valuesInput.get().get(0)) > 1e-10) {
                                isAllClocksAreEqual = false;
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
        }
        List<RealParameter> parameters = operator.parameterInput.get();
        if (!fixMeanRatesCheckBox.isSelected()) {
            fixMeanRatesValidateLabel.setVisible(false);
            repaint();
            return;
        }
        if (parameters.size() == 0) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.red;
            fixMeanRatesValidateLabel.setToolTipText("The model is invalid: At least one substitution rate should be estimated.");
            repaint();
            return;
        }
        if (!isAllClocksAreEqual) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("Not all substitution rates are equal. Are you sure this is what you want?");
        } else if (parameters.size() == 1) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("At least 2 clock models should have their rate estimated");
        } else if (parameters.size() < doc.getPartitions("SiteModel").size()) {
            fixMeanRatesValidateLabel.setVisible(true);
            fixMeanRatesValidateLabel.m_circleColor = Color.orange;
            fixMeanRatesValidateLabel.setToolTipText("Not all partitions have their rate estimated");
        } else {
            fixMeanRatesValidateLabel.setVisible(false);
        }
        repaint();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CompoundDistribution(beast.core.util.CompoundDistribution) CompoundDistribution(beast.core.util.CompoundDistribution) GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) RealParameter(beast.core.parameter.RealParameter) SiteModel(beast.evolution.sitemodel.SiteModel) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)12 CompoundDistribution (beast.core.util.CompoundDistribution)9 BEASTInterface (beast.core.BEASTInterface)8 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)6 Distribution (beast.core.Distribution)5 SiteModel (beast.evolution.sitemodel.SiteModel)5 ParametricDistribution (beast.math.distributions.ParametricDistribution)5 IOException (java.io.IOException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 SAXException (org.xml.sax.SAXException)5 XMLParserException (beast.util.XMLParserException)4 ArrayList (java.util.ArrayList)4 MCMC (beast.core.MCMC)3 RealParameter (beast.core.parameter.RealParameter)3 Alignment (beast.evolution.alignment.Alignment)3 SiteModelInterface (beast.evolution.sitemodel.SiteModelInterface)3 Tree (beast.evolution.tree.Tree)3 TreeInterface (beast.evolution.tree.TreeInterface)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3