OpenStructure
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/base.hh>
26 #include <ost/config.hh>
28 
29 /*
30  Author: Marco Biasini
31  */
32 namespace ost { namespace seq { namespace alg {
33 
34 class SubstWeightMatrix;
35 
36 typedef boost::shared_ptr<SubstWeightMatrix> SubstWeightMatrixPtr;
37 
40 
41 public:
42  typedef short WeightType;
43  const static int ALPHABET_SIZE='Z'-'A'+1;
44  enum Preset{BLOSUM45 = 0,
45  BLOSUM62 = 1,
46  BLOSUM80 = 2,
47  BLOSUM100 = 3,
48  NUC44 = 4};
53  SubstWeightMatrix():max_weight_(0),min_weight_(0) {
54  ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
55  }
56 
58 
63  WeightType GetWeight(char aa_one, char aa_two) const
64  {
65  if (!(IsAlpha(aa_one) && IsAlpha(aa_two))) {
66  return 0;
67  }
68  int i=Index(aa_one, aa_two);
69  return (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) ? weights_[i] : 0;
70  }
71 
73  WeightType GetMinWeight() const { return min_weight_; }
74 
76  WeightType GetMaxWeight() const { return max_weight_; }
77 
82  void SetWeight(char aa_one, char aa_two, WeightType weight)
83  {
84  if ((IsAlpha(aa_one) && IsAlpha(aa_two))) {
85  int i=Index(aa_one, aa_two);
86  if (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) {
87  weights_[i]=weight;
88  min_weight_ = std::min(min_weight_,weight);
89  max_weight_ = std::max(max_weight_,weight);
90  }
91  }
92  }
93 
94  void SetName(const String& name) { name_ = name; }
95 
96  const String& GetName() { return name_; }
97 
98 private:
99  int Index(char aa_one, char aa_two) const {
100  return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
101  }
102 
104  bool IsAlpha(char aa) const {
105  return (toupper(aa)>='A' && toupper(aa)<='Z');
106  }
107  WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
108  WeightType max_weight_;
109  WeightType min_weight_;
110  String name_;
111 };
112 
113 }}}
114 
115 #endif
position-independet substitution weight matrix
WeightType GetMinWeight() const
Get the minimal substitution weight of the matrix.
void SetWeight(char aa_one, char aa_two, WeightType weight)
Set the substitution weight between two amino acids.
WeightType GetMaxWeight() const
Get the maximal substitution weight of the matrix.
void SetName(const String &name)
WeightType GetWeight(char aa_one, char aa_two) const
Get the substitution weight between two amino acids.
SubstWeightMatrix()
Initialize substitution matrix with zero.
std::string String
Definition: base.hh:54
def BLOSUM45
Definition: mat.py:8
def BLOSUM62
Definition: mat.py:9
def BLOSUM80
Definition: mat.py:10
def BLOSUM100
Definition: mat.py:11
boost::shared_ptr< SubstWeightMatrix > SubstWeightMatrixPtr
Definition: base.dox:1
#define DLLEXPORT_OST_SEQ_ALG