Debian Codegraph @

src/dr/evomodelxml/continuous/DataFromTreeTipsParser.java

raw symbols SCIP
1 /*
2 * DataFromTreeTipsParser.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.MutableTreeModel;
29 import dr.evomodelxml.treelikelihood.TreeTraitParserUtilities;
30 import dr.inference.model.MatrixParameter;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 /**
35 * @author Max Tolkoff
36 * @author Marc Suchard
37 */
38
39 public class DataFromTreeTipsParser extends AbstractXMLObjectParser {
40 public final static String DATA_FROM_TREE_TIPS = "dataFromTreeTips";
41 public final static String DATA = "data";
42 public static final String CONTINUOUS = "continuous";
43
44
45 public String getParserName() {
46 return DATA_FROM_TREE_TIPS;
47 }
48
49 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
50
51 TreeTraitParserUtilities utilities = new TreeTraitParserUtilities();
52 String traitName = (String) xo.getAttribute(TreeTraitParserUtilities.TRAIT_NAME);
53
54 MutableTreeModel treeModel = (MutableTreeModel) xo.getChild(MutableTreeModel.class);
55
56 TreeTraitParserUtilities.TraitsAndMissingIndices returnValue =
57 utilities.parseTraitsFromTaxonAttributes(xo, traitName, treeModel, true);
58 MatrixParameter dataParameter = MatrixParameter.recast(returnValue.traitParameter.getId(),
59 returnValue.traitParameter);
60
61 if (xo.hasChildNamed(TreeTraitParserUtilities.MISSING)) {
62 Parameter missing = (Parameter) xo.getChild(TreeTraitParserUtilities.MISSING).getChild(Parameter.class);
63 missing.setDimension(dataParameter.getDimension());
64
65 for (int i = 0; i < missing.getDimension(); i++) {
66 if (returnValue.missingIndices.contains(i)) {
67 missing.setParameterValue(i, 1);
68 } else {
69 missing.setParameterValue(i, 0);
70 }
71 }
72 }
73
74 return dataParameter;
75 }
76
77 private static final XMLSyntaxRule[] rules = {
78 new ElementRule(MutableTreeModel.class),
79 AttributeRule.newStringRule(TreeTraitParserUtilities.TRAIT_NAME),
80 new ElementRule(TreeTraitParserUtilities.TRAIT_PARAMETER, new XMLSyntaxRule[]{
81 new ElementRule(Parameter.class)
82 }),
83 new ElementRule(TreeTraitParserUtilities.MISSING, new XMLSyntaxRule[]{
84 new ElementRule(Parameter.class)
85 }, true),
86 };
87
88 public XMLSyntaxRule[] getSyntaxRules() {
89 return rules;
90 }
91
92 @Override
93 public String getParserDescription() {
94 return "Takes the data from the tips of a tree and puts it into a MatrixParameter";
95 }
96
97 @Override
98 public Class getReturnType() {
99 return MatrixParameter.class;
100 }
101
102
103 }