| 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 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings; |
| 30 |
import dr.evomodel.alloppnet.speciation.AlloppSpeciesNetworkModel; |
| 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 |
|
| 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 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public class AlloppSpeciesNetworkModelParser extends AbstractXMLObjectParser { |
| 92 |
public static final String ALLOPPSPECIESNETWORK = "alloppSpeciesNetwork"; |
| 93 |
public static final String ONEHYBRIDIZATION = "oneHybridization"; |
| 94 |
public static final String DIPLOIDROOT_ISROOT = "diploidRootIsRoot"; |
| 95 |
public static final String TIP_POPULATIONS = "tipPopulations"; |
| 96 |
public static final String ROOT_POPULATIONS = "rootPopulations"; |
| 97 |
public static final String HYBRID_POPULATIONS = "hybridPopulations"; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public String getParserName() { |
| 103 |
return ALLOPPSPECIESNETWORK; |
| 104 |
} |
| 105 |
|
| 106 |
@Override |
| 107 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 108 |
AlloppSpeciesBindings apspb = (AlloppSpeciesBindings) xo.getChild(AlloppSpeciesBindings.class); |
| 109 |
boolean onehyb = xo.getBooleanAttribute(ONEHYBRIDIZATION); |
| 110 |
boolean diprootisroot = xo.getBooleanAttribute(DIPLOIDROOT_ISROOT); |
| 111 |
|
| 112 |
final XMLObject tippopxo = xo.getChild(TIP_POPULATIONS); |
| 113 |
final double tippopvalue = tippopxo.getAttribute(Attributable.VALUE, 1.0); |
| 114 |
final XMLObject rootpopxo = xo.getChild(ROOT_POPULATIONS); |
| 115 |
final double rootpopvalue = rootpopxo.getAttribute(Attributable.VALUE, 1.0); |
| 116 |
final XMLObject hybpopxo = xo.getChild(HYBRID_POPULATIONS); |
| 117 |
final double hybpopvalue = hybpopxo.getAttribute(Attributable.VALUE, 1.0); |
| 118 |
|
| 119 |
AlloppSpeciesNetworkModel asnm = new AlloppSpeciesNetworkModel(apspb, |
| 120 |
tippopvalue, rootpopvalue, hybpopvalue, onehyb, diprootisroot); |
| 121 |
|
| 122 |
ParameterParser.replaceParameter(tippopxo, asnm.tippopvalues); |
| 123 |
final Parameter.DefaultBounds tippopbounds = |
| 124 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.tippopvalues.getDimension()); |
| 125 |
asnm.tippopvalues.addBounds(tippopbounds); |
| 126 |
|
| 127 |
ParameterParser.replaceParameter(rootpopxo, asnm.rootpopvalues); |
| 128 |
final Parameter.DefaultBounds rootpopbounds = |
| 129 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.rootpopvalues.getDimension()); |
| 130 |
asnm.rootpopvalues.addBounds(rootpopbounds); |
| 131 |
|
| 132 |
ParameterParser.replaceParameter(hybpopxo, asnm.logginghybpopvalues); |
| 133 |
final Parameter.DefaultBounds hybpopbounds = |
| 134 |
new Parameter.DefaultBounds(Double.MAX_VALUE, 0, asnm.logginghybpopvalues.getDimension()); |
| 135 |
asnm.logginghybpopvalues.addBounds(hybpopbounds); |
| 136 |
|
| 137 |
return asnm; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
private ElementRule tippopElementRule() { |
| 142 |
return new ElementRule(TIP_POPULATIONS, new XMLSyntaxRule[]{ |
| 143 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 144 |
new ElementRule(Parameter.class)}); |
| 145 |
} |
| 146 |
|
| 147 |
private ElementRule rootpopElementRule() { |
| 148 |
return new ElementRule(ROOT_POPULATIONS, new XMLSyntaxRule[]{ |
| 149 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 150 |
new ElementRule(Parameter.class)}); |
| 151 |
} |
| 152 |
private ElementRule hybpopElementRule() { |
| 153 |
return new ElementRule(HYBRID_POPULATIONS, new XMLSyntaxRule[]{ |
| 154 |
AttributeRule.newDoubleRule(Attributable.VALUE, true), |
| 155 |
new ElementRule(Parameter.class)}); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
@Override |
| 161 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 162 |
return new XMLSyntaxRule[]{ |
| 163 |
AttributeRule.newBooleanRule(ONEHYBRIDIZATION, true), |
| 164 |
AttributeRule.newBooleanRule(DIPLOIDROOT_ISROOT, true), |
| 165 |
new ElementRule(AlloppSpeciesBindings.class), |
| 166 |
tippopElementRule(), |
| 167 |
rootpopElementRule(), |
| 168 |
hybpopElementRule() |
| 169 |
}; |
| 170 |
} |
| 171 |
|
| 172 |
@Override |
| 173 |
public String getParserDescription() { |
| 174 |
return "Species network with population sizes along branches"; |
| 175 |
} |
| 176 |
|
| 177 |
@Override |
| 178 |
public Class getReturnType() { |
| 179 |
return AlloppSpeciesNetworkModel.class; |
| 180 |
} |
| 181 |
|
| 182 |
} |