| 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.tree.Tree; |
| 29 |
import dr.evomodel.speciation.SpeciesBindings; |
| 30 |
import dr.evomodel.speciation.SpeciesTreeModel; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.inference.model.ParameterParser; |
| 33 |
import dr.util.Attributable; |
| 34 |
import dr.xml.*; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class SpeciesTreeModelParser extends AbstractXMLObjectParser { |
| 39 |
public static final String SPECIES_TREE = "speciesTree"; |
| 40 |
|
| 41 |
public static final String SPP_SPLIT_POPULATIONS = "sppSplitPopulations"; |
| 42 |
public static final String COALESCENT_POINTS_POPULATIONS = "coalescentPointsPopulations"; |
| 43 |
public static final String COALESCENT_POINTS_INDICATORS = "coalescentPointsIndicators"; |
| 44 |
|
| 45 |
public static final String BMPRIOR = "bmPrior"; |
| 46 |
public static final String CONST_ROOT_POPULATION = "constantRoot"; |
| 47 |
public static final String CONSTANT_POPULATION = "constantPopulation"; |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
SpeciesBindings spb = (SpeciesBindings) xo.getChild(SpeciesBindings.class); |
| 51 |
|
| 52 |
Parameter coalPointsPops = null; |
| 53 |
Parameter coalPointsIndicators = null; |
| 54 |
final Boolean cr = xo.getAttribute(CONST_ROOT_POPULATION, false); |
| 55 |
final Boolean cp = xo.getAttribute(CONSTANT_POPULATION, false); |
| 56 |
|
| 57 |
final Boolean bmp = xo.getAttribute(BMPRIOR, false); |
| 58 |
{ |
| 59 |
XMLObject cxo = xo.getChild(COALESCENT_POINTS_POPULATIONS); |
| 60 |
if( cxo != null ) { |
| 61 |
final double value = cxo.getAttribute(Attributable.VALUE, 1.0); |
| 62 |
coalPointsPops = SpeciesTreeModel.createCoalPointsPopParameter(spb, cxo.getAttribute(Attributable.VALUE, value), bmp); |
| 63 |
ParameterParser.replaceParameter(cxo, coalPointsPops); |
| 64 |
coalPointsPops.addBounds( |
| 65 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, coalPointsPops.getDimension())); |
| 66 |
|
| 67 |
cxo = xo.getChild(COALESCENT_POINTS_INDICATORS); |
| 68 |
if( cxo == null ) { |
| 69 |
throw new XMLParseException("Must have indicators"); |
| 70 |
} |
| 71 |
coalPointsIndicators = new Parameter.Default(coalPointsPops.getDimension(), 0); |
| 72 |
ParameterParser.replaceParameter(cxo, coalPointsIndicators); |
| 73 |
} else { |
| 74 |
|
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
final XMLObject cxo = xo.getChild(SPP_SPLIT_POPULATIONS); |
| 79 |
|
| 80 |
final double value = cxo.getAttribute(Attributable.VALUE, 1.0); |
| 81 |
final boolean nonConstRootPopulation = coalPointsPops == null && !cr; |
| 82 |
final Parameter sppSplitPopulations = SpeciesTreeModel.createSplitPopulationsParameter(spb, value, nonConstRootPopulation, cp); |
| 83 |
ParameterParser.replaceParameter(cxo, sppSplitPopulations); |
| 84 |
|
| 85 |
final Parameter.DefaultBounds bounds = |
| 86 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, sppSplitPopulations.getDimension()); |
| 87 |
sppSplitPopulations.addBounds(bounds); |
| 88 |
|
| 89 |
final Tree startTree = (Tree) xo.getChild(Tree.class); |
| 90 |
|
| 91 |
return new SpeciesTreeModel(spb, sppSplitPopulations, coalPointsPops, coalPointsIndicators, startTree, bmp, |
| 92 |
nonConstRootPopulation, cp); |
| 93 |
} |
| 94 |
|
| 95 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 96 |
return new XMLSyntaxRule[]{ |
| 97 |
AttributeRule.newBooleanRule(BMPRIOR, true), |
| 98 |
AttributeRule.newBooleanRule(CONST_ROOT_POPULATION, true), |
| 99 |
AttributeRule.newBooleanRule(CONSTANT_POPULATION, true), |
| 100 |
new ElementRule(SpeciesBindings.class), |
| 101 |
|
| 102 |
new ElementRule(Tree.class, true), |
| 103 |
new ElementRule(SPP_SPLIT_POPULATIONS, new XMLSyntaxRule[]{ |
| 104 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 105 |
new ElementRule(Parameter.class)}), |
| 106 |
|
| 107 |
new ElementRule(COALESCENT_POINTS_POPULATIONS, new XMLSyntaxRule[]{ |
| 108 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 109 |
new ElementRule(Parameter.class)}, true), |
| 110 |
|
| 111 |
new ElementRule(COALESCENT_POINTS_INDICATORS, new XMLSyntaxRule[]{ |
| 112 |
new ElementRule(Parameter.class)}, true), |
| 113 |
}; |
| 114 |
} |
| 115 |
|
| 116 |
public String getParserDescription() { |
| 117 |
return "Species tree which includes demographic function per branch."; |
| 118 |
} |
| 119 |
|
| 120 |
public Class getReturnType() { |
| 121 |
return SpeciesTreeModel.class; |
| 122 |
} |
| 123 |
|
| 124 |
public String getParserName() { |
| 125 |
return SPECIES_TREE; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
} |