| 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 |
import dr.evolution.util.Units; |
| 29 |
import dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel; |
| 30 |
import dr.evoxml.util.XMLUnits; |
| 31 |
import dr.inference.model.Parameter; |
| 32 |
import dr.inference.distribution.ParametricDistributionModel; |
| 33 |
import dr.xml.AbstractXMLObjectParser; |
| 34 |
import dr.xml.ElementRule; |
| 35 |
import dr.xml.XMLObject; |
| 36 |
import dr.xml.XMLParseException; |
| 37 |
import dr.xml.XMLSyntaxRule; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public class AlloppNetworkPriorModelParser extends AbstractXMLObjectParser { |
| 87 |
|
| 88 |
public static final String ALLOPPNETWORKPRIORMODEL = "alloppNetworkPriorModel"; |
| 89 |
public static final String EVENTRATE = "eventRate"; |
| 90 |
public static final String POPULATION_SCALING_FACTOR = "populationScalingFactor"; |
| 91 |
public static final String TIP_POPULATION_DISTRIBUTION = "tipPopulationDistribution"; |
| 92 |
public static final String ROOT_POPULATION_DISTRIBUTION = "rootPopulationDistribution"; |
| 93 |
public static final String HYBRID_POPULATION_DISTRIBUTION = "hybridPopulationDistribution"; |
| 94 |
|
| 95 |
|
| 96 |
public String getParserName() { |
| 97 |
return ALLOPPNETWORKPRIORMODEL; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Override |
| 103 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 104 |
final Units.Type units = XMLUnits.Utils.getUnitsAttr(xo); |
| 105 |
final XMLObject erXo = xo.getChild(EVENTRATE); |
| 106 |
final Parameter eventrate = (Parameter) erXo.getChild(Parameter.class); |
| 107 |
final XMLObject psfXo = xo.getChild(POPULATION_SCALING_FACTOR); |
| 108 |
final Parameter popscalingfactor = (Parameter) psfXo.getChild(Parameter.class); |
| 109 |
final XMLObject tpdXo = xo.getChild(TIP_POPULATION_DISTRIBUTION); |
| 110 |
ParametricDistributionModel tippopmodel = (ParametricDistributionModel) tpdXo.getChild(ParametricDistributionModel.class); |
| 111 |
final XMLObject rpdXo = xo.getChild(ROOT_POPULATION_DISTRIBUTION); |
| 112 |
ParametricDistributionModel rootpopmodel = (ParametricDistributionModel) rpdXo.getChild(ParametricDistributionModel.class); |
| 113 |
final XMLObject hpdXo = xo.getChild(HYBRID_POPULATION_DISTRIBUTION); |
| 114 |
ParametricDistributionModel hybpopmodel = (ParametricDistributionModel) hpdXo.getChild(ParametricDistributionModel.class); |
| 115 |
return new AlloppNetworkPriorModel(eventrate, popscalingfactor, tippopmodel, rootpopmodel, hybpopmodel, units); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
private XMLSyntaxRule[] eventrateRules() { |
| 121 |
return new XMLSyntaxRule[]{ |
| 122 |
new ElementRule(Parameter.class) |
| 123 |
}; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
private XMLSyntaxRule[] popscalingfactorRules() { |
| 128 |
return new XMLSyntaxRule[]{ |
| 129 |
new ElementRule(Parameter.class) |
| 130 |
}; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
private XMLSyntaxRule[] tippopmodelRules() { |
| 135 |
return new XMLSyntaxRule[]{ |
| 136 |
new ElementRule(ParametricDistributionModel.class) |
| 137 |
}; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
private XMLSyntaxRule[] rootpopmodelRules() { |
| 143 |
return new XMLSyntaxRule[]{ |
| 144 |
new ElementRule(ParametricDistributionModel.class) |
| 145 |
}; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
private XMLSyntaxRule[] hybpopmodelRules() { |
| 150 |
return new XMLSyntaxRule[]{ |
| 151 |
new ElementRule(ParametricDistributionModel.class) |
| 152 |
}; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
@Override |
| 157 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 158 |
return new XMLSyntaxRule[]{ |
| 159 |
XMLUnits.SYNTAX_RULES[0], |
| 160 |
new ElementRule(EVENTRATE, eventrateRules()), |
| 161 |
new ElementRule(POPULATION_SCALING_FACTOR, popscalingfactorRules()), |
| 162 |
new ElementRule(TIP_POPULATION_DISTRIBUTION, tippopmodelRules()), |
| 163 |
new ElementRule(ROOT_POPULATION_DISTRIBUTION, rootpopmodelRules()), |
| 164 |
new ElementRule(HYBRID_POPULATION_DISTRIBUTION, hybpopmodelRules()) |
| 165 |
}; |
| 166 |
} |
| 167 |
|
| 168 |
@Override |
| 169 |
public String getParserDescription() { |
| 170 |
return "Model for speciation, extinction, hybridization in allopolyploid network."; |
| 171 |
} |
| 172 |
|
| 173 |
@Override |
| 174 |
public Class getReturnType() { |
| 175 |
return AlloppNetworkPriorModel.class; |
| 176 |
} |
| 177 |
|
| 178 |
} |