| 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.speciation; |
| 27 |
|
| 28 |
import dr.evolution.util.Units; |
| 29 |
import dr.evomodel.speciation.BirthDeathSerialSamplingModel; |
| 30 |
import dr.evomodel.speciation.BirthDeathSerialSkylineModel; |
| 31 |
import dr.evoxml.util.XMLUnits; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
import java.util.logging.Logger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class BirthDeathSerialSkylineModelParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String BIRTH_DEATH_SKYLINE_MODEL = "birthDeathSkyline"; |
| 43 |
public static final String TIMES = "times"; |
| 44 |
public static final String LAMBDA = "birthRate"; |
| 45 |
public static final String MU = "deathRate"; |
| 46 |
public static final String RELATIVE_MU = "relativeDeathRate"; |
| 47 |
public static final String PSI = "psi"; |
| 48 |
public static final String SAMPLE_PROBABILITY = "sampleProbability"; |
| 49 |
public static final String SAMPLE_BECOMES_NON_INFECTIOUS = "sampleBecomesNonInfectiousProb"; |
| 50 |
public static final String TIMES_START_FROM_ORIGIN = "timesStartFromOrigin"; |
| 51 |
public static final String R = "r"; |
| 52 |
public static final String ORIGIN = "origin"; |
| 53 |
public static final String TREE_TYPE = "type"; |
| 54 |
|
| 55 |
public String getParserName() { |
| 56 |
return BIRTH_DEATH_SKYLINE_MODEL; |
| 57 |
} |
| 58 |
|
| 59 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 60 |
|
| 61 |
final String modelName = xo.getId(); |
| 62 |
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 63 |
|
| 64 |
final Parameter times = (Parameter) xo.getElementFirstChild(TIMES); |
| 65 |
final Parameter lambda = (Parameter) xo.getElementFirstChild(LAMBDA); |
| 66 |
|
| 67 |
|
| 68 |
boolean relativeDeath = xo.hasChildNamed(RELATIVE_MU); |
| 69 |
Parameter mu; |
| 70 |
if (relativeDeath) { |
| 71 |
mu = (Parameter) xo.getElementFirstChild(RELATIVE_MU); |
| 72 |
} else { |
| 73 |
mu = (Parameter) xo.getElementFirstChild(MU); |
| 74 |
} |
| 75 |
|
| 76 |
final Parameter psi = (Parameter) xo.getElementFirstChild(PSI); |
| 77 |
final Parameter p = (Parameter) xo.getElementFirstChild(SAMPLE_PROBABILITY); |
| 78 |
|
| 79 |
final boolean timesStartFromOrigin = xo.getAttribute(TIMES_START_FROM_ORIGIN, false); |
| 80 |
|
| 81 |
Parameter origin = null; |
| 82 |
if (xo.hasChildNamed(ORIGIN)) { |
| 83 |
origin = (Parameter) xo.getElementFirstChild(ORIGIN); |
| 84 |
} |
| 85 |
|
| 86 |
final Parameter r = xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? |
| 87 |
(Parameter) xo.getElementFirstChild(SAMPLE_BECOMES_NON_INFECTIOUS) : new Parameter.Default(0.0); |
| 88 |
|
| 89 |
|
| 90 |
Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? getCitationRT() : getCitationPsiOrg()); |
| 91 |
|
| 92 |
return new BirthDeathSerialSkylineModel(modelName, times, lambda, mu, psi, p, origin, relativeDeath, |
| 93 |
false, timesStartFromOrigin, units); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static String getCitationPsiOrg() { |
| 101 |
|
| 102 |
return "Stadler T et al (2011, in prep)"; |
| 103 |
} |
| 104 |
|
| 105 |
public static String getCitationRT() { |
| 106 |
return "Stadler T et al (2011, in prep)"; |
| 107 |
} |
| 108 |
|
| 109 |
public String getParserDescription() { |
| 110 |
return "Stadler T et al (2011, in prep)"; |
| 111 |
} |
| 112 |
|
| 113 |
public Class getReturnType() { |
| 114 |
return BirthDeathSerialSamplingModel.class; |
| 115 |
} |
| 116 |
|
| 117 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 118 |
return rules; |
| 119 |
} |
| 120 |
|
| 121 |
private final XMLSyntaxRule[] rules = { |
| 122 |
AttributeRule.newStringRule(TREE_TYPE, true), |
| 123 |
AttributeRule.newBooleanRule(TIMES_START_FROM_ORIGIN, false, "if true, then the time vector represents the " + |
| 124 |
"epoch widths in times starting from the origin and moving tipwards. " + |
| 125 |
"Note that the birth/death/sampling rate vectors still specify the parameters starting from tips " + |
| 126 |
"and moving to root."), |
| 127 |
new ElementRule(ORIGIN, Parameter.class, "The origin of the infection, x0 > tree.rootHeight", true), |
| 128 |
new ElementRule(TIMES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 129 |
new ElementRule(LAMBDA, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 130 |
new XORRule( |
| 131 |
new ElementRule(MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 132 |
new ElementRule(RELATIVE_MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)})), |
| 133 |
new ElementRule(PSI, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 134 |
new ElementRule(SAMPLE_BECOMES_NON_INFECTIOUS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 135 |
new ElementRule(SAMPLE_PROBABILITY, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 136 |
XMLUnits.SYNTAX_RULES[0] |
| 137 |
}; |
| 138 |
} |