bpp-seq3  3.0.0
GranthamAAChemicalDistance.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 // from the STL:
6 #include <string>
7 
9 #include "../Alphabet/AlphabetTools.h"
10 #include <Bpp/Numeric/NumTools.h>
11 
12 using namespace bpp;
13 using namespace std;
14 
18 
21  distanceMatrix_(20, 20),
22  signMatrix_(20, 20),
23  indexMatrix_(20, 20),
24  sign_(0)
25 {
26  // Load the matrix:
27  #include "__GranthamMatrixCode"
29 }
30 
31 double GranthamAAChemicalDistance::getIndex(int state1, int state2) const
32 {
33  double d = distanceMatrix_(getAlphabet()->getStateIndex(state1) - 1, getAlphabet()->getStateIndex(state2) - 1);
34  if (sign_ == SIGN_NONE)
35  return NumTools::abs<double>(d);
36  if (sign_ == SIGN_PC1)
37  return signMatrix_(getAlphabet()->getStateIndex(state1) - 1, getAlphabet()->getStateIndex(state2) - 1) * NumTools::abs<double>(d);
38 
39  return d;
40 }
41 
42 double GranthamAAChemicalDistance::getIndex(const std::string& state1, const std::string& state2) const
43 {
44  return getIndex(getAlphabet()->charToInt(state1), getAlphabet()->charToInt(state2));
45 }
46 
48 {
50  if (sign_ == SIGN_NONE)
51  {
52  for (size_t i = 0; i < 20; ++i)
53  {
54  for (size_t j = 0; j < 20; ++j)
55  {
56  indexMatrix_(i, j) = NumTools::abs<double>(indexMatrix_(i, j));
57  }
58  }
59  }
60  else if (sign_ == SIGN_PC1)
61  {
62  for (size_t i = 0; i < 20; ++i)
63  {
64  for (size_t j = 0; j < 20; ++j)
65  {
66  indexMatrix_(i, j) = signMatrix_(i, j) * NumTools::abs<double>(indexMatrix_(i, j));
67  }
68  }
69  }
70 }
double getIndex(int state1, int state2) const override
Get the index associated to a pair of states.
Virtual AlphabetIndex2 for proteic alphabet.
std::shared_ptr< const Alphabet > getAlphabet() const override
Get the alphabet associated to this index.
This alphabet is used to deal NumericAlphabet.