Debian Codegraph @

src/dr/evomodelxml/treelikelihood/BeagleOperationParser.java

raw symbols SCIP
1 /*
2 * BeagleOperationParser.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.treelikelihood;
27
28 import dr.evomodel.siteratemodel.GammaSiteRateModel;
29 import dr.evomodel.treelikelihood.BeagleOperationReport;
30 import dr.evolution.alignment.Alignment;
31 import dr.evolution.alignment.PatternList;
32 import dr.evolution.alignment.SitePatterns;
33 import dr.evomodel.branchratemodel.BranchRateModel;
34 import dr.evomodel.tree.TreeModel;
35 import dr.xml.*;
36
37 import java.io.PrintWriter;
38
39 /**
40 * @author Marc Suchard
41 * @version $Id$
42 */
43 public class BeagleOperationParser extends AbstractXMLObjectParser {
44
45
46 public static final String OPERATION_REPORT = "beagleOperationReport";
47 public static final String BRANCH_FILE_NAME = "branchFileName";
48 public static final String OPERATION_FILE_NAME = "operationFileName";
49
50 public String getParserName() {
51 return OPERATION_REPORT;
52 }
53
54 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
55
56 SitePatterns patternList = (SitePatterns) xo.getChild(PatternList.class);
57 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
58 BranchRateModel rateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
59 Alignment alignment = (Alignment) xo.getChild(Alignment.class);
60 GammaSiteRateModel substitutionModel = (GammaSiteRateModel) xo.getChild(GammaSiteRateModel.class);
61
62 PrintWriter branch = null, operation = null;
63
64 if (xo.hasAttribute(BRANCH_FILE_NAME)) {
65 branch = XMLParser.getFilePrintWriter(xo, OPERATION_REPORT, BRANCH_FILE_NAME);
66 }
67 if (xo.hasAttribute(OPERATION_FILE_NAME)) {
68 operation = XMLParser.getFilePrintWriter(xo, OPERATION_REPORT, OPERATION_FILE_NAME);
69 }
70
71 return new BeagleOperationReport(treeModel, patternList, rateModel, substitutionModel, alignment, branch, operation);
72 }
73
74 //************************************************************************
75 // AbstractXMLObjectParser implementation
76 //************************************************************************
77
78 public String getParserDescription() {
79 return "This element represents the likelihood of a patternlist on a tree given the site model.";
80 }
81
82 public Class getReturnType() {
83 return BeagleOperationReport.class;
84 }
85
86 public static final XMLSyntaxRule[] rules = {
87 new ElementRule(PatternList.class, 2, 2),
88 new ElementRule(TreeModel.class),
89 new ElementRule(BranchRateModel.class),
90 new ElementRule(GammaSiteRateModel.class),
91 // new ElementRule(Alignment.class),
92 AttributeRule.newStringRule(BRANCH_FILE_NAME, true),
93 AttributeRule.newStringRule(OPERATION_FILE_NAME, true),
94 };
95
96 public XMLSyntaxRule[] getSyntaxRules() {
97 return rules;
98 }
99 }