Debian Codegraph @

src/dr/evomodel/transmission/HierarchicalTransmissionDemographicModel.java

raw symbols SCIP
1 /*
2 * HierarchicalTransmissionDemographicModel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * A demographic model for within patient evolution in a transmission history with a hierarchical parameterization.
34 *
35 * @author Marc A. Suchard
36 * @author Andrew Rambaut
37 * @version $Id: TransmissionDemographicModel.java,v 1.7 2005/05/24 20:25:58 rambaut Exp $
38 */
39 public class HierarchicalTransmissionDemographicModel extends TransmissionDemographicModel {
40
41 //
42 // Public stuff
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 // N0Parameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, hostCount));
77 }
78
79 if (N1Parameter != null) {
80 N1Parameter.setDimension(hostCount);
81 // N1Parameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1));
82 }
83
84 if (growthRateParameter != null) {
85 growthRateParameter.setDimension(hostCount);
86 // growthRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, hostCount));
87 }
88
89 if (doublingTimeParameter != null) {
90 doublingTimeParameter.setDimension(hostCount);
91 // doublingTimeParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, hostCount));
92 }
93 }
94
95 protected int getIndexFromHost(int host) {
96 return host - 1;
97 }
98
99 /**
100 * Parses an element from an DOM document into a ExponentialGrowth.
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 // AbstractXMLObjectParser implementation
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 }