Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
AASequence.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2015.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Andreas Bertsch $
32 // $Authors: Andreas Bertsch $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CHEMISTRY_AASEQUENCE_H
36 #define OPENMS_CHEMISTRY_AASEQUENCE_H
37 
41 #include <OpenMS/CONCEPT/Types.h>
43 
44 #include <vector>
45 #include <iosfwd>
46 
47 namespace OpenMS
48 {
49 
50  //forward declarations
51  class ResidueModification;
52 
70  class OPENMS_DLLAPI AASequence
71  {
72 public:
73 
74  class Iterator;
75 
80  class OPENMS_DLLAPI ConstIterator
81  {
82 public:
83 
84  // TODO Iterator constructor for ConstIterator
85 
86  typedef const Residue& const_reference;
87  typedef Residue& reference;
88  typedef const Residue* const_pointer;
89  typedef std::vector<const Residue*>::difference_type difference_type;
91  typedef const Residue* pointer;
92  typedef std::random_access_iterator_tag iterator_category;
93 
99  {
100  }
101 
103  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
104  {
105  vector_ = vec_ptr;
106  position_ = position;
107  }
108 
111  vector_(rhs.vector_),
112  position_(rhs.position_)
113  {
114  }
115 
118  vector_(rhs.vector_),
119  position_(rhs.position_)
120  {
121  }
122 
124  virtual ~ConstIterator()
125  {
126  }
127 
129 
132  {
133  if (this != &rhs)
134  {
135  position_ = rhs.position_;
136  vector_ = rhs.vector_;
137  }
138  return *this;
139  }
140 
144  const_reference operator*() const
146  {
147  return *(*vector_)[position_];
148  }
149 
151  const_pointer operator->() const
152  {
153  return (*vector_)[position_];
154  }
155 
157  const ConstIterator operator+(difference_type diff) const
158  {
159  return ConstIterator(vector_, position_ + diff);
160  }
161 
162  difference_type operator-(ConstIterator rhs) const
163  {
164  return position_ - rhs.position_;
165  }
166 
168  const ConstIterator operator-(difference_type diff) const
169  {
170  return ConstIterator(vector_, position_ - diff);
171  }
172 
174  bool operator==(const ConstIterator& rhs) const
175  {
176  return vector_ == rhs.vector_ && position_ == rhs.position_;
177  }
178 
180  bool operator!=(const ConstIterator& rhs) const
181  {
182  return vector_ != rhs.vector_ || position_ != rhs.position_;
183  }
184 
187  {
188  ++position_;
189  return *this;
190  }
191 
194  {
195  --position_;
196  return *this;
197  }
198 
200 
201 protected:
202 
203  // pointer to the AASequence vector
204  const std::vector<const Residue*>* vector_;
205 
206  // position in the AASequence vector
207  difference_type position_;
208  };
209 
210 
215  class OPENMS_DLLAPI Iterator
216  {
217 public:
218 
220 
221  typedef const Residue& const_reference;
222  typedef Residue& reference;
223  typedef const Residue* const_pointer;
224  typedef const Residue* pointer;
225  typedef std::vector<const Residue*>::difference_type difference_type;
226 
230  Iterator()
232  {
233  }
234 
236  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
237  {
238  vector_ = vec_ptr;
239  position_ = position;
240  }
241 
243  Iterator(const Iterator& rhs) :
244  vector_(rhs.vector_),
245  position_(rhs.position_)
246  {
247  }
248 
250  virtual ~Iterator()
251  {
252  }
253 
255 
258  {
259  if (this != &rhs)
260  {
261  position_ = rhs.position_;
262  vector_ = rhs.vector_;
263  }
264  return *this;
265  }
266 
270  const_reference operator*() const
272  {
273  return *(*vector_)[position_];
274  }
275 
277  const_pointer operator->() const
278  {
279  return (*vector_)[position_];
280  }
281 
283  pointer operator->()
284  {
285  return (*vector_)[position_];
286  }
287 
289  const Iterator operator+(difference_type diff) const
290  {
291  return Iterator(vector_, position_ + diff);
292  }
293 
294  difference_type operator-(Iterator rhs) const
295  {
296  return position_ - rhs.position_;
297  }
298 
300  const Iterator operator-(difference_type diff) const
301  {
302  return Iterator(vector_, position_ - diff);
303  }
304 
306  bool operator==(const Iterator& rhs) const
307  {
308  return vector_ == rhs.vector_ && position_ == rhs.position_;
309  }
310 
312  bool operator!=(const Iterator& rhs) const
313  {
314  return vector_ != rhs.vector_ || position_ != rhs.position_;
315  }
316 
319  {
320  ++position_;
321  return *this;
322  }
323 
326  {
327  --position_;
328  return *this;
329  }
330 
332 
333 protected:
334 
335  // pointer to the AASequence vector
336  std::vector<const Residue*>* vector_;
337 
338  // position in the AASequence vector
339  difference_type position_;
340  };
341 
345  AASequence();
347 
349  AASequence(const AASequence& rhs);
350 
352  virtual ~AASequence();
354 
356  AASequence& operator=(const AASequence& rhs);
357 
359  bool empty() const;
360 
364  String toString() const;
366 
368  String toUnmodifiedString() const;
369 
371  void setModification(Size index, const String& modification);
372 
374  void setNTerminalModification(const String& modification);
375 
377  const String& getNTerminalModification() const;
378 
380  void setCTerminalModification(const String& modification);
381 
383  const String& getCTerminalModification() const;
384 
386  const Residue& getResidue(SignedSize index) const;
387 
389  const Residue& getResidue(Size index) const;
390 
392  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
393 
395  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
396 
398  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
399 
401  const Residue& operator[](SignedSize index) const;
402 
404  const Residue& operator[](Size index) const;
405 
407  AASequence operator+(const AASequence& peptide) const;
408 
410  AASequence& operator+=(const AASequence&);
411 
413  AASequence operator+(const Residue* residue) const;
414 
416  AASequence& operator+=(const Residue*);
417 
419  Size size() const;
420 
422  AASequence getPrefix(Size index) const;
423 
425  AASequence getSuffix(Size index) const;
426 
428  AASequence getSubsequence(Size index, UInt number) const;
429 
431  void getAAFrequencies(Map<String, Size>& frequency_table) const;
432 
434 
438  bool has(const Residue& residue) const;
440 
443  bool hasSubsequence(const AASequence& peptide) const;
444 
447  bool hasPrefix(const AASequence& peptide) const;
448 
451  bool hasSuffix(const AASequence& peptide) const;
452 
454  bool hasNTerminalModification() const;
455 
457  bool hasCTerminalModification() const;
458 
460  bool isModified() const;
461 
463  bool isModified(Size index) const;
464 
466  bool operator==(const AASequence& rhs) const;
467 
469  bool operator<(const AASequence& rhs) const;
470 
472  bool operator!=(const AASequence& rhs) const;
474 
478  inline Iterator begin() { return Iterator(&peptide_, 0); }
479 
480  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
481 
482  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
483 
484  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
486 
490  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
492 
494  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
496 
503  static AASequence fromString(const String& s,
504  bool permissive = true);
505 
512  static AASequence fromString(const char* s,
513  bool permissive = true);
514 
515  protected:
516  std::vector<const Residue*> peptide_;
517 
519 
521 
522  static String::ConstIterator parseModRoundBrackets_(
523  const String::ConstIterator str_it, const String& str, AASequence& aas);
524 
525  static String::ConstIterator parseModSquareBrackets_(
526  const String::ConstIterator str_it, const String& str, AASequence& aas);
527 
528  static void parseString_(const String& peptide, AASequence& aas,
529  bool permissive = true);
530  };
531 
532  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
533 
534  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
535 
536 } // namespace OpenMS
537 
538 
539 #endif
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:257
virtual ~ConstIterator()
destructor
Definition: AASequence.h:124
A more convenient string class.
Definition: String.h:57
difference_type position_
Definition: AASequence.h:207
const Residue & const_reference
Definition: AASequence.h:221
ConstIterator & operator=(const ConstIterator &rhs)
assignment operator
Definition: AASequence.h:131
Iterator end()
Definition: AASequence.h:482
Residue & reference
Definition: AASequence.h:87
Representation of a modification.
Definition: ResidueModification.h:65
difference_type operator-(ConstIterator rhs) const
Definition: AASequence.h:162
const Residue * const_pointer
Definition: AASequence.h:88
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:128
Representation of a peptide/protein sequence.
Definition: AASequence.h:70
Iterator begin()
Definition: AASequence.h:478
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::vector< const Residue * > * vector_
Definition: AASequence.h:336
Iterator & operator++()
increment operator
Definition: AASequence.h:318
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:92
Representation of a residue.
Definition: Residue.h:62
difference_type position_
Definition: AASequence.h:339
ConstIterator(const ConstIterator &rhs)
copy constructor
Definition: AASequence.h:110
Representation of an empirical formula.
Definition: EmpiricalFormula.h:79
void setModification(int location, int max_size, String modification, OpenMS::AASequence &aas)
helper function that sets a modification on a AASequence object
Residue value_type
Definition: AASequence.h:90
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:180
Iterator(const Iterator &rhs)
copy constructor
Definition: AASequence.h:243
const_pointer operator->() const
dereference operator
Definition: AASequence.h:277
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
pointer operator->()
mutable dereference operator
Definition: AASequence.h:283
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:421
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:300
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:225
ConstIterator for AASequence.
Definition: AASequence.h:80
ResidueType
Definition: Residue.h:359
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:168
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:289
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:312
Iterator & operator--()
decrement operator
Definition: AASequence.h:325
Residue & reference
Definition: AASequence.h:222
const Residue * const_pointer
Definition: AASequence.h:223
const_iterator ConstIterator
Const Iterator.
Definition: String.h:71
std::vector< const Residue * > peptide_
Definition: AASequence.h:516
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:89
std::istream & operator>>(std::istream &os, const AASequence &peptide)
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:193
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:117
const ResidueModification * n_term_mod_
Definition: AASequence.h:518
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:174
const ResidueModification * c_term_mod_
Definition: AASequence.h:520
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:157
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:294
Iterator class for AASequence.
Definition: AASequence.h:215
ConstIterator(const std::vector< const Residue * > *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:103
Definition: Residue.h:361
const Residue * pointer
Definition: AASequence.h:224
Iterator(std::vector< const Residue * > *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:236
const Residue & const_reference
Definition: AASequence.h:86
const_pointer operator->() const
dereference operator
Definition: AASequence.h:151
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
const Residue * pointer
Definition: AASequence.h:91
const std::vector< const Residue * > * vector_
Definition: AASequence.h:204
int Int
Signed integer type.
Definition: Types.h:96
ConstIterator end() const
Definition: AASequence.h:484
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:306
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
ConstIterator begin() const
Definition: AASequence.h:480
virtual ~Iterator()
destructor
Definition: AASequence.h:250
ConstIterator & operator++()
increment operator
Definition: AASequence.h:186

OpenMS / TOPP release 2.0.0 Documentation generated on Thu Aug 20 2015 01:44:21 using doxygen 1.8.9.1