Search in sources :

Example 36 with Attribute

use of dr.util.Attribute in project beast-mcmc by beast-dev.

the class TestStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.hasId() ? xo.getId() : "");
    Attribute attr = (Attribute) xo.getChild(Attribute.class);
    double testValue1;
    TestStatistic statistic;
    if (xo.hasChildNamed(SEQUALS)) {
        Attribute attr2 = (Attribute) xo.getElementFirstChild(SEQUALS);
        statistic = new TestStatistic(name, attr, attr2, TestStatistic.EQUALS);
    } else if (xo.hasChildNamed(SGREATER_THAN)) {
        Attribute attr2 = (Attribute) xo.getElementFirstChild(SGREATER_THAN);
        statistic = new TestStatistic(name, attr, attr2, TestStatistic.GREATER_THAN);
    } else if (xo.hasChildNamed(SLESS_THAN)) {
        Attribute attr2 = (Attribute) xo.getElementFirstChild(SLESS_THAN);
        statistic = new TestStatistic(name, attr, attr2, TestStatistic.LESS_THAN);
    } else if (xo.hasAttribute(SEQUALS)) {
        testValue1 = xo.getDoubleAttribute(SEQUALS);
        statistic = new TestStatistic(name, attr, testValue1, TestStatistic.EQUALS);
    } else if (xo.hasAttribute(SGREATER_THAN)) {
        testValue1 = xo.getDoubleAttribute(SGREATER_THAN);
        statistic = new TestStatistic(name, attr, testValue1, TestStatistic.GREATER_THAN);
    } else if (xo.hasAttribute(SLESS_THAN)) {
        testValue1 = xo.getDoubleAttribute(SLESS_THAN);
        statistic = new TestStatistic(name, attr, testValue1, TestStatistic.LESS_THAN);
    } else if (xo.hasAttribute(SINSIDE)) {
        double[] values = xo.getDoubleArrayAttribute(SINSIDE);
        if (values.length != 2)
            throw new XMLParseException("inside attribute of test element requires two values");
        statistic = new TestStatistic(name, attr, values[0], values[1], TestStatistic.INSIDE);
    } else if (xo.hasAttribute(SOUTSIDE)) {
        double[] values = xo.getDoubleArrayAttribute(SOUTSIDE);
        if (values.length != 2)
            throw new XMLParseException("outside attribute of test element requires two values");
        statistic = new TestStatistic(name, attr, values[0], values[1], TestStatistic.OUTSIDE);
    } else
        throw new XMLParseException();
    return statistic;
}
Also used : TestStatistic(dr.inference.model.TestStatistic) Attribute(dr.util.Attribute)

Example 37 with Attribute

use of dr.util.Attribute in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method writeJointParameters.

private void writeJointParameters(XMLWriter writer, TaxonList taxa) {
    for (int i = 0; i < taxa.getTaxonCount(); i++) {
        Taxon taxon = taxa.getTaxon(i);
        Set<PartitionTreeModel> treeModels = new HashSet<PartitionTreeModel>();
        for (PartitionTreeModel treeModel : options.getPartitionTreeModels()) {
            for (AbstractPartitionData data : options.getDataPartitions(treeModel)) {
                if (data.getTaxonList().asList().contains(taxon)) {
                    treeModels.add(treeModel);
                }
            }
        }
        // if we are sampling within precisions then only include this leaf if precision > 0
        if (treeModels.size() > 0) {
            writer.writeOpenTag("jointParameter", new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "age(" + taxon.getId() + ")") });
            for (PartitionTreeModel treeModel : treeModels) {
                writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.IDREF, treeModel.getPrefix() + "age(" + taxon.getId() + ")"), true);
            }
            writer.writeCloseTag("jointParameter");
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel) HashSet(java.util.HashSet)

Example 38 with Attribute

use of dr.util.Attribute in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method generate.

