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-2020 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,
47  IDENTITY = 4,
48  MATCH = 5,
49  NUC44 = 6};
54  SubstWeightMatrix():max_weight_(0),min_weight_(0) {
55  ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
56  }
57 
58  void AssignPreset(Preset p);
59 
64  WeightType GetWeight(char aa_one, char aa_two) const
65  {
66  if (!(IsAlpha(aa_one) && IsAlpha(aa_two))) {
67  return 0;
68  }
69  int i=Index(aa_one, aa_two);
70  return (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) ? weights_[i] : 0;
71  }
72 
74  WeightType GetMinWeight() const { return min_weight_; }
75 
77  WeightType GetMaxWeight() const { return max_weight_; }
78 
83  void SetWeight(char aa_one, char aa_two, WeightType weight)
84  {
85  if ((IsAlpha(aa_one) && IsAlpha(aa_two))) {
86  int i=Index(aa_one, aa_two);
87  if (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) {
88  weights_[i]=weight;
89  min_weight_ = std::min(min_weight_,weight);
90  max_weight_ = std::max(max_weight_,weight);
91  }
92  }
93  }
94 
95 private:
96  int Index(char aa_one, char aa_two) const {
97  return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
98  }
99 
101  bool IsAlpha(char aa) const {
102  return (toupper(aa)>='A' && toupper(aa)<='Z');
103  }
104  WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
105  WeightType max_weight_;
106  WeightType min_weight_;
107 };
108 
109 }}}
110 
111 #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.
tuple NUC44
Definition: mat.py:14
WeightType GetMaxWeight() const
Get the maximal substitution weight of the matrix.
tuple MATCH
Definition: mat.py:13
position-independet substitution weight matrix
tuple BLOSUM100
Definition: mat.py:11
tuple IDENTITY
Definition: mat.py:12
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.