Search in sources :

Example 1 with BranchSpecificBranchModel

use of dr.evomodel.branchmodel.BranchSpecificBranchModel in project beast-mcmc by beast-dev.

the class BranchSpecificBranchModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing clade-specific branch model.");
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    BranchSpecificBranchModel branchModel = new BranchSpecificBranchModel(tree, substitutionModel);
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject xoc = (XMLObject) xo.getChild(i);
            if (xoc.getName().equals(CLADE)) {
                double stemWeight = xoc.getAttribute(STEM_WEIGHT, 0.0);
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                if (taxonList.getTaxonCount() == 1) {
                    throw new XMLParseException("A clade must be defined by at least two taxa");
                }
                try {
                    branchModel.addClade(taxonList, substitutionModel, stemWeight);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(EXTERNAL_BRANCHES)) {
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    branchModel.addExternalBranches(taxonList, substitutionModel);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(BACKBONE)) {
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    branchModel.addBackbone(taxonList, substitutionModel);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            }
        }
    }
    return branchModel;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TaxonList(dr.evolution.util.TaxonList) BranchSpecificBranchModel(dr.evomodel.branchmodel.BranchSpecificBranchModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) TreeUtils(dr.evolution.tree.TreeUtils)

Aggregations

TreeUtils (dr.evolution.tree.TreeUtils)1 TaxonList (dr.evolution.util.TaxonList)1 BranchSpecificBranchModel (dr.evomodel.branchmodel.BranchSpecificBranchModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 TreeModel (dr.evomodel.tree.TreeModel)1