Debian Codegraph @

src/dr/evomodelxml/continuous/RestrictedPartialsParser.java

raw symbols SCIP
1 /*
2 * RestrictedPartialsParser.java
3 *
4 * Copyright (c) 2002-2016 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.evomodelxml.continuous;
27
28 import dr.evolution.tree.TreeUtils;
29 import dr.evolution.util.Taxa;
30 import dr.evolution.util.Taxon;
31 import dr.evolution.util.TaxonList;
32 import dr.evomodel.continuous.AbstractMultivariateTraitLikelihood;
33 import dr.evomodel.continuous.RestrictedPartials;
34 import dr.evomodel.tree.TreeModel;
35 import dr.evomodelxml.tree.MonophylyStatisticParser;
36 import dr.inference.distribution.MultivariateDistributionLikelihood;
37 import dr.inference.model.Parameter;
38 import dr.xml.*;
39
40 /**
41 * @author Marc A. Suchard
42 */
43 public class RestrictedPartialsParser extends AbstractXMLObjectParser {
44
45 public static final String RESTRICTED_PARTIALS = "restrictedPartials";
46
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48
49 String name = xo.getId();
50
51 TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
52 TaxonList taxa = MonophylyStatisticParser.parseTaxonListOrTaxa(xo.getChild(MonophylyStatisticParser.MRCA));
53
54 Parameter meanParameter = (Parameter) xo.getElementFirstChild(MultivariateDistributionLikelihood.MVN_MEAN);
55 Parameter priorSampleSize =
56 (Parameter) xo.getElementFirstChild(AbstractMultivariateTraitLikelihood.PRIOR_SAMPLE_SIZE);
57
58 RestrictedPartials rp = null;
59
60 try {
61 rp = new RestrictedPartials(name, tree, taxa, meanParameter, priorSampleSize);
62 } catch (TreeUtils.MissingTaxonException e) {
63 throw new XMLParseException("Unable to find taxa for " + xo.getId());
64 }
65
66 return rp;
67 }
68
69 public XMLSyntaxRule[] getSyntaxRules() {
70 return rules;
71 }
72
73 private final XMLSyntaxRule[] rules = {
74 new ElementRule(TreeModel.class),
75 new ElementRule(MonophylyStatisticParser.MRCA, new XMLSyntaxRule[]{
76 new XORRule(
77 new ElementRule(Taxon.class, 1, Integer.MAX_VALUE),
78 new ElementRule(Taxa.class)
79 )
80 }),
81 new ElementRule(MultivariateDistributionLikelihood.MVN_MEAN,
82 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
83 new ElementRule(AbstractMultivariateTraitLikelihood.PRIOR_SAMPLE_SIZE,
84 new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
85 };
86
87 public String getParserDescription() {
88 return "A restricted partials assignment for a set of taxa";
89 }
90
91 public Class getReturnType() {
92 return RestrictedPartials.class;
93 }
94
95 public String getParserName() {
96 return RESTRICTED_PARTIALS;
97 }
98
99 }