| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodelxml.tipstatesmodel; |
| 27 |
|
| 28 |
import dr.evolution.util.TaxonList; |
| 29 |
import dr.evomodel.tipstatesmodel.SequenceErrorModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
import java.util.logging.Logger; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class SequenceErrorModelParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String SEQUENCE_ERROR_MODEL = "sequenceErrorModel"; |
| 40 |
public static final String BASE_ERROR_RATE = "baseErrorRate"; |
| 41 |
public static final String AGE_RELATED_RATE = "ageRelatedErrorRate"; |
| 42 |
public static final String INDICATORS = "indicators"; |
| 43 |
|
| 44 |
public static final String EXCLUDE = "exclude"; |
| 45 |
public static final String INCLUDE = "include"; |
| 46 |
|
| 47 |
public static final String TYPE = "type"; |
| 48 |
|
| 49 |
public String getParserName() { |
| 50 |
return SEQUENCE_ERROR_MODEL; |
| 51 |
} |
| 52 |
|
| 53 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 54 |
|
| 55 |
SequenceErrorModel.ErrorType errorType = SequenceErrorModel.ErrorType.ALL_SUBSTITUTIONS; |
| 56 |
|
| 57 |
if (xo.hasAttribute(TYPE)) { |
| 58 |
if (xo.getStringAttribute(TYPE).equalsIgnoreCase("transitions")) { |
| 59 |
errorType = SequenceErrorModel.ErrorType.TRANSITIONS_ONLY; |
| 60 |
} else if (!xo.getStringAttribute(TYPE).equalsIgnoreCase("all")) { |
| 61 |
throw new XMLParseException("unrecognized option for attribute, 'type': " + xo.getStringAttribute(TYPE)); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
Parameter baseDamageRateParameter = null; |
| 66 |
if (xo.hasChildNamed(BASE_ERROR_RATE)) { |
| 67 |
baseDamageRateParameter = (Parameter) xo.getElementFirstChild(BASE_ERROR_RATE); |
| 68 |
} |
| 69 |
|
| 70 |
Parameter ageRelatedRateParameter = null; |
| 71 |
if (xo.hasChildNamed(AGE_RELATED_RATE)) { |
| 72 |
ageRelatedRateParameter = (Parameter) xo.getElementFirstChild(AGE_RELATED_RATE); |
| 73 |
} |
| 74 |
|
| 75 |
if (baseDamageRateParameter == null && ageRelatedRateParameter == null) { |
| 76 |
throw new XMLParseException("You must specify one or other or both of " + |
| 77 |
BASE_ERROR_RATE + " and " + AGE_RELATED_RATE + " parameters"); |
| 78 |
} |
| 79 |
|
| 80 |
Parameter indicatorParameter = null; |
| 81 |
if (xo.hasChildNamed(INDICATORS)) { |
| 82 |
indicatorParameter = (Parameter)xo.getElementFirstChild(INDICATORS); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
TaxonList includeTaxa = null; |
| 87 |
TaxonList excludeTaxa = null; |
| 88 |
|
| 89 |
if (xo.hasChildNamed(INCLUDE)) { |
| 90 |
includeTaxa = (TaxonList) xo.getElementFirstChild(INCLUDE); |
| 91 |
} |
| 92 |
|
| 93 |
if (xo.hasChildNamed(EXCLUDE)) { |
| 94 |
excludeTaxa = (TaxonList) xo.getElementFirstChild(EXCLUDE); |
| 95 |
} |
| 96 |
|
| 97 |
SequenceErrorModel aDNADamageModel = new SequenceErrorModel(includeTaxa, excludeTaxa, |
| 98 |
errorType, baseDamageRateParameter, ageRelatedRateParameter, indicatorParameter); |
| 99 |
|
| 100 |
Logger.getLogger("dr.evomodel").info("Using sequence error model, assuming errors cause " + |
| 101 |
(errorType == SequenceErrorModel.ErrorType.TRANSITIONS_ONLY ? "transitions only." : "any substitution.")); |
| 102 |
|
| 103 |
return aDNADamageModel; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public String getParserDescription() { |
| 111 |
return "This element returns a model that allows for post-mortem DNA damage."; |
| 112 |
} |
| 113 |
|
| 114 |
public Class getReturnType() { |
| 115 |
return SequenceErrorModel.class; |
| 116 |
} |
| 117 |
|
| 118 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 119 |
return rules; |
| 120 |
} |
| 121 |
|
| 122 |
private final XMLSyntaxRule[] rules = { |
| 123 |
AttributeRule.newStringRule(TYPE, true), |
| 124 |
new ElementRule(BASE_ERROR_RATE, Parameter.class, "The base error rate per site per sequence", true), |
| 125 |
new ElementRule(AGE_RELATED_RATE, Parameter.class, "The error rate per site per unit time", true), |
| 126 |
new ElementRule(INDICATORS, Parameter.class, "A binary indicator of whether the sequence has errors", true), |
| 127 |
new XORRule( |
| 128 |
new ElementRule(INCLUDE, TaxonList.class, "A set of taxa to which to apply the damage model to"), |
| 129 |
new ElementRule(EXCLUDE, TaxonList.class, "A set of taxa to which to not apply the damage model to") |
| 130 |
, true) |
| 131 |
}; |
| 132 |
|
| 133 |
} |