Search in sources :

Example 41 with Attribute

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

the class AlignmentGenerator method writeAlignment.

/**
     * Generate an alignment block from these beast options
     *
     * @param alignment the alignment to write
     * @param writer    the writer
     */
private void writeAlignment(Alignment alignment, XMLWriter writer) {
    writer.writeText("");
    writer.writeComment("The sequence alignment (each sequence refers to a taxon above).", "ntax=" + alignment.getTaxonCount() + " nchar=" + alignment.getSiteCount());
    if (options.samplePriorOnly) {
        writer.writeComment("Null sequences generated in order to sample from the prior only.");
    }
    if (getAlignmentDataTypeDescription(alignment) != null) {
        writer.writeOpenTag(AlignmentParser.ALIGNMENT, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, alignment.getId()), new Attribute.Default<String>(DataType.DATA_TYPE, getAlignmentDataTypeDescription(alignment)) });
    } else {
        writer.writeOpenTag(AlignmentParser.ALIGNMENT, new Attribute.Default<String>(XMLParser.ID, alignment.getId()));
        writer.writeIDref(DataType.DATA_TYPE, getAlignmentDataTypeIdref(alignment));
    }
    for (int i = 0; i < alignment.getTaxonCount(); i++) {
        Taxon taxon = alignment.getTaxon(i);
        writer.writeOpenTag(SequenceParser.SEQUENCE);
        writer.writeIDref(TaxonParser.TAXON, taxon.getId());
        if (!options.samplePriorOnly) {
            //                writer.checkText(alignment.getAlignedSequenceString(i));
            writer.writeText(alignment.getAlignedSequenceString(i));
        //                System.out.println(taxon.getId() + ": \n" + alignment.getAlignedSequenceString(i));
        //                System.out.println("len = " + alignment.getAlignedSequenceString(i).length() + "\n");
        } else {
            // generate a codon in case there is codon partitioning
            writer.writeText(NULL_SEQUENCE);
        }
        writer.writeCloseTag(SequenceParser.SEQUENCE);
    }
    writer.writeCloseTag(AlignmentParser.ALIGNMENT);
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon)

Example 42 with Attribute

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

the class SimpleNodeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    SimpleNode node = new SimpleNode();
    Taxon taxon = null;
    if (xo.hasAttribute(HEIGHT)) {
        node.setHeight(xo.getDoubleAttribute(HEIGHT));
    }
    if (xo.hasAttribute(RATE)) {
        node.setRate(xo.getDoubleAttribute(RATE));
    }
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof dr.evolution.tree.SimpleNode) {
            node.addChild((dr.evolution.tree.SimpleNode) child);
        } else if (child instanceof Taxon) {
            taxon = (Taxon) child;
        } else if (child instanceof Date) {
            node.setAttribute("date", child);
        } else if (child instanceof Attribute) {
            Attribute attr = (Attribute) child;
            String name = attr.getAttributeName();
            Object value = attr.getAttributeValue();
            node.setAttribute(name, value);
        } else if (child instanceof Attribute[]) {
            Attribute[] attrs = (Attribute[]) child;
            for (int j = 0; j < attrs.length; j++) {
                String name = attrs[j].getAttributeName();
                Object value = attrs[j].getAttributeValue();
                node.setAttribute(name, value);
            }
        } else if (child instanceof XMLObject) {
            XMLObject xoc = (XMLObject) child;
            if (xoc.getName().equals(Attributable.ATTRIBUTE)) {
                node.setAttribute(xoc.getStringAttribute(Attributable.NAME), xoc.getAttribute(Attributable.VALUE));
            } else {
                throw new XMLParseException("Unrecognized element" + xoc.getName() + " found in node element!");
            }
        } else {
            throw new XMLParseException("Unrecognized element found in node element!");
        }
    }
    if (taxon != null) {
        node.setTaxon(taxon);
    }
    return node;
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date) SimpleNode(dr.evolution.tree.SimpleNode)

Example 43 with Attribute

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

