bpp-seq3  3.0.0
MiyataAAChemicalDistance.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 
8 using namespace std;
9 
11 #include "../Alphabet/AlphabetTools.h"
12 #include <Bpp/Numeric/NumTools.h>
13 
14 using namespace bpp;
15 
16 MiyataAAChemicalDistance::MiyataAAChemicalDistance() :
18  distanceMatrix_(20, 20),
19  indexMatrix_(20, 20),
20  sym_(true)
21 {
22  #include "__MiyataMatrixCode"
23 }
24 
25 double MiyataAAChemicalDistance::getIndex(int state1, int state2) const
26 {
27  double d = distanceMatrix_(getAlphabet()->getStateIndex(state1) - 1, getAlphabet()->getStateIndex(state2) - 1);
28  return sym_ ? NumTools::abs<double>(d) : d;
29 }
30 
31 double MiyataAAChemicalDistance::getIndex(const string& state1, const string& state2) const
32 {
33  return getIndex(getAlphabet()->charToInt(state1), getAlphabet()->charToInt(state2));
34 }
35 
37 {
39  if (sym_)
40  {
41  for (unsigned int i = 0; i < 20; i++)
42  {
43  for (unsigned int j = 0; j < 20; j++)
44  {
45  indexMatrix_(i, j) = NumTools::abs<double>(indexMatrix_(i, j));
46  }
47  }
48  }
49 }
double getIndex(int state1, int state2) const override
Get the index associated to a pair of states.
LinearMatrix< double > distanceMatrix_
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.