| 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.MutableTree; |
| 29 |
import dr.evomodelxml.tree.TreeModelParser; |
| 30 |
import dr.inference.model.CompoundParameter; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class LeafTraitExtractorParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String NAME = "leafTraitParameter"; |
| 40 |
public static final String SET_BOUNDS = "setBounds"; |
| 41 |
|
| 42 |
@Override |
| 43 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 44 |
|
| 45 |
MutableTree model = (MutableTree) xo.getChild(MutableTree.class); |
| 46 |
final CompoundParameter allTraits = (CompoundParameter) xo.getChild(CompoundParameter.class); |
| 47 |
|
| 48 |
String taxonString = (String) xo.getAttribute(TreeModelParser.TAXON); |
| 49 |
final int leafIndex = model.getTaxonIndex(taxonString); |
| 50 |
if (leafIndex == -1) { |
| 51 |
throw new XMLParseException("Unable to find taxon '" + taxonString + "' in trees."); |
| 52 |
} |
| 53 |
final Parameter leafTrait = allTraits.getParameter(leafIndex); |
| 54 |
|
| 55 |
boolean setBounds = xo.getAttribute(SET_BOUNDS, true); |
| 56 |
if (setBounds) { |
| 57 |
|
| 58 |
Parameter.DefaultBounds bound = new Parameter.DefaultBounds(Double.MAX_VALUE, -Double.MAX_VALUE, |
| 59 |
leafTrait.getDimension()); |
| 60 |
leafTrait.addBounds(bound); |
| 61 |
} |
| 62 |
|
| 63 |
return leafTrait; |
| 64 |
} |
| 65 |
|
| 66 |
@Override |
| 67 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 68 |
return new XMLSyntaxRule[]{ |
| 69 |
AttributeRule.newStringRule(TreeModelParser.TAXON), |
| 70 |
AttributeRule.newBooleanRule(SET_BOUNDS, true), |
| 71 |
new ElementRule(MutableTree.class), |
| 72 |
new ElementRule(CompoundParameter.class), |
| 73 |
}; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public String getParserDescription() { |
| 78 |
return "Parses the leaf trait parameter out of the compound parameter of an integrated trait likelihood"; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public Class getReturnType() { |
| 83 |
return Parameter.class; |
| 84 |
} |
| 85 |
|
| 86 |
public String getParserName() { |
| 87 |
return NAME; |
| 88 |
} |
| 89 |
} |