Search in sources :

Example 6 with XMLObject

use of dr.xml.XMLObject in project beast-mcmc by beast-dev.

the class BranchAssignmentModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing branch assignment branch model.");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    String annotation = xo.getStringAttribute(ANNOTATION);
    LinkedHashMap<Integer, SubstitutionModel> modelIndexMap = new LinkedHashMap<Integer, 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(ASSIGNMENT)) {
                Integer index = null;
                if (xoc.hasAttribute(ANNOTATION_VALUE)) {
                    index = xoc.getIntegerAttribute(ANNOTATION_VALUE);
                }
                SubstitutionModel model = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                modelIndexMap.put(index, model);
            }
        }
    }
    SubstitutionModel baseModel = (SubstitutionModel) xo.getElementFirstChild(BASE_MODEL);
    return new BranchAssignmentModel(treeModel, annotation, modelIndexMap, baseModel);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchAssignmentModel(dr.evomodel.branchmodel.BranchAssignmentModel) XMLObject(dr.xml.XMLObject) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with XMLObject

use of dr.xml.XMLObject in project beast-mcmc by beast-dev.

the class DataTypeUtils method getDataType.

public static DataType getDataType(XMLObject xo) throws XMLParseException {
    DataType dataType = null;
    if (xo.hasAttribute(DataType.DATA_TYPE)) {
        String dataTypeStr = xo.getStringAttribute(DataType.DATA_TYPE);
        if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
            dataTypeStr += "-" + xo.getStringAttribute(GeneticCode.GENETIC_CODE);
        }
        dataType = DataType.getRegisteredDataTypeByName(dataTypeStr);
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof DataType) {
            if (dataType != null) {
                throw new XMLParseException("Multiple dataTypes defined for alignment element");
            }
            dataType = (DataType) child;
        }
    }
    return dataType;
}
Also used : DataType(dr.evolution.datatype.DataType) XMLObject(dr.xml.XMLObject) XMLParseException(dr.xml.XMLParseException)

Example 8 with XMLObject

use of dr.xml.XMLObject in project beast-mcmc by beast-dev.

the class EpochBranchModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing multi-epoch branch model.");
    MutableTreeModel treeModel = (MutableTreeModel) xo.getChild(MutableTreeModel.class);
    SubstitutionModel ancestralSubstitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    List<Epoch> epochs = new ArrayList<Epoch>();
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject xoc = (XMLObject) xo.getChild(i);
            if (xoc.getName().equals(EPOCH)) {
                Parameter tt = null;
                if (xoc.hasAttribute(TRANSITION_TIME)) {
                    double t = xoc.getAttribute(TRANSITION_TIME, 0.0);
                    tt = new Parameter.Default(1, t);
                }
                SubstitutionModel s = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                if (xoc.hasChildNamed(TRANSITION_TIME)) {
                    if (tt != null) {
                        throw new XMLParseException("An epoch cannot have a transitionTime attribute and a parameter");
                    }
                    tt = (Parameter) xoc.getElementFirstChild(TRANSITION_TIME);
                }
                epochs.add(new Epoch(s, tt));
            }
        }
    }
    Collections.sort(epochs);
    List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
    CompoundParameter transitionTimes = new CompoundParameter("epochTimes");
    for (Epoch epoch : epochs) {
        substitutionModels.add(epoch.substitutionModel);
        transitionTimes.addParameter(epoch.timeParameter);
    }
    substitutionModels.add(ancestralSubstitutionModel);
    return new EpochBranchModel(treeModel, substitutionModels, transitionTimes);
}
Also used : EpochBranchModel(dr.evomodel.branchmodel.EpochBranchModel) ArrayList(java.util.ArrayList) XMLObject(dr.xml.XMLObject) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) CompoundParameter(dr.inference.model.CompoundParameter) MutableTreeModel(dr.evolution.tree.MutableTreeModel) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter) XMLParseException(dr.xml.XMLParseException)

Example 9 with XMLObject

use of dr.xml.XMLObject in project beast-mcmc by beast-dev.

