Search in sources :

Example 1 with CountableBranchCategoryProvider

use of dr.evomodel.branchratemodel.CountableBranchCategoryProvider 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)

Aggregations

TreeUtils (dr.evolution.tree.TreeUtils)1 TaxonList (dr.evolution.util.TaxonList)1 CountableBranchCategoryProvider (dr.evomodel.branchratemodel.CountableBranchCategoryProvider)1 TreeModel (dr.evomodel.tree.TreeModel)1 Parameter (dr.inference.model.Parameter)1