| 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.clock; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodel.branchratemodel.AbstractBranchRateModel; |
| 31 |
import dr.inference.model.Model; |
| 32 |
import dr.inference.model.Parameter; |
| 33 |
import dr.inference.model.Variable; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class UniversalClock extends AbstractBranchRateModel { |
| 43 |
|
| 44 |
public static final String UNIVERSAL_CLOCK = "universalClock"; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public UniversalClock( |
| 55 |
Parameter rateParameter, |
| 56 |
Parameter massParameter, |
| 57 |
Parameter temperatureParameter, |
| 58 |
Parameter scaleParameter |
| 59 |
) { |
| 60 |
|
| 61 |
super(UNIVERSAL_CLOCK); |
| 62 |
|
| 63 |
this.rateParameter = rateParameter; |
| 64 |
this.massParameter = massParameter; |
| 65 |
this.temperatureParameter = temperatureParameter; |
| 66 |
this.scaleParameter = scaleParameter; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
addVariable(massParameter); |
| 71 |
addVariable(temperatureParameter); |
| 72 |
addVariable(scaleParameter); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 85 |
|
| 86 |
if ((variable == massParameter) || (variable == temperatureParameter)) { |
| 87 |
if (index == -1) { |
| 88 |
calculateAllRates(); |
| 89 |
} else calculateRate(index); |
| 90 |
} else if (variable == scaleParameter) { |
| 91 |
calculateAllRates(); |
| 92 |
} else { |
| 93 |
throw new RuntimeException("unknown parameter changed in " + UNIVERSAL_CLOCK); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
protected void storeState() { |
| 98 |
} |
| 99 |
|
| 100 |
protected void restoreState() { |
| 101 |
} |
| 102 |
|
| 103 |
protected void acceptState() { |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
private void calculateAllRates() { |
| 111 |
int numNodes = massParameter.getDimension(); |
| 112 |
for (int i = 0; i < numNodes; i++) { |
| 113 |
calculateRate(i); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
private void calculateRate(int index) { |
| 118 |
|
| 119 |
double mass = massParameter.getParameterValue(index); |
| 120 |
double temperature = temperatureParameter.getParameterValue(index); |
| 121 |
|
| 122 |
double scale = scaleParameter.getParameterValue(0); |
| 123 |
|
| 124 |
|
| 125 |
double substitutionRate = scale * Math.pow(mass, -0.25) * Math.exp(temperature); |
| 126 |
|
| 127 |
rateParameter.setParameterValue(index, substitutionRate); |
| 128 |
} |
| 129 |
|
| 130 |
public double getBranchRate(Tree tree, NodeRef node) { |
| 131 |
throw new RuntimeException("Look at code before running this class!"); |
| 132 |
} |
| 133 |
|
| 134 |
Parameter rateParameter = null; |
| 135 |
Parameter massParameter = null; |
| 136 |
Parameter temperatureParameter = null; |
| 137 |
Parameter scaleParameter = null; |
| 138 |
|
| 139 |
} |
| 140 |
|