bpp-phyl  2.2.0
StateMap.h
Go to the documentation of this file.
1 //
2 // File: StateMap.h
3 // Created by: Julien Dutheil
4 // Created on: Wed Jun 13 15:03 2012
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _STATEMAP_H_
41 #define _STATEMAP_H_
42 
43 #include <Bpp/Clonable.h>
44 #include <Bpp/Seq/Alphabet/Alphabet.h>
45 #include <Bpp/Seq/Alphabet/NucleicAlphabet.h>
46 #include <Bpp/Numeric/VectorTools.h>
47 
48 //From the STL:
49 #include <vector>
50 #include <string>
51 
52 namespace bpp
53 {
54 
58  class StateMap:
59  public virtual Clonable
60  {
61  public:
62  virtual ~StateMap() {}
63  virtual StateMap* clone() const = 0;
64 
65  public:
69  virtual const Alphabet* getAlphabet() const = 0;
70 
74  virtual size_t getNumberOfModelStates() const = 0;
75 
81  virtual const std::vector<int>& getAlphabetStates() const = 0;
82 
87  virtual std::string getAlphabetStateAsChar(size_t index) const = 0;
88 
93  virtual int getAlphabetStateAsInt(size_t index) const = 0;
94 
99  virtual std::vector<size_t> getModelStates(const std::string& code) const = 0;
100 
105  virtual std::vector<size_t> getModelStates(int code) const = 0;
106 
107  };
108 
116  public virtual StateMap
117  {
118  protected:
119  const Alphabet* alphabet_;
120  std::vector<int> states_;
121 
122  public:
123  AbstractStateMap(const Alphabet* alphabet):
124  alphabet_(alphabet),
125  states_()
126  {}
127 
129  alphabet_(absm.alphabet_),
130  states_(absm.states_)
131  {}
132 
134  {
135  alphabet_ = absm.alphabet_;
136  states_ = absm.states_;
137  return *this;
138  }
139 
140  public:
141  virtual const Alphabet* getAlphabet() const { return alphabet_; }
142  virtual size_t getNumberOfModelStates() const { return states_.size(); }
143  virtual const std::vector<int>& getAlphabetStates() const { return states_; }
144  virtual int getAlphabetStateAsInt(size_t index) const { return states_[index]; }
145  virtual std::string getAlphabetStateAsChar(size_t index) const { return alphabet_->intToChar(states_[index]); }
146  virtual std::vector<size_t> getModelStates(int code) const {
147  return VectorTools::whichAll(states_, code);
148  }
149  virtual std::vector<size_t> getModelStates(const std::string& code) const {
150  return VectorTools::whichAll(states_, alphabet_->charToInt(code));
151  }
152 
153  };
154 
162  public AbstractStateMap
163  {
164  public:
165  CanonicalStateMap(const Alphabet* alphabet, bool includeGaps);
166 
171  CanonicalStateMap(const StateMap& sm, bool includeGaps);
172 
173  virtual CanonicalStateMap* clone() const { return new CanonicalStateMap(*this); }
174 
175  };
176 
177 
178 
186  public AbstractStateMap
187  {
188  public:
189  MarkovModulatedStateMap(const StateMap& unitMap, unsigned int nbClasses);
190  virtual MarkovModulatedStateMap* clone() const { return new MarkovModulatedStateMap(*this); }
191 
192  };
193 
194 }// end of namespace bpp
195 
196 #endif //_STATEMAP_H_
197 
AbstractStateMap(const AbstractStateMap &absm)
Definition: StateMap.h:128
virtual std::vector< size_t > getModelStates(const std::string &code) const
Definition: StateMap.h:149
virtual const Alphabet * getAlphabet() const
Definition: StateMap.h:141
virtual int getAlphabetStateAsInt(size_t index) const =0
virtual const std::vector< int > & getAlphabetStates() const
Definition: StateMap.h:143
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:161
virtual size_t getNumberOfModelStates() const
Definition: StateMap.h:142
virtual CanonicalStateMap * clone() const
Definition: StateMap.h:173
virtual size_t getNumberOfModelStates() const =0
virtual std::string getAlphabetStateAsChar(size_t index) const =0
AbstractStateMap & operator=(const AbstractStateMap &absm)
Definition: StateMap.h:133
virtual StateMap * clone() const =0
virtual std::vector< size_t > getModelStates(int code) const
Definition: StateMap.h:146
MarkovModulatedStateMap(const StateMap &unitMap, unsigned int nbClasses)
Definition: StateMap.cpp:64
virtual MarkovModulatedStateMap * clone() const
Definition: StateMap.h:190
virtual std::vector< size_t > getModelStates(const std::string &code) const =0
virtual const Alphabet * getAlphabet() const =0
virtual ~StateMap()
Definition: StateMap.h:62
CanonicalStateMap(const Alphabet *alphabet, bool includeGaps)
Definition: StateMap.cpp:44
const Alphabet * alphabet_
Definition: StateMap.h:119
virtual std::string getAlphabetStateAsChar(size_t index) const
Definition: StateMap.h:145
virtual const std::vector< int > & getAlphabetStates() const =0
virtual int getAlphabetStateAsInt(size_t index) const
Definition: StateMap.h:144
This class implements a state map for Markov modulated models.
Definition: StateMap.h:185
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58
std::vector< int > states_
Definition: StateMap.h:120
A convenience partial implementation of the StateMap interface.
Definition: StateMap.h:115
AbstractStateMap(const Alphabet *alphabet)
Definition: StateMap.h:123