Debian Codegraph @

src/dr/evomodelxml/continuous/GaussianProcessFromTreeParser.java

raw symbols SCIP
1 /*
2 * GaussianProcessFromTreeParser.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.evomodelxml.continuous;
27
28 import dr.evolution.tree.TreeTrait;
29 import dr.evomodel.continuous.FullyConjugateMultivariateTraitLikelihood;
30 import dr.evomodel.continuous.GaussianProcessFromTree;
31 import dr.evomodel.continuous.GibbsSampleMissingTraitsOperator;
32 import dr.evomodel.treedatalikelihood.TreeDataLikelihood;
33 import dr.evomodel.treedatalikelihood.continuous.ContinuousDataLikelihoodDelegate;
34 import dr.evomodel.treedatalikelihood.continuous.TreeTipGaussianProcess;
35 import dr.math.distributions.GaussianProcessRandomGenerator;
36 import dr.xml.*;
37
38 /**
39 * @author Marc A. Suchard
40 * @author Max R. Tolkoff
41 */
42 public class GaussianProcessFromTreeParser extends AbstractXMLObjectParser {
43
44 public static final String GAUSSIAN_PROCESS_FROM_TREE = "gaussianProcessFromTree";
45 public static final String MASK_TO_MISSING = "maskDrawToMissingOnly";
46
47 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
48 new XORRule(
49 new ElementRule(FullyConjugateMultivariateTraitLikelihood.class),
50 new ElementRule(TreeDataLikelihood.class)
51 ),
52 AttributeRule.newBooleanRule(MASK_TO_MISSING, true),
53 };
54
55 @Override
56 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
57
58 FullyConjugateMultivariateTraitLikelihood traitModel = (FullyConjugateMultivariateTraitLikelihood)
59 xo.getChild(FullyConjugateMultivariateTraitLikelihood.class);
60
61 if (traitModel != null) {
62 return new GaussianProcessFromTree(traitModel);
63 }
64
65 TreeDataLikelihood treeDataLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
66 ContinuousDataLikelihoodDelegate dataDelegate =
67 GibbsSampleMissingTraitsOperator.parseContinuousDataLikelihoodDelegate(xo);
68
69 boolean mask = xo.getAttribute(MASK_TO_MISSING, true);
70
71 TreeTipGaussianProcess process = new TreeTipGaussianProcess(dataDelegate.getDataModel().getModelName(),
72 treeDataLikelihood, dataDelegate, null, true);
73
74 return process;
75
76 }
77
78 @Override
79 public XMLSyntaxRule[] getSyntaxRules() {
80 return rules;
81 }
82
83 @Override
84 public String getParserDescription() {
85 return "Returns a random draw of traits given a trait model and a prior";
86 }
87
88 @Override
89 public Class getReturnType() {
90 return GaussianProcessRandomGenerator.class;
91 }
92
93 @Override
94 public String getParserName() {
95 return GAUSSIAN_PROCESS_FROM_TREE;
96 }
97 }