| 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.evomodel.coalescent.GMRFPopSizeStatistic; |
| 29 |
import dr.evomodel.coalescent.GMRFSkyrideLikelihood; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class GMRFPopSizeStatisticParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public final static String TIMES = "time"; |
| 38 |
public final static String FROM = "from"; |
| 39 |
public final static String TO = "to"; |
| 40 |
public final static String NUMBER_OF_INTERVALS = "number"; |
| 41 |
public final static String GMRF_POP_SIZE_STATISTIC = "gmrfPopSizeStatistic"; |
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return GMRF_POP_SIZE_STATISTIC; |
| 45 |
} |
| 46 |
|
| 47 |
public String getParserDescription() { |
| 48 |
return "The pop sizes at the given times"; |
| 49 |
} |
| 50 |
|
| 51 |
public Class getReturnType() { |
| 52 |
return GMRFPopSizeStatistic.class; |
| 53 |
} |
| 54 |
|
| 55 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 56 |
|
| 57 |
double[] times; |
| 58 |
|
| 59 |
if (xo.hasAttribute(FROM)) { |
| 60 |
double from = xo.getDoubleAttribute(FROM); |
| 61 |
double to = xo.getDoubleAttribute(TO); |
| 62 |
int number = xo.getIntegerAttribute(NUMBER_OF_INTERVALS); |
| 63 |
|
| 64 |
double length = (to - from) / number; |
| 65 |
|
| 66 |
times = new double[number + 1]; |
| 67 |
|
| 68 |
for (int i = 0; i < times.length; i++) { |
| 69 |
times[i] = from + i * length; |
| 70 |
} |
| 71 |
} else { |
| 72 |
times = xo.getDoubleArrayAttribute(TIMES); |
| 73 |
} |
| 74 |
|
| 75 |
GMRFSkyrideLikelihood gsl = (GMRFSkyrideLikelihood) xo.getChild(GMRFSkyrideLikelihood.class); |
| 76 |
|
| 77 |
return new GMRFPopSizeStatistic(times, gsl); |
| 78 |
} |
| 79 |
|
| 80 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 81 |
return new XMLSyntaxRule[]{ |
| 82 |
AttributeRule.newDoubleRule(FROM, true), |
| 83 |
AttributeRule.newDoubleRule(TO, true), |
| 84 |
AttributeRule.newIntegerRule(NUMBER_OF_INTERVALS, true), |
| 85 |
AttributeRule.newDoubleArrayRule(TIMES, true), |
| 86 |
|
| 87 |
new ElementRule(GMRFSkyrideLikelihood.class), |
| 88 |
}; |
| 89 |
} |
| 90 |
|
| 91 |
} |