| 1 | /* |
| 2 | * CovarionHKY.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.oldevomodel.substmodel; |
| 27 | |
| 28 | import dr.evolution.datatype.OldHiddenNucleotides; |
| 29 | import dr.oldevomodelxml.substmodel.CovarionHKYParser; |
| 30 | import dr.inference.model.Parameter; |
| 31 | |
| 32 | /** |
| 33 | * A model with hidden states that represent different rates. |
| 34 | * |
| 35 | * @author Alexei Drummond |
| 36 | * @version $Id: CovarionHKY.java,v 1.4 2005/05/24 20:25:58 rambaut Exp $ |
| 37 | */ |
| 38 | public class CovarionHKY extends AbstractCovarionDNAModel { |
| 39 | |
| 40 | /** |
| 41 | * kappa |
| 42 | */ |
| 43 | private Parameter kappaParameter; |
| 44 | |
| 45 | /** |
| 46 | * @param dataType the datatype to be used |
| 47 | * @param kappaParameter the rate of transitions versus transversions |
| 48 | * @param hiddenClassRates the relative rates of the hidden categories |
| 49 | * (first hidden category has rate 1.0 so this parameter |
| 50 | * has dimension one less than number of hidden categories. |
| 51 | * each hidden category. |
| 52 | * @param switchingRates rate of switching between hidden categories |
| 53 | * @param freqModel the frequencies |
| 54 | */ |
| 55 | public CovarionHKY(OldHiddenNucleotides dataType, Parameter kappaParameter, Parameter hiddenClassRates, Parameter switchingRates, FrequencyModel freqModel) { |
| 56 | |
| 57 | super(CovarionHKYParser.COVARION_HKY, dataType, hiddenClassRates, switchingRates, freqModel); |
| 58 | |
| 59 | this.kappaParameter = kappaParameter; |
| 60 | addVariable(kappaParameter); |
| 61 | setupRelativeRates(); |
| 62 | } |
| 63 | |
| 64 | double[] getRelativeDNARates() { |
| 65 | double kappa = kappaParameter.getParameterValue(0); |
| 66 | return new double[]{1.0, kappa, 1.0, 1.0, kappa, 1.0}; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * set kappa |
| 71 | * |
| 72 | * @param kappa the new value of kappa to set |
| 73 | */ |
| 74 | public void setKappa(double kappa) { |
| 75 | kappaParameter.setParameterValue(0, kappa); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return kappa |
| 80 | */ |
| 81 | public double getKappa() { |
| 82 | return kappaParameter.getParameterValue(0); |
| 83 | } |
| 84 | |
| 85 | public String toString() { |
| 86 | StringBuilder builder = new StringBuilder(); |
| 87 | builder.append("Covarion HKY model with "); |
| 88 | builder.append(getHiddenClassCount()).append(" rate classes.\n"); |
| 89 | builder.append("Relative rates: \n"); |
| 90 | builder.append(SubstitutionModelUtils.toString(relativeRates, dataType, true, 2)); |
| 91 | return builder.toString(); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | } |