OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
subst_weight_matrix.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_SEQ_SUBST_WEIGHT_MATRIX_HH
20 #define OST_SEQ_SUBST_WEIGHT_MATRIX_HH
21 
22 #include <ctype.h>
23 #include <string.h>
24 #include <boost/shared_ptr.hpp>
25 #include <ost/config.hh>
27 
28 /*
29  Author: Marco Biasini
30  */
31 namespace ost { namespace seq { namespace alg {
32 
34 
35 typedef boost::shared_ptr<SubstWeightMatrix> SubstWeightMatrixPtr;
36 
39 
40 public:
41  typedef short WeightType;
42  const static int ALPHABET_SIZE='Z'-'A'+1;
43  enum Preset{BLOSUM45 = 0,
44  BLOSUM62 = 1,
45  BLOSUM80 = 2,
46  BLOSUM100 = 3};
51  SubstWeightMatrix():max_weight_(0),min_weight_(0) {
52  ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
53  }
54 
55  void AssignPreset(Preset p);
56 
61  WeightType GetWeight(char aa_one, char aa_two) const
62  {
63  if (!(IsAlpha(aa_one) && IsAlpha(aa_two))) {
64  return 0;
65  }
66  int i=Index(aa_one, aa_two);
67  return (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) ? weights_[i] : 0;
68  }
69 
71  WeightType GetMinWeight() const { return min_weight_; }
72 
74  WeightType GetMaxWeight() const { return max_weight_; }
75 
80  void SetWeight(char aa_one, char aa_two, WeightType weight)
81  {
82  if ((IsAlpha(aa_one) && IsAlpha(aa_two))) {
83  int i=Index(aa_one, aa_two);
84  if (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) {
85  weights_[i]=weight;
86  min_weight_ = std::min(min_weight_,weight);
87  max_weight_ = std::max(max_weight_,weight);
88  }
89  }
90  }
91 
92 private:
93  int Index(char aa_one, char aa_two) const {
94  return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
95  }
96 
98  bool IsAlpha(char aa) const {
99  return (toupper(aa)>='A' && toupper(aa)<='Z');
100  }
101  WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
102  WeightType max_weight_;
103  WeightType min_weight_;
104 };
105 
106 }}}
107 
108 #endif
void SetWeight(char aa_one, char aa_two, WeightType weight)
Set the substitution weight between two amino acids.
#define DLLEXPORT_OST_SEQ_ALG
tuple BLOSUM80
Definition: mat.py:10
SubstWeightMatrix()
Initialize substitution matrix with zero.
tuple BLOSUM62
Definition: mat.py:9
WeightType GetMinWeight() const
Get the minimal substitution weight of the matrix.
WeightType GetMaxWeight() const
Get the maximal substitution weight of the matrix.
position-independet substitution weight matrix
tuple BLOSUM100
Definition: mat.py:11
boost::shared_ptr< SubstWeightMatrix > SubstWeightMatrixPtr
tuple BLOSUM45
Definition: mat.py:8
WeightType GetWeight(char aa_one, char aa_two) const
Get the substitution weight between two amino acids.