| 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.evoxml.util.XMLUnits; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
import java.util.logging.Logger; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class BirthDeathSerialSamplingModelParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String BIRTH_DEATH_SERIAL_MODEL = "birthDeathSerialSampling"; |
| 43 |
public static final String LAMBDA = "birthRate"; |
| 44 |
public static final String MU = "deathRate"; |
| 45 |
public static final String RELATIVE_MU = "relativeDeathRate"; |
| 46 |
public static final String PSI = "psi"; |
| 47 |
public static final String SAMPLE_PROBABILITY = "sampleProbability"; |
| 48 |
public static final String SAMPLE_BECOMES_NON_INFECTIOUS = "sampleBecomesNonInfectiousProb"; |
| 49 |
public static final String R = "r"; |
| 50 |
|
| 51 |
public static final String ORIGIN = "origin"; |
| 52 |
public static final String TREE_TYPE = "type"; |
| 53 |
public static final String BDSS = "bdss"; |
| 54 |
public static final String HAS_FINAL_SAMPLE = "hasFinalSample"; |
| 55 |
|
| 56 |
public String getParserName() { |
| 57 |
return BIRTH_DEATH_SERIAL_MODEL; |
| 58 |
} |
| 59 |
|
| 60 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 61 |
|
| 62 |
final String modelName = xo.getId(); |
| 63 |
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 64 |
|
| 65 |
boolean hasFinalSample = xo.getAttribute(HAS_FINAL_SAMPLE, false); |
| 66 |
|
| 67 |
final Parameter lambda = (Parameter) xo.getElementFirstChild(LAMBDA); |
| 68 |
|
| 69 |
boolean relativeDeath = xo.hasChildNamed(RELATIVE_MU); |
| 70 |
Parameter mu; |
| 71 |
if (relativeDeath) { |
| 72 |
mu = (Parameter) xo.getElementFirstChild(RELATIVE_MU); |
| 73 |
} else { |
| 74 |
mu = (Parameter) xo.getElementFirstChild(MU); |
| 75 |
} |
| 76 |
|
| 77 |
final Parameter psi = (Parameter) xo.getElementFirstChild(PSI); |
| 78 |
|
| 79 |
final Parameter p = xo.hasChildNamed(SAMPLE_PROBABILITY) ? |
| 80 |
(Parameter) xo.getElementFirstChild(SAMPLE_PROBABILITY) : new Parameter.Default(0.0); |
| 81 |
|
| 82 |
Parameter origin = null; |
| 83 |
if (xo.hasChildNamed(ORIGIN)) { |
| 84 |
origin = (Parameter) xo.getElementFirstChild(ORIGIN); |
| 85 |
} |
| 86 |
|
| 87 |
final Parameter r = xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? |
| 88 |
(Parameter) xo.getElementFirstChild(SAMPLE_BECOMES_NON_INFECTIOUS) : new Parameter.Default(0.0); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_BECOMES_NON_INFECTIOUS) ? getCitationRT() : getCitationPsiOrg()); |
| 95 |
|
| 96 |
return new BirthDeathSerialSamplingModel(modelName, lambda, mu, psi, p, relativeDeath, |
| 97 |
r, hasFinalSample, origin, units); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public static String getCitationPsiOrg() { |
| 105 |
|
| 106 |
return "Stadler T (2010) J Theor Biol 267, 396-404 [Birth-Death with Serial Samples]."; |
| 107 |
} |
| 108 |
|
| 109 |
public static String getCitationRT() { |
| 110 |
return "Stadler et al (2011) : Estimating the basic reproductive number from viral sequence data, " + |
| 111 |
"Mol.Biol.Evol., doi: 10.1093/molbev/msr217, 2011"; |
| 112 |
} |
| 113 |
|
| 114 |
public String getParserDescription() { |
| 115 |
return "Stadler et al (2010) model of speciation."; |
| 116 |
} |
| 117 |
|
| 118 |
public Class getReturnType() { |
| 119 |
return BirthDeathSerialSamplingModel.class; |
| 120 |
} |
| 121 |
|
| 122 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 123 |
return rules; |
| 124 |
} |
| 125 |
|
| 126 |
private final XMLSyntaxRule[] rules = { |
| 127 |
AttributeRule.newStringRule(TREE_TYPE, true), |
| 128 |
AttributeRule.newBooleanRule(HAS_FINAL_SAMPLE, true), |
| 129 |
|
| 130 |
new ElementRule(ORIGIN, Parameter.class, "The origin of the infection, x0 > tree.rootHeight", true), |
| 131 |
new ElementRule(LAMBDA, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 132 |
new XORRule( |
| 133 |
new ElementRule(MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 134 |
new ElementRule(RELATIVE_MU, new XMLSyntaxRule[]{new ElementRule(Parameter.class)})), |
| 135 |
new ElementRule(PSI, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 136 |
new ElementRule(SAMPLE_BECOMES_NON_INFECTIOUS, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
}; |
| 141 |
} |