| 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.tree.Tree; |
| 29 |
import dr.evolution.tree.TreeUtils; |
| 30 |
import dr.evolution.util.Taxa; |
| 31 |
import dr.evolution.util.TaxonList; |
| 32 |
import dr.evomodel.tree.ParsimonyStatistic; |
| 33 |
import dr.evomodel.tree.TreeModel; |
| 34 |
import dr.inference.model.Statistic; |
| 35 |
import dr.xml.*; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class ParsimonyStatisticParser extends AbstractXMLObjectParser { |
| 40 |
|
| 41 |
public static final String PARSIMONY_STATISTIC = "parsimonyStatistic"; |
| 42 |
public static final String STATE = "state"; |
| 43 |
|
| 44 |
public String getParserName() { |
| 45 |
return PARSIMONY_STATISTIC; |
| 46 |
} |
| 47 |
|
| 48 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 49 |
|
| 50 |
String name = xo.getAttribute(Statistic.NAME, xo.getId()); |
| 51 |
Tree tree = (Tree) xo.getChild(Tree.class); |
| 52 |
XMLObject cxo = xo.getChild(STATE); |
| 53 |
TaxonList taxa = (TaxonList) cxo.getChild(TaxonList.class); |
| 54 |
|
| 55 |
try { |
| 56 |
return new ParsimonyStatistic(name, tree, taxa); |
| 57 |
} catch (TreeUtils.MissingTaxonException mte) { |
| 58 |
throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + "was not found in the tree."); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public String getParserDescription() { |
| 67 |
return "A statistic that has as its value the parsimony tree length of a set of a " + |
| 68 |
"binary state defined by a set of taxa for a given tree"; |
| 69 |
} |
| 70 |
|
| 71 |
public Class getReturnType() { |
| 72 |
return ParsimonyStatistic.class; |
| 73 |
} |
| 74 |
|
| 75 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 76 |
return rules; |
| 77 |
} |
| 78 |
|
| 79 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 80 |
new StringAttributeRule(Statistic.NAME, "A name for this statistic primarily for the purposes of logging", true), |
| 81 |
new ElementRule(TreeModel.class), |
| 82 |
new ElementRule(STATE, |
| 83 |
new XMLSyntaxRule[]{new ElementRule(Taxa.class)}) |
| 84 |
}; |
| 85 |
|
| 86 |
} |