use of dr.evolution.datatype.Nucleotides in project beast-mcmc by beast-dev.
the class BeagleSequenceSimulatorParser method parseXMLObject.
// END: getSyntaxRules
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String msg = "";
boolean parallel = false;
boolean outputAncestralSequences = false;
if (xo.hasAttribute(PARALLEL)) {
parallel = xo.getBooleanAttribute(PARALLEL);
}
if (xo.hasAttribute(OUTPUT_ANCESTRAL_SEQUENCES)) {
outputAncestralSequences = xo.getBooleanAttribute(OUTPUT_ANCESTRAL_SEQUENCES);
}
SimpleAlignment.OutputType output = SimpleAlignment.OutputType.FASTA;
if (xo.hasAttribute(OUTPUT)) {
output = SimpleAlignment.OutputType.parseFromString(xo.getStringAttribute(OUTPUT));
}
int siteCount = 0;
int to = 0;
for (int i = 0; i < xo.getChildCount(); i++) {
Partition partition = (Partition) xo.getChild(i);
to = partition.to + 1;
if (to > siteCount) {
siteCount = to;
}
}
// END: partitions loop
ArrayList<Partition> partitionsList = new ArrayList<Partition>();
for (int i = 0; i < xo.getChildCount(); i++) {
Partition partition = (Partition) xo.getChild(i);
if (partition.from > siteCount) {
throw new XMLParseException("Illegal 'from' attribute in " + PartitionParser.PARTITION + " element");
}
if (partition.to > siteCount) {
throw new XMLParseException("Illegal 'to' attribute in " + PartitionParser.PARTITION + " element");
}
if (partition.to == -1) {
partition.to = siteCount - 1;
}
if (partition.getRootSequence() != null) {
// TODO: what about 'every'?
int partitionSiteCount = (partition.to - partition.from) + 1;
if (partition.getRootSequence().getLength() != 3 * partitionSiteCount && partition.getFreqModel().getDataType() instanceof Codons) {
throw new RuntimeException("Root codon sequence " + "for partition " + (i + 1) + " has " + partition.getRootSequence().getLength() + " characters " + "expecting " + 3 * partitionSiteCount + " characters");
} else if (partition.getRootSequence().getLength() != partitionSiteCount && partition.getFreqModel().getDataType() instanceof Nucleotides) {
throw new RuntimeException("Root nuleotide sequence " + "for partition " + (i + 1) + " has " + partition.getRootSequence().getLength() + " characters " + "expecting " + partitionSiteCount + " characters");
}
// END: dataType check
// System.exit(-1);
}
// END: ancestralSequence check
partitionsList.add(partition);
}
// END: partitions loop
msg += "\n\t" + partitionsList.size() + " partitions with a total of ";
msg += siteCount + ((siteCount > 1) ? " replications " : " replication");
if (msg.length() > 0) {
Logger.getLogger("dr.app.beagle.tools").info("\nUsing Beagle Sequence Simulator: " + msg + "\n");
}
BeagleSequenceSimulator s = new BeagleSequenceSimulator(partitionsList);
SimpleAlignment alignment = s.simulate(parallel, outputAncestralSequences);
alignment.setOutputType(output);
return alignment;
}
Aggregations