Search in sources :

Example 6 with Attribute

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
}
Also used : Attribute(dr.util.Attribute) DataType(dr.evolution.datatype.DataType)

Example 7 with Attribute

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();
}
Also used : StringWriter(java.io.StringWriter) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) XMLWriter(dr.app.beauti.util.XMLWriter)

Example 8 with Attribute

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();
    }
}
Also used : Attribute(dr.util.Attribute)

Example 9 with Attribute

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);
}
Also used : java.util(java.util) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon)

Example 10 with Attribute

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);
}
Also used : Attribute(dr.util.Attribute) TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon)

Aggregations

Attribute (dr.util.Attribute)45 Taxa (dr.evolution.util.Taxa)11 Taxon (dr.evolution.util.Taxon)11 Parameter (dr.app.beauti.options.Parameter)6 AbstractPartitionData (dr.app.beauti.options.AbstractPartitionData)5 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)5 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)4 TreePriorType (dr.app.beauti.types.TreePriorType)4 AncestralStatesComponentOptions (dr.app.beauti.components.ancestralstates.AncestralStatesComponentOptions)3 DataType (dr.evolution.datatype.DataType)3 ArrayList (java.util.ArrayList)3 SequenceErrorType (dr.app.beauti.types.SequenceErrorType)2 Alignment (dr.evolution.alignment.Alignment)2 SitePatterns (dr.evolution.alignment.SitePatterns)2 Date (dr.evolution.util.Date)2 TaxonList (dr.evolution.util.TaxonList)2 HashSet (java.util.HashSet)2 SequenceErrorModelComponentOptions (dr.app.beauti.components.sequenceerror.SequenceErrorModelComponentOptions)1 TreePriorParameterizationType (dr.app.beauti.types.TreePriorParameterizationType)1 XMLWriter (dr.app.beauti.util.XMLWriter)1