use of dr.evomodel.branchratemodel.DiscreteTraitBranchRateModel in project beast-mcmc by beast-dev.
the class DiscreteTraitBranchRateModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
PatternList patternList = (PatternList) xo.getChild(PatternList.class);
TreeTraitProvider traitProvider = (TreeTraitProvider) xo.getChild(TreeTraitProvider.class);
DataType dataType = DataTypeUtils.getDataType(xo);
Parameter rateParameter = null;
Parameter relativeRatesParameter = null;
Parameter indicatorsParameter = null;
if (xo.getChild(RATE) != null) {
rateParameter = (Parameter) xo.getElementFirstChild(RATE);
}
if (xo.getChild(RATES) != null) {
rateParameter = (Parameter) xo.getElementFirstChild(RATES);
}
if (xo.getChild(RELATIVE_RATES) != null) {
relativeRatesParameter = (Parameter) xo.getElementFirstChild(RELATIVE_RATES);
}
if (xo.getChild(INDICATORS) != null) {
indicatorsParameter = (Parameter) xo.getElementFirstChild(INDICATORS);
}
int traitIndex = xo.getAttribute(TRAIT_INDEX, 1) - 1;
String traitName = "states";
Logger.getLogger("dr.evomodel").info("Using discrete trait branch rate model.\n" + "\tIf you use this model, please cite:\n" + "\t\tDrummond and Suchard (in preparation)");
if (traitProvider == null) {
// Use the version that reconstructs the trait using parsimony:
return new DiscreteTraitBranchRateModel(treeModel, patternList, traitIndex, rateParameter);
} else {
if (traitName != null) {
TreeTrait trait = traitProvider.getTreeTrait(traitName);
if (trait == null) {
throw new XMLParseException("A trait called, " + traitName + ", was not available from the TreeTraitProvider supplied to " + getParserName() + ", with ID " + xo.getId());
}
if (relativeRatesParameter != null) {
return new DiscreteTraitBranchRateModel(traitProvider, dataType, treeModel, trait, traitIndex, rateParameter, relativeRatesParameter, indicatorsParameter);
} else {
return new DiscreteTraitBranchRateModel(traitProvider, dataType, treeModel, trait, traitIndex, rateParameter);
}
} else {
TreeTrait[] traits = new TreeTrait[dataType.getStateCount()];
for (int i = 0; i < dataType.getStateCount(); i++) {
traits[i] = traitProvider.getTreeTrait(dataType.getCode(i));
if (traits[i] == null) {
throw new XMLParseException("A trait called, " + dataType.getCode(i) + ", was not available from the TreeTraitProvider supplied to " + getParserName() + ", with ID " + xo.getId());
}
}
return new DiscreteTraitBranchRateModel(traitProvider, traits, treeModel, rateParameter);
}
}
}
Aggregations