bpp-phyl3  3.0.0
StateMap.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 #include "StateMap.h"
6 
7 using namespace bpp;
8 using namespace std;
9 
10 CanonicalStateMap::CanonicalStateMap(std::shared_ptr<const Alphabet> alphabet, bool includeGaps) :
11  AbstractStateMap(alphabet)
12 {
13  size_t i = 0;
14  while (states_.size() < alphabet->getSize())
15  {
17  states_.push_back(alphabet->getIntCodeAt(i));
18  i++;
19  }
20 
21  if (includeGaps)
22  states_.push_back(alphabet->getGapCharacterCode());
23 }
24 
26  AbstractStateMap(sm.getAlphabet())
27 {
28  for (size_t i = 0; i < sm.getNumberOfModelStates(); ++i)
29  {
30  states_.push_back(sm.getAlphabetStateAsInt(i));
31  }
32  if (includeGaps)
33  states_.push_back(sm.getAlphabet()->getGapCharacterCode());
34 }
35 
37  AbstractStateMap(unitMap.getAlphabet()),
38  nbClasses_(nbClasses)
39 {
40  for (unsigned int j = 0; j < nbClasses; ++j)
41  {
42  for (size_t i = 0; i < unitMap.getNumberOfModelStates(); ++i)
43  {
44  states_.push_back(unitMap.getAlphabetStateAsInt(i));
45  }
46  }
47 }
A convenience partial implementation of the StateMap interface.
Definition: StateMap.h:106
const Alphabet & alphabet() const override
Definition: StateMap.h:130
std::vector< int > states_
Definition: StateMap.h:109
virtual bool isGap(int state) const=0
virtual int getGapCharacterCode() const=0
virtual int getIntCodeAt(size_t stateIndex) const=0
virtual unsigned int getSize() const=0
CanonicalStateMap(std::shared_ptr< const Alphabet > alphabet, bool includeGaps)
Definition: StateMap.cpp:10
MarkovModulatedStateMap(const StateMapInterface &unitMap, unsigned int nbClasses)
Definition: StateMap.cpp:36
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual size_t getNumberOfModelStates() const =0
virtual int getAlphabetStateAsInt(size_t index) const =0
Defines the basic types of data flow nodes.