| 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.evomodel.transmission; |
| 27 |
|
| 28 |
import dr.evoxml.util.XMLUnits; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class HierarchicalTransmissionDemographicModel extends TransmissionDemographicModel { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static String HIERARCHICAL_TRANSMISSION_MODEL = "hierarchicalTransmissionModel"; |
| 46 |
|
| 47 |
public static String CONSTANT = TransmissionDemographicModel.CONSTANT; |
| 48 |
public static String EXPONENTIAL = TransmissionDemographicModel.EXPONENTIAL; |
| 49 |
public static String LOGISTIC = TransmissionDemographicModel.LOGISTIC; |
| 50 |
|
| 51 |
public static String POPULATION_SIZE = TransmissionDemographicModel.POPULATION_SIZE; |
| 52 |
public static String ANCESTRAL_PROPORTION = TransmissionDemographicModel.ANCESTRAL_PROPORTION; |
| 53 |
public static String GROWTH_RATE = TransmissionDemographicModel.GROWTH_RATE; |
| 54 |
public static String DOUBLING_TIME = TransmissionDemographicModel.DOUBLING_TIME; |
| 55 |
|
| 56 |
public static final String HOST_COUNT = "hostCount"; |
| 57 |
|
| 58 |
public HierarchicalTransmissionDemographicModel(int model, |
| 59 |
Parameter N0Parameter, Parameter N1Parameter, |
| 60 |
Parameter growthRateParameter, Parameter doublingTimeParameter, Type units) { |
| 61 |
|
| 62 |
this(HIERARCHICAL_TRANSMISSION_MODEL, model, N0Parameter, N1Parameter, growthRateParameter, doublingTimeParameter, units); |
| 63 |
} |
| 64 |
|
| 65 |
public HierarchicalTransmissionDemographicModel(String name, int model, |
| 66 |
Parameter N0Parameter, Parameter N1Parameter, |
| 67 |
Parameter growthRateParameter, Parameter doublingTimeParameter, Type units) { |
| 68 |
|
| 69 |
super(name, model, N0Parameter, N1Parameter, growthRateParameter, doublingTimeParameter, units); |
| 70 |
} |
| 71 |
|
| 72 |
public void resizeHierarchicalParameters(int hostCount) { |
| 73 |
|
| 74 |
if (N0Parameter != null) { |
| 75 |
N0Parameter.setDimension(hostCount); |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
if (N1Parameter != null) { |
| 80 |
N1Parameter.setDimension(hostCount); |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
if (growthRateParameter != null) { |
| 85 |
growthRateParameter.setDimension(hostCount); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
if (doublingTimeParameter != null) { |
| 90 |
doublingTimeParameter.setDimension(hostCount); |
| 91 |
|
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
protected int getIndexFromHost(int host) { |
| 96 |
return host - 1; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 103 |
|
| 104 |
public String getParserName() { |
| 105 |
return HIERARCHICAL_TRANSMISSION_MODEL; |
| 106 |
} |
| 107 |
|
| 108 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 109 |
|
| 110 |
Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 111 |
|
| 112 |
int model = 0; |
| 113 |
|
| 114 |
Parameter N0Param = null; |
| 115 |
Parameter N1Param = null; |
| 116 |
Parameter rParam = null; |
| 117 |
Parameter dParam = null; |
| 118 |
|
| 119 |
if (xo.hasChildNamed(CONSTANT)) { |
| 120 |
|
| 121 |
XMLObject cxo = xo.getChild(CONSTANT); |
| 122 |
|
| 123 |
N0Param = (Parameter) cxo.getElementFirstChild(POPULATION_SIZE); |
| 124 |
model = 0; |
| 125 |
|
| 126 |
} else if (xo.hasChildNamed(EXPONENTIAL)) { |
| 127 |
|
| 128 |
XMLObject cxo = xo.getChild(EXPONENTIAL); |
| 129 |
|
| 130 |
N1Param = (Parameter) cxo.getElementFirstChild(ANCESTRAL_PROPORTION); |
| 131 |
if (cxo.hasChildNamed(GROWTH_RATE)) { |
| 132 |
rParam = (Parameter) cxo.getElementFirstChild(GROWTH_RATE); |
| 133 |
} else { |
| 134 |
dParam = (Parameter) cxo.getElementFirstChild(DOUBLING_TIME); |
| 135 |
} |
| 136 |
model = 1; |
| 137 |
|
| 138 |
} else if (xo.hasChildNamed(LOGISTIC)) { |
| 139 |
|
| 140 |
XMLObject cxo = xo.getChild(LOGISTIC); |
| 141 |
|
| 142 |
N0Param = (Parameter) cxo.getElementFirstChild(POPULATION_SIZE); |
| 143 |
N1Param = (Parameter) cxo.getElementFirstChild(ANCESTRAL_PROPORTION); |
| 144 |
|
| 145 |
if (cxo.hasChildNamed(GROWTH_RATE)) { |
| 146 |
rParam = (Parameter) cxo.getElementFirstChild(GROWTH_RATE); |
| 147 |
} else { |
| 148 |
dParam = (Parameter) cxo.getElementFirstChild(DOUBLING_TIME); |
| 149 |
} |
| 150 |
model = 2; |
| 151 |
} |
| 152 |
|
| 153 |
HierarchicalTransmissionDemographicModel demoModel = |
| 154 |
new HierarchicalTransmissionDemographicModel(model, N0Param, N1Param, rParam, dParam, units); |
| 155 |
demoModel.resizeHierarchicalParameters(xo.getAttribute(HOST_COUNT, 1)); |
| 156 |
|
| 157 |
return demoModel; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public String getParserDescription() { |
| 165 |
return "A SiteModel that has a gamma distributed rates across sites"; |
| 166 |
} |
| 167 |
|
| 168 |
public Class getReturnType() { |
| 169 |
return HierarchicalTransmissionDemographicModel.class; |
| 170 |
} |
| 171 |
|
| 172 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 173 |
return rules; |
| 174 |
} |
| 175 |
|
| 176 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 177 |
XMLUnits.UNITS_RULE, |
| 178 |
AttributeRule.newIntegerRule(HOST_COUNT, false), |
| 179 |
new XORRule( |
| 180 |
new ElementRule(CONSTANT, |
| 181 |
new XMLSyntaxRule[]{ |
| 182 |
new ElementRule(POPULATION_SIZE, |
| 183 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 184 |
"This parameter represents the carrying capacity (maximum population size). " + |
| 185 |
"If the shape is very large then the current day population size will be very close to the carrying capacity."), |
| 186 |
} |
| 187 |
), |
| 188 |
new XORRule( |
| 189 |
new ElementRule(EXPONENTIAL, |
| 190 |
new XMLSyntaxRule[]{ |
| 191 |
new XORRule( |
| 192 |
new ElementRule(GROWTH_RATE, |
| 193 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 194 |
"This parameter determines the rate of growth during the exponential phase. See exponentialGrowth for details."), |
| 195 |
new ElementRule(DOUBLING_TIME, |
| 196 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 197 |
"This parameter determines the doubling time at peak growth rate.")), |
| 198 |
new ElementRule(ANCESTRAL_PROPORTION, |
| 199 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 200 |
"This parameter determines the populaation size at transmission.") |
| 201 |
} |
| 202 |
), |
| 203 |
new ElementRule(LOGISTIC, |
| 204 |
new XMLSyntaxRule[]{ |
| 205 |
new ElementRule(POPULATION_SIZE, |
| 206 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 207 |
"This parameter represents the carrying capacity (maximum population size). " + |
| 208 |
"If the shape is very large then the current day population size will be very close to the carrying capacity."), |
| 209 |
new XORRule( |
| 210 |
new ElementRule(GROWTH_RATE, |
| 211 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 212 |
"This parameter determines the rate of growth during the exponential phase. See exponentialGrowth for details."), |
| 213 |
new ElementRule(DOUBLING_TIME, |
| 214 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 215 |
"This parameter determines the doubling time at peak growth rate.")), |
| 216 |
new ElementRule(ANCESTRAL_PROPORTION, |
| 217 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, |
| 218 |
"This parameter determines the populaation size at transmission.") |
| 219 |
} |
| 220 |
) |
| 221 |
) |
| 222 |
) |
| 223 |
}; |
| 224 |
|
| 225 |
}; |
| 226 |
|
| 227 |
} |