| 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.treelikelihood; |
| 27 |
|
| 28 |
import dr.evomodel.branchmodel.BranchModel; |
| 29 |
import dr.evomodel.siteratemodel.GammaSiteRateModel; |
| 30 |
import dr.evomodel.substmodel.FrequencyModel; |
| 31 |
import dr.evomodel.substmodel.SubstitutionModel; |
| 32 |
import dr.evomodel.treelikelihood.AncestralStateBeagleTreeLikelihood; |
| 33 |
import dr.evomodel.treelikelihood.BeagleTreeLikelihood; |
| 34 |
import dr.evomodel.treelikelihood.PartialsRescalingScheme; |
| 35 |
import dr.evolution.alignment.PatternList; |
| 36 |
import dr.evolution.datatype.DataType; |
| 37 |
import dr.evolution.util.TaxonList; |
| 38 |
import dr.evomodel.branchratemodel.BranchRateModel; |
| 39 |
import dr.evomodel.tree.TreeModel; |
| 40 |
import dr.oldevomodel.treelikelihood.AncestralStateTreeLikelihood; |
| 41 |
import dr.evomodel.tipstatesmodel.TipStatesModel; |
| 42 |
import dr.inference.model.Parameter; |
| 43 |
import dr.xml.*; |
| 44 |
|
| 45 |
import java.util.Map; |
| 46 |
import java.util.Set; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public class AncestralStateTreeLikelihoodParser extends BeagleTreeLikelihoodParser { |
| 54 |
|
| 55 |
public static final String RECONSTRUCTING_TREE_LIKELIHOOD = "ancestralTreeLikelihood"; |
| 56 |
public static final String RECONSTRUCTION_TAG = AncestralStateTreeLikelihood.STATES_KEY; |
| 57 |
public static final String RECONSTRUCTION_TAG_NAME = "stateTagName"; |
| 58 |
public static final String MAP_RECONSTRUCTION = "useMAP"; |
| 59 |
public static final String MARGINAL_LIKELIHOOD = "useMarginalLikelihood"; |
| 60 |
|
| 61 |
public String getParserName() { |
| 62 |
return RECONSTRUCTING_TREE_LIKELIHOOD; |
| 63 |
} |
| 64 |
|
| 65 |
protected BeagleTreeLikelihood createTreeLikelihood( |
| 66 |
PatternList patternList, |
| 67 |
TreeModel treeModel, |
| 68 |
BranchModel branchModel, |
| 69 |
GammaSiteRateModel siteRateModel, |
| 70 |
BranchRateModel branchRateModel, |
| 71 |
TipStatesModel tipStatesModel, |
| 72 |
boolean useAmbiguities, |
| 73 |
PartialsRescalingScheme scalingScheme, |
| 74 |
boolean delayScaling, |
| 75 |
Map<Set<String>, |
| 76 |
Parameter> partialsRestrictions, |
| 77 |
XMLObject xo |
| 78 |
) throws XMLParseException { |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
DataType dataType = branchModel.getRootSubstitutionModel().getDataType(); |
| 84 |
|
| 85 |
|
| 86 |
String tag = xo.getAttribute(RECONSTRUCTION_TAG_NAME, RECONSTRUCTION_TAG); |
| 87 |
|
| 88 |
boolean useMAP = xo.getAttribute(MAP_RECONSTRUCTION, false); |
| 89 |
boolean useMarginalLogLikelihood = xo.getAttribute(MARGINAL_LIKELIHOOD, true); |
| 90 |
|
| 91 |
if (patternList.areUnique()) { |
| 92 |
throw new XMLParseException("Ancestral state reconstruction cannot be used with compressed (unique) patterns."); |
| 93 |
} |
| 94 |
|
| 95 |
return new AncestralStateBeagleTreeLikelihood( |
| 96 |
patternList, |
| 97 |
treeModel, |
| 98 |
branchModel, |
| 99 |
siteRateModel, |
| 100 |
branchRateModel, |
| 101 |
tipStatesModel, |
| 102 |
useAmbiguities, |
| 103 |
scalingScheme, |
| 104 |
delayScaling, |
| 105 |
partialsRestrictions, |
| 106 |
dataType, |
| 107 |
tag, |
| 108 |
useMAP, |
| 109 |
useMarginalLogLikelihood |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 114 |
return new XMLSyntaxRule[] { |
| 115 |
AttributeRule.newBooleanRule(BeagleTreeLikelihoodParser.USE_AMBIGUITIES, true), |
| 116 |
AttributeRule.newStringRule(RECONSTRUCTION_TAG_NAME, true), |
| 117 |
new ElementRule(PatternList.class), |
| 118 |
new ElementRule(TreeModel.class), |
| 119 |
new ElementRule(GammaSiteRateModel.class), |
| 120 |
new ElementRule(BranchModel.class, true), |
| 121 |
new ElementRule(BranchRateModel.class, true), |
| 122 |
new ElementRule(TipStatesModel.class, true), |
| 123 |
new ElementRule(SubstitutionModel.class, true), |
| 124 |
AttributeRule.newStringRule(BeagleTreeLikelihoodParser.SCALING_SCHEME,true), |
| 125 |
AttributeRule.newStringRule(BeagleTreeLikelihoodParser.DELAY_SCALING,true), |
| 126 |
new ElementRule(PARTIALS_RESTRICTION, new XMLSyntaxRule[] { |
| 127 |
new ElementRule(TaxonList.class), |
| 128 |
new ElementRule(Parameter.class), |
| 129 |
}, true), |
| 130 |
new ElementRule(FrequencyModel.class, true), |
| 131 |
}; |
| 132 |
} |
| 133 |
} |