Search in sources :

Example 51 with TaxonList

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

the class SequenceErrorModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    SequenceErrorModel.ErrorType errorType = SequenceErrorModel.ErrorType.ALL_SUBSTITUTIONS;
    if (xo.hasAttribute(TYPE)) {
        if (xo.getStringAttribute(TYPE).equalsIgnoreCase("transitions")) {
            errorType = SequenceErrorModel.ErrorType.TRANSITIONS_ONLY;
        } else if (!xo.getStringAttribute(TYPE).equalsIgnoreCase("all")) {
            throw new XMLParseException("unrecognized option for attribute, 'type': " + xo.getStringAttribute(TYPE));
        }
    }
    Parameter baseDamageRateParameter = null;
    if (xo.hasChildNamed(BASE_ERROR_RATE)) {
        baseDamageRateParameter = (Parameter) xo.getElementFirstChild(BASE_ERROR_RATE);
    }
    Parameter ageRelatedRateParameter = null;
    if (xo.hasChildNamed(AGE_RELATED_RATE)) {
        ageRelatedRateParameter = (Parameter) xo.getElementFirstChild(AGE_RELATED_RATE);
    }
    if (baseDamageRateParameter == null && ageRelatedRateParameter == null) {
        throw new XMLParseException("You must specify one or other or both of " + BASE_ERROR_RATE + " and " + AGE_RELATED_RATE + " parameters");
    }
    Parameter indicatorParameter = null;
    if (xo.hasChildNamed(INDICATORS)) {
        indicatorParameter = (Parameter) xo.getElementFirstChild(INDICATORS);
    }
    TaxonList includeTaxa = null;
    TaxonList excludeTaxa = null;
    if (xo.hasChildNamed(INCLUDE)) {
        includeTaxa = (TaxonList) xo.getElementFirstChild(INCLUDE);
    }
    if (xo.hasChildNamed(EXCLUDE)) {
        excludeTaxa = (TaxonList) xo.getElementFirstChild(EXCLUDE);
    }
    SequenceErrorModel aDNADamageModel = new SequenceErrorModel(includeTaxa, excludeTaxa, errorType, baseDamageRateParameter, ageRelatedRateParameter, indicatorParameter);
    Logger.getLogger("dr.evomodel").info("Using sequence error model, assuming errors cause " + (errorType == SequenceErrorModel.ErrorType.TRANSITIONS_ONLY ? "transitions only." : "any substitution."));
    return aDNADamageModel;
}
Also used : TaxonList(dr.evolution.util.TaxonList) Parameter(dr.inference.model.Parameter) SequenceErrorModel(dr.evomodel.tipstatesmodel.SequenceErrorModel)

Example 52 with TaxonList

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

the class AncestralTraitTreeModelParser method parseAncestor.

private static AncestralTaxonInTree parseAncestor(MutableTreeModel tree, XMLObject xo, final int index) throws XMLParseException {
    Taxon ancestor = (Taxon) xo.getChild(Taxon.class);
    Parameter pseudoBranchLength = (Parameter) xo.getChild(Parameter.class);
    AncestralTaxonInTree ancestorInTree;
    NodeRef node = new NodeRef() {

        @Override
        public int getNumber() {
            return index;
        }

        @Override
        public void setNumber(int n) {
            throw new RuntimeException("Do not set");
        }
    };
    if (xo.hasChildNamed(MonophylyStatisticParser.MRCA)) {
        TaxonList descendants = MonophylyStatisticParser.parseTaxonListOrTaxa(xo.getChild(MonophylyStatisticParser.MRCA));
        try {
            ancestorInTree = new AncestralTaxonInTree(ancestor, tree, descendants, pseudoBranchLength, null, node, index, 0.0);
        } catch (TreeUtils.MissingTaxonException e) {
            throw new XMLParseException("Unable to find taxa for " + ancestor.getId());
        }
    } else {
        XMLObject cxo = xo.getChild(ANCESTRAL_PATH);
        Taxon taxon = (Taxon) cxo.getChild(Taxon.class);
        Parameter time = (Parameter) cxo.getChild(Parameter.class);
        boolean relativeHeight = cxo.getAttribute(RELATIVE_HEIGHT, false);
        double offset = 0;
        if (relativeHeight) {
            Object date = taxon.getAttribute("date");
            if (date != null && date instanceof Date) {
                offset = taxon.getHeight();
            } else {
                throw new XMLParseException("Taxon '" + taxon.getId() + "' has no specified date");
            }
        } else {
            if (time.getParameterValue(0) <= taxon.getHeight()) {
                throw new XMLParseException("Ancestral path time must be > sampling time for taxon '" + taxon.getId() + "'");
            }
        }
        Taxa descendent = new Taxa();
        descendent.addTaxon(taxon);
        try {
            ancestorInTree = new AncestralTaxonInTree(ancestor, tree, descendent, pseudoBranchLength, time, node, index, // TODO Refactor into separate class from MRCA version
            offset);
        } catch (TreeUtils.MissingTaxonException e) {
            throw new XMLParseException("Unable to find taxa for " + ancestor.getId());
        }
    }
    return ancestorInTree;
}
Also used : TaxonList(dr.evolution.util.TaxonList) Taxon(dr.evolution.util.Taxon) Date(dr.evolution.util.Date) NodeRef(dr.evolution.tree.NodeRef) Taxa(dr.evolution.util.Taxa) AncestralTaxonInTree(dr.evomodel.continuous.AncestralTaxonInTree) FastMatrixParameter(dr.inference.model.FastMatrixParameter) Parameter(dr.inference.model.Parameter) TreeUtils(dr.evolution.tree.TreeUtils)

