bpp-seq  2.1.0
Bpp/Seq/SequenceWithAnnotation.h
Go to the documentation of this file.
00001 //
00002 // File: SequenceWithAnnotation.h
00003 // Created by: Julien Dutheil
00004 // Created on: Mon Jul 19 2010
00005 //
00006 
00007 /*
00008 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
00009 
00010 This software is a computer program whose purpose is to provide classes
00011 for sequences analysis.
00012 
00013 This software is governed by the CeCILL  license under French law and
00014 abiding by the rules of distribution of free software.  You can  use, 
00015 modify and/ or redistribute the software under the terms of the CeCILL
00016 license as circulated by CEA, CNRS and INRIA at the following URL
00017 "http://www.cecill.info". 
00018 
00019 As a counterpart to the access to the source code and  rights to copy,
00020 modify and redistribute granted by the license, users are provided only
00021 with a limited warranty  and the software's author,  the holder of the
00022 economic rights,  and the successive licensors  have only  limited
00023 liability. 
00024 
00025 In this respect, the user's attention is drawn to the risks associated
00026 with loading,  using,  modifying and/or developing or reproducing the
00027 software by the user in light of its specific status of free software,
00028 that may mean  that it is complicated to manipulate,  and  that  also
00029 therefore means  that it is reserved for developers  and  experienced
00030 professionals having in-depth computer knowledge. Users are therefore
00031 encouraged to load and test the software's suitability as regards their
00032 requirements in conditions enabling the security of their systems and/or 
00033 data to be ensured and,  more generally, to use and operate it in the 
00034 same conditions as regards security. 
00035 
00036 The fact that you are presently reading this means that you have had
00037 knowledge of the CeCILL license and that you accept its terms.
00038 */
00039 
00040 #ifndef _SEQUENCEWITHANNOTATION_H_
00041 #define _SEQUENCEWITHANNOTATION_H_
00042 
00043 #include "Sequence.h"
00044 
00045 // From the STL:
00046 #include <string>
00047 #include <vector>
00048 
00049 namespace bpp
00050 {
00051 
00052 class SequenceWithAnnotation;
00053 
00057 class SequenceAnnotation :
00058   public virtual SymbolListListener
00059 {
00060   public:
00061     virtual SequenceAnnotation* clone() const = 0;
00062 
00068     virtual void init(const Sequence& seq) = 0;
00069 
00073     virtual const std::string& getType() const = 0;
00074 
00082     virtual bool isValidWith(const SequenceWithAnnotation& sequence, bool throwException = true) const = 0;
00083 
00090     virtual bool merge(const SequenceAnnotation& anno) = 0;
00091 
00098     virtual SequenceAnnotation* getPartAnnotation(size_t pos, size_t len) const throw (Exception) = 0;
00099 };
00100 
00118 class SequenceWithAnnotation :
00119   public Sequence,
00120   public EdSymbolList
00121 {
00122   private:
00123 
00127     std::string name_;
00128 
00132     Comments comments_;
00133 
00134   public:
00135 
00144     SequenceWithAnnotation(const Alphabet* alpha);
00145 
00158     SequenceWithAnnotation(const std::string& name, const std::string& sequence, const Alphabet* alpha) throw (BadCharException);
00159   
00174     SequenceWithAnnotation(const std::string& name, const std::string& sequence, const Comments& comments, const Alphabet* alpha) throw (BadCharException);
00175   
00186     SequenceWithAnnotation(const std::string& name, const std::vector<std::string>& sequence, const Alphabet* alpha) throw (BadCharException);
00187     
00199     SequenceWithAnnotation(const std::string& name, const std::vector<std::string>& sequence, const Comments& comments, const Alphabet* alpha) throw (BadCharException);
00200   
00208     SequenceWithAnnotation(const std::string& name, const std::vector<int>& sequence, const Alphabet* alpha) throw (BadIntException);
00209     
00218     SequenceWithAnnotation(const std::string& name, const std::vector<int>& sequence, const Comments& comments, const Alphabet* alpha) throw (BadIntException);
00219 
00223     SequenceWithAnnotation(const Sequence& s);
00224    
00228     SequenceWithAnnotation(const SequenceWithAnnotation& s);
00229  
00235     SequenceWithAnnotation& operator=(const Sequence& s);
00236    
00242     SequenceWithAnnotation& operator=(const SequenceWithAnnotation& s);
00243 
00244     virtual ~SequenceWithAnnotation() {}
00245 
00246   public:
00247   
00253     SequenceWithAnnotation* clone() const { return new SequenceWithAnnotation(*this); }
00268     const std::string& getName() const { return name_; }
00269     
00275     void setName(const std::string& name) { name_ = name; }
00276     
00290     const Comments& getComments() const { return comments_; }
00291     
00297     void setComments(const Comments& comments) { comments_ = comments; }
00298     
00314     virtual void setContent(const std::string& sequence) throw (BadCharException);
00315     void setContent(const std::vector<int>& list) throw (BadIntException)
00316     {
00317       EdSymbolList::setContent(list);
00318     }
00319     void setContent(const std::vector<std::string>& list) throw (BadCharException)
00320     {
00321       EdSymbolList::setContent(list);
00322     }
00323 
00324 
00333     virtual void setToSizeR(size_t newSize);
00334     
00343     virtual void setToSizeL(size_t newSize);
00344 
00351     void append(const std::vector<int>& content) throw (BadIntException);
00352 
00359     void append(const std::vector<std::string>& content) throw (BadCharException);
00360 
00367     void append(const std::string& content) throw (BadCharException);
00368 
00380     virtual void addAnnotation(SequenceAnnotation* anno) throw (Exception)
00381     {
00382       anno->isValidWith(*this);
00383       addSymbolListListener(anno);
00384     }
00385  
00386     virtual bool hasAnnotation(const std::string& type) const
00387     {
00388       for (size_t i = 0; i < getNumberOfListeners(); ++i) {
00389         const SymbolListListener* listener = &getListener(i);
00390         const SequenceAnnotation* anno = dynamic_cast<const SequenceAnnotation*>(listener);
00391         if (anno && anno->getType() == type) return true;
00392       }
00393       return false;
00394     }
00395 
00396    
00397     virtual const SequenceAnnotation& getAnnotation(const std::string& type) const
00398     {
00399       for (size_t i = 0; i < getNumberOfListeners(); ++i) {
00400         const SymbolListListener* listener = &getListener(i);
00401         const SequenceAnnotation* anno = dynamic_cast<const SequenceAnnotation*>(listener);
00402         if (anno && anno->getType() == type) return *anno;
00403       }
00404       throw Exception("SequenceWithAnnotation::getAnnotation. No annotation found with type '" + type + "'.");
00405     }
00406     
00407     virtual SequenceAnnotation& getAnnotation(const std::string& type)
00408     {
00409       for (size_t i = 0; i < getNumberOfListeners(); ++i) {
00410         SymbolListListener* listener = &getListener(i);
00411         SequenceAnnotation* anno = dynamic_cast<SequenceAnnotation*>(listener);
00412         if (anno && anno->getType() == type) return *anno;
00413       }
00414       throw Exception("SequenceWithAnnotation::getAnnotation. No annotation found with type '" + type + "'.");
00415     }
00416 
00420     virtual std::vector<std::string> getAnnotationTypes() const;
00421 
00434     virtual void merge(const SequenceWithAnnotation& swa)
00435         throw (AlphabetMismatchException, Exception);
00436 
00437 
00438 };
00439 
00440 } //end of namespace bpp.
00441 
00442 #endif // _SEQUENCEWITHANNOTATION_H_
00443 
 All Classes Namespaces Files Functions Variables Typedefs Friends