| 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.evomodel.alloppnet.parsers; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
import dr.evolution.tree.Tree; |
| 35 |
import dr.evolution.util.Units; |
| 36 |
import dr.evomodel.alloppnet.speciation.BirthDeathCollapseModel; |
| 37 |
import dr.evoxml.util.XMLUnits; |
| 38 |
import dr.inference.model.Parameter; |
| 39 |
import dr.xml.*; |
| 40 |
|
| 41 |
|
| 42 |
import static dr.xml.AttributeRule.newDoubleRule; |
| 43 |
|
| 44 |
|
| 45 |
public class BirthDeathCollapseModelParser extends AbstractXMLObjectParser { |
| 46 |
|
| 47 |
public static final String BIRTH_DEATH_COLLAPSE_MODEL = "birthDeathCollapseModel"; |
| 48 |
|
| 49 |
public static final String COLLAPSE_HEIGHT = "collapseHeight"; |
| 50 |
|
| 51 |
public static final String TREE = "speciesTree"; |
| 52 |
|
| 53 |
public static final String BIRTHDIFF_RATE = "birthMinusDeathRate"; |
| 54 |
public static final String RELATIVE_DEATH_RATE = "relativeDeathRate"; |
| 55 |
public static final String ORIGIN_HEIGHT = "originHeight"; |
| 56 |
public static final String COLLAPSE_WEIGHT = "collapseWeight"; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public String getParserName() { |
| 61 |
return BIRTH_DEATH_COLLAPSE_MODEL; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 66 |
|
| 67 |
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 68 |
|
| 69 |
final double collH = xo.getDoubleAttribute(COLLAPSE_HEIGHT); |
| 70 |
|
| 71 |
XMLObject cxo = xo.getChild(TREE); |
| 72 |
final Tree tree = (Tree) cxo.getChild(Tree.class); |
| 73 |
|
| 74 |
final Parameter birthMinusDeath = (Parameter) xo.getElementFirstChild(BIRTHDIFF_RATE); |
| 75 |
final Parameter relativeDeathRate = (Parameter) xo.getElementFirstChild(RELATIVE_DEATH_RATE); |
| 76 |
final Parameter originHeight = (Parameter) xo.getElementFirstChild(ORIGIN_HEIGHT); |
| 77 |
final Parameter collapseWeight = (Parameter) xo.getElementFirstChild(COLLAPSE_WEIGHT); |
| 78 |
|
| 79 |
final String modelName = xo.getId(); |
| 80 |
|
| 81 |
return new BirthDeathCollapseModel(modelName, tree, units, |
| 82 |
birthMinusDeath, relativeDeathRate, originHeight, collapseWeight, collH); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public Class getReturnType() { |
| 90 |
return BirthDeathCollapseModel.class; |
| 91 |
} |
| 92 |
|
| 93 |
public String getParserDescription() { |
| 94 |
return "A speciation model aimed at species delimitation, mixing birth-death model with spike near zero for node heights."; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 99 |
return rules; |
| 100 |
} |
| 101 |
|
| 102 |
private final XMLSyntaxRule[] rules = { |
| 103 |
new ElementRule(TREE, new XMLSyntaxRule[]{new ElementRule(Tree.class)}), |
| 104 |
new ElementRule(BIRTHDIFF_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 105 |
new ElementRule(RELATIVE_DEATH_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 106 |
new ElementRule(ORIGIN_HEIGHT, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 107 |
new ElementRule(COLLAPSE_WEIGHT, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 108 |
XMLUnits.SYNTAX_RULES[0], |
| 109 |
newDoubleRule(COLLAPSE_HEIGHT), |
| 110 |
}; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|