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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations