| 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.oldevomodel.indel; |
| 27 |
|
| 28 |
import dr.evolution.alignment.Alignment; |
| 29 |
import dr.oldevomodel.sitemodel.GammaSiteModel; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.oldevomodelxml.indel.TKF91LikelihoodParser; |
| 32 |
import dr.inference.model.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class TKF91Likelihood extends AbstractModelLikelihood { |
| 42 |
|
| 43 |
public TKF91Likelihood(TreeModel treeModel, Alignment alignment, GammaSiteModel siteModel, TKF91Model tkfModel) { |
| 44 |
|
| 45 |
super(TKF91LikelihoodParser.TKF91_LIKELIHOOD); |
| 46 |
|
| 47 |
if (siteModel.getAlphaParameter() != null) |
| 48 |
throw new IllegalArgumentException("TKF91 model cannot handle gamma-distributed rates"); |
| 49 |
if (siteModel.getPInvParameter() != null) |
| 50 |
throw new IllegalArgumentException("TKF91 model cannot handle invariant sites"); |
| 51 |
|
| 52 |
addModel(siteModel); |
| 53 |
addModel(tkfModel); |
| 54 |
addModel(treeModel); |
| 55 |
|
| 56 |
this.treeModel = treeModel; |
| 57 |
this.alignment = alignment; |
| 58 |
this.siteModel = siteModel; |
| 59 |
this.tkfModel = tkfModel; |
| 60 |
|
| 61 |
recursion = new HomologyRecursion(); |
| 62 |
recursion.init( |
| 63 |
treeModel, |
| 64 |
alignment, |
| 65 |
siteModel.getSubstitutionModel(), |
| 66 |
siteModel.getMutationRateParameter().getParameterValue(0), |
| 67 |
tkfModel.getLengthDistributionValue(), |
| 68 |
tkfModel.getDeathRate(1)); |
| 69 |
|
| 70 |
addStatistic(new AlignmentLengthStatistic()); |
| 71 |
} |
| 72 |
|
| 73 |
public class AlignmentLengthStatistic extends Statistic.Abstract { |
| 74 |
|
| 75 |
public double getStatisticValue(int dim) { |
| 76 |
return alignment.getSiteCount(); |
| 77 |
} |
| 78 |
|
| 79 |
public int getDimension() { |
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
public String getStatisticName() { |
| 84 |
return "alignmentLength"; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public void acceptState() { |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
public void handleModelChangedEvent(Model m, Object o, int i) { |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void setAlignment(Alignment a) { |
| 104 |
alignment = a; |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
protected void storeState() { |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
protected void restoreState() { |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
public Alignment getAlignment() { |
| 122 |
return alignment; |
| 123 |
} |
| 124 |
|
| 125 |
public GammaSiteModel getSiteModel() { |
| 126 |
return siteModel; |
| 127 |
} |
| 128 |
|
| 129 |
public TreeModel getTreeModel() { |
| 130 |
return treeModel; |
| 131 |
} |
| 132 |
|
| 133 |
public void makeDirty() { |
| 134 |
} |
| 135 |
|
| 136 |
public Model getModel() { |
| 137 |
return this; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public double getLogLikelihood() { |
| 146 |
|
| 147 |
recursion.init( |
| 148 |
treeModel, |
| 149 |
alignment, |
| 150 |
siteModel.getSubstitutionModel(), |
| 151 |
siteModel.getMutationRateParameter().getParameterValue(0), |
| 152 |
tkfModel.getLengthDistributionValue(), |
| 153 |
tkfModel.getDeathRate(1)); |
| 154 |
|
| 155 |
double logL = recursion.recursion(); |
| 156 |
|
| 157 |
|
| 158 |
return logL; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
private String id = null; |
| 166 |
|
| 167 |
public void setId(String id) { |
| 168 |
this.id = id; |
| 169 |
} |
| 170 |
|
| 171 |
public String getId() { |
| 172 |
return id; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
public String toString() { |
| 177 |
if (id != null) { |
| 178 |
return id; |
| 179 |
} |
| 180 |
return super.toString(); |
| 181 |
} |
| 182 |
|
| 183 |
protected boolean getLikelihoodKnown() { |
| 184 |
return false; |
| 185 |
} |
| 186 |
|
| 187 |
private final TreeModel treeModel; |
| 188 |
private Alignment alignment; |
| 189 |
|
| 190 |
private final GammaSiteModel siteModel; |
| 191 |
private final TKF91Model tkfModel; |
| 192 |
private HomologyRecursion recursion = null; |
| 193 |
} |