Debian Codegraph @

src/dr/evomodelxml/tree/MicrosatelliteSamplerTreeModelParser.java

raw symbols SCIP
1 /*
2 * MicrosatelliteSamplerTreeModelParser.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.alignment.Patterns;
29 import dr.evomodel.tree.MicrosatelliteSamplerTreeModel;
30 import dr.evomodel.tree.TreeModel;
31 import dr.inference.model.Parameter;
32 import dr.xml.*;
33
34 import java.util.HashMap;
35
36 /**
37 * @author Chieh-Hsi Wu
38 *
39 * Parser for MicrsatelliteSamplerTreeModel
40 *
41 */
42 public class MicrosatelliteSamplerTreeModelParser extends AbstractXMLObjectParser {
43 public static final String TREE_MICROSATELLITE_SAMPLER_MODEL = "microsatelliteSamplerTreeModel";
44 public static final String TREE = "tree";
45 public static final String INTERNAL_VALUES = "internalValues";
46 public static final String EXTERNAL_VALUES = "externalValues";
47 public static final String USE_PROVIDED_INTERNAL_VALUES = "provideInternalNodeValues";
48
49 public String getParserName(){
50 return TREE_MICROSATELLITE_SAMPLER_MODEL;
51 }
52
53 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
54 TreeModel tree = (TreeModel)xo.getElementFirstChild(TREE);
55 Parameter internalVal = (Parameter)xo.getElementFirstChild(INTERNAL_VALUES);
56 Patterns microsatellitePattern = (Patterns)xo.getElementFirstChild(EXTERNAL_VALUES);
57 int[] externalValues = microsatellitePattern.getPattern(0);
58 HashMap<String, Integer> taxaMap = new HashMap<String, Integer>(externalValues.length);
59 boolean internalValuesProvided = false;
60 if(xo.hasAttribute(USE_PROVIDED_INTERNAL_VALUES)){
61 internalValuesProvided = xo.getBooleanAttribute(USE_PROVIDED_INTERNAL_VALUES);
62 }
63 for(int i = 0; i < externalValues.length; i++){
64 taxaMap.put(microsatellitePattern.getTaxonId(i),i);
65 }
66
67 String modelId = xo.getAttribute("id", "treeMicrosatelliteSamplerModel");
68 return new MicrosatelliteSamplerTreeModel(modelId, tree, internalVal, microsatellitePattern, externalValues, taxaMap, internalValuesProvided);
69 }
70
71 public XMLSyntaxRule[] getSyntaxRules() { return rules; }
72 private final XMLSyntaxRule[] rules = {
73 AttributeRule.newBooleanRule(USE_PROVIDED_INTERNAL_VALUES, true),
74 new ElementRule(TREE, TreeModel.class),
75 new ElementRule(INTERNAL_VALUES, Parameter.class),
76 new ElementRule(EXTERNAL_VALUES, Patterns.class)
77 };
78
79 public String getParserDescription(){
80 return "This parser returns a TreeMicrosatelliteSamplerModel Object";
81 }
82
83 public Class getReturnType(){
84 return MicrosatelliteSamplerTreeModel.class;
85
86 }
87 }