Debian Codegraph @

src/dr/evomodelxml/branchratemodel/RelaxedDriftModelParser.java

raw symbols SCIP
1 /*
2 * RelaxedDriftModelParser.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.branchratemodel;
27
28 import dr.evolution.tree.TreeTraitProvider;
29 import dr.evomodel.branchratemodel.ArbitraryBranchRates;
30 import dr.evomodel.branchratemodel.RelaxedDriftModel;
31 import dr.evomodel.tree.TreeModel;
32 import dr.inference.model.Parameter;
33 import dr.xml.*;
34
35 import java.util.logging.Logger;
36
37 /**
38 * Created by IntelliJ IDEA.
39 * User: mandevgill
40 * Date: 7/28/14
41 * Time: 3:24 PM
42 * To change this template use File | Settings | File Templates.
43 */
44 public class RelaxedDriftModelParser extends AbstractXMLObjectParser {
45
46 public static final String RELAXED_DRIFT = "relaxedDriftModel";
47 public static final String RATES = "rates";
48 public static final String RATE_IND = "rateIndicator";
49 public static final String DRIFT_RATES = "driftRates";
50 public static final String BRANCH_CHANGES = "branchChanges";
51
52 public String getParserName() {
53 return RELAXED_DRIFT;
54 }
55
56 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
57
58 TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
59
60 Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES);
61
62 Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_IND);
63
64 Parameter driftRates = null;
65 if (xo.hasChildNamed(DRIFT_RATES)) {
66 driftRates = (Parameter) xo.getElementFirstChild(DRIFT_RATES);
67 }
68
69 ArbitraryBranchRates branchChanges = null;
70 if (xo.hasChildNamed(BRANCH_CHANGES)){
71 branchChanges = (ArbitraryBranchRates) xo.getElementFirstChild(BRANCH_CHANGES);
72 }
73
74 Logger.getLogger("dr.evomodel").info("Using relaxed drift model.");
75
76
77 return new RelaxedDriftModel(tree, rateIndicatorParameter,
78 ratesParameter, driftRates, branchChanges);
79 }
80
81 //************************************************************************
82 // AbstractXMLObjectParser implementation
83 //************************************************************************
84
85 public String getParserDescription() {
86 return
87 "This element returns a relaxed drift model.";
88 }
89
90 public Class getReturnType() {
91 return RelaxedDriftModel.class;
92 }
93
94 public XMLSyntaxRule[] getSyntaxRules() {
95 return rules;
96 }
97
98 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
99 new ElementRule(TreeModel.class),
100 new ElementRule(RATES, Parameter.class, "The rates parameter", false),
101 new ElementRule(RATE_IND, Parameter.class, "The indicator parameter", false),
102 new ElementRule(DRIFT_RATES, Parameter.class, "The drift rates parameter", true),
103 new ElementRule(BRANCH_CHANGES, ArbitraryBranchRates.class, "Branch specific rate change indicators", true)
104 };
105 }