protected void generate(final InsertionPoint point, final Object item, final String prefix, final XMLWriter writer) {
    TipDateSamplingComponentOptions comp = (TipDateSamplingComponentOptions) options.getComponentOptions(TipDateSamplingComponentOptions.class);
    TaxonList taxa = comp.getTaxonSet();
    switch(point) {
        case IN_TREE_MODEL:
            {
                writeLeafHeightParameters(writer, (PartitionTreeModel) item, taxa);
            }
            break;
        case AFTER_TREE_MODEL:
            if (options.getPartitionTreeModels().size() > 1) {
                // we have multiple treeModels with some or all the same taxa - create a JointParameter for each...
                writeJointParameters(writer, taxa);
            }
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
                writer.writeOpenTag("compoundParameter", new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "treeModel.tipDates") });
                for (int i = 0; i < taxa.getTaxonCount(); i++) {
                    Taxon taxon = taxa.getTaxon(i);
                    writer.writeIDref(ParameterParser.PARAMETER, "age(" + taxon.getId() + ")");
                }
                writer.writeCloseTag("compoundParameter");
            }
            break;
        case IN_MCMC_PRIOR:
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
            // nothing to do - individual parameter priors are written automatically
            } else if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
            }
            break;
        case IN_FILE_LOG_PARAMETERS:
            if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
                for (int i = 0; i < taxa.getTaxonCount(); i++) {
                    Taxon taxon = taxa.getTaxon(i);
                    writer.writeIDref(ParameterParser.PARAMETER, "age(" + taxon.getId() + ")");
                }
            } else if (comp.tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
                writer.writeIDref(ParameterParser.PARAMETER, "treeModel.tipDates");
            }
            break;
        default:
            throw new IllegalArgumentException("This insertion point is not implemented for " + this.getClass().getName());
    }
}
Also used : Attribute(dr.util.Attribute) TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel)

Example 39 with Attribute

use of dr.util.Attribute in project beast-mcmc by beast-dev.

the class TipDateSamplingComponentGenerator method writeLeafHeightParameters.

private void writeLeafHeightParameters(XMLWriter writer, PartitionTreeModel item, TaxonList taxa) {
    // only include this taxon as a leaf height if it found in this partition.
    PartitionTreeModel treeModel = (PartitionTreeModel) item;
    Set<Taxon> taxonSet = new HashSet<Taxon>();
    for (AbstractPartitionData data : options.getDataPartitions(treeModel)) {
        if (data.getTaxonList() != null) {
            for (Taxon taxon : data.getTaxonList()) {
                taxonSet.add(taxon);
            }
        }
    }
    for (int i = 0; i < taxa.getTaxonCount(); i++) {
        Taxon taxon = taxa.getTaxon(i);
        if (taxonSet.contains(taxon)) {
            // if we are sampling within precisions then only include this leaf if precision > 0
            writer.writeOpenTag("leafHeight", new Attribute[] { new Attribute.Default<String>(TaxonParser.TAXON, taxon.getId()) });
            writer.writeTag(ParameterParser.PARAMETER, new Attribute.Default<String>(XMLParser.ID, treeModel.getPrefix() + "age(" + taxon.getId() + ")"), true);
            writer.writeCloseTag("leafHeight");
        }
    }
}
Also used : AbstractPartitionData(dr.app.beauti.options.AbstractPartitionData) Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel) HashSet(java.util.HashSet)

Example 40 with Attribute

use of dr.util.Attribute in project beast-mcmc by beast-dev.

the class AncestralStatesComponentGenerator method writeCountingParameter.

// END: generate
private void writeCountingParameter(XMLWriter writer, AbstractPartitionData partition, String prefix) {
    AncestralStatesComponentOptions component = (AncestralStatesComponentOptions) options.getComponentOptions(AncestralStatesComponentOptions.class);
    if (!component.isCountingStates(partition)) {
        return;
    }
    StringBuilder matrix = new StringBuilder();
    DataType dataType = partition.getDataType();
    int stateCount = dataType.getStateCount();
    if (dataType.getType() == DataType.GENERAL) {
        PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
        stateCount = substModel.getDiscreteStateSet().size();
    }
    for (int i = 0; i < stateCount; i++) {
        for (int j = 0; j < stateCount; j++) {
            if (i == j) {
                matrix.append(" 0.0");
            } else {
                matrix.append(" 1.0");
            }
        }
    }
    writer.writeTag("parameter", new Attribute[] { new Attribute.Default<String>("id", partition.getPrefix() + "count"), new Attribute.Default<String>("value", matrix.toString()) }, true);
}
Also used : Attribute(dr.util.Attribute) DataType(dr.evolution.datatype.DataType) PartitionSubstitutionModel(dr.app.beauti.options.PartitionSubstitutionModel)

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