| 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.coalescent; |
| 27 |
|
| 28 |
import dr.evolution.util.Units; |
| 29 |
import dr.evomodel.coalescent.ConstExpConstModel; |
| 30 |
import dr.evomodel.coalescent.ConstantExponentialModel; |
| 31 |
import dr.evoxml.util.XMLUnits; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class ConstExpConstModelParser extends AbstractXMLObjectParser { |
| 42 |
|
| 43 |
public static String CONST_EXP_CONST_MODEL = "constExpConst"; |
| 44 |
public static String POPULATION_SIZE = "populationSize"; |
| 45 |
public static String GROWTH_RATE = "growthRate"; |
| 46 |
public static String ANCESTRAL_POPULATION_SIZE = "ancestralPopulationSize"; |
| 47 |
public static String FINAL_PHASE_START_TIME = "finalPhaseStartTime"; |
| 48 |
public static String GROWTH_PHASE_TIME = "growthPhaseTime"; |
| 49 |
public static String USE_NUMERICAL_INTEGRATION = "useNumericalIntegration"; |
| 50 |
|
| 51 |
public String getParserName() { |
| 52 |
return CONST_EXP_CONST_MODEL; |
| 53 |
} |
| 54 |
|
| 55 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 56 |
|
| 57 |
Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 58 |
|
| 59 |
XMLObject cxo = xo.getChild(POPULATION_SIZE); |
| 60 |
Parameter N0Param = (Parameter) cxo.getChild(Parameter.class); |
| 61 |
|
| 62 |
Parameter N1Param = null; |
| 63 |
Parameter growthRateParam = null; |
| 64 |
|
| 65 |
if (xo.hasChildNamed(ANCESTRAL_POPULATION_SIZE)) { |
| 66 |
cxo = xo.getChild(ANCESTRAL_POPULATION_SIZE); |
| 67 |
N1Param = (Parameter) cxo.getChild(Parameter.class); |
| 68 |
} else { |
| 69 |
cxo = xo.getChild(GROWTH_RATE); |
| 70 |
growthRateParam = (Parameter) cxo.getChild(Parameter.class); |
| 71 |
} |
| 72 |
|
| 73 |
cxo = xo.getChild(FINAL_PHASE_START_TIME); |
| 74 |
Parameter timeParam = (Parameter) cxo.getChild(Parameter.class); |
| 75 |
|
| 76 |
cxo = xo.getChild(GROWTH_PHASE_TIME); |
| 77 |
Parameter epochParam = (Parameter) cxo.getChild(Parameter.class); |
| 78 |
|
| 79 |
boolean useNumericalIntegrator = false; |
| 80 |
if (xo.hasAttribute(USE_NUMERICAL_INTEGRATION)) { |
| 81 |
useNumericalIntegrator = xo.getBooleanAttribute(USE_NUMERICAL_INTEGRATION); |
| 82 |
} |
| 83 |
|
| 84 |
return new ConstExpConstModel(N0Param, N1Param, growthRateParam, timeParam, epochParam, useNumericalIntegrator, units); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public String getParserDescription() { |
| 92 |
return "A demographic model of constant population size followed by exponential growth."; |
| 93 |
} |
| 94 |
|
| 95 |
public Class getReturnType() { |
| 96 |
return ConstantExponentialModel.class; |
| 97 |
} |
| 98 |
|
| 99 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 100 |
return rules; |
| 101 |
} |
| 102 |
|
| 103 |
private final XMLSyntaxRule[] rules = { |
| 104 |
XMLUnits.SYNTAX_RULES[0], |
| 105 |
AttributeRule.newBooleanRule(USE_NUMERICAL_INTEGRATION, true), |
| 106 |
new ElementRule(POPULATION_SIZE, |
| 107 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 108 |
new XORRule( |
| 109 |
new ElementRule(ANCESTRAL_POPULATION_SIZE, |
| 110 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 111 |
new ElementRule(GROWTH_RATE, |
| 112 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}) |
| 113 |
), |
| 114 |
new ElementRule(FINAL_PHASE_START_TIME, |
| 115 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 116 |
new ElementRule(GROWTH_PHASE_TIME, |
| 117 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
} |