| 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.oldevomodelxml.substmodel; |
| 27 |
|
| 28 |
import dr.evolution.datatype.Microsatellite; |
| 29 |
import dr.oldevomodel.substmodel.FrequencyModel; |
| 30 |
import dr.oldevomodel.substmodel.LinearBiasModel; |
| 31 |
import dr.oldevomodel.substmodel.OnePhaseModel; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class LinearBiasModelParser extends AbstractXMLObjectParser { |
| 40 |
public static final String SUBMODEL = "Submodel"; |
| 41 |
public static final String BIAS_CONSTANT = "BiasConstant"; |
| 42 |
public static final String BIAS_LINEAR = "BiasLinear"; |
| 43 |
public static final String ESTIMATE_SUBMODEL_PARAMS = "estimateSubmodelParameters"; |
| 44 |
public static final String LOGISTICS = "logistics"; |
| 45 |
public static final String IS_SUBMODEL = "isSubmodel"; |
| 46 |
|
| 47 |
|
| 48 |
public String getParserName() { |
| 49 |
return LinearBiasModel.LINEAR_BIAS_MODEL; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 55 |
OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL); |
| 56 |
Microsatellite dataType = (Microsatellite)subModel.getDataType(); |
| 57 |
|
| 58 |
Parameter biasConst = null; |
| 59 |
if(xo.hasChildNamed(BIAS_CONSTANT)){ |
| 60 |
biasConst =(Parameter) xo.getElementFirstChild(BIAS_CONSTANT); |
| 61 |
} |
| 62 |
|
| 63 |
Parameter biasLin = null; |
| 64 |
if(xo.hasChildNamed(BIAS_LINEAR)){ |
| 65 |
biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
FrequencyModel freqModel = null; |
| 70 |
if(xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)){ |
| 71 |
freqModel = (FrequencyModel)xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES); |
| 72 |
} |
| 73 |
|
| 74 |
boolean estimateSubmodelParams = false; |
| 75 |
if(xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)){ |
| 76 |
estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS); |
| 77 |
} |
| 78 |
System.out.println("Is estimating submodel parameter(s): "+estimateSubmodelParams); |
| 79 |
|
| 80 |
boolean logistics = false; |
| 81 |
if(xo.hasAttribute(LOGISTICS)){ |
| 82 |
logistics = xo.getBooleanAttribute(LOGISTICS); |
| 83 |
} |
| 84 |
System.out.println("Using logistic regression: "+ logistics); |
| 85 |
|
| 86 |
boolean isSubmodel = false; |
| 87 |
if(xo.hasAttribute(IS_SUBMODEL)){ |
| 88 |
isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL); |
| 89 |
} |
| 90 |
System.out.println("Is a submodel: "+isSubmodel); |
| 91 |
|
| 92 |
return new LinearBiasModel( |
| 93 |
dataType, |
| 94 |
freqModel, |
| 95 |
subModel, |
| 96 |
biasConst, |
| 97 |
biasLin, |
| 98 |
logistics, |
| 99 |
estimateSubmodelParams, |
| 100 |
isSubmodel |
| 101 |
); |
| 102 |
} |
| 103 |
|
| 104 |
public String getParserDescription() { |
| 105 |
return "This element represents an instance of the stepwise mutation model of microsatellite evolution."; |
| 106 |
} |
| 107 |
|
| 108 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 109 |
return rules; |
| 110 |
} |
| 111 |
|
| 112 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 113 |
new ElementRule(FrequencyModelParser.FREQUENCIES, new XMLSyntaxRule[]{ |
| 114 |
new ElementRule(FrequencyModel.class)},true), |
| 115 |
new ElementRule(SUBMODEL,new XMLSyntaxRule[]{new ElementRule(OnePhaseModel.class)}), |
| 116 |
new ElementRule(Microsatellite.class), |
| 117 |
new ElementRule(BIAS_CONSTANT,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 118 |
new ElementRule(BIAS_LINEAR,new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true), |
| 119 |
new StringAttributeRule(ESTIMATE_SUBMODEL_PARAMS,"whether or not to esitmate the parameters of the submodel",true), |
| 120 |
AttributeRule.newBooleanRule(LOGISTICS,true), |
| 121 |
AttributeRule.newBooleanRule(IS_SUBMODEL,true) |
| 122 |
}; |
| 123 |
|
| 124 |
public Class getReturnType() { |
| 125 |
return LinearBiasModel.class; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
} |