use of dr.evolution.alignment.UncertainSiteList in project beast-mcmc by beast-dev.
the class UncertainAttributePatternsParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String attributeName = xo.getStringAttribute(ATTRIBUTE);
TaxonList taxa = (TaxonList) xo.getChild(TaxonList.class);
DataType dataType = DataTypeUtils.getDataType(xo);
if (dataType == null) {
throw new XMLParseException("dataType expected for attributePatterns element");
}
// using a SimpleSiteList rather than Patterns to allow ancestral reconstruction
UncertainSiteList patterns = new UncertainSiteList(dataType, taxa);
boolean normalize = xo.getAttribute(NORMALIZE, true);
if (dataType == null) {
// TODO Is this necessary given XMLSyntaxRules?
throw new XMLParseException("dataType expected for attributePatterns element");
}
double[][] uncertainPattern = new double[taxa.getTaxonCount()][];
// Parse attributes
boolean attributeFound = false;
for (int i = 0; i < taxa.getTaxonCount(); i++) {
Taxon taxon = taxa.getTaxon(i);
Object value = taxon.getAttribute(attributeName);
if (value != null) {
attributeFound = true;
List<StateProbability> stateProbabilities;
try {
stateProbabilities = parseStates(value.toString(), dataType);
} catch (StateParseException e) {
throw new XMLParseException("State or probability for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is invalid; state = \"" + e.getState() + "\" and probability =\"" + e.getProbability() + "\"");
}
uncertainPattern[i] = convertToPartials(stateProbabilities, dataType, normalize);
} else {
throw new XMLParseException("State for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is unknown.");
}
}
if (!attributeFound) {
throw new XMLParseException("The attribute (" + attributeName + ") was missing in all taxa. Check the name of the attribute.");
}
patterns.addPattern(uncertainPattern);
Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating an uncertain attribute model for attribute \"" + attributeName + "\"");
Logger.getLogger("dr.evolution").info("\tIf you publish results using this model, please reference:");
Logger.getLogger("dr.evolution").info("\t" + Citable.Utils.getCitationString(patterns));
Logger.getLogger("dr.evolution").info("\n");
return patterns;
}
Aggregations