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;
}
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;
}
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.");
}
}
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.");
}
}
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.");
}
}
Aggregations