| 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.evomodel.arg; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodel.arg.ARGModel.Node; |
| 31 |
import dr.evomodel.branchratemodel.AbstractBranchRateModel; |
| 32 |
import dr.inference.model.Model; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
import dr.inference.model.Variable; |
| 35 |
import dr.inference.model.Variable.ChangeType; |
| 36 |
import dr.xml.*; |
| 37 |
|
| 38 |
public class ARGRelaxedClock extends AbstractBranchRateModel { |
| 39 |
|
| 40 |
public static final String ARG_LOCAL_CLOCK = "argLocalClock"; |
| 41 |
public static final String PARTITION = "partition"; |
| 42 |
|
| 43 |
private Parameter globalRateParameter; |
| 44 |
|
| 45 |
private ARGModel arg; |
| 46 |
private int partition; |
| 47 |
|
| 48 |
|
| 49 |
public ARGRelaxedClock(String name) { |
| 50 |
super(name); |
| 51 |
} |
| 52 |
|
| 53 |
public ARGRelaxedClock(String name, ARGModel arg, int partition, Parameter rate) { |
| 54 |
super(name); |
| 55 |
|
| 56 |
this.arg = arg; |
| 57 |
this.partition = partition; |
| 58 |
|
| 59 |
globalRateParameter = rate; |
| 60 |
|
| 61 |
addModel(arg); |
| 62 |
addVariable(rate); |
| 63 |
} |
| 64 |
|
| 65 |
protected void acceptState() { |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
protected void handleVariableChangedEvent(Variable variable, int index, ChangeType type) { |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
protected void restoreState() { |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
protected void storeState() { |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
public double getBranchRate(Tree tree, NodeRef nodeRef) { |
| 89 |
|
| 90 |
Node treeNode = (Node) nodeRef; |
| 91 |
Node argNode = (Node) treeNode.mirrorNode; |
| 92 |
|
| 93 |
|
| 94 |
return globalRateParameter.getParameterValue(0) * argNode.getRate(partition); |
| 95 |
} |
| 96 |
|
| 97 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 98 |
|
| 99 |
public String getParserDescription() { |
| 100 |
return null; |
| 101 |
} |
| 102 |
|
| 103 |
public Class getReturnType() { |
| 104 |
|
| 105 |
return ARGRelaxedClock.class; |
| 106 |
} |
| 107 |
|
| 108 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 109 |
|
| 110 |
return null; |
| 111 |
} |
| 112 |
|
| 113 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 114 |
|
| 115 |
ARGModel arg = (ARGModel) xo.getChild(ARGModel.class); |
| 116 |
|
| 117 |
int partition = xo.getAttribute(PARTITION, 0); |
| 118 |
|
| 119 |
Parameter rate = (Parameter) xo.getChild(Parameter.class); |
| 120 |
|
| 121 |
return new ARGRelaxedClock("", arg, partition, rate); |
| 122 |
} |
| 123 |
|
| 124 |
public String getParserName() { |
| 125 |
return ARG_LOCAL_CLOCK; |
| 126 |
} |
| 127 |
|
| 128 |
}; |
| 129 |
|
| 130 |
} |