| 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.oldevomodelxml.MSSD; |
| 27 |
|
| 28 |
import dr.oldevomodel.sitemodel.GammaSiteModel; |
| 29 |
import dr.oldevomodel.substmodel.SubstitutionModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
import java.util.logging.Logger; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class ALSSiteModelParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String ALS_SITE_MODEL = "alsSiteModel"; |
| 43 |
|
| 44 |
public static final String SUBSTITUTION_MODEL = "substitutionModel"; |
| 45 |
public static final String MUTATION_RATE = "mutationRate"; |
| 46 |
public static final String SUBSTITUTION_RATE = "substitutionRate"; |
| 47 |
public static final String RELATIVE_RATE = "relativeRate"; |
| 48 |
public static final String GAMMA_SHAPE = "gammaShape"; |
| 49 |
public static final String GAMMA_CATEGORIES = "gammaCategories"; |
| 50 |
public static final String PROPORTION_INVARIANT = "proportionInvariant"; |
| 51 |
|
| 52 |
|
| 53 |
public String[] getParserNames() { |
| 54 |
return new String[]{ |
| 55 |
getParserName(), "beast_" + getParserName() |
| 56 |
}; |
| 57 |
} |
| 58 |
|
| 59 |
public String getParserName() { |
| 60 |
return ALS_SITE_MODEL; |
| 61 |
} |
| 62 |
|
| 63 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 64 |
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL); |
| 65 |
|
| 66 |
String msg = ""; |
| 67 |
|
| 68 |
Parameter muParam = null; |
| 69 |
if (xo.hasChildNamed(SUBSTITUTION_RATE)) { |
| 70 |
muParam = (Parameter) xo.getElementFirstChild(SUBSTITUTION_RATE); |
| 71 |
|
| 72 |
msg += "\n with initial substitution rate = " + muParam.getParameterValue(0); |
| 73 |
} else if (xo.hasChildNamed(MUTATION_RATE)) { |
| 74 |
muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE); |
| 75 |
|
| 76 |
msg += "\n with initial substitution rate = " + muParam.getParameterValue(0); |
| 77 |
} else if (xo.hasChildNamed(RELATIVE_RATE)) { |
| 78 |
muParam = (Parameter) xo.getElementFirstChild(RELATIVE_RATE); |
| 79 |
|
| 80 |
msg += "\n with initial relative rate = " + muParam.getParameterValue(0); |
| 81 |
} |
| 82 |
|
| 83 |
Parameter shapeParam = null; |
| 84 |
int catCount = 4; |
| 85 |
if (xo.hasChildNamed(GAMMA_SHAPE)) { |
| 86 |
final XMLObject cxo = xo.getChild(GAMMA_SHAPE); |
| 87 |
catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES); |
| 88 |
shapeParam = (Parameter) cxo.getChild(Parameter.class); |
| 89 |
|
| 90 |
msg += "\n " + catCount + " category discrete gamma with initial shape = " + shapeParam.getParameterValue(0); |
| 91 |
} |
| 92 |
|
| 93 |
Parameter invarParam = null; |
| 94 |
if (xo.hasChildNamed(PROPORTION_INVARIANT)) { |
| 95 |
invarParam = (Parameter) xo.getElementFirstChild(PROPORTION_INVARIANT); |
| 96 |
msg += "\n initial proportion of invariant sites = " + invarParam.getParameterValue(0); |
| 97 |
} |
| 98 |
|
| 99 |
Logger.getLogger("dr.evomodel").info("Creating site model." + (msg.length() > 0 ? msg : "")); |
| 100 |
|
| 101 |
return new GammaSiteModel(substitutionModel, muParam, shapeParam, catCount, invarParam); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public String getParserDescription() { |
| 109 |
return "A SiteModel that has a gamma distributed rates across sites"; |
| 110 |
} |
| 111 |
|
| 112 |
public Class getReturnType() { |
| 113 |
return GammaSiteModel.class; |
| 114 |
} |
| 115 |
|
| 116 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 117 |
return rules; |
| 118 |
} |
| 119 |
|
| 120 |
private final XMLSyntaxRule[] rules = { |
| 121 |
new ElementRule(SUBSTITUTION_MODEL, new XMLSyntaxRule[]{ |
| 122 |
new ElementRule(SubstitutionModel.class) |
| 123 |
}), |
| 124 |
new XORRule( |
| 125 |
new XORRule( |
| 126 |
new ElementRule(SUBSTITUTION_RATE, new XMLSyntaxRule[]{ |
| 127 |
new ElementRule(Parameter.class) |
| 128 |
}), |
| 129 |
new ElementRule(MUTATION_RATE, new XMLSyntaxRule[]{ |
| 130 |
new ElementRule(Parameter.class) |
| 131 |
}) |
| 132 |
), |
| 133 |
new ElementRule(RELATIVE_RATE, new XMLSyntaxRule[]{ |
| 134 |
new ElementRule(Parameter.class) |
| 135 |
}), true |
| 136 |
), |
| 137 |
new ElementRule(GAMMA_SHAPE, new XMLSyntaxRule[]{ |
| 138 |
AttributeRule.newIntegerRule(GAMMA_CATEGORIES, true), |
| 139 |
new ElementRule(Parameter.class) |
| 140 |
}, true), |
| 141 |
new ElementRule(PROPORTION_INVARIANT, new XMLSyntaxRule[]{ |
| 142 |
new ElementRule(Parameter.class) |
| 143 |
}, true) |
| 144 |
}; |
| 145 |
} |