ppALIGN API documentation
src/frequencies.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 00021 #ifndef _FREQUENCIES_HPP_ 00022 #define _FREQUENCIES_HPP_ 00023 00024 #include "drand48.hpp" 00025 #include "alphabet.hpp" 00026 #include "sequence.hpp" 00027 00028 #include <vector> 00032 class Frequencies : public std::vector<double> 00033 { 00034 const Alphabet * alpha; 00035 public: 00036 Frequencies(const Alphabet & a); 00037 00042 void Normalize(bool setupUIPAC=false); 00043 00044 void Reset(); 00045 00046 double & operator[](unsigned long i) 00047 { return std::vector<double>::operator[](i); } 00048 00049 const double & operator[](unsigned long i) const 00050 { return std::vector<double>::operator[](i); } 00051 00052 00053 double & operator[](unsigned int i) 00054 { return std::vector<double>::operator[](i); } 00055 00056 const double & operator[](unsigned int i) const 00057 { return std::vector<double>::operator[](i); } 00058 00059 00060 double & operator[](int i) 00061 { return std::vector<double>::operator[](i); } 00062 00063 const double & operator[](int i) const 00064 { return std::vector<double>::operator[](i); } 00065 00066 00067 double & operator[](char ch) 00068 { return std::vector<double>::operator[](alpha->ValidEncode(ch) ); } 00069 00070 const double & operator[](char ch) const 00071 { return std::vector<double>::operator[](alpha->ValidEncode(ch)); } 00072 00079 inline double GetNormWeight(size_t i) const; 00080 inline double GetLogWeight(size_t i) const; 00081 inline double GetCumWeight(size_t i) const; 00083 00084 void Count(const Sequence & seq); 00085 00098 int RandomLetter(DRand48 & rng) const; 00099 00100 void RandomSequence(DRand48 & rng, const Sequence::iterator & begin, const Sequence::iterator & end) const; 00107 void RandomSequence(DRand48 & rng, Sequence & seq, size_t length) const; 00108 00115 inline void RandomSequence(DRand48 & rng, Sequence & seq) const 00116 { 00117 RandomSequence(rng,seq.begin(),seq.end()); 00118 } 00120 00121 private: 00122 std::vector<double> cumWeights; 00123 std::vector<double> normWeights; 00124 std::vector<double> logWeights; 00125 00126 size_t asize; 00127 }; 00128 00130 double Frequencies::GetNormWeight(size_t i) const { return normWeights[i]; } 00131 double Frequencies::GetLogWeight(size_t i) const { return logWeights[i]; } 00132 double Frequencies::GetCumWeight(size_t i) const { return cumWeights[i]; } 00133 00134 00135 #endif