| 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.operators; |
| 27 |
|
| 28 |
import dr.xml.*; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.inference.operators.MCMCOperator; |
| 31 |
import dr.evomodel.operators.MicrosatelliteBitFlipOperator; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class MicrosatelliteBitFlipOperatorParser extends AbstractXMLObjectParser{ |
| 39 |
public static final String MODEL_CHOOSE = "modelChoose"; |
| 40 |
public static final String DEPENDENCIES = "dependencies"; |
| 41 |
public static final String VARIABLE_INDICES = "variableIndices"; |
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return "msatModelSwitchOperator"; |
| 45 |
} |
| 46 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 47 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 48 |
Parameter modelChoose = (Parameter) xo.getElementFirstChild(MODEL_CHOOSE); |
| 49 |
Parameter dependencies = (Parameter)xo.getElementFirstChild(DEPENDENCIES); |
| 50 |
int[] variableIndices; |
| 51 |
if(xo.hasChildNamed(VARIABLE_INDICES)){ |
| 52 |
|
| 53 |
double[] temp = ((Parameter)xo.getElementFirstChild(VARIABLE_INDICES)).getParameterValues(); |
| 54 |
variableIndices = new int[temp.length]; |
| 55 |
for(int i = 0; i < temp.length;i++){ |
| 56 |
variableIndices[i] = (int)temp[i]; |
| 57 |
} |
| 58 |
|
| 59 |
}else{ |
| 60 |
variableIndices = new int[]{0, 1, 2, 3, 4, 5}; |
| 61 |
} |
| 62 |
|
| 63 |
return new MicrosatelliteBitFlipOperator(modelChoose, dependencies, weight, variableIndices); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public String getParserDescription() { |
| 69 |
return "This element returns a microsatellite averaging operator on a given parameter."; |
| 70 |
} |
| 71 |
public Class getReturnType() { |
| 72 |
return MCMCOperator.class; |
| 73 |
} |
| 74 |
|
| 75 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 76 |
return rules; |
| 77 |
} |
| 78 |
|
| 79 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 80 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 81 |
new ElementRule(MODEL_CHOOSE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 82 |
new ElementRule(DEPENDENCIES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 83 |
new ElementRule(VARIABLE_INDICES, new XMLSyntaxRule[]{new ElementRule(Parameter.class)},true) |
| 84 |
}; |
| 85 |
} |