use of dr.evolution.datatype.DataType 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;
}
use of dr.evolution.datatype.DataType 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.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class IstvanOperator method initSubstitutionModel.
/**
* initialize the iProbs array from the substitution model -- must be called after populating tree!
*/
private void initSubstitutionModel(SubstitutionModel model) {
DataType dataType = model.getDataType();
int stateCount = dataType.getStateCount();
iProbs = new double[iTau.length][stateCount][stateCount];
double[] transProb = new double[stateCount * stateCount];
int count;
for (int i = 0; i < iTau.length; i++) {
model.getTransitionProbabilities(iTau[i], transProb);
count = 0;
for (int j = 0; j < stateCount; j++) {
for (int k = 0; k < stateCount; k++) {
iProbs[i][j][k] = transProb[count];
count += 1;
}
}
}
// initialize equlibrium distribution
iBaseFreqs = new double[stateCount];
for (int k = 0; k < stateCount; k++) {
iBaseFreqs[k] = model.getFrequencyModel().getFrequency(k);
}
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class IstvanOperator method initAlignment.
/**
* Initializes the iAlignment array from the given alignment.
*/
private void initAlignment(Alignment alignment, int[] treeIndex) {
int numSeqs = alignment.getSequenceCount();
int numSites = alignment.getSiteCount();
DataType dataType = alignment.getDataType();
int numStates = dataType.getStateCount();
iAlignment = new int[numSeqs][numSites];
// populate alignment in order of tree
for (int i = 0; i < numSeqs; i++) {
for (int j = 0; j < numSites; j++) {
iAlignment[treeIndex[i]][j] = alignment.getState(i, j);
}
}
}
use of dr.evolution.datatype.DataType in project beast-mcmc by beast-dev.
the class HomologyRecursion method initAlignment.
/**
* Initializes the iAlignment array from the given alignment.
*/
private void initAlignment(Alignment alignment, int[] treeIndex) {
int numSeqs = alignment.getSequenceCount();
int numSites = alignment.getSiteCount();
DataType dataType = alignment.getDataType();
int numStates = dataType.getStateCount();
iAlignment = new IntMathVec[numSites];
int[] column = new int[numSeqs];
for (int i = 0; i < numSites; i++) {
for (int j = 0; j < numSeqs; j++) {
column[treeIndex[j]] = ((alignment.getState(j, i) >= numStates) ? 0 : 1);
}
iAlignment[i] = new IntMathVec(column);
}
}
Aggregations