Search in sources :

Example 11 with TaxonList

use of dr.evolution.util.TaxonList 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)

Example 12 with TaxonList

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

the class TipDateSamplingComponentOptions method selectOperators.

public void selectOperators(final ModelOptions modelOptions, final List<Operator> ops) {
    if (tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY || tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
        TaxonList taxa = getTaxonSet();
        String description = "Random walk for the age of this tip";
        //OperatorType type = OperatorType.RANDOM_WALK_ABSORBING;
        OperatorType type = OperatorType.UNIFORM;
        if (tipDateSamplingType == TipDateSamplingType.SAMPLE_PRECISION) {
            description = "Uniform sample from precision of age of this tip";
        //type = OperatorType.UNIFORM;
        }
        for (int i = 0; i < taxa.getTaxonCount(); i++) {
            Taxon taxon = taxa.getTaxon(i);
            Operator operator = tipDateOperators.get(taxon);
            if (operator == null) {
                Parameter parameter = getTipDateParameter(taxon);
                //                    operator = new Operator("age(" + taxon.getId() + ")", "", parameter, OperatorType.SCALE, 0.75, 1.0);
                operator = new Operator.Builder("age(" + taxon.getId() + ")", description, parameter, type, 1.0, 1.0).build();
                if (tipDateSamplingType == TipDateSamplingType.SAMPLE_INDIVIDUALLY) {
                    operator.setWeight(2.0);
                }
                tipDateOperators.put(taxon, operator);
            }
            ops.add(operator);
        }
    } else if (tipDateSamplingType == TipDateSamplingType.SAMPLE_JOINT) {
        ops.add(modelOptions.getOperator("treeModel.tipDates"));
    }
}
Also used : TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) OperatorType(dr.app.beauti.types.OperatorType)

Example 13 with TaxonList

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

the class UncertainAttributePatternsParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String attributeName = xo.getStringAttribute(ATTRIBUTE);
    TaxonList taxa = (TaxonList) xo.getChild(TaxonList.class);
    DataType dataType = DataTypeUtils.getDataType(xo);
    if (dataType == null) {
        throw new XMLParseException("dataType expected for attributePatterns element");
    }
    // using a SimpleSiteList rather than Patterns to allow ancestral reconstruction
    UncertainSiteList patterns = new UncertainSiteList(dataType, taxa);
    boolean normalize = xo.getAttribute(NORMALIZE, true);
    if (dataType == null) {
        // TODO Is this necessary given XMLSyntaxRules?
        throw new XMLParseException("dataType expected for attributePatterns element");
    }
    double[][] uncertainPattern = new double[taxa.getTaxonCount()][];
    // Parse attributes
    boolean attributeFound = false;
    for (int i = 0; i < taxa.getTaxonCount(); i++) {
        Taxon taxon = taxa.getTaxon(i);
        Object value = taxon.getAttribute(attributeName);
        if (value != null) {
            attributeFound = true;
            List<StateProbability> stateProbabilities;
            try {
                stateProbabilities = parseStates(value.toString(), dataType);
            } catch (StateParseException e) {
                throw new XMLParseException("State or probability for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is invalid; state = \"" + e.getState() + "\" and probability =\"" + e.getProbability() + "\"");
            }
            uncertainPattern[i] = convertToPartials(stateProbabilities, dataType, normalize);
        } else {
            throw new XMLParseException("State for attribute (" + attributeName + ") in taxon " + taxon.getId() + " is unknown.");
        }
    }
    if (!attributeFound) {
        throw new XMLParseException("The attribute (" + attributeName + ") was missing in all taxa. Check the name of the attribute.");
    }
    patterns.addPattern(uncertainPattern);
    Logger.getLogger("dr.evolution").info("\n ---------------------------------\nCreating an uncertain attribute model for attribute \"" + attributeName + "\"");
    Logger.getLogger("dr.evolution").info("\tIf you publish results using this model, please reference:");
    Logger.getLogger("dr.evolution").info("\t" + Citable.Utils.getCitationString(patterns));
    Logger.getLogger("dr.evolution").info("\n");
    return patterns;
}
Also used : UncertainSiteList(dr.evolution.alignment.UncertainSiteList) TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) DataType(dr.evolution.datatype.DataType)

Example 14 with TaxonList

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

