bpp-seq3  3.0.0
ProbabilisticSymbolList.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_PROBABILISTICSYMBOLLIST_H
6 #define BPP_SEQ_PROBABILISTICSYMBOLLIST_H
7 
8 #include <Bpp/Clonable.h>
9 #include <Bpp/Numeric/Table.h>
10 
11 #include "Alphabet/Alphabet.h"
12 #include "CoreSymbolList.h"
13 
14 // From the STL :
15 #include <string>
16 #include <vector>
17 
18 namespace bpp
19 {
32 {
33 public:
34  typedef std::vector<double> SymbolType;
36 
37 public:
39 
40  // class destructor
42 
43 public:
44  virtual const DTable& getTable() const = 0;
45 
47 
48  virtual void setContent(const DTable& list) = 0;
49 };
50 
63 {
64 private:
71  std::shared_ptr<const Alphabet> alphabet_;
72 
73 protected:
78 
79 public:
85  ProbabilisticSymbolList(std::shared_ptr<const Alphabet>& alpha);
86 
94  ProbabilisticSymbolList(const DTable& list, std::shared_ptr<const Alphabet>& alpha);
95 
103  ProbabilisticSymbolList(const std::vector< std::vector<double>>& list, std::shared_ptr<const Alphabet>& alpha);
104 
109 
111 
116 
121 
126 
132  ProbabilisticSymbolList* clone() const override { return new ProbabilisticSymbolList(*this); }
133 
138  // class destructor
140 
141 public:
142  std::shared_ptr<const Alphabet> getAlphabet() const override { return alphabet_; }
143 
144  const Alphabet& alphabet() const override { return *alphabet_; }
145 
146  size_t size() const override { return static_cast<size_t>(content_.getNumberOfColumns()); }
147 
148  void setContent(const std::vector<std::vector<double>>& list) override;
149 
150  void setContent(const DTable& list) override;
151 
152  /*
153  * @brief String output, as a concatenate of:
154  * alphabet character(value)
155  *
156  * with letters ordered alphabetically. Value is written with
157  * scientific format, and precision 8.
158  */
159  std::string toString() const override;
160 
161  void addElement(const std::vector<double>& element) override;
162 
163  void addElement(size_t pos, const std::vector<double>& element) override;
164 
165  void setElement(size_t pos, const std::vector<double>& element) override;
166 
167  const std::vector<double>& getElement(size_t pos) const override
168  {
169  return content_.getColumn(pos);
170  }
171 
172  virtual void deleteElement(size_t pos) override
173  {
174  content_.deleteColumn(pos);
175  }
176 
177  virtual void deleteElements(size_t pos, size_t len) override
178  {
179  content_.deleteColumns(pos, len);
180  }
181 
182  const std::vector<std::vector<double>>& getContent() const override
183  {
184  return content_.getData();
185  }
186 
187  const DTable& getTable() const override
188  {
189  return content_;
190  }
191 
192  const std::vector<double>& getValue(size_t pos) const override
193  {
194  return getElement(pos);
195  }
196 
197  const std::vector<double>& operator[](size_t pos) const override
198  {
199  return content_.getColumn(pos);
200  }
201 
202  std::vector<double>& operator[](size_t pos) override
203  {
204  return content_.getColumn(pos);
205  }
206 
207  double getStateValueAt(size_t siteIndex, int state) const override
208  {
209  if (siteIndex >= content_.getNumberOfColumns())
210  throw IndexOutOfBoundsException("ProbabilisticSymbolList::getStateValueAt.", siteIndex, 0, content_.getNumberOfColumns() - 1);
211  return content_.getColumn(siteIndex)[getAlphabet()->getStateIndex(state) - 1];
212  }
213 
214  double operator()(size_t siteIndex, int state) const override
215  {
216  return content_.getColumn(siteIndex)[getAlphabet()->getStateIndex(state) - 1];
217  }
218 
219  void shuffle() override
220  {
221  throw Exception("ProbabilisticSymbolList::shuffle not implemented, yet.");
222  }
223 };
224 } // end of namespace bpp
225 #endif // BPP_SEQ_PROBABILISTICSYMBOLLIST_H
The Alphabet interface.
Definition: Alphabet.h:99
The CruxSymbolList interface.
The ProbabilisticSymbolList interface.
virtual const DTable & getTable() const =0
virtual void setContent(const DTable &list)=0
virtual void setContent(const std::vector< T > &list)=0
Set the whole content of the list.
ProbabilisticSymbolList object.
double operator()(size_t siteIndex, int state) const override
get value of a state at a position
virtual void deleteElement(size_t pos) override
Remove the element at position 'pos'.
ProbabilisticSymbolList & operator=(const ProbabilisticSymbolListInterface &list)
The generic assignment operator.
const std::vector< double > & getElement(size_t pos) const override
Get the element at position 'pos' as a character.
std::shared_ptr< const Alphabet > getAlphabet() const override
Get the alphabet associated to the list.
DTable content_
The list content.
ProbabilisticSymbolList * clone() const override
double getStateValueAt(size_t siteIndex, int state) const override
get value of a state at a position
size_t size() const override
Get the number of elements in the list.
const std::vector< double > & operator[](size_t pos) const override
Operator [] overloaded for quick access to a character in list.
ProbabilisticSymbolList(std::shared_ptr< const Alphabet > &alpha)
Build a new void ProbabilisticSymbolList object with the specified alphabet.
std::vector< double > & operator[](size_t pos) override
Operator [] overloaded for quick access to a character in list.
virtual void deleteElements(size_t pos, size_t len) override
Remove the elements at position 'pos'.
const std::vector< std::vector< double > > & getContent() const override
void addElement(const std::vector< double > &element) override
std::string toString() const override
Convert the list as a string.
std::shared_ptr< const Alphabet > alphabet_
The Alphabet attribute must be initialized in the constructor and then can never be changed.
const DTable & getTable() const override
void setElement(size_t pos, const std::vector< double > &element) override
const Alphabet & alphabet() const override
Get the alphabet associated to the list.
void shuffle() override
Randomly shuffle the content of the list, with linear complexity.
const std::vector< double > & getValue(size_t pos) const override
checked access to a character in list.
size_t getNumberOfColumns() const
std::vector< T > & getColumn(size_t index)
void deleteColumn(size_t index)
const std::vector< std::vector< T > > & getData() const
void deleteColumns(size_t index, size_t len)
The CoreSymbolList interface.
virtual void setContent(const std::vector< T > &list)=0
Set the whole content of the list.
This alphabet is used to deal NumericAlphabet.