the class GammaSiteModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String msg = "";
    SubstitutionModel substitutionModel = null;
    double muWeight = 1.0;
    Parameter muParam = null;
    if (xo.hasChildNamed(SUBSTITUTION_RATE)) {
        muParam = (Parameter) xo.getElementFirstChild(SUBSTITUTION_RATE);
        msg += "\n  with initial substitution rate = " + muParam.getParameterValue(0);
    } else if (xo.hasChildNamed(MUTATION_RATE)) {
        muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
        msg += "\n  with initial substitution rate = " + muParam.getParameterValue(0);
    } else if (xo.hasChildNamed(RELATIVE_RATE)) {
        XMLObject cxo = xo.getChild(RELATIVE_RATE);
        muParam = (Parameter) cxo.getChild(Parameter.class);
        msg += "\n  with initial relative rate = " + muParam.getParameterValue(0);
        if (cxo.hasAttribute(WEIGHT)) {
            muWeight = cxo.getDoubleAttribute(WEIGHT);
            msg += " with weight: " + muWeight;
        }
    }
    Parameter shapeParam = null;
    int catCount = 4;
    if (xo.hasChildNamed(GAMMA_SHAPE)) {
        XMLObject cxo = xo.getChild(GAMMA_SHAPE);
        catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES);
        shapeParam = (Parameter) cxo.getChild(Parameter.class);
        msg += "\n  " + catCount + " category discrete gamma with initial shape = " + shapeParam.getParameterValue(0);
    }
    Parameter invarParam = null;
    if (xo.hasChildNamed(PROPORTION_INVARIANT)) {
        invarParam = (Parameter) xo.getElementFirstChild(PROPORTION_INVARIANT);
        msg += "\n  initial proportion of invariant sites = " + invarParam.getParameterValue(0);
    }
    if (msg.length() > 0) {
        Logger.getLogger("dr.evomodel").info("\nCreating site rate model: " + msg);
    } else {
        Logger.getLogger("dr.evomodel").info("\nCreating site rate model.");
    }
    GammaSiteRateModel siteRateModel = new GammaSiteRateModel(SITE_MODEL, muParam, muWeight, shapeParam, catCount, invarParam);
    if (xo.hasChildNamed(SUBSTITUTION_MODEL)) {
        // System.err.println("Doing the substitution model stuff");
        // set this to pass it along to the OldTreeLikelihoodParser...
        substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL);
        siteRateModel.setSubstitutionModel(substitutionModel);
    }
    return siteRateModel;
}
Also used : Parameter(dr.inference.model.Parameter) XMLObject(dr.xml.XMLObject) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

Example 10 with XMLObject

use of dr.xml.XMLObject in project beast-mcmc by beast-dev.

the class BranchingLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) {
    XMLObject cxo = xo.getChild(MODEL);
    BranchingModel branchingModel = (BranchingModel) cxo.getChild(BranchingModel.class);
    cxo = xo.getChild(TREE);
    TreeModel treeModel = (TreeModel) cxo.getChild(TreeModel.class);
    return new BranchingLikelihood(treeModel, branchingModel);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchingModel(dr.evomodel.speciation.BranchingModel) XMLObject(dr.xml.XMLObject) BranchingLikelihood(dr.evomodel.speciation.BranchingLikelihood)

Aggregations

XMLObject (dr.xml.XMLObject)13 Parameter (dr.inference.model.Parameter)7 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)6 TreeModel (dr.evomodel.tree.TreeModel)6 ArrayList (java.util.ArrayList)5 XMLParseException (dr.xml.XMLParseException)4 DataType (dr.evolution.datatype.DataType)2 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)2 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)2 Partition (dr.app.beagle.tools.Partition)1 Sequence (dr.evolution.sequence.Sequence)1 MutableTreeModel (dr.evolution.tree.MutableTreeModel)1 Units (dr.evolution.util.Units)1 AlloppNetworkPriorModel (dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel)1 MulSpeciesTreeModel (dr.evomodel.alloppnet.speciation.MulSpeciesTreeModel)1 MulSpeciesTreePrior (dr.evomodel.alloppnet.speciation.MulSpeciesTreePrior)1 BranchAssignmentModel (dr.evomodel.branchmodel.BranchAssignmentModel)1 BranchModel (dr.evomodel.branchmodel.BranchModel)1 EpochBranchModel (dr.evomodel.branchmodel.EpochBranchModel)1 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)1