Debian Codegraph @

src/dr/evomodelxml/substmodel/OldGLMSubstitutionModelParser.java

raw symbols SCIP
1 /*
2 * OldGLMSubstitutionModelParser.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.substmodel;
27
28 import dr.evolution.datatype.DataType;
29 import dr.evomodel.substmodel.FrequencyModel;
30 import dr.evomodel.substmodel.OldGLMSubstitutionModel;
31 import dr.evomodel.substmodel.SubstitutionModel;
32 import dr.evoxml.util.DataTypeUtils;
33 import dr.inference.distribution.GeneralizedLinearModel;
34 import dr.inference.distribution.LogLinearModel;
35 import dr.xml.*;
36
37 /**
38 */
39 @Deprecated // This uses the old (deprecated) GLM stuff and is here for XML compatibility for now
40 // Only one of OldGLMSubstitutionModelParser and GLMSubstitutionModelParser should be in the parser list.
41 public class OldGLMSubstitutionModelParser extends AbstractXMLObjectParser {
42
43 public static final String GLM_SUBSTITUTION_MODEL = "glmSubstitutionModel";
44
45
46 public String getParserName() {
47 return GLM_SUBSTITUTION_MODEL;
48 }
49
50 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
51
52 DataType dataType = DataTypeUtils.getDataType(xo);
53
54 if (dataType == null) dataType = (DataType) xo.getChild(DataType.class);
55
56 int rateCount = (dataType.getStateCount() - 1) * dataType.getStateCount();
57
58 LogLinearModel glm = (LogLinearModel) xo.getChild(GeneralizedLinearModel.class);
59
60 int length = glm.getXBeta().length;
61
62 if (length != rateCount) {
63 throw new XMLParseException("Rates parameter in " + getParserName() + " element should have " + (rateCount) + " dimensions. However GLM dimension is " + length);
64 }
65
66 XMLObject cxo = xo.getChild(dr.oldevomodelxml.substmodel.ComplexSubstitutionModelParser.ROOT_FREQUENCIES);
67 FrequencyModel rootFreq = (FrequencyModel) cxo.getChild(FrequencyModel.class);
68
69 if (dataType != rootFreq.getDataType()) {
70 throw new XMLParseException("Data type of " + getParserName() + " element does not match that of its rootFrequencyModel.");
71 }
72
73 return new OldGLMSubstitutionModel(xo.getId(), dataType, rootFreq, glm);
74 }
75
76 //************************************************************************
77 // AbstractXMLObjectParser implementation
78 //************************************************************************
79
80 public String getParserDescription() {
81 return "A general model of sequence substitution for any data type where the rates come from the generalized linear model.";
82 }
83
84 public Class getReturnType() {
85 return OldGLMSubstitutionModel.class;
86 }
87
88 public XMLSyntaxRule[] getSyntaxRules() {
89 return rules;
90 }
91
92 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
93 new XORRule(
94 new StringAttributeRule(DataType.DATA_TYPE, "The type of sequence data",
95 DataType.getRegisteredDataTypeNames(), false),
96 new ElementRule(DataType.class)
97 ),
98 new ElementRule(ComplexSubstitutionModelParser.ROOT_FREQUENCIES, FrequencyModel.class),
99 new ElementRule(GeneralizedLinearModel.class),
100 };
101
102 }