Debian Codegraph @

src/dr/evomodelxml/coalescent/BNPRSamplingLikelihoodParser.java

raw symbols SCIP
1 package dr.evomodelxml.coalescent;
2
3 import dr.evomodel.coalescent.BNPRSamplingLikelihood;
4 import dr.evomodel.coalescent.DemographicModel;
5 import dr.evomodel.tree.TreeModel;
6 import dr.inference.model.MatrixParameter;
7 import dr.inference.model.Parameter;
8 import dr.xml.*;
9
10 /**
11 * Created by mkarcher on 3/10/17.
12 */
13 public class BNPRSamplingLikelihoodParser extends AbstractXMLObjectParser {
14 public static final String SAMPLING_LIKELIHOOD = "bnprSamplingLikelihood";
15 public static final String MODEL = "model";
16 public static final String BETAS = "betas";
17 public static final String POPULATION_TREE = "populationTree";
18 public static final String EPOCH_WIDTHS = "epochWidths";
19 public static final String WIDTHS = "widths";
20 public static final String COVARIATES = "covariates";
21 public static final String POWER_COVARIATES = "powerCovariates";
22 public static final String POWER_BETAS = "powerBetas";
23
24 @Override
25 public String getParserName() {
26 return SAMPLING_LIKELIHOOD;
27 }
28
29 //************************************************************************
30 // AbstractXMLObjectParser implementation
31 //************************************************************************
32
33 @Override
34 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
35
36 XMLObject cxo = xo.getChild(MODEL);
37 DemographicModel demoModel = (DemographicModel) cxo.getChild(DemographicModel.class);
38
39 cxo = xo.getChild(BETAS);
40 Parameter betas = (Parameter) cxo.getChild(Parameter.class);
41
42 cxo = xo.getChild(POPULATION_TREE); // May need to adapt to multiple trees, a la CoalescentLikelihoodParser
43 TreeModel tree = (TreeModel) cxo.getChild(TreeModel.class);
44
45 double[] epochWidths = null;
46 if (xo.hasChildNamed(EPOCH_WIDTHS)) {
47 cxo = xo.getChild(EPOCH_WIDTHS);
48 epochWidths = cxo.getDoubleArrayAttribute(WIDTHS);
49 }
50
51 MatrixParameter covariates = null;
52 if (xo.hasChildNamed(COVARIATES)) {
53 cxo = xo.getChild(COVARIATES);
54 covariates = (MatrixParameter) cxo.getChild(MatrixParameter.class);
55 }
56
57 MatrixParameter powerCovariates = null;
58 if (xo.hasChildNamed(POWER_COVARIATES)) {
59 cxo = xo.getChild(POWER_COVARIATES);
60 powerCovariates = (MatrixParameter) cxo.getChild(MatrixParameter.class);
61 }
62
63 Parameter powerBetas = null;
64 if (xo.hasChildNamed(POWER_BETAS)) {
65 cxo = xo.getChild(POWER_BETAS);
66 powerBetas = (Parameter) cxo.getChild(Parameter.class);
67 }
68
69 return new BNPRSamplingLikelihood(tree, betas, demoModel, epochWidths, covariates, powerCovariates, powerBetas);
70 }
71
72 @Override
73 public String getParserDescription() {
74 return "This element represents the likelihood of the sampling times given the demographic function.";
75 }
76
77 @Override
78 public Class getReturnType() {
79 return BNPRSamplingLikelihood.class;
80 }
81
82 @Override
83 public XMLSyntaxRule[] getSyntaxRules() {
84 return rules;
85 }
86
87 private final XMLSyntaxRule[] rules = {
88 new ElementRule(MODEL, new XMLSyntaxRule[]{
89 new ElementRule(DemographicModel.class)
90 }, "The demographic model which describes the effective population size over time"),
91
92 new ElementRule(BETAS, new XMLSyntaxRule[]{
93 new ElementRule(Parameter.class)
94 }, "The log-linear coefficients of effective population size, used to calculate sampling intensity"),
95
96 new ElementRule(POPULATION_TREE, new XMLSyntaxRule[]{
97 new ElementRule(TreeModel.class)
98 }, "Tree/sampling times to compute likelihood for"),
99
100 new ElementRule(EPOCH_WIDTHS,
101 new XMLSyntaxRule[]{AttributeRule.newDoubleArrayRule(WIDTHS)}),
102
103 new ElementRule(COVARIATES, new XMLSyntaxRule[]{
104 new ElementRule(MatrixParameter.class)
105 }, "Matrix parameter specifying covariate values at latent points.", true),
106
107 new ElementRule(POWER_COVARIATES, new XMLSyntaxRule[]{
108 new ElementRule(MatrixParameter.class)
109 }, "Matrix parameter specifying power covariate values at latent points.", true),
110
111 new ElementRule(POWER_BETAS, new XMLSyntaxRule[]{
112 new ElementRule(Parameter.class)
113 }, "The coefficients of the power covariates, used to calculate sampling intensity", true)
114 };
115 }