| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by BUI Quang Minh * |
| 3 | * [email protected] * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | #ifndef RATEMEYERHAESELER_H |
| 21 | #define RATEMEYERHAESELER_Hcxx . . $ `model/ratemeyerhaeseler.h:21:9`! |
| 22 | |
| 23 | #include "rateheterogeneity.h"cxx . . $ `<file>/model/rateheterogeneity.h`/ |
| 24 | #include "utils/tools.h"cxx . . $ `<file>/utils/tools.h`/ |
| 25 | #include "tree/iqtree.h"cxx . . $ `<file>/tree/iqtree.h`/ |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | Implementation for site-specific rates of Meyer & von Haeseler (2003) |
| 30 | Inherited from Optimization and the double vector for storing site-specific rates |
| 31 | |
| 32 | @author BUI Quang Minh <[email protected]> |
| 33 | */ |
| 34 | class RateMeyerHaeselercxx . . $ RateMeyerHaeseler# : public RateHeterogeneitycxx . . $ RateHeterogeneity#, public DoubleVectorcxx . . $ DoubleVector# |
| 35 | { |
| 36 | public: |
| 37 | /** |
| 38 | constructor |
| 39 | */ |
| 40 | RateMeyerHaeselercxx . . $ RateMeyerHaeseler#RateMeyerHaeseler(ad1562f249482cc2).(char *file_name, PhyloTreecxx . . $ PhyloTree# *tree, bool rate_type); |
| 41 | |
| 42 | RateMeyerHaeselercxx . . $ RateMeyerHaeseler#RateMeyerHaeseler(49f6e7a06ebc5aa8).(); |
| 43 | |
| 44 | /** |
| 45 | destructor |
| 46 | */ |
| 47 | ~cxx . . $ RateMeyerHaeseler#`~RateMeyerHaeseler`(ced63f7c635d850d).RateMeyerHaeselercxx . . $ RateMeyerHaeseler#(); |
| 48 | |
| 49 | void readRateFilecxx . . $ RateMeyerHaeseler#readRateFile(fda57c8427c60377).(char *rate_file); |
| 50 | |
| 51 | /** |
| 52 | @return true |
| 53 | */ |
| 54 | virtual bool isSiteSpecificRatecxx . . $ RateMeyerHaeseler#isSiteSpecificRate(c9857a73d68e59ba).() { return true; } |
| 55 | |
| 56 | /** |
| 57 | get the number of rate categories. |
| 58 | @return the number of rate categories |
| 59 | */ |
| 60 | //virtual int getNRate() { return size(); } |
| 61 | |
| 62 | |
| 63 | /** |
| 64 | return the number of dimensions |
| 65 | */ |
| 66 | virtual int getNDimcxx . . $ RateMeyerHaeseler#getNDim(b126dc7c1de90089).(); |
| 67 | |
| 68 | /** |
| 69 | get the rate of a specified category |
| 70 | @param category category ID from 0 to #category-1 |
| 71 | @return the rate of the specified category |
| 72 | */ |
| 73 | //virtual double getRate(int category); |
| 74 | |
| 75 | /** |
| 76 | get the rate of a specified site-pattern. Default returns 1.0 since it is homogeneous model |
| 77 | @param ptn pattern ID |
| 78 | @return the rate of the specified site-pattern |
| 79 | */ |
| 80 | virtual double getPtnRatecxx . . $ RateMeyerHaeseler#getPtnRate(4badf5dbac1308a7).(int ptn); |
| 81 | |
| 82 | /** |
| 83 | Compute site-specific rates. Override this for Gamma model |
| 84 | @param pattern_rates (OUT) pattern rates. Resizing if necesary |
| 85 | @return total number of categories |
| 86 | */ |
| 87 | virtual int computePatternRatescxx . . $ RateMeyerHaeseler#computePatternRates(318c0de86fd2392a).(DoubleVectorcxx . . $ DoubleVector# &pattern_rates, IntVectorcxx . . $ IntVector# &pattern_cat); |
| 88 | |
| 89 | void getRatescxx . . $ RateMeyerHaeseler#getRates(4790946ce95165bb).(DoubleVectorcxx . . $ DoubleVector# &rates); |
| 90 | |
| 91 | |
| 92 | void setRatescxx . . $ RateMeyerHaeseler#setRates(4790946ce95165bb).(DoubleVectorcxx . . $ DoubleVector# &rates); |
| 93 | |
| 94 | void initializeRatescxx . . $ RateMeyerHaeseler#initializeRates(49f6e7a06ebc5aa8).(); |
| 95 | |
| 96 | /** |
| 97 | optimize parameters, the rates in this case |
| 98 | @return the best likelihood |
| 99 | */ |
| 100 | virtual double optimizeParameterscxx . . $ RateMeyerHaeseler#optimizeParameters(447c67c6676f75c3).(double epsilon); |
| 101 | |
| 102 | /** |
| 103 | optimize rate of site |
| 104 | @param pattern target pattern |
| 105 | @return the optimized rate value, also update the corresponding element of the vector |
| 106 | */ |
| 107 | double optimizeRatecxx . . $ RateMeyerHaeseler#optimizeRate(4badf5dbac1308a7).(int pattern); |
| 108 | |
| 109 | /** |
| 110 | optimize rates of all site-patterns |
| 111 | */ |
| 112 | virtual void optimizeRatescxx . . $ RateMeyerHaeseler#optimizeRates(49f6e7a06ebc5aa8).(); |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | This function is inherited from Optimization class for optimizting site rates |
| 117 | @param value x-value of the function |
| 118 | @return f(value) of function f you want to minimize |
| 119 | */ |
| 120 | virtual double computeFunctioncxx . . $ RateMeyerHaeseler#computeFunction(447c67c6676f75c3).(double value); |
| 121 | |
| 122 | /** |
| 123 | This function calculate f(value), first derivative f'(value) and 2nd derivative f''(value). |
| 124 | @param value x-value of the function |
| 125 | @param df (OUT) first derivative |
| 126 | @param ddf (OUT) second derivative |
| 127 | @return f(value) of function f you want to minimize |
| 128 | */ |
| 129 | virtual void computeFuncDervcxx . . $ RateMeyerHaeseler#computeFuncDerv(7e959a8e454dd3f7).(double value, double &df, double &ddf); |
| 130 | |
| 131 | |
| 132 | void runIterativeProccxx . . $ RateMeyerHaeseler#runIterativeProc(14ab24009fdf4562).(Paramscxx . . $ Params# ¶ms, IQTreecxx . . $ IQTree# &tree); |
| 133 | |
| 134 | /** |
| 135 | distance matrix inferred from the path lengths of the tree (not from the sequences) |
| 136 | */ |
| 137 | double *dist_matcxx . . $ RateMeyerHaeseler#dist_mat.; |
| 138 | |
| 139 | |
| 140 | protected: |
| 141 | |
| 142 | char *rate_filecxx . . $ RateMeyerHaeseler#rate_file.; |
| 143 | |
| 144 | /** |
| 145 | current pattern under optimization. Note that this is not thread-safe |
| 146 | */ |
| 147 | int optimizing_patterncxx . . $ RateMeyerHaeseler#optimizing_pattern.; |
| 148 | |
| 149 | /** |
| 150 | FALSE to use MH Model, FALSE for using tree-likelihood |
| 151 | */ |
| 152 | bool rate_mhcxx . . $ RateMeyerHaeseler#rate_mh.; |
| 153 | |
| 154 | double cur_scalecxx . . $ RateMeyerHaeseler#cur_scale.; |
| 155 | |
| 156 | PhyloTreecxx . . $ PhyloTree# *ptn_treecxx . . $ RateMeyerHaeseler#ptn_tree.; |
| 157 | |
| 158 | void prepareRateMLcxx . . $ RateMeyerHaeseler#prepareRateML(a34795ad5d75a5d3).(IntVectorcxx . . $ IntVector# &ptn_id); |
| 159 | void completeRateMLcxx . . $ RateMeyerHaeseler#completeRateML(49f6e7a06ebc5aa8).(); |
| 160 | }; |
| 161 | |
| 162 | #endif |