Debian Codegraph @

src/dr/evomodelxml/operators/EmpiricalTreeDistributionOperatorParser.java

raw symbols SCIP
1 /*
2 * EmpiricalTreeDistributionOperatorParser.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.operators;
27
28 import dr.util.FileHelpers;
29 import dr.xml.*;
30 import dr.evolution.io.NexusImporter;
31 import dr.evolution.io.Importer;
32 import dr.evolution.tree.Tree;
33 import dr.evolution.util.TaxonList;
34 import dr.evomodel.tree.EmpiricalTreeDistributionModel;
35 import dr.evomodel.tree.TreeModel;
36 import dr.evomodel.operators.WilsonBalding;
37 import dr.evomodel.operators.EmpiricalTreeDistributionOperator;
38 import dr.inference.operators.MCMCOperator;
39
40 import java.io.*;
41
42 /**
43 * @author Andrew Rambaut
44 * <p/>
45 * Reads a list of trees from a NEXUS file.
46 */
47 public class EmpiricalTreeDistributionOperatorParser extends AbstractXMLObjectParser {
48
49 public String getParserName() {
50 return EmpiricalTreeDistributionOperator.EMPIRICAL_TREE_DISTRIBUTION_OPERATOR;
51 }
52
53 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
54
55 final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
56 boolean metropolisHastings = false;
57
58 if (xo.hasAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS)) {
59 metropolisHastings = xo.getBooleanAttribute(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS);
60 }
61
62 final EmpiricalTreeDistributionModel treeModel = (EmpiricalTreeDistributionModel) xo.getChild(EmpiricalTreeDistributionModel.class);
63
64 return new EmpiricalTreeDistributionOperator(treeModel, metropolisHastings, weight);
65 }
66
67 //************************************************************************
68 // AbstractXMLObjectParser implementation
69 //************************************************************************
70
71 public XMLSyntaxRule[] getSyntaxRules() {
72 return rules;
73 }
74
75 private final XMLSyntaxRule[] rules = {
76 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
77 AttributeRule.newBooleanRule(EmpiricalTreeDistributionOperator.METROPOLIS_HASTINGS, true),
78 new ElementRule(EmpiricalTreeDistributionModel.class)
79 };
80
81 public String getParserDescription() {
82 return "Operator which switches between trees in an empirical distribution.";
83 }
84
85 public Class getReturnType() {
86 return EmpiricalTreeDistributionOperator.class;
87 }
88 }