the class SitePatternsParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Alignment alignment = (Alignment) xo.getChild(Alignment.class);
    TaxonList taxa = null;
    int from = 0;
    int to = -1;
    int every = xo.getAttribute(EVERY, 1);
    boolean strip = xo.getAttribute(STRIP, true);
    boolean unique = xo.getAttribute(UNIQUE, true);
    if (xo.hasAttribute(FROM)) {
        from = xo.getIntegerAttribute(FROM) - 1;
        if (from < 0)
            throw new XMLParseException("illegal 'from' attribute in patterns element");
    }
    if (xo.hasAttribute(TO)) {
        to = xo.getIntegerAttribute(TO) - 1;
        if (to < 0 || to < from)
            throw new XMLParseException("illegal 'to' attribute in patterns element");
    }
    if (every <= 0)
        throw new XMLParseException("illegal 'every' attribute in patterns element");
    if (xo.hasChildNamed(TAXON_LIST)) {
        taxa = (TaxonList) xo.getElementFirstChild(TAXON_LIST);
    }
    int[] constantPatternCounts = null;
    if (xo.hasChildNamed(CONSTANT_PATTERNS)) {
        Parameter param = (Parameter) xo.getElementFirstChild(CONSTANT_PATTERNS);
        if (param.getDimension() != alignment.getStateCount()) {
            throw new XMLParseException("The " + CONSTANT_PATTERNS + " parameter length should be equal to the number of states");
        }
        constantPatternCounts = new int[param.getDimension()];
        int i = 0;
        for (double value : param.getParameterValues()) {
            constantPatternCounts[i] = (int) value;
            i++;
        }
    }
    if (from > alignment.getSiteCount())
        throw new XMLParseException("illegal 'from' attribute in patterns element");
    if (to > alignment.getSiteCount())
        throw new XMLParseException("illegal 'to' attribute in patterns element");
    SitePatterns patterns = new SitePatterns(alignment, taxa, from, to, every, strip, unique, constantPatternCounts);
    int f = from + 1;
    // fixed a *display* error by adding + 1 for consistency with f = from + 1
    int t = to + 1;
    if (to == -1)
        t = alignment.getSiteCount();
    if (xo.hasAttribute(XMLParser.ID)) {
        final Logger logger = Logger.getLogger("dr.evoxml");
        logger.info("Site patterns '" + xo.getId() + "' created from positions " + Integer.toString(f) + "-" + Integer.toString(t) + " of alignment '" + alignment.getId() + "'");
        if (every > 1) {
            logger.info("  only using every " + every + " site");
        }
        logger.info("  " + (unique ? "unique " : "") + "pattern count = " + patterns.getPatternCount());
    }
    return patterns;
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns) Alignment(dr.evolution.alignment.Alignment) TaxonList(dr.evolution.util.TaxonList) Parameter(dr.inference.model.Parameter) Logger(java.util.logging.Logger)

Example 15 with TaxonList

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

the class LinkedGroupParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TaxonList taxa = null;
    double linkageProbability = 0.9999999999;
    if (xo.hasAttribute("probability")) {
        linkageProbability = xo.getDoubleAttribute("probability");
    }
    taxa = (TaxonList) xo.getChild(TaxonList.class);
    LinkedGroup lg = new LinkedGroup(taxa, linkageProbability);
    return lg;
}
Also used : TaxonList(dr.evolution.util.TaxonList) LinkedGroup(dr.evolution.LinkedGroup)

Aggregations

TaxonList (dr.evolution.util.TaxonList)59 Tree (dr.evolution.tree.Tree)18 Taxon (dr.evolution.util.Taxon)18 TreeUtils (dr.evolution.tree.TreeUtils)15 Taxa (dr.evolution.util.Taxa)13 Parameter (dr.inference.model.Parameter)13 ArrayList (java.util.ArrayList)13 TreeModel (dr.evomodel.tree.TreeModel)11 Alignment (dr.evolution.alignment.Alignment)6 SitePatterns (dr.evolution.alignment.SitePatterns)5 SimpleTree (dr.evolution.tree.SimpleTree)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 Importer (dr.evolution.io.Importer)4 ImportException (dr.evolution.io.Importer.ImportException)4 NexusImporter (dr.evolution.io.NexusImporter)4 CoalescentLikelihood (dr.evomodel.coalescent.CoalescentLikelihood)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 NodeRef (dr.evolution.tree.NodeRef)3 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)3 CompoundLikelihood (dr.inference.model.CompoundLikelihood)3