Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

AASequence.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Andreas Bertsch $
00032 // $Authors: Andreas Bertsch $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_CHEMISTRY_AASEQUENCE_H
00036 #define OPENMS_CHEMISTRY_AASEQUENCE_H
00037 
00038 #include <OpenMS/CHEMISTRY/EmpiricalFormula.h>
00039 #include <OpenMS/DATASTRUCTURES/String.h>
00040 #include <OpenMS/DATASTRUCTURES/Map.h>
00041 #include <OpenMS/CONCEPT/Types.h>
00042 #include <OpenMS/CHEMISTRY/Residue.h>
00043 #include <OpenMS/CHEMISTRY/ResidueModification.h>
00044 
00045 #include <vector>
00046 #include <iostream>
00047 
00048 namespace OpenMS
00049 {
00050   class ResidueDB;
00084   class OPENMS_DLLAPI AASequence
00085   {
00086 
00087 public:
00088     class Iterator;
00089 
00094     class OPENMS_DLLAPI ConstIterator
00095     {
00096 public:
00097 
00098       // TODO Iterator constructor for ConstIterator
00099 
00100       typedef const Residue & const_reference;
00101       typedef Residue & reference;
00102       typedef const Residue * const_pointer;
00103       typedef std::vector<const Residue *>::difference_type difference_type;
00104       typedef Residue value_type;
00105       typedef const Residue * pointer;
00106       typedef std::random_access_iterator_tag iterator_category;
00107 
00111 
00112       ConstIterator()
00113       {
00114       }
00115 
00117       ConstIterator(const std::vector<const Residue *> * vec_ptr, difference_type position)
00118       {
00119         vector_ = vec_ptr;
00120         position_ = position;
00121       }
00122 
00124       ConstIterator(const ConstIterator & rhs) :
00125         vector_(rhs.vector_),
00126         position_(rhs.position_)
00127       {
00128       }
00129 
00131       ConstIterator(const AASequence::Iterator & rhs) :
00132         vector_(rhs.vector_),
00133         position_(rhs.position_)
00134       {
00135       }
00136 
00138       virtual ~ConstIterator()
00139       {
00140       }
00141 
00143 
00145       ConstIterator & operator=(const ConstIterator & rhs)
00146       {
00147         if (this != &rhs)
00148         {
00149           position_ = rhs.position_;
00150           vector_ = rhs.vector_;
00151         }
00152         return *this;
00153       }
00154 
00158 
00159       const_reference operator*() const
00160       {
00161         return *(*vector_)[position_];
00162       }
00163 
00165       const_pointer operator->() const
00166       {
00167         return (*vector_)[position_];
00168       }
00169 
00171       const ConstIterator operator+(difference_type diff) const
00172       {
00173         return ConstIterator(vector_, position_ + diff);
00174       }
00175 
00176       difference_type operator-(ConstIterator rhs) const
00177       {
00178         return position_ - rhs.position_;
00179       }
00180 
00182       const ConstIterator operator-(difference_type diff) const
00183       {
00184         return ConstIterator(vector_, position_ - diff);
00185       }
00186 
00188       bool operator==(const ConstIterator & rhs) const
00189       {
00190         return vector_ == rhs.vector_ && position_ == rhs.position_;
00191       }
00192 
00194       bool operator!=(const ConstIterator & rhs) const
00195       {
00196         return vector_ != rhs.vector_ || position_ != rhs.position_;
00197       }
00198 
00200       ConstIterator & operator++()
00201       {
00202         ++position_;
00203         return *this;
00204       }
00205 
00207       ConstIterator & operator--()
00208       {
00209         --position_;
00210         return *this;
00211       }
00212 
00214 
00215 protected:
00216 
00217       // pointer to the AASequence vector
00218       const std::vector<const Residue *> * vector_;
00219 
00220       // position in the AASequence vector
00221       difference_type position_;
00222     };
00223 
00224 
00229     class OPENMS_DLLAPI Iterator
00230     {
00231 public:
00232 
00233       friend class AASequence::ConstIterator;
00234 
00235       typedef const Residue & const_reference;
00236       typedef Residue & reference;
00237       typedef const Residue * const_pointer;
00238       typedef const Residue * pointer;
00239       typedef std::vector<const Residue *>::difference_type difference_type;
00240 
00244 
00245       Iterator()
00246       {
00247       }
00248 
00250       Iterator(std::vector<const Residue *> * vec_ptr, difference_type position)
00251       {
00252         vector_ = vec_ptr;
00253         position_ = position;
00254       }
00255 
00257       Iterator(const Iterator & rhs) :
00258         vector_(rhs.vector_),
00259         position_(rhs.position_)
00260       {
00261       }
00262 
00264       virtual ~Iterator()
00265       {
00266       }
00267 
00269 
00271       Iterator & operator=(const Iterator & rhs)
00272       {
00273         if (this != &rhs)
00274         {
00275           position_ = rhs.position_;
00276           vector_ = rhs.vector_;
00277         }
00278         return *this;
00279       }
00280 
00284 
00285       const_reference operator*() const
00286       {
00287         return *(*vector_)[position_];
00288       }
00289 
00291       const_pointer operator->() const
00292       {
00293         return (*vector_)[position_];
00294       }
00295 
00297       pointer operator->()
00298       {
00299         return (*vector_)[position_];
00300       }
00301 
00303       const Iterator operator+(difference_type diff) const
00304       {
00305         return Iterator(vector_, position_ + diff);
00306       }
00307 
00308       difference_type operator-(Iterator rhs) const
00309       {
00310         return position_ - rhs.position_;
00311       }
00312 
00314       const Iterator operator-(difference_type diff) const
00315       {
00316         return Iterator(vector_, position_ - diff);
00317       }
00318 
00320       bool operator==(const Iterator & rhs) const
00321       {
00322         return vector_ == rhs.vector_ && position_ == rhs.position_;
00323       }
00324 
00326       bool operator!=(const Iterator & rhs) const
00327       {
00328         return vector_ != rhs.vector_ || position_ != rhs.position_;
00329       }
00330 
00332       Iterator & operator++()
00333       {
00334         ++position_;
00335         return *this;
00336       }
00337 
00339       Iterator & operator--()
00340       {
00341         --position_;
00342         return *this;
00343       }
00344 
00346 
00347 protected:
00348 
00349       // pointer to the AASequence vector
00350       std::vector<const Residue *> * vector_;
00351 
00352       // position in the AASequence vector
00353       difference_type position_;
00354     };
00355 
00356 
00357 
00361 
00362     AASequence();
00363 
00365     AASequence(const AASequence & rhs);
00366 
00368     AASequence(const String & rhs);
00369 
00371     AASequence(const char * rhs);
00372 
00374     virtual ~AASequence();
00376 
00378     AASequence & operator=(const AASequence & rhs);
00379 
00381     bool empty() const;
00382 
00386 
00387     String toString() const;
00388 
00390     String toUnmodifiedString() const;
00391 
00393     void setModification(Size index, const String & modification);
00394 
00396     void setNTerminalModification(const String & modification);
00397 
00399     const String & getNTerminalModification() const;
00400 
00402     void setCTerminalModification(const String & modification);
00403 
00405     const String & getCTerminalModification() const;
00406 
00408     bool setStringSequence(const String & sequence);
00409 
00411     const Residue & getResidue(SignedSize index) const;
00412 
00414     const Residue & getResidue(Size index) const;
00415 
00417     EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
00418 
00420     DoubleReal getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
00421 
00423     DoubleReal getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
00424 
00426     const Residue & operator[](SignedSize index) const;
00427 
00429     const Residue & operator[](Size index) const;
00430 
00432     AASequence operator+(const AASequence & peptide) const;
00433 
00435     AASequence operator+(const String & peptide) const;
00436 
00438     AASequence operator+(const char * rhs) const;
00439 
00441     AASequence operator+(const Residue * residue) const;
00442 
00444     AASequence & operator+=(const AASequence &);
00445 
00447     AASequence & operator+=(const String &);
00448 
00450     AASequence & operator+=(const char * rhs);
00451 
00453     AASequence & operator+=(const Residue * residue);
00454 
00456     Size size() const;
00457 
00459     AASequence getPrefix(Size index) const;
00460 
00462     AASequence getSuffix(Size index) const;
00463 
00465     AASequence getSubsequence(Size index, UInt number) const;
00466 
00468     Size getNumberOf(const String & residue) const;
00469 
00471     void getAAFrequencies(Map<String, Size> & frequency_table) const;
00472 
00474 
00484     bool isValid() const;
00485 
00487     bool has(const Residue & residue) const;
00488 
00490     bool has(const String & name) const;
00491 
00494     bool hasSubsequence(const AASequence & peptide) const;
00495 
00498     bool hasSubsequence(const String & peptide) const;
00499 
00502     bool hasPrefix(const AASequence & peptide) const;
00503 
00506     bool hasPrefix(const String & peptide) const;
00507 
00510     bool hasSuffix(const AASequence & peptide) const;
00511 
00514     bool hasSuffix(const String & peptide) const;
00515 
00517     bool hasNTerminalModification() const;
00518 
00520     bool hasCTerminalModification() const;
00521 
00522     // returns true if any of the residues is modified
00523     bool isModified() const;
00524 
00526     bool isModified(Size index) const;
00527 
00529     bool operator==(const AASequence & rhs) const;
00530 
00532     bool operator==(const String & rhs) const;
00533 
00535     bool operator==(const char * rhs) const;
00536 
00538     bool operator<(const AASequence & rhs) const;
00539 
00541     bool operator!=(const AASequence & rhs) const;
00542 
00544     bool operator!=(const String & rhs) const;
00545 
00547     bool operator!=(const char * rhs) const;
00549 
00553     inline Iterator begin() { return Iterator(&peptide_, 0); }
00554 
00555     inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
00556 
00557     inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
00558 
00559     inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
00561 
00565 
00566     friend OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const AASequence & peptide);
00567 
00569     friend OPENMS_DLLAPI std::istream & operator>>(std::istream & is, const AASequence & peptide);
00571 
00572 protected:
00573 
00574     std::vector<const Residue *> peptide_;
00575 
00576     String sequence_string_;
00577 
00578     void parseString_(std::vector<const Residue *> & sequence, const String & peptide);
00579 
00580     ResidueDB * getResidueDB_() const;
00581 
00582     bool valid_;
00583 
00584     const ResidueModification * n_term_mod_;
00585 
00586     const ResidueModification * c_term_mod_;
00587   };
00588 
00589   OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const AASequence & peptide);
00590 
00591   OPENMS_DLLAPI std::istream & operator>>(std::istream & os, const AASequence & peptide);
00592 
00593 } // namespace OpenMS
00594 
00595 #endif

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:37 using doxygen 1.7.1