1 /* 2 Copyright 2009-2012 Andreas Biegert, Christof Angermueller 3 4 This file is part of the CS-BLAST package. 5 6 The CS-BLAST package is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 The CS-BLAST package is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef CS_PROFILE_H_ 21 #define CS_PROFILE_H_ 22 23 24 namespace cs { 25 26 // Forward declaration 27 template <class Abc> 28 struct CountProfile; 29 30 // A simple container class acting pretty much like a matrix but with column size 31 // fixed to Abc::kSizeAny 32 template <class Abc> 33 class Profile { 34 public: 35 Profile(); 36 explicit Profile(size_t n); 37 Profile(size_t n, const double &a); 38 Profile(size_t n, const double *a); 39 Profile(const Profile &rhs); 40 Profile(const CountProfile<Abc>& cp); 41 ~Profile(); 42 43 Profile & operator=(const Profile &rhs); 44 double* operator[](const size_t i); 45 const double* operator[](const size_t i) const; length()46 size_t length() const { return nn; } 47 void Resize(size_t newn); 48 void Assign(size_t newn, const double &a); 49 void Insert(size_t idx, const Profile<Abc>& other); 50 51 private: 52 size_t nn; 53 double **v; 54 }; 55 56 // Assigns given constant value or default to all entries in matrix 57 template <class Abc> 58 void Assign(Profile<Abc>& p, double val = 0.0); 59 60 // Normalizes all profile columns to fixed value. Iff 'incl_any' is true, 61 // normalization also includes values for ANY letter 62 template <class Abc> 63 void Normalize(Profile<Abc>& p, double val, bool incl_any = false); 64 65 // Normalizes all profile columns to corresponding value in vector 'norm'. 66 // Iff 'incl_any' is true, normalization also includes values for ANY letter. 67 template <class Abc> 68 void Normalize(Profile<Abc>& p, const Vector<double>& norm, bool incl_any = false); 69 70 // Prints profile in human-readable format for debugging. 71 template<class Abc> 72 std::ostream& operator<< (std::ostream& out, const Profile<Abc>& p); 73 74 // Calculates the entropy of the given profile using logarithm base 2. 75 template <class Abc> 76 inline double Entropy(const Profile<Abc>& p); 77 78 // Calculates the Neff in the given profile. 79 template <class Abc> 80 inline double Neff(const Profile<Abc>& p); 81 82 } // namespace cs 83 84 #endif // CS_PROFILE_H_ 85