the class TaxonParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    if (dr.xml.XMLParser.ID.contains("\'") && dr.xml.XMLParser.ID.contains("\"")) {
        // as it won't be possible to wrap it in either.
        throw new XMLParseException("Illegal taxon name, " + dr.xml.XMLParser.ID + ", - contains both single and double quotes");
    }
    Taxon taxon = new Taxon(xo.getStringAttribute(dr.xml.XMLParser.ID));
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof Date) {
            taxon.setDate((Date) child);
        } else if (child instanceof Location) {
            taxon.setLocation((Location) child);
        } else if (child instanceof Attribute) {
            final Attribute attr = (Attribute) child;
            taxon.setAttribute(attr.getAttributeName(), attr.getAttributeValue());
        } else if (child instanceof Attribute[]) {
            Attribute[] attrs = (Attribute[]) child;
            for (Attribute attr : attrs) {
                taxon.setAttribute(attr.getAttributeName(), attr.getAttributeValue());
            }
        } else {
            throw new XMLParseException("Unrecognized element found in taxon element");
        }
    }
    return taxon;
}
Also used : Attribute(dr.util.Attribute) Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date) Location(dr.evolution.util.Location)

Example 44 with Attribute

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

the class CompoundGaussianProcessParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    List<GaussianProcessRandomGenerator> gpList = new ArrayList<GaussianProcessRandomGenerator>();
    List<Likelihood> likelihoodList = new ArrayList<Likelihood>();
    List<Integer> copyList = new ArrayList<Integer>();
    for (int i = 0; i < xo.getChildCount(); ++i) {
        Object obj = xo.getChild(i);
        GaussianProcessRandomGenerator gp = null;
        Likelihood likelihood = null;
        int copies = -1;
        if (obj instanceof DistributionLikelihood) {
            DistributionLikelihood dl = (DistributionLikelihood) obj;
            if (!(dl.getDistribution() instanceof GaussianProcessRandomGenerator)) {
                throw new XMLParseException("Not a Gaussian process");
            }
            likelihood = dl;
            gp = (GaussianProcessRandomGenerator) dl.getDistribution();
            copies = 0;
            for (Attribute<double[]> datum : dl.getDataList()) {
                //                    Double draw = (Double) gp.nextRandom();
                //                    System.err.println("DL: " + datum.getAttributeName() + " " + datum.getAttributeValue().length + " " + "1");
                copies += datum.getAttributeValue().length;
            }
        } else if (obj instanceof MultivariateDistributionLikelihood) {
            MultivariateDistributionLikelihood mdl = (MultivariateDistributionLikelihood) obj;
            if (!(mdl.getDistribution() instanceof GaussianProcessRandomGenerator)) {
                throw new XMLParseException("Not a Gaussian process");
            }
            likelihood = mdl;
            gp = (GaussianProcessRandomGenerator) mdl.getDistribution();
            copies = 0;
            double[] draw = (double[]) gp.nextRandom();
            for (Attribute<double[]> datum : mdl.getDataList()) {
                //                    System.err.println("ML: " + datum.getAttributeName() + " " + datum.getAttributeValue().length + " " + draw.length);
                copies += datum.getAttributeValue().length / draw.length;
            }
        } else if (obj instanceof GaussianProcessRandomGenerator) {
            gp = (GaussianProcessRandomGenerator) obj;
            likelihood = gp.getLikelihood();
            copies = 1;
        } else {
            throw new XMLParseException("Not a Gaussian process");
        }
        gpList.add(gp);
        likelihoodList.add(likelihood);
        copyList.add(copies);
    }
    //        System.exit(-1);
    return new CompoundGaussianProcess(gpList, likelihoodList, copyList);
}
Also used : MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) Attribute(dr.util.Attribute) Likelihood(dr.inference.model.Likelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood) CompoundGaussianProcess(dr.math.distributions.CompoundGaussianProcess) ArrayList(java.util.ArrayList) GaussianProcessRandomGenerator(dr.math.distributions.GaussianProcessRandomGenerator) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) CachedDistributionLikelihood(dr.inference.distribution.CachedDistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) AbstractDistributionLikelihood(dr.inference.distribution.AbstractDistributionLikelihood)

Example 45 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)

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