Debian Codegraph @

src/dr/evomodelxml/treelikelihood/DnDsLoggerParser.java

raw symbols SCIP
1 /*
2 * DnDsLoggerParser.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.treelikelihood;
27
28 import dr.evomodel.substmodel.CodonPartitionedRobustCounting;
29 import dr.evomodel.treelikelihood.utilities.DnDsLogger;
30 import dr.evolution.tree.Tree;
31 import dr.evolution.tree.TreeTrait;
32 import dr.xml.*;
33
34 /**
35 * @author Philippe Lemey
36 * @author Marc A. Suchard
37 */
38 public class DnDsLoggerParser extends AbstractXMLObjectParser {
39
40 public static final String PARSER_NAME = "dNdSLogger";
41 public static final String USE_SMOOTHING = "smooth";
42 public static final String USE_DNMINUSDS = "dn-ds";
43 public static final String COUNTS = "counts";
44 public static final String SYNONYMOUS = "synonymous";
45
46 @Override
47 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
48
49 String[] names = DnDsLogger.traitNames;
50 TreeTrait[] foundTraits = new TreeTrait[names.length];
51
52 for (int i = 0; i < xo.getChildCount(); i++) {
53 Object obj = xo.getChild(i);
54 if (obj instanceof CodonPartitionedRobustCounting) {
55 CodonPartitionedRobustCounting thisCount = (CodonPartitionedRobustCounting) obj;
56 for (int j = 0; j < names.length; j++) {
57 TreeTrait trait = thisCount.getTreeTrait(names[j]);
58 if (trait != null) {
59 foundTraits[j] = trait;
60 }
61 }
62 }
63 }
64
65 for (int i = 0; i < foundTraits.length; i++) {
66 if (foundTraits[i] == null) {
67 throw new XMLParseException("Unable to find trait '" + names[i] + "'");
68 }
69 }
70
71 Tree tree = (Tree) xo.getChild(Tree.class);
72
73 // Use AttributeRules for options here
74
75 boolean useSmoothing = xo.getAttribute(USE_SMOOTHING, true);
76 boolean useDnMinusDs = xo.getAttribute(USE_DNMINUSDS, false);
77 boolean conditionalCounts = xo.getAttribute(COUNTS, false);
78 boolean synonymous = xo.getAttribute(SYNONYMOUS, false);
79
80 return new DnDsLogger(xo.getId(), tree, foundTraits, useSmoothing, useDnMinusDs, conditionalCounts, synonymous);
81 }
82
83 @Override
84 public XMLSyntaxRule[] getSyntaxRules() {
85 return rules;
86 }
87
88 private static XMLSyntaxRule[] rules = {
89 new ElementRule(CodonPartitionedRobustCounting.class, 2, 2),
90 new ElementRule(Tree.class),
91 AttributeRule.newBooleanRule(USE_SMOOTHING, true),
92 AttributeRule.newBooleanRule(COUNTS, true),
93 AttributeRule.newBooleanRule(SYNONYMOUS, true),
94 AttributeRule.newBooleanRule(USE_DNMINUSDS, true),
95 };
96
97 @Override
98 public String getParserDescription() {
99 return null;
100 }
101
102 @Override
103 public Class getReturnType() {
104 return DnDsLogger.class;
105 }
106
107 public String getParserName() {
108 return PARSER_NAME;
109 }
110 }