| 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.tree; |
| 27 |
|
| 28 |
import dr.evolution.alignment.Patterns; |
| 29 |
import dr.evomodel.tree.MicrosatelliteSamplerTreeModel; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
import java.util.HashMap; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class MicrosatelliteSamplerTreeModelParser extends AbstractXMLObjectParser { |
| 43 |
public static final String TREE_MICROSATELLITE_SAMPLER_MODEL = "microsatelliteSamplerTreeModel"; |
| 44 |
public static final String TREE = "tree"; |
| 45 |
public static final String INTERNAL_VALUES = "internalValues"; |
| 46 |
public static final String EXTERNAL_VALUES = "externalValues"; |
| 47 |
public static final String USE_PROVIDED_INTERNAL_VALUES = "provideInternalNodeValues"; |
| 48 |
|
| 49 |
public String getParserName(){ |
| 50 |
return TREE_MICROSATELLITE_SAMPLER_MODEL; |
| 51 |
} |
| 52 |
|
| 53 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 54 |
TreeModel tree = (TreeModel)xo.getElementFirstChild(TREE); |
| 55 |
Parameter internalVal = (Parameter)xo.getElementFirstChild(INTERNAL_VALUES); |
| 56 |
Patterns microsatellitePattern = (Patterns)xo.getElementFirstChild(EXTERNAL_VALUES); |
| 57 |
int[] externalValues = microsatellitePattern.getPattern(0); |
| 58 |
HashMap<String, Integer> taxaMap = new HashMap<String, Integer>(externalValues.length); |
| 59 |
boolean internalValuesProvided = false; |
| 60 |
if(xo.hasAttribute(USE_PROVIDED_INTERNAL_VALUES)){ |
| 61 |
internalValuesProvided = xo.getBooleanAttribute(USE_PROVIDED_INTERNAL_VALUES); |
| 62 |
} |
| 63 |
for(int i = 0; i < externalValues.length; i++){ |
| 64 |
taxaMap.put(microsatellitePattern.getTaxonId(i),i); |
| 65 |
} |
| 66 |
|
| 67 |
String modelId = xo.getAttribute("id", "treeMicrosatelliteSamplerModel"); |
| 68 |
return new MicrosatelliteSamplerTreeModel(modelId, tree, internalVal, microsatellitePattern, externalValues, taxaMap, internalValuesProvided); |
| 69 |
} |
| 70 |
|
| 71 |
public XMLSyntaxRule[] getSyntaxRules() { return rules; } |
| 72 |
private final XMLSyntaxRule[] rules = { |
| 73 |
AttributeRule.newBooleanRule(USE_PROVIDED_INTERNAL_VALUES, true), |
| 74 |
new ElementRule(TREE, TreeModel.class), |
| 75 |
new ElementRule(INTERNAL_VALUES, Parameter.class), |
| 76 |
new ElementRule(EXTERNAL_VALUES, Patterns.class) |
| 77 |
}; |
| 78 |
|
| 79 |
public String getParserDescription(){ |
| 80 |
return "This parser returns a TreeMicrosatelliteSamplerModel Object"; |
| 81 |
} |
| 82 |
|
| 83 |
public Class getReturnType(){ |
| 84 |
return MicrosatelliteSamplerTreeModel.class; |
| 85 |
|
| 86 |
} |
| 87 |
} |