OpenMS  2.4.0
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-2018.
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: Timo Sachsenberg $
32 // $Authors: Andreas Bertsch $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 #include <OpenMS/CONCEPT/Types.h>
42 
43 #include <vector>
44 #include <iosfwd>
45 
46 namespace OpenMS
47 {
48 
49  //forward declarations
50  class ResidueModification;
51 
107  class OPENMS_DLLAPI AASequence
108  {
109 public:
110 
111  class Iterator;
112 
117  class OPENMS_DLLAPI ConstIterator
118  {
119 public:
120 
121  // TODO Iterator constructor for ConstIterator
122 
123  typedef const Residue& const_reference;
124  typedef Residue& reference;
125  typedef const Residue* const_pointer;
126  typedef std::vector<const Residue*>::difference_type difference_type;
128  typedef const Residue* pointer;
129  typedef std::random_access_iterator_tag iterator_category;
130 
134  ConstIterator()
136  {
137  }
138 
140  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
141  {
142  vector_ = vec_ptr;
143  position_ = position;
144  }
145 
148  vector_(rhs.vector_),
149  position_(rhs.position_)
150  {
151  }
152 
155  vector_(rhs.vector_),
156  position_(rhs.position_)
157  {
158  }
159 
161  virtual ~ConstIterator()
162  {
163  }
164 
166 
169  {
170  if (this != &rhs)
171  {
172  position_ = rhs.position_;
173  vector_ = rhs.vector_;
174  }
175  return *this;
176  }
177 
181  const_reference operator*() const
183  {
184  return *(*vector_)[position_];
185  }
186 
189  {
190  return (*vector_)[position_];
191  }
192 
195  {
196  return ConstIterator(vector_, position_ + diff);
197  }
198 
200  {
201  return position_ - rhs.position_;
202  }
203 
206  {
207  return ConstIterator(vector_, position_ - diff);
208  }
209 
211  bool operator==(const ConstIterator& rhs) const
212  {
213  return vector_ == rhs.vector_ && position_ == rhs.position_;
214  }
215 
217  bool operator!=(const ConstIterator& rhs) const
218  {
219  return vector_ != rhs.vector_ || position_ != rhs.position_;
220  }
221 
224  {
225  ++position_;
226  return *this;
227  }
228 
231  {
232  --position_;
233  return *this;
234  }
235 
237 
238 protected:
239 
240  // pointer to the AASequence vector
241  const std::vector<const Residue*>* vector_;
242 
243  // position in the AASequence vector
245  };
246 
247 
252  class OPENMS_DLLAPI Iterator
253  {
254 public:
255 
257 
258  typedef const Residue& const_reference;
259  typedef Residue& reference;
260  typedef const Residue* const_pointer;
261  typedef const Residue* pointer;
262  typedef std::vector<const Residue*>::difference_type difference_type;
263 
267  Iterator()
269  {
270  }
271 
273  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
274  {
275  vector_ = vec_ptr;
276  position_ = position;
277  }
278 
280  Iterator(const Iterator& rhs) :
281  vector_(rhs.vector_),
282  position_(rhs.position_)
283  {
284  }
285 
287  virtual ~Iterator()
288  {
289  }
290 
292 
295  {
296  if (this != &rhs)
297  {
298  position_ = rhs.position_;
299  vector_ = rhs.vector_;
300  }
301  return *this;
302  }
303 
307  const_reference operator*() const
309  {
310  return *(*vector_)[position_];
311  }
312 
315  {
316  return (*vector_)[position_];
317  }
318 
321  {
322  return (*vector_)[position_];
323  }
324 
327  {
328  return Iterator(vector_, position_ + diff);
329  }
330 
332  {
333  return position_ - rhs.position_;
334  }
335 
338  {
339  return Iterator(vector_, position_ - diff);
340  }
341 
343  bool operator==(const Iterator& rhs) const
344  {
345  return vector_ == rhs.vector_ && position_ == rhs.position_;
346  }
347 
349  bool operator!=(const Iterator& rhs) const
350  {
351  return vector_ != rhs.vector_ || position_ != rhs.position_;
352  }
353 
356  {
357  ++position_;
358  return *this;
359  }
360 
363  {
364  --position_;
365  return *this;
366  }
367 
369 
370 protected:
371 
372  // pointer to the AASequence vector
373  std::vector<const Residue*>* vector_;
374 
375  // position in the AASequence vector
377  };
378 
382  AASequence();
384 
386  AASequence(const AASequence& rhs);
387 
389  virtual ~AASequence();
391 
393  AASequence& operator=(const AASequence& rhs);
394 
396  bool empty() const;
397 
401 
410  String toString() const;
411 
413  String toUnmodifiedString() const;
414 
423  String toUniModString() const;
424 
432  String toBracketString(bool integer_mass = true, const std::vector<String> & fixed_modifications = std::vector<String>()) const;
433 
436  void setModification(Size index, const String& modification);
437 
439  void setNTerminalModification(const String& modification);
440 
442  const String& getNTerminalModificationName() const;
443 
445  const ResidueModification* getNTerminalModification() const;
446 
448  void setCTerminalModification(const String& modification);
449 
451  const String& getCTerminalModificationName() const;
452 
454  const ResidueModification* getCTerminalModification() const;
455 
457  const Residue& getResidue(Size index) const;
458 
460  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
461 
463  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
464 
469  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
470 
472  const Residue& operator[](Size index) const;
473 
475  AASequence operator+(const AASequence& peptide) const;
476 
478  AASequence& operator+=(const AASequence&);
479 
481  AASequence operator+(const Residue* residue) const;
482 
484  AASequence& operator+=(const Residue*);
485 
487  Size size() const;
488 
490  AASequence getPrefix(Size index) const;
491 
493  AASequence getSuffix(Size index) const;
494 
496  AASequence getSubsequence(Size index, UInt number) const;
497 
499  void getAAFrequencies(Map<String, Size>& frequency_table) const;
500 
502 
506  bool has(const Residue& residue) const;
508 
511  bool hasSubsequence(const AASequence& peptide) const;
512 
515  bool hasPrefix(const AASequence& peptide) const;
516 
519  bool hasSuffix(const AASequence& peptide) const;
520 
522  bool hasNTerminalModification() const;
523 
525  bool hasCTerminalModification() const;
526 
528  bool isModified() const;
529 
531  bool operator==(const AASequence& rhs) const;
532 
534  bool operator<(const AASequence& rhs) const;
535 
537  bool operator!=(const AASequence& rhs) const;
539 
543  inline Iterator begin() { return Iterator(&peptide_, 0); }
544 
545  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
546 
547  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
548 
549  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
551 
555  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
557 
559  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
561 
570  static AASequence fromString(const String& s,
571  bool permissive = true);
572 
581  static AASequence fromString(const char* s,
582  bool permissive = true);
583 
584  protected:
585  std::vector<const Residue*> peptide_;
586 
588 
590 
605  static String::ConstIterator parseModRoundBrackets_(const String::ConstIterator str_it,
606  const String& str,
607  AASequence& aas,
608  const ResidueModification::TermSpecificity& specificity);
609 
623  static String::ConstIterator parseModSquareBrackets_(const String::ConstIterator str_it,
624  const String& str,
625  AASequence& aas,
626  const ResidueModification::TermSpecificity& specificity);
627 
628  static void parseString_(const String& peptide, AASequence& aas,
629  bool permissive = true);
630  };
631 
632  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
633 
634  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
635 
636 } // namespace OpenMS
637 
638 
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:294
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:326
virtual ~ConstIterator()
destructor
Definition: AASequence.h:161
A more convenient string class.
Definition: String.h:57
difference_type position_
Definition: AASequence.h:244
ConstIterator(const std::vector< const Residue *> *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:140
Size< TNeedle >::Type position(const PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:561
const Residue & const_reference
Definition: AASequence.h:258
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:217
ConstIterator & operator=(const ConstIterator &rhs)
assignment operator
Definition: AASequence.h:168
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
Iterator end()
Definition: AASequence.h:547
Residue & reference
Definition: AASequence.h:124
Representation of a modification.
Definition: ResidueModification.h:76
const Residue * const_pointer
Definition: AASequence.h:125
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
difference_type operator-(ConstIterator rhs) const
Definition: AASequence.h:199
const_pointer operator->() const
dereference operator
Definition: AASequence.h:188
Representation of a peptide/protein sequence.
Definition: AASequence.h:107
Iterator begin()
Definition: AASequence.h:543
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:349
ConstIterator end() const
Definition: AASequence.h:549
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
std::vector< const Residue * > * vector_
Definition: AASequence.h:373
Iterator & operator++()
increment operator
Definition: AASequence.h:355
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:129
Representation of a residue.
Definition: Residue.h:61
difference_type position_
Definition: AASequence.h:376
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:211
const_iterator ConstIterator
Const Iterator.
Definition: String.h:71
ConstIterator(const ConstIterator &rhs)
copy constructor
Definition: AASequence.h:147
Representation of an empirical formula.
Definition: EmpiricalFormula.h:81
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:127
Iterator(const Iterator &rhs)
copy constructor
Definition: AASequence.h:280
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:331
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
TermSpecificity
Position where the modification is allowed to occur.
Definition: ResidueModification.h:95
pointer operator->()
mutable dereference operator
Definition: AASequence.h:320
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:420
with N-terminus and C-terminus
Definition: Residue.h:152
const_pointer operator->() const
dereference operator
Definition: AASequence.h:314
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:262
ConstIterator for AASequence.
Definition: AASequence.h:117
Iterator & operator--()
decrement operator
Definition: AASequence.h:362
Residue & reference
Definition: AASequence.h:259
const Residue * const_pointer
Definition: AASequence.h:260
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
std::vector< const Residue * > peptide_
Definition: AASequence.h:585
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:126
std::istream & operator>>(std::istream &os, const AASequence &peptide)
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:230
ResidueType
Definition: Residue.h:150
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:154
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:343
const ResidueModification * n_term_mod_
Definition: AASequence.h:587
const ResidueModification * c_term_mod_
Definition: AASequence.h:589
Iterator class for AASequence.
Definition: AASequence.h:252
const Residue * pointer
Definition: AASequence.h:261
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:205
const Residue & const_reference
Definition: AASequence.h:123
Iterator(std::vector< const Residue *> *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:273
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:194
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:337
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
const Residue * pointer
Definition: AASequence.h:128
const std::vector< const Residue * > * vector_
Definition: AASequence.h:241
int Int
Signed integer type.
Definition: Types.h:102
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
ConstIterator begin() const
Definition: AASequence.h:545
virtual ~Iterator()
destructor
Definition: AASequence.h:287
ConstIterator & operator++()
increment operator
Definition: AASequence.h:223