bpp-seq3  3.0.0
Sequence.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_SEQUENCE_H
6 #define BPP_SEQ_SEQUENCE_H
7 
8 
9 #include "CoreSequence.h"
10 #include "IntSymbolList.h"
11 #include "SequenceExceptions.h"
12 
13 // From the STL:
14 #include <string>
15 #include <vector>
16 
17 namespace bpp
18 {
32  public virtual CoreSequenceInterface,
33  public virtual IntSymbolListInterface
34 {
35 public:
36  typedef int ElementType;
37 
38 public:
39  virtual ~SequenceInterface() {}
40 
41 public:
42  SequenceInterface* clone() const override = 0;
43 
44 
57  virtual void setContent(const std::string& sequence) = 0;
58 
59  virtual void setContent(const std::vector<std::string>& list) override = 0;
60 
61  virtual void setContent(const std::vector<int>& list) override = 0;
62 
69  virtual void append(const SequenceInterface& seq) = 0;
70 
77  virtual void append(const std::vector<int>& content) = 0;
78 
85  virtual void append(const std::vector<std::string>& content) = 0;
86 
93  virtual void append(const std::string& content) = 0;
94 
96 };
97 
98 
113 class Sequence :
114  public virtual SequenceInterface,
115  public AbstractCoreSequence,
116  public IntSymbolList
117 {
118 public:
127  Sequence(std::shared_ptr<const Alphabet>& alpha) :
128  AbstractTemplateSymbolList<int>(alpha),
130  IntSymbolList(alpha)
131  {}
132 
133 
147  const std::string& name,
148  const std::string& sequence,
149  std::shared_ptr<const Alphabet>& alpha) :
150  AbstractTemplateSymbolList<int>(alpha),
151  AbstractCoreSequence(name),
152  IntSymbolList(alpha)
153  {
154  if (sequence != "")
155  setContent(sequence);
156  }
157 
158 
174  const std::string& name,
175  const std::string& sequence,
176  const Comments& comments,
177  std::shared_ptr<const Alphabet>& alpha) :
178  AbstractTemplateSymbolList<int>(alpha),
179  AbstractCoreSequence(name, comments),
180  IntSymbolList(alpha)
181  {
182  if (sequence != "")
183  setContent(sequence);
184  }
185 
186 
198  const std::string& name,
199  const std::vector<std::string>& sequence,
200  std::shared_ptr<const Alphabet>& alpha) :
201  AbstractTemplateSymbolList<int>(alpha),
202  AbstractCoreSequence(name),
203  IntSymbolList(sequence, alpha)
204  {}
205 
206 
219  const std::string& name,
220  const std::vector<std::string>& sequence,
221  const Comments& comments,
222  std::shared_ptr<const Alphabet>& alpha) :
223  AbstractTemplateSymbolList<int>(alpha),
224  AbstractCoreSequence(name, comments),
225  IntSymbolList(sequence, alpha)
226  {}
227 
228 
237  const std::string& name,
238  const std::vector<int>& sequence,
239  std::shared_ptr<const Alphabet>& alpha) :
240  AbstractTemplateSymbolList<int>(sequence, alpha),
241  AbstractCoreSequence(name),
242  IntSymbolList(sequence, alpha)
243  {}
244 
245 
255  const std::string& name,
256  const std::vector<int>& sequence,
257  const Comments& comments,
258  std::shared_ptr<const Alphabet>& alpha) :
259  AbstractTemplateSymbolList<int>(sequence, alpha),
260  AbstractCoreSequence(name, comments),
261  IntSymbolList(sequence, alpha)
262  {}
263 
264 
272  {}
273 
274 
278  Sequence(const Sequence& s) :
282  {}
283 
284 
291  {
293  setContent(s.getContent());
294  return *this;
295  }
296 
297 
304  {
307  return *this;
308  }
309 
310 
311  virtual ~Sequence() {}
312 
313 public:
319  Sequence* clone() const override { return new Sequence(*this); }
327  void setContent(const std::string& sequence) override;
328 
330 
331  void setContent(const std::vector<std::string>& list) override
332  {
334  }
335 
336  void setContent(const std::vector<int>& list) override
337  {
339  }
340 
341  std::string toString() const override
342  {
343  return IntSymbolList::toString();
344  }
345 
346  std::string getChar(size_t pos) const override
347  {
348  return IntSymbolList::getChar(pos);
349  }
350 
351  void setToSizeR(size_t newSize) override;
352 
353  void setToSizeL(size_t newSize) override;
354 
355  void append(const SequenceInterface& seq) override;
356 
357  void append(const std::vector<int>& content) override;
358 
359  void append(const std::vector<std::string>& content) override;
360 
361  void append(const std::string& content) override;
362 
366  double getStateValueAt(size_t sitePosition, int state) const override
367  {
368  if (sitePosition >= size()) throw IndexOutOfBoundsException("BasicSequence::getStateValueAt.", sitePosition, 0, size() - 1);
369  return getAlphabet()->isResolvedIn((*this)[sitePosition], state) ? 1. : 0.;
370  }
371 };
372 } // end of namespace bpp.
373 #endif // BPP_SEQ_SEQUENCE_H
A partial implementation of the CoreSequence interface.
Definition: CoreSequence.h:98
AbstractCoreSequence & operator=(const AbstractCoreSequence &s)
Definition: CoreSequence.h:134
A partial implementation of a SymbolList object.
Definition: SymbolList.h:34
virtual const std::vector< int > & getContent() const override
Definition: SymbolList.h:131
std::shared_ptr< const Alphabet > getAlphabet() const override
Definition: SymbolList.h:120
size_t size() const override
Definition: SymbolList.h:124
The core sequence interface.
Definition: CoreSequence.h:28
The specific IntSymbolList interface.
Definition: IntSymbolList.h:29
virtual void setContent(const std::vector< T > &list)=0
Set the whole content of the list.
A basic IntSymbolList object.
IntSymbolList & operator=(const IntSymbolListInterface &list)
The generic assignment operator.
std::string getChar(size_t pos) const override
Get the element at position 'pos' as a character.
void addElement(const T &v) override
Definition: SymbolList.h:152
std::string toString() const override
Convert the list as a string.
The sequence interface.
Definition: Sequence.h:34
virtual void append(const SequenceInterface &seq)=0
Append the content of the sequence.
virtual ~SequenceInterface()
Definition: Sequence.h:39
virtual void setContent(const std::vector< std::string > &list) override=0
Set the whole content of the list.
virtual void append(const std::vector< int > &content)=0
Append the specified content to the sequence.
virtual void setContent(const std::vector< int > &list) override=0
SequenceInterface * clone() const override=0
virtual void append(const std::string &content)=0
Append the specified content to the sequence.
virtual void setContent(const std::string &sequence)=0
Set the whole content of the sequence.
virtual void append(const std::vector< std::string > &content)=0
Append the specified content to the sequence.
A basic implementation of the Sequence interface.
Definition: Sequence.h:117
Sequence(const std::string &name, const std::vector< int > &sequence, const Comments &comments, std::shared_ptr< const Alphabet > &alpha)
General purpose constructor, can be used with any alphabet.
Definition: Sequence.h:254
Sequence(const Sequence &s)
The Sequence copy constructor. This does not perform a hard copy of the alphabet object.
Definition: Sequence.h:278
void setContent(const std::vector< int > &list) override
Definition: Sequence.h:336
void setToSizeL(size_t newSize) override
Set up the size of a sequence from the left side.
Definition: Sequence.cpp:51
std::string toString() const override
Convert the list as a string.
Definition: Sequence.h:341
void setToSizeR(size_t newSize) override
Set up the size of a sequence from the right side.
Definition: Sequence.cpp:30
void append(const SequenceInterface &seq) override
Append the content of the sequence.
Definition: Sequence.cpp:73
Sequence(const SequenceInterface &s)
The Sequence generic copy constructor. This does not perform a hard copy of the alphabet object.
Definition: Sequence.h:268
double getStateValueAt(size_t sitePosition, int state) const override
get value of a state at a position
Definition: Sequence.h:366
Sequence & operator=(const SequenceInterface &s)
The Sequence generic assignment operator. This does not perform a hard copy of the alphabet object.
Definition: Sequence.h:290
Sequence * clone() const override
Definition: Sequence.h:319
void setContent(const std::vector< std::string > &list) override
Set the whole content of the list.
Definition: Sequence.h:331
virtual ~Sequence()
Definition: Sequence.h:311
Sequence(const std::string &name, const std::string &sequence, const Comments &comments, std::shared_ptr< const Alphabet > &alpha)
Direct constructor: build a Sequence object from a std::string.
Definition: Sequence.h:173
Sequence & operator=(const Sequence &s)
The Sequence assignment operator. This does not perform a hard copy of the alphabet object.
Definition: Sequence.h:303
std::string getChar(size_t pos) const override
Get the element at position 'pos' as a character.
Definition: Sequence.h:346
Sequence(const std::string &name, const std::string &sequence, std::shared_ptr< const Alphabet > &alpha)
Direct constructor: build a Sequence object from a std::string You can use it safely for RNA,...
Definition: Sequence.h:146
Sequence(const std::string &name, const std::vector< int > &sequence, std::shared_ptr< const Alphabet > &alpha)
General purpose constructor, can be used with any alphabet.
Definition: Sequence.h:236
Sequence(std::shared_ptr< const Alphabet > &alpha)
Empty constructor: build a void Sequence with just an Alphabet.
Definition: Sequence.h:127
Sequence(const std::string &name, const std::vector< std::string > &sequence, const Comments &comments, std::shared_ptr< const Alphabet > &alpha)
General purpose constructor, can be used with any alphabet.
Definition: Sequence.h:218
Sequence(const std::string &name, const std::vector< std::string > &sequence, std::shared_ptr< const Alphabet > &alpha)
General purpose constructor, can be used with any alphabet.
Definition: Sequence.h:197
virtual const std::vector< T > & getContent() const =0
This alphabet is used to deal NumericAlphabet.
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Commentable.h:21