bpp-seq  2.2.0
SequenceWithAnnotation.h
Go to the documentation of this file.
1 //
2 // File: SequenceWithAnnotation.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Jul 19 2010
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences 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 _SEQUENCEWITHANNOTATION_H_
41 #define _SEQUENCEWITHANNOTATION_H_
42 
43 #include "Sequence.h"
44 
45 // From the STL:
46 #include <string>
47 #include <vector>
48 
49 namespace bpp
50 {
51 
52 class SequenceWithAnnotation;
53 
58  public virtual SymbolListListener
59 {
60  public:
61  virtual SequenceAnnotation* clone() const = 0;
62 
68  virtual void init(const Sequence& seq) = 0;
69 
73  virtual const std::string& getType() const = 0;
74 
82  virtual bool isValidWith(const SequenceWithAnnotation& sequence, bool throwException = true) const = 0;
83 
90  virtual bool merge(const SequenceAnnotation& anno) = 0;
91 
98  virtual SequenceAnnotation* getPartAnnotation(size_t pos, size_t len) const throw (Exception) = 0;
99 };
100 
119  public Sequence,
120  public EdSymbolList
121 {
122  private:
123 
127  std::string name_;
128 
133 
134  public:
135 
144  SequenceWithAnnotation(const Alphabet* alpha);
145 
158  SequenceWithAnnotation(const std::string& name, const std::string& sequence, const Alphabet* alpha) throw (BadCharException);
159 
174  SequenceWithAnnotation(const std::string& name, const std::string& sequence, const Comments& comments, const Alphabet* alpha) throw (BadCharException);
175 
186  SequenceWithAnnotation(const std::string& name, const std::vector<std::string>& sequence, const Alphabet* alpha) throw (BadCharException);
187 
199  SequenceWithAnnotation(const std::string& name, const std::vector<std::string>& sequence, const Comments& comments, const Alphabet* alpha) throw (BadCharException);
200 
208  SequenceWithAnnotation(const std::string& name, const std::vector<int>& sequence, const Alphabet* alpha) throw (BadIntException);
209 
218  SequenceWithAnnotation(const std::string& name, const std::vector<int>& sequence, const Comments& comments, const Alphabet* alpha) throw (BadIntException);
219 
224 
229 
236 
243 
245 
246  public:
247 
253  SequenceWithAnnotation* clone() const { return new SequenceWithAnnotation(*this); }
268  const std::string& getName() const { return name_; }
269 
275  void setName(const std::string& name) { name_ = name; }
276 
290  const Comments& getComments() const { return comments_; }
291 
297  void setComments(const Comments& comments) { comments_ = comments; }
298 
314  virtual void setContent(const std::string& sequence) throw (BadCharException);
315  void setContent(const std::vector<int>& list) throw (BadIntException)
316  {
318  }
319  void setContent(const std::vector<std::string>& list) throw (BadCharException)
320  {
322  }
323 
324 
333  virtual void setToSizeR(size_t newSize);
334 
343  virtual void setToSizeL(size_t newSize);
344 
351  void append(const std::vector<int>& content) throw (BadIntException);
352 
359  void append(const std::vector<std::string>& content) throw (BadCharException);
360 
367  void append(const std::string& content) throw (BadCharException);
368 
380  virtual void addAnnotation(SequenceAnnotation* anno) throw (Exception)
381  {
382  anno->isValidWith(*this);
383  addSymbolListListener(anno);
384  }
385 
386  virtual bool hasAnnotation(const std::string& type) const
387  {
388  for (size_t i = 0; i < getNumberOfListeners(); ++i) {
389  const SymbolListListener* listener = &getListener(i);
390  const SequenceAnnotation* anno = dynamic_cast<const SequenceAnnotation*>(listener);
391  if (anno && anno->getType() == type) return true;
392  }
393  return false;
394  }
395 
396 
397  virtual const SequenceAnnotation& getAnnotation(const std::string& type) const
398  {
399  for (size_t i = 0; i < getNumberOfListeners(); ++i) {
400  const SymbolListListener* listener = &getListener(i);
401  const SequenceAnnotation* anno = dynamic_cast<const SequenceAnnotation*>(listener);
402  if (anno && anno->getType() == type) return *anno;
403  }
404  throw Exception("SequenceWithAnnotation::getAnnotation. No annotation found with type '" + type + "'.");
405  }
406 
407  virtual SequenceAnnotation& getAnnotation(const std::string& type)
408  {
409  for (size_t i = 0; i < getNumberOfListeners(); ++i) {
410  SymbolListListener* listener = &getListener(i);
411  SequenceAnnotation* anno = dynamic_cast<SequenceAnnotation*>(listener);
412  if (anno && anno->getType() == type) return *anno;
413  }
414  throw Exception("SequenceWithAnnotation::getAnnotation. No annotation found with type '" + type + "'.");
415  }
416 
420  virtual std::vector<std::string> getAnnotationTypes() const;
421 
434  virtual void merge(const SequenceWithAnnotation& swa)
435  throw (AlphabetMismatchException, Exception);
436 
437 
438 };
439 
440 } //end of namespace bpp.
441 
442 #endif // _SEQUENCEWITHANNOTATION_H_
443 
An alphabet exception thrown when trying to specify a bad char to the alphabet.
std::vector< std::string > Comments
Declaration of Comments type.
Definition: Sequence.h:60
virtual void setContent(const std::string &sequence)
Set the whole content of the sequence.
virtual SequenceAnnotation * clone() const =0
void setContent(const std::vector< std::string > &list)
Set the whole content of the list.
const Comments & getComments() const
Get the comments associated to this sequence.
virtual void setToSizeR(size_t newSize)
Set up the size of a sequence from the right side.
void setName(const std::string &name)
Set the name of this sequence.
virtual std::vector< std::string > getAnnotationTypes() const
virtual size_t getNumberOfListeners() const
Definition: SymbolList.h:645
This alphabet is used to deal NumericAlphabet.
virtual void setContent(const std::vector< int > &list)
Set the whole content of the list.
Definition: SymbolList.cpp:297
SequenceWithAnnotation(const Alphabet *alpha)
Empty constructor: build a void Sequence with just an Alphabet.
std::string name_
The sequence name.
The Alphabet interface.
Definition: Alphabet.h:130
void setComments(const Comments &comments)
Set the comments associated to this sequence.
virtual const std::string & getType() const =0
virtual void addAnnotation(SequenceAnnotation *anno)
Add a new annotation to the sequence.
virtual bool hasAnnotation(const std::string &type) const
virtual SequenceAnnotation * getPartAnnotation(size_t pos, size_t len) const =0
virtual void merge(const SequenceWithAnnotation &swa)
Merge a sequence with the current one.
void setContent(const std::vector< int > &list)
Set the whole content of the list.
virtual bool isValidWith(const SequenceWithAnnotation &sequence, bool throwException=true) const =0
Test is the annotation is valid for a given sequence.
virtual bool merge(const SequenceAnnotation &anno)=0
Merge the input annotation with the current one.
virtual void addSymbolListListener(SymbolListListener *listener)
Definition: SymbolList.h:657
virtual const SequenceAnnotation & getAnnotation(const std::string &type) const
Interface for sequence annotations.
virtual SequenceAnnotation & getAnnotation(const std::string &type)
An implementation of the Sequence interface that supports annotation.
SequenceWithAnnotation * clone() const
virtual void setToSizeL(size_t newSize)
Set up the size of a sequence from the left side.
SequenceWithAnnotation & operator=(const Sequence &s)
The Sequence generic assignment operator. This does not perform a hard copy of the alphabet object...
The sequence interface.
Definition: Sequence.h:74
Comments comments_
The sequence comments.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
A event-driven SymbolList object.
Definition: SymbolList.h:500
virtual const SymbolListListener & getListener(size_t i) const
Definition: SymbolList.h:647
const std::string & getName() const
Get the name of this sequence.
Exception thrown when two alphabets do not match.
virtual void init(const Sequence &seq)=0
void append(const std::vector< int > &content)
Append the specified content to the sequence.