Debian Codegraph @

src/dr/evomodelxml/tree/TransformedTreeModelParser.java

raw symbols SCIP
1 /*
2 * TransformedTreeModelParser.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.tree;
27
28 import dr.evolution.tree.MutableTreeModel;
29 import dr.evomodel.tree.*;
30 import dr.inference.model.Parameter;
31 import dr.xml.*;
32
33 import java.util.logging.Logger;
34
35 /**
36 * @author Marc Suchard
37 */
38 public class TransformedTreeModelParser extends AbstractXMLObjectParser {
39
40 public static final String TRANSFORMED_TREE_MODEL = "transformedTreeModel";
41 public static final String VERSION = "version";
42
43 public String getParserName() {
44 return TRANSFORMED_TREE_MODEL;
45 }
46
47 /**
48 * @return a tree object based on the XML element it was passed.
49 */
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52
53 MutableTreeModel tree = (MutableTreeModel) xo.getChild(MutableTreeModel.class);
54 Parameter scale = (Parameter) xo.getChild(Parameter.class);
55
56 String id = tree.getId();
57 if (!xo.hasId()) {
58 // System.err.println("No check!");
59 id = "transformed." + id;
60 } else {
61 // System.err.println("Why am I here?");
62 id = xo.getId();
63 }
64 Logger.getLogger("dr.evomodel").info("Creating a transformed tree model, '" + id + "'");
65
66 TreeTransform transform;
67
68 String version = xo.getAttribute(VERSION, "generic");
69
70 if (version.compareTo("new") == 0) {
71 transform = new ProgressiveScalarTreeTransform(scale);
72 } else if (version.compareTo("branch") == 0) {
73 transform = new ProgressiveScalarTreeTransform(tree, scale);
74 } else if (version.compareTo("ou") == 0) {
75 transform = new OuScalarTreeTransform(scale);
76 } else {
77 transform = new SingleScalarTreeTransform(scale);
78 }
79
80 return new TransformedTreeModel(id, tree, transform);
81 }
82
83 //************************************************************************
84 // AbstractXMLObjectParser implementation
85 //************************************************************************
86
87 public String getParserDescription() {
88 return "This element represents a transformed model of the tree.";
89 }
90
91 public Class getReturnType() {
92 return TransformedTreeModel.class;
93 }
94
95 public XMLSyntaxRule[] getSyntaxRules() {
96 return rules;
97 }
98
99 private final XMLSyntaxRule[] rules =
100 new XMLSyntaxRule[]{
101 new ElementRule(MutableTreeModel.class),
102 new ElementRule(Parameter.class),
103 AttributeRule.newStringRule(VERSION, true),
104 };
105 }