Example 53 with TaxonList

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

the class ExternalLengthStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Tree tree = (Tree) xo.getChild(Tree.class);
    TaxonList taxa = (TaxonList) xo.getChild(Taxa.class);
    try {
        return new ExternalLengthStatistic(name, tree, taxa);
    } catch (TreeUtils.MissingTaxonException mte) {
        throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + "was not found in the tree.");
    }
}
Also used : Taxa(dr.evolution.util.Taxa) TaxonList(dr.evolution.util.TaxonList) Tree(dr.evolution.tree.Tree) ExternalLengthStatistic(dr.evomodel.tree.ExternalLengthStatistic) TreeUtils(dr.evolution.tree.TreeUtils)

Example 54 with TaxonList

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

the class MRCATraitStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(NAME, xo.getId());
    String trait = xo.getStringAttribute(TRAIT);
    DefaultTreeModel tree = (DefaultTreeModel) xo.getChild(DefaultTreeModel.class);
    TaxonList taxa = (TaxonList) xo.getElementFirstChild(MRCA);
    try {
        return new MRCATraitStatistic(name, trait, tree, taxa);
    } catch (TreeUtils.MissingTaxonException mte) {
        throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + "was not found in the tree.");
    }
}
Also used : MRCATraitStatistic(dr.evomodel.tree.MRCATraitStatistic) TaxonList(dr.evolution.util.TaxonList) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) TreeUtils(dr.evolution.tree.TreeUtils)

Example 55 with TaxonList

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

the class MonophylyStatisticParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getAttribute(Statistic.NAME, xo.getId());
    Boolean inverse = xo.getAttribute(INVERSE, false);
    Tree tree = (Tree) xo.getChild(Tree.class);
    TaxonList taxa = parseTaxonListOrTaxa(xo.getChild(MRCA));
    TaxonList ignore = null;
    if (xo.hasChildNamed(IGNORE)) {
        ignore = parseTaxonListOrTaxa(xo.getChild(IGNORE));
    }
    try {
        return new MonophylyStatistic(name, tree, taxa, ignore, inverse);
    } catch (TreeUtils.MissingTaxonException mte) {
        throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + "was not found in the tree.");
    }
}
Also used : TaxonList(dr.evolution.util.TaxonList) Tree(dr.evolution.tree.Tree) MonophylyStatistic(dr.evomodel.tree.MonophylyStatistic) TreeUtils(dr.evolution.tree.TreeUtils)

Aggregations

TaxonList (dr.evolution.util.TaxonList)60 Taxon (dr.evolution.util.Taxon)20 Tree (dr.evolution.tree.Tree)19 TreeUtils (dr.evolution.tree.TreeUtils)16 Taxa (dr.evolution.util.Taxa)14 Parameter (dr.inference.model.Parameter)12 TreeModel (dr.evomodel.tree.TreeModel)9 ArrayList (java.util.ArrayList)9 Alignment (dr.evolution.alignment.Alignment)6 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 NodeRef (dr.evolution.tree.NodeRef)4 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)4 PatternList (dr.evolution.alignment.PatternList)3 Patterns (dr.evolution.alignment.Patterns)3 DataType (dr.evolution.datatype.DataType)3