Search in sources :

Example 1 with LocalClockModel

use of dr.evomodel.branchratemodel.LocalClockModel in project beast-mcmc by beast-dev.

the class LocalClockModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    Parameter globalRateParameter = (Parameter) xo.getElementFirstChild(RATE);
    LocalClockModel localClockModel = new LocalClockModel(tree, globalRateParameter);
    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)) {
                boolean relative = xoc.getAttribute(RELATIVE, false);
                Parameter rateParameter = (Parameter) xoc.getChild(Parameter.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                if (taxonList.getTaxonCount() == 1) {
                    throw new XMLParseException("A local clock for a clade must be defined by at least two taxa");
                }
                boolean excludeClade = false;
                double stemProportion = 0.0;
                if (xoc.hasAttribute(INCLUDE_STEM)) {
                    // if includeStem=true then assume it is the whole stem
                    stemProportion = xoc.getBooleanAttribute(INCLUDE_STEM) ? 1.0 : 0.0;
                }
                if (xoc.hasAttribute(STEM_PROPORTION)) {
                    stemProportion = xoc.getDoubleAttribute(STEM_PROPORTION);
                    if (stemProportion < 0.0 || stemProportion > 1.0) {
                        throw new XMLParseException("A stem proportion should be between 0, 1");
                    }
                }
                if (xoc.hasAttribute(EXCLUDE_CLADE)) {
                    excludeClade = xoc.getBooleanAttribute(EXCLUDE_CLADE);
                }
                try {
                    localClockModel.addCladeClock(taxonList, rateParameter, relative, stemProportion, excludeClade);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(EXTERNAL_BRANCHES)) {
                boolean relative = xoc.getAttribute(RELATIVE, false);
                Parameter rateParameter = (Parameter) xoc.getChild(Parameter.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    localClockModel.addExternalBranchClock(taxonList, rateParameter, relative);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(TRUNK)) {
                boolean relative = xoc.getAttribute(RELATIVE, false);
                Parameter indexParameter = null;
                if (xoc.hasChildNamed(INDEX)) {
                    indexParameter = (Parameter) xoc.getElementFirstChild(INDEX);
                }
                Parameter rateParameter = (Parameter) xoc.getChild(Parameter.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    localClockModel.addTrunkClock(taxonList, rateParameter, indexParameter, relative);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            }
        }
    }
    Logger.getLogger("dr.evomodel").info("\nUsing local clock branch rate model.");
    return localClockModel;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TaxonList(dr.evolution.util.TaxonList) LocalClockModel(dr.evomodel.branchratemodel.LocalClockModel) Parameter(dr.inference.model.Parameter) TreeUtils(dr.evolution.tree.TreeUtils)

Aggregations

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