use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class XMLGenerator method writeFrequencyModel.
// END: writeBranchModel
private void writeFrequencyModel(PartitionData data, XMLWriter writer) {
DataType dataType = null;
String frequencies = null;
// int dataTypeIndex = data.dataTypeIndex;
int frequencyModelIndex = data.frequencyModelIndex;
switch(frequencyModelIndex) {
case // Nucleotide
0:
dataType = data.createDataType();
// dataType = Nucleotides.INSTANCE;
frequencies = data.frequencyParameterValues[0] + "";
for (int i = 1; i < 4; i++) {
frequencies += " " + data.frequencyParameterValues[i];
}
// tagname
writer.writeOpenTag(// tagname
FrequencyModelParser.FREQUENCY_MODEL, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, // id
data.frequencyModelIdref), new Attribute.Default<String>(DataType.DATA_TYPE, // dataType
dataType.getDescription()) });
writeParameter(FrequencyModelParser.FREQUENCIES, null, dataType.getStateCount(), frequencies, writer);
writer.writeCloseTag(FrequencyModelParser.FREQUENCY_MODEL);
break;
case // Codon
1:
dataType = data.createDataType();
// dataType = Codons.UNIVERSAL;
frequencies = data.frequencyParameterValues[4] + "";
for (int i = 5; i < 65; i++) {
frequencies += " " + data.frequencyParameterValues[i];
}
// tagname
writer.writeOpenTag(// tagname
FrequencyModelParser.FREQUENCY_MODEL, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, // id
data.frequencyModelIdref), new Attribute.Default<String>(DataType.DATA_TYPE, // dataType.getDescription()
Utils.CODON_UNIVERSAL) });
writeParameter(FrequencyModelParser.FREQUENCIES, null, dataType.getStateCount(), frequencies, writer);
writer.writeCloseTag(FrequencyModelParser.FREQUENCY_MODEL);
break;
case // Amino acid
2:
dataType = data.createDataType();
// dataType = AminoAcids.INSTANCE;
frequencies = data.frequencyParameterValues[65] + "";
for (int i = 66; i < 85; i++) {
frequencies += " " + data.frequencyParameterValues[i];
}
// tagname
writer.writeOpenTag(// tagname
FrequencyModelParser.FREQUENCY_MODEL, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, // id
data.frequencyModelIdref), new Attribute.Default<String>(DataType.DATA_TYPE, // dataType.getDescription()
AminoAcids.DESCRIPTION) });
writeParameter(FrequencyModelParser.FREQUENCIES, null, dataType.getStateCount(), frequencies, writer);
writer.writeCloseTag(FrequencyModelParser.FREQUENCY_MODEL);
break;
}
// END: switch
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class XMLExporter method exportAlignment.
// END: Constructor
public String exportAlignment(SimpleAlignment alignment) throws IOException {
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw);
// TODO: if we keep the taxa element than lets also write dates
// writer.writeOpenTag(TaxaParser.TAXA, // tagname
// new Attribute[] { // attributes[]
// new Attribute.Default<String>(XMLParser.ID, TaxaParser.TAXA) });
//
// for (int i = 0; i < alignment.getTaxonCount(); i++) {
//
// Taxon taxon = alignment.getTaxon(i);
//
// writer.writeTag(
// TaxonParser.TAXON, // tagname
// new Attribute[] { // attributes[]
// new Attribute.Default<String>(XMLParser.ID, taxon.getId()) },
// true // close
// );
//
//// System.out.println(taxon.getAttribute(Utils.ABSOLUTE_HEIGHT));
//
//// writer.writeCloseTag(TaxonParser.TAXON);
//
// }// END: taxon loop
//
// writer.writeCloseTag(TaxaParser.TAXA);
//
// writer.writeBlankLine();
// tagname
writer.writeOpenTag(// tagname
AlignmentParser.ALIGNMENT, new Attribute[] { // attributes[]
new Attribute.Default<String>(XMLParser.ID, AlignmentParser.ALIGNMENT), new Attribute.Default<String>(DataType.DATA_TYPE, alignment.getDataType().getDescription()) });
for (int i = 0; i < alignment.getSequenceCount(); i++) {
Taxon taxon = alignment.getTaxon(i);
writer.writeOpenTag(SequenceParser.SEQUENCE);
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
writer.writeText(alignment.getSequence(i).getSequenceString());
writer.writeCloseTag(SequenceParser.SEQUENCE);
}
//END: sequences loop
writer.writeCloseTag(AlignmentParser.ALIGNMENT);
writer.close();
return sw.toString();
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class XMLWriter method writeTag.
public void writeTag(String tagname, Attribute[] attributes, boolean close) {
StringBuffer buffer = new StringBuffer("<");
buffer.append(tagname);
for (Attribute attribute : attributes) {
if (attribute != null) {
buffer.append(' ');
buffer.append(attribute.getAttributeName());
buffer.append("=\"");
buffer.append(attribute.getAttributeValue());
buffer.append("\"");
}
}
if (close) {
buffer.append("/");
}
buffer.append(">");
writeText(buffer.toString());
if (!close) {
increaseLevel();
}
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class BeastGenerator method writeTaxa.
/**
* Generate a taxa block from these beast options
*
* @param writer the writer
* @param taxonList the taxon list to write
* @throws dr.app.util.Arguments.ArgumentException
* ArgumentException
*/
private void writeTaxa(TaxonList taxonList, XMLWriter writer) throws Arguments.ArgumentException {
// -1 (single taxa), 0 (1st gene of multi-taxa)
writer.writeComment("The list of taxa to be analysed (can also include dates/ages).", "ntax=" + taxonList.getTaxonCount());
writer.writeOpenTag(TaxaParser.TAXA, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, TaxaParser.TAXA) });
boolean hasAttr = options.traits.size() > 0;
boolean firstDate = true;
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
Taxon taxon = taxonList.getTaxon(i);
boolean hasDate = false;
if (options.clockModelOptions.isTipCalibrated()) {
hasDate = TaxonList.Utils.hasAttribute(taxonList, i, dr.evolution.util.Date.DATE);
}
if (hasDate) {
dr.evolution.util.Date date = (dr.evolution.util.Date) taxon.getAttribute(dr.evolution.util.Date.DATE);
if (firstDate) {
options.units = date.getUnits();
firstDate = false;
} else {
if (options.units != date.getUnits()) {
System.err.println("Error: Units in dates do not match.");
}
}
}
writeTaxon(taxon, hasDate, hasAttr, writer);
}
writer.writeCloseTag(TaxaParser.TAXA);
}
use of dr.util.Attribute in project beast-mcmc by beast-dev.
the class BeastGenerator method writeDifferentTaxa.
public void writeDifferentTaxa(AbstractPartitionData dataPartition, XMLWriter writer) {
TaxonList taxonList = dataPartition.getTaxonList();
String name = dataPartition.getPartitionTreeModel().getName();
writer.writeComment("gene name = " + name + ", ntax= " + taxonList.getTaxonCount());
writer.writeOpenTag(TaxaParser.TAXA, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, name + "." + TaxaParser.TAXA) });
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
if (!(dataPartition instanceof PartitionPattern && ((PartitionPattern) dataPartition).getPatterns().isMasked(i))) {
final Taxon taxon = taxonList.getTaxon(i);
writer.writeIDref(TaxonParser.TAXON, taxon.getId());
}
}
writer.writeCloseTag(TaxaParser.TAXA);
}
Aggregations