Debian Codegraph @

src/dr/evomodelxml/operators/MicrosatelliteBitFlipOperatorParser.java

raw symbols SCIP
1 /*
2 * MsatBitFlipOperatorParser.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.operators;
27
28 import dr.xml.*;
29 import dr.inference.model.Parameter;
30 import dr.inference.operators.MCMCOperator;
31 import dr.evomodel.operators.MicrosatelliteBitFlipOperator;
32
33 /**
34 * @author Chieh-Hsi Wu
35 *
36 * Parser for MicrosatelliteBitFlipOperator
37 */
38 public class MicrosatelliteBitFlipOperatorParser extends AbstractXMLObjectParser{
39 public static final String MODEL_CHOOSE = "modelChoose";
40 public static final String DEPENDENCIES = "dependencies";
41 public static final String VARIABLE_INDICES = "variableIndices";
42
43 public String getParserName() {
44 return "msatModelSwitchOperator";
45 }
46 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
47 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
48 Parameter modelChoose = (Parameter) xo.getElementFirstChild(MODEL_CHOOSE);
49 Parameter dependencies = (Parameter)xo.getElementFirstChild(DEPENDENCIES);
50 int[] variableIndices;
51 if(xo.hasChildNamed(VARIABLE_INDICES)){
52
53 double[] temp = ((Parameter)xo.getElementFirstChild(VARIABLE_INDICES)).getParameterValues();
54 variableIndices = new int[temp.length];
55 for(int i = 0; i < temp.length;i++){
56 variableIndices[i] = (int)temp[i];
57 }
58
59 }else{
60 variableIndices = new int[]{0, 1, 2, 3, 4, 5};
61 }
62
63 return new MicrosatelliteBitFlipOperator(modelChoose, dependencies, weight, variableIndices);
64 }
65 //************************************************************************
66 // AbstractXMLObjectParser implementation
67 //************************************************************************
68 public String getParserDescription() {
69 return "This element returns a microsatellite averaging operator on a given parameter.";
70 }
71 public Class getReturnType() {
72 return MCMCOperator.class;
73 }
74
75 public XMLSyntaxRule[] getSyntaxRules() {
76 return rules;
77 }
78
79 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
80 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
81 new ElementRule(MODEL_CHOOSE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
82 new ElementRule(DEPENDENCIES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
83 new ElementRule(VARIABLE_INDICES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true)
84 };
85 }