| 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.evoxml; |
| 27 |
|
| 28 |
import dr.evolution.util.Taxa; |
| 29 |
import dr.evolution.util.Taxon; |
| 30 |
import dr.evolution.util.TaxonList; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class TaxaParser extends AbstractXMLObjectParser { |
| 40 |
|
| 41 |
public static final String TAXA = "taxa"; |
| 42 |
public static final String EXCLUDE = "exclude"; |
| 43 |
|
| 44 |
public String getParserName() { return TAXA; } |
| 45 |
|
| 46 |
public String getExample() { |
| 47 |
return "<!-- A list of six taxa -->\n"+ |
| 48 |
"<taxa id=\"greatApes\">\n"+ |
| 49 |
" <taxon id=\"human\"/>\n"+ |
| 50 |
" <taxon id=\"chimp\"/>\n"+ |
| 51 |
" <taxon id=\"bonobo\"/>\n"+ |
| 52 |
" <taxon id=\"gorilla\"/>\n"+ |
| 53 |
" <taxon id=\"orangutan\"/>\n"+ |
| 54 |
" <taxon id=\"siamang\"/>\n"+ |
| 55 |
"</taxa>\n" + |
| 56 |
"\n" + |
| 57 |
"<!-- A list of three taxa by references to above taxon objects -->\n"+ |
| 58 |
"<taxa id=\"humanAndChimps\">\n"+ |
| 59 |
" <taxon idref=\"human\"/>\n"+ |
| 60 |
" <taxon idref=\"chimp\"/>\n"+ |
| 61 |
" <taxon idref=\"bonobo\"/>\n"+ |
| 62 |
"</taxa>\n"; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 67 |
|
| 68 |
Taxa taxonList = new Taxa(); |
| 69 |
|
| 70 |
for (Taxon taxon : xo.getAllChildren(Taxon.class)) { |
| 71 |
taxonList.addTaxon(taxon); |
| 72 |
} |
| 73 |
|
| 74 |
for (Taxa taxa : xo.getAllChildren(Taxa.class)) { |
| 75 |
taxonList.addTaxa(taxa); |
| 76 |
} |
| 77 |
|
| 78 |
for (XMLObject cxo : xo.getAllChildren(EXCLUDE)) { |
| 79 |
for (Taxa exclude : cxo.getAllChildren(Taxa.class)) { |
| 80 |
taxonList.removeTaxa(exclude); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
return taxonList; |
| 85 |
} |
| 86 |
|
| 87 |
public XMLSyntaxRule[] getSyntaxRules() { return rules; } |
| 88 |
|
| 89 |
private final XMLSyntaxRule[] rules = { |
| 90 |
new OrRule( |
| 91 |
new ElementRule(Taxa.class, 1, Integer.MAX_VALUE), |
| 92 |
new ElementRule(Taxon.class, 1, Integer.MAX_VALUE) |
| 93 |
), |
| 94 |
new ElementRule("exclude", Taxa.class, "taxa to exclude", 0, Integer.MAX_VALUE) |
| 95 |
}; |
| 96 |
|
| 97 |
public String getParserDescription() { |
| 98 |
return "Defines a set of taxon objects."; |
| 99 |
} |
| 100 |
|
| 101 |
public Class getReturnType() { return Taxa.class; } |
| 102 |
} |
| 103 |
|
| 104 |
|