Search in sources :

Example 31 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class RandomBranchAssignmentModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    XMLObject cxo = xo.getChild(MODELS);
    List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
    for (int i = 0; i < cxo.getChildCount(); i++) {
        SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
        substitutionModels.add(substModel);
    }
    return new RandomBranchAssignmentModel(treeModel, substitutionModels);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) ArrayList(java.util.ArrayList) XMLObject(dr.xml.XMLObject) RandomBranchAssignmentModel(dr.evomodel.branchmodel.RandomBranchAssignmentModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

Example 32 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class RandomBranchModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    GY94CodonModel baseSubstitutionModel = (GY94CodonModel) xo.getElementFirstChild(BASE_MODEL);
    long seed = -1;
    boolean hasSeed = false;
    if (xo.hasAttribute(SEED)) {
        seed = xo.getLongIntegerAttribute(SEED);
        hasSeed = true;
    }
    double rate = 1;
    if (xo.hasAttribute(RATE)) {
        rate = xo.getDoubleAttribute(RATE);
    }
    return new RandomBranchModel(treeModel, baseSubstitutionModel, rate, hasSeed, seed);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) RandomBranchModel(dr.evomodel.branchmodel.RandomBranchModel) GY94CodonModel(dr.evomodel.substmodel.codon.GY94CodonModel)

Example 33 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class BranchCategoriesParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter allocationParameter = (Parameter) xo.getElementFirstChild(ALLOCATION);
    CountableBranchCategoryProvider cladeModel;
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    if (!xo.getAttribute(RANDOMIZE, true)) {
        CountableBranchCategoryProvider.CladeBranchCategoryModel cm = new CountableBranchCategoryProvider.CladeBranchCategoryModel(treeModel, allocationParameter);
        for (int i = 0; i < xo.getChildCount(); ++i) {
            if (xo.getChild(i) instanceof XMLObject) {
                XMLObject xoc = (XMLObject) xo.getChild(i);
                if (xoc.getName().equals(LocalClockModelParser.CLADE)) {
                    TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                    boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
                    boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
                    // XML index-start = 1 not 0
                    int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
                    try {
                        cm.setClade(taxonList, rateCategory, includeStem, excludeClade, false);
                    } catch (TreeUtils.MissingTaxonException e) {
                        throw new XMLParseException("Unable to find taxon for clade in countable mixture model: " + e.getMessage());
                    }
                } else if (xoc.getName().equals(LocalClockModelParser.TRUNK)) {
                    TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                    boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
                    boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
                    // XML index-start = 1 not 0
                    int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
                    try {
                        cm.setClade(taxonList, rateCategory, includeStem, excludeClade, true);
                    } catch (TreeUtils.MissingTaxonException e) {
                        throw new XMLParseException("Unable to find taxon for trunk in countable mixture model: " + e.getMessage());
                    }
                }
            }
        }
        cladeModel = cm;
    } else {
        CountableBranchCategoryProvider.IndependentBranchCategoryModel cm = new CountableBranchCategoryProvider.IndependentBranchCategoryModel(treeModel, allocationParameter);
        cm.randomize();
        cladeModel = cm;
    }
    return cladeModel;
}
Also used : TaxonList(dr.evolution.util.TaxonList) TreeModel(dr.evomodel.tree.TreeModel) Parameter(dr.inference.model.Parameter) CountableBranchCategoryProvider(dr.evomodel.branchratemodel.CountableBranchCategoryProvider) TreeUtils(dr.evolution.tree.TreeUtils)

Example 34 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class TKF91LikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    Alignment alignment = (Alignment) xo.getChild(Alignment.class);
    GammaSiteModel siteModel = (GammaSiteModel) xo.getChild(GammaSiteModel.class);
    TKF91Model tkfModel = (TKF91Model) xo.getChild(TKF91Model.class);
    return new TKF91Likelihood(tree, alignment, siteModel, tkfModel);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TKF91Likelihood(dr.oldevomodel.indel.TKF91Likelihood) Alignment(dr.evolution.alignment.Alignment) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) TKF91Model(dr.oldevomodel.indel.TKF91Model)

Example 35 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class MicrosatelliteSamplerTreeLikelihood method traverse.

private void traverse() {
    TreeModel tree = treeMicrosatSamplerModel.getTreeModel();
    int updateNum = updatedNodeList.size();
    for (int i = 0; i < updateNum; i++) {
        NodeRef node = tree.getNode(updatedNodeList.get(i));
        int nodeState = treeMicrosatSamplerModel.getNodeValue(node);
        if (!tree.isRoot(node)) {
            NodeRef parent = tree.getParent(node);
            int parentState = treeMicrosatSamplerModel.getNodeValue(parent);
            double branchLength = tree.getBranchLength(node) * branchRateModel.getBranchRate(tree, node);
            double nodePr = microsatelliteModel.getLogOneTransitionProbabilityEntry(branchLength, parentState, nodeState);
            treeMicrosatSamplerModel.setLogBranchLikelihood(node, nodePr);
        } else {
            double logEqFreq = Math.log(microsatelliteModel.getStationaryDistribution()[nodeState]);
            treeMicrosatSamplerModel.setLogBranchLikelihood(node, logEqFreq);
        }
    }
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) MicrosatelliteSamplerTreeModel(dr.evomodel.tree.MicrosatelliteSamplerTreeModel) NodeRef(dr.evolution.tree.NodeRef)

Aggregations

TreeModel (dr.evomodel.tree.TreeModel)142 Parameter (dr.inference.model.Parameter)62 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)28 ArrayList (java.util.ArrayList)28 Tree (dr.evolution.tree.Tree)26 NewickImporter (dr.evolution.io.NewickImporter)21 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)20 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)19 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)18 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)15 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)15 PatternList (dr.evolution.alignment.PatternList)14 NodeRef (dr.evolution.tree.NodeRef)14 Partition (dr.app.beagle.tools.Partition)12 BranchModel (dr.evomodel.branchmodel.BranchModel)12 IOException (java.io.IOException)12 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)11 Taxon (dr.evolution.util.Taxon)11 TaxonList (dr.evolution.util.TaxonList)11 Patterns (dr.evolution.alignment.Patterns)9