bpp-seq3  3.0.0
SimpleScore.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 
10 #include "SimpleScore.h"
11 
12 using namespace bpp;
13 
14 SimpleScore::SimpleScore(const Alphabet* alphabet, double match, double mismatch) :
15  distanceMatrix_(alphabet->getSize(), alphabet->getSize()),
16  alphabet_(alphabet)
17 {
18  // Load the matrix:
19  size_t n = alphabet_->getSize();
20  for (size_t i = 0; i < n; ++i)
21  {
22  for (size_t j = 0; j < n; ++j)
23  {
24  distanceMatrix_(i, j) = (i == j ? match : mismatch);
25  }
26  }
27 }
28 
29 double SimpleScore::getIndex(int state1, int state2) const
30 {
31  size_t stateIndex1 = alphabet_->getStateIndex(state1) - 1;
32  size_t stateIndex2 = alphabet_->getStateIndex(state2) - 1;
33  return distanceMatrix_(stateIndex1, stateIndex2);
34 }
35 
36 double SimpleScore::getIndex(const std::string& state1, const std::string& state2) const
37 {
38  size_t stateIndex1 = alphabet_->getStateIndex(state1) - 1;
39  size_t stateIndex2 = alphabet_->getStateIndex(state2) - 1;
40  return distanceMatrix_(stateIndex1, stateIndex2);
41 }
The Alphabet interface.
Definition: Alphabet.h:99
double getIndex(int state1, int state2) const override
Get the index associated to a pair of states.
Definition: SimpleScore.cpp:29
std::shared_ptr< const Alphabet > alphabet_
Definition: SimpleScore.h:28
LinearMatrix< double > distanceMatrix_
Definition: SimpleScore.h:27
This alphabet is used to deal NumericAlphabet.