| 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.branchratemodel; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
import dr.evomodelxml.branchratemodel.CompoundBranchRateModelParser; |
| 31 |
import dr.inference.model.AbstractModel; |
| 32 |
import dr.inference.model.Model; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
import dr.inference.model.Variable; |
| 35 |
|
| 36 |
import java.util.ArrayList; |
| 37 |
import java.util.Collection; |
| 38 |
import java.util.List; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class CompoundBranchRateModel extends AbstractBranchRateModel { |
| 48 |
|
| 49 |
private final List<BranchRateModel> branchRateModels = new ArrayList<BranchRateModel>(); |
| 50 |
|
| 51 |
public CompoundBranchRateModel(Collection<BranchRateModel> branchRateModels) { |
| 52 |
super(CompoundBranchRateModelParser.COMPOUND_BRANCH_RATE_MODEL); |
| 53 |
for (BranchRateModel branchRateModel : branchRateModels) { |
| 54 |
addModel(branchRateModel); |
| 55 |
this.branchRateModels.add(branchRateModel); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public void handleModelChangedEvent(Model model, Object object, int index) { |
| 60 |
if (index != -1) { |
| 61 |
fireModelChanged(null, index); |
| 62 |
} else { |
| 63 |
fireModelChanged(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 68 |
} |
| 69 |
|
| 70 |
protected void storeState() { |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
protected void restoreState() { |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
protected void acceptState() { |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
public double getBranchRate(final Tree tree, final NodeRef node) { |
| 83 |
double rate = 1.0; |
| 84 |
for (BranchRateModel branchRateModel : branchRateModels) { |
| 85 |
rate *= branchRateModel.getBranchRate(tree, node); |
| 86 |
} |
| 87 |
return rate; |
| 88 |
} |
| 89 |
|
| 90 |
} |