| 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.continuous; |
| 27 |
|
| 28 |
import dr.evolution.tree.MutableTreeModel; |
| 29 |
import dr.evomodelxml.treelikelihood.TreeTraitParserUtilities; |
| 30 |
import dr.inference.model.MatrixParameter; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class DataFromTreeTipsParser extends AbstractXMLObjectParser { |
| 40 |
public final static String DATA_FROM_TREE_TIPS = "dataFromTreeTips"; |
| 41 |
public final static String DATA = "data"; |
| 42 |
public static final String CONTINUOUS = "continuous"; |
| 43 |
|
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return DATA_FROM_TREE_TIPS; |
| 47 |
} |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
|
| 51 |
TreeTraitParserUtilities utilities = new TreeTraitParserUtilities(); |
| 52 |
String traitName = (String) xo.getAttribute(TreeTraitParserUtilities.TRAIT_NAME); |
| 53 |
|
| 54 |
MutableTreeModel treeModel = (MutableTreeModel) xo.getChild(MutableTreeModel.class); |
| 55 |
|
| 56 |
TreeTraitParserUtilities.TraitsAndMissingIndices returnValue = |
| 57 |
utilities.parseTraitsFromTaxonAttributes(xo, traitName, treeModel, true); |
| 58 |
MatrixParameter dataParameter = MatrixParameter.recast(returnValue.traitParameter.getId(), |
| 59 |
returnValue.traitParameter); |
| 60 |
|
| 61 |
if (xo.hasChildNamed(TreeTraitParserUtilities.MISSING)) { |
| 62 |
Parameter missing = (Parameter) xo.getChild(TreeTraitParserUtilities.MISSING).getChild(Parameter.class); |
| 63 |
missing.setDimension(dataParameter.getDimension()); |
| 64 |
|
| 65 |
for (int i = 0; i < missing.getDimension(); i++) { |
| 66 |
if (returnValue.missingIndices.contains(i)) { |
| 67 |
missing.setParameterValue(i, 1); |
| 68 |
} else { |
| 69 |
missing.setParameterValue(i, 0); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return dataParameter; |
| 75 |
} |
| 76 |
|
| 77 |
private static final XMLSyntaxRule[] rules = { |
| 78 |
new ElementRule(MutableTreeModel.class), |
| 79 |
AttributeRule.newStringRule(TreeTraitParserUtilities.TRAIT_NAME), |
| 80 |
new ElementRule(TreeTraitParserUtilities.TRAIT_PARAMETER, new XMLSyntaxRule[]{ |
| 81 |
new ElementRule(Parameter.class) |
| 82 |
}), |
| 83 |
new ElementRule(TreeTraitParserUtilities.MISSING, new XMLSyntaxRule[]{ |
| 84 |
new ElementRule(Parameter.class) |
| 85 |
}, true), |
| 86 |
}; |
| 87 |
|
| 88 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 89 |
return rules; |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public String getParserDescription() { |
| 94 |
return "Takes the data from the tips of a tree and puts it into a MatrixParameter"; |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public Class getReturnType() { |
| 99 |
return MatrixParameter.class; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
} |