| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
| 40 |
|
| 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 |
|
| 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 |
} |