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>
26 #if(OST_INFO_ENABLED)
27 #include <ost/info/info_fw.hh>
28 #endif
30 
31 /*
32  Author: Marco Biasini
33  */
34 namespace ost { namespace seq { namespace alg {
35 
37 
38 typedef boost::shared_ptr<SubstWeightMatrix> SubstWeightMatrixPtr;
39 
42 
43 public:
44  typedef short WeightType;
45  const static int ALPHABET_SIZE='Z'-'A'+1;
51  ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
52  }
53 
58  WeightType GetWeight(char aa_one, char aa_two) const
59  {
60  if (!(IsAlpha(aa_one) && IsAlpha(aa_two))) {
61  return 0;
62  }
63  int i=Index(aa_one, aa_two);
64  return (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) ? weights_[i] : 0;
65  }
66 
71  void SetWeight(char aa_one, char aa_two, WeightType weight)
72  {
73  if ((IsAlpha(aa_one) && IsAlpha(aa_two))) {
74  int i=Index(aa_one, aa_two);
75  if (i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE) {
76  weights_[i]=weight;
77  }
78  }
79  }
80 
81 private:
82  int Index(char aa_one, char aa_two) const {
83  return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
84  }
85 
87  bool IsAlpha(char aa) const {
88  return (toupper(aa)>='A' && toupper(aa)<='Z');
89  }
90  WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
91 };
92 
93 #if(OST_INFO_ENABLED)
95 SubstWeightMatrixFromInfo(const info::InfoGroup& group);
96 
98 SubstWeightMatrixToInfo(const SubstWeightMatrixPtr& subst_mat,
99  info::InfoGroup& group);
100 #endif
101 
102 }}}
103 
104 #endif