ppALIGN API documentation
src/weights.hpp
00001 /****************************************************************************** 00002 Copyright 2009 Stefan Wolfsheimer & Gregory Nuel. 00003 00004 This file is part of ppALIGN 00005 00006 ppALIGN is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 ppALIGN is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with ppALIGN; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 *******************************************************************************/ 00020 //changelog 00021 // 2010-01-23 sw: gap costs int -> double 00022 00023 00024 /* the scale of the blosum matrices are: 00025 00026 blosum30.sij 1/5 bit 00027 blosum35.sij 1/4 bit 00028 blosum40.sij 1/4 bit 00029 blosum45.sij 1/3 bit 00030 blosum50.sij 1/3 bit 00031 blosum55.sij 1/3 bit 00032 blosum60.sij 1/2 bit 00033 blosum62.sij 1/2 bit 00034 blosum65.sij 1/2 bit 00035 .... 00036 blosum100.sij 1/2 bit 00037 00038 To get the integer matrix use: 00039 s_ij = int( \lambda * \log p(i,j) / q(i) / q(j) ) 00040 with lambda = (1/r) / log(2) 00041 where r = 1/5,1/4,1/3 ... 00042 */ 00043 00044 #ifndef _WEIGHTS_HPP_ 00045 #define _WEIGHTS_HPP_ 00046 00047 00048 #include "xdouble.hpp" 00049 #include "frequencies.hpp" 00050 #include "scorematrix.hpp" 00051 00052 #include <vector> 00053 00054 00056 typedef enum 00057 { 00058 GlobalBounded = 1, 00060 Global = 2, 00061 LocalBounded = 8 00062 } AlignmentType; 00063 00066 static const int LocalAlign = LocalBounded; 00067 00070 static const int BoundedAlign = GlobalBounded | LocalBounded; 00071 00072 00075 class Weight 00076 : public std::vector<std::vector<xdouble> > 00077 { 00078 const Alphabet * alphabet1; 00079 const Alphabet * alphabet2; 00080 00081 public: 00084 Frequencies freq1; 00085 00088 Frequencies freq2; 00089 00097 Weight(const Alphabet & a1, 00098 const Alphabet & a2, 00099 AlignmentType t, 00100 bool _allow_DI=true, 00101 bool _allow_ID=false); 00102 00103 00104 00107 virtual ~Weight() {} 00108 00112 virtual void StreamOut(std::ostream & ost); 00113 00117 inline const Alphabet & GetAlphabet1() const 00118 { 00119 return *alphabet1; 00120 } 00121 00125 inline const Alphabet & GetAlphabet2() const 00126 { 00127 return *alphabet2; 00128 } 00129 00133 virtual bool IsBoltzmann() const 00134 { 00135 return false; 00136 } 00137 00138 00143 double scale; 00144 00150 AlignmentType align_type; 00151 00155 bool allow_DI; 00156 00160 bool allow_ID; 00161 00163 00169 int gap_open; 00170 00173 int gap_extension; 00174 00178 xdouble tMM,tMI,tMD; 00179 xdouble tIM,tII,tID; 00180 xdouble tDM,tDI,tDD; 00182 00186 xdouble tSM,tSI,tSD; 00187 xdouble tME,tIE,tDE; 00189 00190 protected: 00195 void Normalize(bool setupUIPAC=false); 00196 00197 void AverageUIPAC(); 00198 00199 }; 00200 00201 00202 /****************************************************************************/ 00232 class BoltzmannWeight : public Weight 00233 { 00234 private: 00235 void Init(double temperature, 00236 double gap_open, 00237 double gap_extension); 00238 00239 public: 00241 double temper; 00243 double alpha; 00245 double beta; 00246 00255 xdouble exp_alpha; 00256 00265 xdouble exp_beta; 00266 00288 BoltzmannWeight(const ScoreMatrix & s, 00289 double _scale, 00290 double temperature, 00291 double gap_open, 00292 double gap_extension, 00293 AlignmentType t, 00294 bool allow_DI=true, 00295 bool allow_ID=false); 00296 00317 BoltzmannWeight(const Alphabet & alphabet1, 00318 const Alphabet & alphabet2, 00319 const std::string & matrix_name, 00320 double temperature, 00321 double gap_open, 00322 double gap_extension, 00323 AlignmentType t, 00324 bool allow_DI=true, 00325 bool allow_ID=false); 00326 00329 virtual ~BoltzmannWeight() {} 00330 00337 xdouble Average(const Frequencies & freq1, 00338 const Frequencies & freq2) const; 00339 00343 inline double Temperature() const { return temper; } 00344 00345 00349 virtual bool IsBoltzmann() const { return true; } 00350 00351 00352 private: 00353 void Init(const Alphabet & alphabet1, 00354 const Alphabet & alphabet2, 00355 const std::string & matrix_name, 00356 double temperature, 00357 double gap_open, 00358 double gap_extension, 00359 AlignmentType t, 00360 bool allow_DI=true, 00361 bool allow_ID=false); 00362 00363 }; 00364 00369 00370 00373 class HmmWeight : public Weight 00374 { 00375 public: 00376 00387 HmmWeight(const Alphabet &, 00388 const Alphabet &, 00389 const std::string & name, 00390 double gap_open, 00391 double gap_extension, 00392 AlignmentType t, 00393 bool _allow_DI=true, 00394 bool _allow_ID=false); 00395 00396 00397 HmmWeight(const ScoreMatrix & matrix, 00398 double _scale, 00399 const Frequencies & freq1, 00400 const Frequencies & freq2, 00401 double gap_open, 00402 double gap_extension, 00403 AlignmentType t, 00404 bool _allow_DI=true, 00405 bool _allow_ID=false); 00406 00407 HmmWeight(const ScoreMatrix & matrix, 00408 const Sequence & seq1, 00409 const Sequence & seq2, 00410 double gap_open, 00411 double gap_extension, 00412 AlignmentType t, 00413 bool _allow_DI=true, 00414 bool _allow_ID=false); 00415 00416 private: 00417 xdouble nu,nu2,nuI,eps,eps1,etaI,etaD; 00418 bool CheckTrans(xdouble & tXM, xdouble & tXI, xdouble & tXD, char x); 00419 void InitTrans(double gap_open, 00420 double gap_extension); 00421 void Init(const ScoreMatrix & matrix, 00422 double _scale, 00423 const Frequencies & _freq1, 00424 const Frequencies & _freq2, 00425 double gap_open, 00426 double gap_extension, 00427 AlignmentType t, 00428 bool _allow_DI, 00429 bool _allow_ID) ; 00430 00431 }; 00432 #endif