| 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.sitemodel; |
| 27 |
|
| 28 |
import dr.xml.*; |
| 29 |
import dr.evomodel.branchratemodel.DiscretizedBranchRates; |
| 30 |
import dr.oldevomodel.sitemodel.DiscretizedLociRates; |
| 31 |
import dr.inference.distribution.ParametricDistributionModel; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.inference.model.CompoundParameter; |
| 34 |
|
| 35 |
import java.util.logging.Logger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class DiscretizedLociRatesParser extends AbstractXMLObjectParser { |
| 42 |
public final String DISCRETIZED_LOCI_RATES = "DiscretizedLociRates"; |
| 43 |
public final String NORMALIZE = "normalize"; |
| 44 |
public final String NORMALIZE_MEAN_LOCI_RATE_TO = "normalizeMeanLociRateTo"; |
| 45 |
public final String RATE_CATEGORIES = "rateCategories"; |
| 46 |
public final String CATEGORY_COUNT = "categoryCount"; |
| 47 |
public final String LOCI_RATES = "lociRates"; |
| 48 |
public final String DISTRIBUTION = "distribution"; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public String getParserName(){ |
| 53 |
return DISCRETIZED_LOCI_RATES; |
| 54 |
} |
| 55 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 56 |
|
| 57 |
|
| 58 |
final boolean normalize = xo.getAttribute(NORMALIZE, false); |
| 59 |
final double normalizeBranchRateTo = xo.getAttribute(NORMALIZE_MEAN_LOCI_RATE_TO, Double.NaN); |
| 60 |
final int categoryCount = xo.getIntegerAttribute(CATEGORY_COUNT); |
| 61 |
|
| 62 |
CompoundParameter lociRates = (CompoundParameter) xo.getElementFirstChild(LOCI_RATES); |
| 63 |
Parameter rateCategoryParameter = (Parameter) xo.getElementFirstChild(RATE_CATEGORIES); |
| 64 |
ParametricDistributionModel distributionModel = (ParametricDistributionModel) xo.getElementFirstChild(DISTRIBUTION); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
Logger.getLogger("dr.evomodel").info("Using discretized loci rates model."); |
| 69 |
Logger.getLogger("dr.evomodel").info("Number of categories: "+categoryCount); |
| 70 |
Logger.getLogger("dr.evomodel").info(" parametric model = " + distributionModel.getModelName()); |
| 71 |
if(normalize) { |
| 72 |
Logger.getLogger("dr.evomodel").info(" mean rate is normalized to " + normalizeBranchRateTo); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
return new DiscretizedLociRates( |
| 77 |
lociRates, |
| 78 |
rateCategoryParameter, |
| 79 |
distributionModel, |
| 80 |
normalize, |
| 81 |
normalizeBranchRateTo, |
| 82 |
categoryCount); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public String getParserDescription() { |
| 90 |
return |
| 91 |
"This element returns an discretized loci rate model." + |
| 92 |
"The loci rates are drawn from a discretized parametric distribution."; |
| 93 |
} |
| 94 |
|
| 95 |
public Class getReturnType() { |
| 96 |
return DiscretizedBranchRates.class; |
| 97 |
} |
| 98 |
|
| 99 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 100 |
return rules; |
| 101 |
} |
| 102 |
|
| 103 |
private final XMLSyntaxRule[] rules = { |
| 104 |
AttributeRule.newBooleanRule(NORMALIZE, true, "Whether the mean rate has to be normalized to a particular value"), |
| 105 |
AttributeRule.newDoubleRule(NORMALIZE_MEAN_LOCI_RATE_TO, true, "The mean rate to normalize to, if normalizing"), |
| 106 |
AttributeRule.newIntegerRule(CATEGORY_COUNT, true, "The number of categories that the distribution will be divided into"), |
| 107 |
new ElementRule(LOCI_RATES, CompoundParameter.class, "The compound parameter that contains all the loci rate parameters", false), |
| 108 |
new ElementRule(DISTRIBUTION, ParametricDistributionModel.class, "The distribution model for rates among branches", false), |
| 109 |
new ElementRule(RATE_CATEGORIES, Parameter.class, "The rate categories parameter", false), |
| 110 |
}; |
| 111 |
} |