Debian Codegraph @

src/dr/oldevomodelxml/treelikelihood/TreeLikelihoodParser.java

raw symbols SCIP
1 /*
2 * TreeLikelihoodParser.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.oldevomodelxml.treelikelihood;
27
28 import dr.evolution.alignment.PatternList;
29 import dr.evomodel.branchratemodel.BranchRateModel;
30 import dr.oldevomodel.sitemodel.SiteModel;
31 import dr.evomodel.tipstatesmodel.TipStatesModel;
32 import dr.evomodel.tree.TreeModel;
33 import dr.oldevomodel.treelikelihood.TreeLikelihood;
34 import dr.xml.*;
35
36 /**
37 */
38 @Deprecated // Switching to BEAGLE
39 public class TreeLikelihoodParser extends AbstractXMLObjectParser {
40
41 public static final String TREE_LIKELIHOOD = "treeLikelihood";
42 public static final String ANCESTRAL_TREE_LIKELIHOOD = "ancestralTreeLikelihood";
43 public static final String USE_AMBIGUITIES = "useAmbiguities";
44 public static final String ALLOW_MISSING_TAXA = "allowMissingTaxa";
45 public static final String STORE_PARTIALS = "storePartials";
46 public static final String SCALING_FACTOR = "scalingFactor";
47 public static final String SCALING_THRESHOLD = "scalingThreshold";
48 public static final String FORCE_JAVA_CORE = "forceJavaCore";
49 public static final String FORCE_RESCALING = "forceRescaling";
50
51
52 public String getParserName() {
53 return TREE_LIKELIHOOD;
54 }
55
56 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
57
58 boolean useAmbiguities = xo.getAttribute(USE_AMBIGUITIES, false);
59 boolean allowMissingTaxa = xo.getAttribute(ALLOW_MISSING_TAXA, false);
60 boolean storePartials = xo.getAttribute(STORE_PARTIALS, true);
61 boolean forceJavaCore = xo.getAttribute(FORCE_JAVA_CORE, false);
62
63 if (Boolean.valueOf(System.getProperty("java.only"))) {
64 forceJavaCore = true;
65 }
66
67 PatternList patternList = (PatternList) xo.getChild(PatternList.class);
68 TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
69 SiteModel siteModel = (SiteModel) xo.getChild(SiteModel.class);
70
71 BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
72
73 TipStatesModel tipStatesModel = (TipStatesModel) xo.getChild(TipStatesModel.class);
74 if (tipStatesModel != null && tipStatesModel.getPatternList() != null) {
75 throw new XMLParseException("The same sequence error model cannot be used for multiple partitions");
76 }
77 if (tipStatesModel != null && tipStatesModel.getModelType() == TipStatesModel.Type.STATES) {
78 throw new XMLParseException("The state emitting TipStateModel requires BEAGLE");
79 }
80
81
82 boolean forceRescaling = xo.getAttribute(FORCE_RESCALING, false);
83
84 return new TreeLikelihood(
85 patternList,
86 treeModel,
87 siteModel,
88 branchRateModel,
89 tipStatesModel,
90 useAmbiguities, allowMissingTaxa, storePartials, forceJavaCore, forceRescaling);
91 }
92
93 //************************************************************************
94 // AbstractXMLObjectParser implementation
95 //************************************************************************
96
97 public String getParserDescription() {
98 return "This element represents the likelihood of a patternlist on a tree given the site model.";
99 }
100
101 public Class getReturnType() {
102 return TreeLikelihood.class;
103 }
104
105 public XMLSyntaxRule[] getSyntaxRules() {
106 return rules;
107 }
108
109 private final XMLSyntaxRule[] rules = {
110 AttributeRule.newBooleanRule(USE_AMBIGUITIES, true),
111 AttributeRule.newBooleanRule(ALLOW_MISSING_TAXA, true),
112 AttributeRule.newBooleanRule(STORE_PARTIALS, true),
113 AttributeRule.newBooleanRule(FORCE_JAVA_CORE, true),
114 AttributeRule.newBooleanRule(FORCE_RESCALING, true),
115 new ElementRule(PatternList.class),
116 new ElementRule(TreeModel.class),
117 new ElementRule(SiteModel.class),
118 new ElementRule(BranchRateModel.class, true),
119 new ElementRule(TipStatesModel.class, true)
120 };
121 }