| 1 | /* |
| 2 | * FixedDriftModel.java |
| 3 | * |
| 4 | * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard |
| 5 | * |
| 6 | * This file is part of BEAST. |
| 7 | * See the NOTICE file distributed with this work for additional |
| 8 | * information regarding copyright ownership and licensing. |
| 9 | * |
| 10 | * BEAST is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * BEAST is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with BEAST; if not, write to the |
| 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 23 | * Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | package dr.evomodel.branchratemodel; |
| 27 | |
| 28 | import dr.evolution.tree.NodeRef; |
| 29 | import dr.evolution.tree.Tree; |
| 30 | import dr.evolution.util.TaxonList; |
| 31 | import dr.evomodel.tree.BackboneNodeFilter; |
| 32 | import dr.evomodel.tree.TreeModel; |
| 33 | import dr.evomodelxml.branchratemodel.FixedDriftModelParser; |
| 34 | import dr.inference.model.Model; |
| 35 | import dr.inference.model.Parameter; |
| 36 | import dr.inference.model.Variable; |
| 37 | |
| 38 | /** |
| 39 | * Created by mandevgill on 12/22/14. |
| 40 | */ |
| 41 | public class FixedDriftModel extends AbstractBranchRateModel { |
| 42 | |
| 43 | /* |
| 44 | public FixedDriftModel(Parameter rateOne, |
| 45 | Parameter rateTwo, |
| 46 | Parameter remainingRates, |
| 47 | String rateOneID, |
| 48 | String rateTwoID) { |
| 49 | |
| 50 | super(FixedDriftModelParser.FIXED_DRIFT); |
| 51 | |
| 52 | |
| 53 | // addModel(treeModel); |
| 54 | // this.treeModel = treeModel; |
| 55 | |
| 56 | this.rateOne = rateOne; |
| 57 | addVariable(rateOne); |
| 58 | |
| 59 | this.rateTwo = rateTwo; |
| 60 | addVariable(rateTwo); |
| 61 | |
| 62 | this.remainingRates = remainingRates; |
| 63 | addVariable(remainingRates); |
| 64 | |
| 65 | this.rateOneID = rateOneID; |
| 66 | this.rateTwoID = rateTwoID; |
| 67 | } |
| 68 | */ |
| 69 | |
| 70 | public FixedDriftModel(TreeModel treeModel, Parameter backboneDrift, Parameter otherDrift, TaxonList taxonList) { |
| 71 | |
| 72 | super(FixedDriftModelParser.FIXED_DRIFT); |
| 73 | |
| 74 | this.backboneDrift = backboneDrift; |
| 75 | addVariable(backboneDrift); |
| 76 | |
| 77 | this.otherDrift = otherDrift; |
| 78 | addVariable(otherDrift); |
| 79 | |
| 80 | |
| 81 | this.backbone = new BackboneNodeFilter("backbone", treeModel, taxonList, true, true); |
| 82 | |
| 83 | } |
| 84 | |
| 85 | |
| 86 | public void handleModelChangedEvent(Model model, Object object, int index) { |
| 87 | fireModelChanged(); |
| 88 | } |
| 89 | |
| 90 | protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 91 | fireModelChanged(); |
| 92 | } |
| 93 | |
| 94 | protected void storeState() { |
| 95 | } |
| 96 | |
| 97 | protected void restoreState() { |
| 98 | // calculateBranchRates(treeModel); |
| 99 | // recalculateScaleFactor(); |
| 100 | backbone.computeBackBoneMap(); |
| 101 | } |
| 102 | |
| 103 | protected void acceptState() { |
| 104 | } |
| 105 | |
| 106 | public double getBranchRate(final Tree tree, final NodeRef node) { |
| 107 | |
| 108 | if (backbone.includeNode(tree, node)) { |
| 109 | return backboneDrift.getParameterValue(0); |
| 110 | } else { |
| 111 | return otherDrift.getParameterValue(0); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | public double getBranchRate(final Tree tree, final NodeRef node) { |
| 117 | |
| 118 | if (tree.isExternal(node)) { |
| 119 | if (tree.getTaxonId(node.getNumber()).matches(rateOneID)) { |
| 120 | // System.err.println("node one id " + tree.getTaxonId(node.getNumber())); |
| 121 | return rateOne.getParameterValue(0); |
| 122 | } else if (tree.getTaxonId(node.getNumber()).matches(rateTwoID)) { |
| 123 | // System.err.println("node two id " + tree.getTaxonId(node.getNumber())); |
| 124 | return rateTwo.getParameterValue(0); |
| 125 | } else { |
| 126 | return remainingRates.getParameterValue(0); |
| 127 | } |
| 128 | } else { |
| 129 | return remainingRates.getParameterValue(0); |
| 130 | } |
| 131 | } |
| 132 | */ |
| 133 | |
| 134 | // the tree model |
| 135 | private TreeModel treeModel; |
| 136 | |
| 137 | private Parameter backboneDrift; |
| 138 | private Parameter otherDrift; |
| 139 | private BackboneNodeFilter backbone; |
| 140 | |
| 141 | /* |
| 142 | private Parameter remainingRates; |
| 143 | private Parameter rateOne; |
| 144 | private Parameter rateTwo; |
| 145 | private String rateOneID; |
| 146 | private String rateTwoID; |
| 147 | */ |
| 148 | } |