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-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 <ost/info/info_fw.hh>
26 
27 /*
28  Author: Marco Biasini
29  */
30 namespace ost { namespace seq { namespace alg {
31 
33 
34 typedef boost::shared_ptr<SubstWeightMatrix> SubstWeightMatrixPtr;
35 
38 
39 public:
40  typedef short WeightType;
41  const static int ALPHABET_SIZE='Z'-'A'+1;
47  ::memset(weights_, 0, sizeof(WeightType)*ALPHABET_SIZE*ALPHABET_SIZE);
48  }
49 
50  WeightType GetWeight(char aa_one, char aa_two) const
51  {
52  int i=Index(aa_one, aa_two);
53  assert(i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE);
54  return weights_[i];
55  }
56 
57  void SetWeight(char aa_one, char aa_two, WeightType weight)
58  {
59  int i=Index(aa_one, aa_two);
60  assert(i>=0 && i<ALPHABET_SIZE*ALPHABET_SIZE);
61  weights_[i]=weight;
62  }
63 private:
64  int Index(char aa_one, char aa_two) const {
65  return (toupper(aa_one)-'A')*ALPHABET_SIZE+(toupper(aa_two)-'A');
66  }
67  WeightType weights_[ALPHABET_SIZE*ALPHABET_SIZE];
68 };
69 
72 
75  info::InfoGroup& group);
76 
77 }}}
78 
79 #endif