| 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.speciation; |
| 27 |
|
| 28 |
import dr.evolution.util.Units; |
| 29 |
import dr.evomodel.speciation.BirthDeathGernhard08Model; |
| 30 |
import dr.evoxml.util.XMLUnits; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
import java.util.logging.Logger; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class BirthDeathModelParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String BIRTH_DEATH_MODEL = "birthDeathModel"; |
| 43 |
public static final String BIRTHDIFF_RATE = "birthMinusDeathRate"; |
| 44 |
public static final String RELATIVE_DEATH_RATE = "relativeDeathRate"; |
| 45 |
public static final String SAMPLE_PROB = "sampleProbability"; |
| 46 |
public static final String TREE_TYPE = "type"; |
| 47 |
public static final String CONDITIONAL_ON_ROOT = "conditionalOnRoot"; |
| 48 |
|
| 49 |
public static final String BIRTH_DEATH = "birthDeath"; |
| 50 |
public static final String MEAN_GROWTH_RATE_PARAM_NAME = BIRTH_DEATH + ".meanGrowthRate"; |
| 51 |
public static final String RELATIVE_DEATH_RATE_PARAM_NAME = BIRTH_DEATH + "." + RELATIVE_DEATH_RATE; |
| 52 |
|
| 53 |
public String getParserName() { |
| 54 |
return BIRTH_DEATH_MODEL; |
| 55 |
} |
| 56 |
|
| 57 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 58 |
|
| 59 |
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 60 |
|
| 61 |
final String s = xo.getAttribute(TREE_TYPE, BirthDeathGernhard08Model.TreeType.UNSCALED.toString()); |
| 62 |
final BirthDeathGernhard08Model.TreeType treeType = BirthDeathGernhard08Model.TreeType.valueOf(s); |
| 63 |
final boolean conditonalOnRoot = xo.getAttribute(CONDITIONAL_ON_ROOT, false); |
| 64 |
|
| 65 |
final Parameter birthParameter = (Parameter) xo.getElementFirstChild(BIRTHDIFF_RATE); |
| 66 |
final Parameter deathParameter = (Parameter) xo.getElementFirstChild(RELATIVE_DEATH_RATE); |
| 67 |
final Parameter sampleProbability = xo.hasChildNamed(SAMPLE_PROB) ? |
| 68 |
(Parameter) xo.getElementFirstChild(SAMPLE_PROB) : null; |
| 69 |
|
| 70 |
Logger.getLogger("dr.evomodel").info(xo.hasChildNamed(SAMPLE_PROB) ? getCitationRHO() : getCitation()); |
| 71 |
|
| 72 |
final String modelName = xo.getId(); |
| 73 |
|
| 74 |
return new BirthDeathGernhard08Model(modelName, birthParameter, deathParameter, sampleProbability, |
| 75 |
treeType, units, conditonalOnRoot); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static String getCitationRHO() { |
| 82 |
return "Stadler, T; On incomplete sampling under birth-death models and connections to the sampling-based coalescent;\n" + |
| 83 |
"JOURNAL OF THEORETICAL BIOLOGY (2009) 261:58-66"; |
| 84 |
} |
| 85 |
|
| 86 |
public static String getCitation() { |
| 87 |
return "Using birth-death model on tree: Gernhard T (2008) J Theor Biol, Volume 253, Issue 4, Pages 769-778 In press"; |
| 88 |
} |
| 89 |
|
| 90 |
public String getParserDescription() { |
| 91 |
return "Gernhard (2008) model of speciation (equation at bottom of page 19 of draft)."; |
| 92 |
} |
| 93 |
|
| 94 |
public Class getReturnType() { |
| 95 |
return BirthDeathGernhard08Model.class; |
| 96 |
} |
| 97 |
|
| 98 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 99 |
return rules; |
| 100 |
} |
| 101 |
|
| 102 |
private final XMLSyntaxRule[] rules = { |
| 103 |
AttributeRule.newStringRule(TREE_TYPE, true), |
| 104 |
AttributeRule.newBooleanRule(CONDITIONAL_ON_ROOT, true), |
| 105 |
new ElementRule(BIRTHDIFF_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 106 |
new ElementRule(RELATIVE_DEATH_RATE, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 107 |
new ElementRule(SAMPLE_PROB, new XMLSyntaxRule[]{new ElementRule(Parameter.class)}, true), |
| 108 |
XMLUnits.SYNTAX_RULES[0] |
| 109 |
}; |
| 110 |
} |