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-2017.
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 #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 
108  class OPENMS_DLLAPI AASequence
109  {
110 public:
111 
112  class Iterator;
113 
118  class OPENMS_DLLAPI ConstIterator
119  {
120 public:
121 
122  // TODO Iterator constructor for ConstIterator
123 
124  typedef const Residue& const_reference;
125  typedef Residue& reference;
126  typedef const Residue* const_pointer;
127  typedef std::vector<const Residue*>::difference_type difference_type;
129  typedef const Residue* pointer;
130  typedef std::random_access_iterator_tag iterator_category;
131 
135  ConstIterator()
137  {
138  }
139 
141  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
142  {
143  vector_ = vec_ptr;
144  position_ = position;
145  }
146 
149  vector_(rhs.vector_),
150  position_(rhs.position_)
151  {
152  }
153 
156  vector_(rhs.vector_),
157  position_(rhs.position_)
158  {
159  }
160 
162  virtual ~ConstIterator()
163  {
164  }
165 
167 
170  {
171  if (this != &rhs)
172  {
173  position_ = rhs.position_;
174  vector_ = rhs.vector_;
175  }
176  return *this;
177  }
178 
182  const_reference operator*() const
184  {
185  return *(*vector_)[position_];
186  }
187 
189  const_pointer operator->() const
190  {
191  return (*vector_)[position_];
192  }
193 
195  const ConstIterator operator+(difference_type diff) const
196  {
197  return ConstIterator(vector_, position_ + diff);
198  }
199 
200  difference_type operator-(ConstIterator rhs) const
201  {
202  return position_ - rhs.position_;
203  }
204 
206  const ConstIterator operator-(difference_type diff) const
207  {
208  return ConstIterator(vector_, position_ - diff);
209  }
210 
212  bool operator==(const ConstIterator& rhs) const
213  {
214  return vector_ == rhs.vector_ && position_ == rhs.position_;
215  }
216 
218  bool operator!=(const ConstIterator& rhs) const
219  {
220  return vector_ != rhs.vector_ || position_ != rhs.position_;
221  }
222 
225  {
226  ++position_;
227  return *this;
228  }
229 
232  {
233  --position_;
234  return *this;
235  }
236 
238 
239 protected:
240 
241  // pointer to the AASequence vector
242  const std::vector<const Residue*>* vector_;
243 
244  // position in the AASequence vector
245  difference_type position_;
246  };
247 
248 
253  class OPENMS_DLLAPI Iterator
254  {
255 public:
256 
258 
259  typedef const Residue& const_reference;
260  typedef Residue& reference;
261  typedef const Residue* const_pointer;
262  typedef const Residue* pointer;
263  typedef std::vector<const Residue*>::difference_type difference_type;
264 
268  Iterator()
270  {
271  }
272 
274  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
275  {
276  vector_ = vec_ptr;
277  position_ = position;
278  }
279 
281  Iterator(const Iterator& rhs) :
282  vector_(rhs.vector_),
283  position_(rhs.position_)
284  {
285  }
286 
288  virtual ~Iterator()
289  {
290  }
291 
293 
296  {
297  if (this != &rhs)
298  {
299  position_ = rhs.position_;
300  vector_ = rhs.vector_;
301  }
302  return *this;
303  }
304 
308  const_reference operator*() const
310  {
311  return *(*vector_)[position_];
312  }
313 
315  const_pointer operator->() const
316  {
317  return (*vector_)[position_];
318  }
319 
321  pointer operator->()
322  {
323  return (*vector_)[position_];
324  }
325 
327  const Iterator operator+(difference_type diff) const
328  {
329  return Iterator(vector_, position_ + diff);
330  }
331 
332  difference_type operator-(Iterator rhs) const
333  {
334  return position_ - rhs.position_;
335  }
336 
338  const Iterator operator-(difference_type diff) const
339  {
340  return Iterator(vector_, position_ - diff);
341  }
342 
344  bool operator==(const Iterator& rhs) const
345  {
346  return vector_ == rhs.vector_ && position_ == rhs.position_;
347  }
348 
350  bool operator!=(const Iterator& rhs) const
351  {
352  return vector_ != rhs.vector_ || position_ != rhs.position_;
353  }
354 
357  {
358  ++position_;
359  return *this;
360  }
361 
364  {
365  --position_;
366  return *this;
367  }
368 
370 
371 protected:
372 
373  // pointer to the AASequence vector
374  std::vector<const Residue*>* vector_;
375 
376  // position in the AASequence vector
377  difference_type position_;
378  };
379 
383  AASequence();
385 
387  AASequence(const AASequence& rhs);
388 
390  virtual ~AASequence();
392 
394  AASequence& operator=(const AASequence& rhs);
395 
397  bool empty() const;
398 
402 
411  String toString() const;
412 
414  String toUnmodifiedString() const;
415 
423  String toBracketString(bool integer_mass = true, const std::vector<String> & fixed_modifications = std::vector<String>()) const;
424 
427  void setModification(Size index, const String& modification);
428 
430  void setNTerminalModification(const String& modification);
431 
433  const String& getNTerminalModificationName() const;
434 
436  const ResidueModification* getNTerminalModification() const;
437 
439  void setCTerminalModification(const String& modification);
440 
442  const String& getCTerminalModificationName() const;
443 
445  const ResidueModification* getCTerminalModification() const;
446 
448  const Residue& getResidue(Size index) const;
449 
451  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
452 
454  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
455 
460  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
461 
463  const Residue& operator[](Size index) const;
464 
466  AASequence operator+(const AASequence& peptide) const;
467 
469  AASequence& operator+=(const AASequence&);
470 
472  AASequence operator+(const Residue* residue) const;
473 
475  AASequence& operator+=(const Residue*);
476 
478  Size size() const;
479 
481  AASequence getPrefix(Size index) const;
482 
484  AASequence getSuffix(Size index) const;
485 
487  AASequence getSubsequence(Size index, UInt number) const;
488 
490  void getAAFrequencies(Map<String, Size>& frequency_table) const;
491 
493 
497  bool has(const Residue& residue) const;
499 
502  bool hasSubsequence(const AASequence& peptide) const;
503 
506  bool hasPrefix(const AASequence& peptide) const;
507 
510  bool hasSuffix(const AASequence& peptide) const;
511 
513  bool hasNTerminalModification() const;
514 
516  bool hasCTerminalModification() const;
517 
519  bool isModified() const;
520 
522  bool operator==(const AASequence& rhs) const;
523 
525  bool operator<(const AASequence& rhs) const;
526 
528  bool operator!=(const AASequence& rhs) const;
530 
534  inline Iterator begin() { return Iterator(&peptide_, 0); }
535 
536  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
537 
538  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
539 
540  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
542 
546  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
548 
550  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
552 
561  static AASequence fromString(const String& s,
562  bool permissive = true);
563 
572  static AASequence fromString(const char* s,
573  bool permissive = true);
574 
575  protected:
576  std::vector<const Residue*> peptide_;
577 
579 
581 
596  static String::ConstIterator parseModRoundBrackets_(
597  const String::ConstIterator str_it, const String& str, AASequence& aas, bool dot_notation, bool dot_terminal);
598 
612  static String::ConstIterator parseModSquareBrackets_(
613  const String::ConstIterator str_it, const String& str, AASequence& aas,
614  const ResidueModification::TermSpecificity& specificity);
615 
616  static void parseString_(const String& peptide, AASequence& aas,
617  bool permissive = true);
618  };
619 
620  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
621 
622  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
623 
624 } // namespace OpenMS
625 
626 
627 #endif
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:295
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:327
virtual ~ConstIterator()
destructor
Definition: AASequence.h:162
A more convenient string class.
Definition: String.h:57
difference_type position_
Definition: AASequence.h:245
ConstIterator(const std::vector< const Residue *> *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:141
const Residue & const_reference
Definition: AASequence.h:259
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:218
ConstIterator & operator=(const ConstIterator &rhs)
assignment operator
Definition: AASequence.h:169
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
Iterator end()
Definition: AASequence.h:538
Residue & reference
Definition: AASequence.h:125
Representation of a modification.
Definition: ResidueModification.h:77
const Residue * const_pointer
Definition: AASequence.h:126
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:200
const_pointer operator->() const
dereference operator
Definition: AASequence.h:189
Representation of a peptide/protein sequence.
Definition: AASequence.h:108
Iterator begin()
Definition: AASequence.h:534
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:350
ConstIterator end() const
Definition: AASequence.h:540
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::vector< const Residue * > * vector_
Definition: AASequence.h:374
Iterator & operator++()
increment operator
Definition: AASequence.h:356
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:130
Representation of a residue.
Definition: Residue.h:62
difference_type position_
Definition: AASequence.h:377
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:212
const_iterator ConstIterator
Const Iterator.
Definition: String.h:71
ConstIterator(const ConstIterator &rhs)
copy constructor
Definition: AASequence.h:148
Representation of an empirical formula.
Definition: EmpiricalFormula.h:80
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:128
Iterator(const Iterator &rhs)
copy constructor
Definition: AASequence.h:281
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:332
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
TermSpecificity
Position where the modification is allowed to occur.
Definition: ResidueModification.h:96
pointer operator->()
mutable dereference operator
Definition: AASequence.h:321
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:421
Definition: Residue.h:146
const_pointer operator->() const
dereference operator
Definition: AASequence.h:315
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:263
ConstIterator for AASequence.
Definition: AASequence.h:118
Iterator & operator--()
decrement operator
Definition: AASequence.h:363
Residue & reference
Definition: AASequence.h:260
const Residue * const_pointer
Definition: AASequence.h:261
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
std::vector< const Residue * > peptide_
Definition: AASequence.h:576
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:127
std::istream & operator>>(std::istream &os, const AASequence &peptide)
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:231
ResidueType
Definition: Residue.h:144
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:155
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:344
const ResidueModification * n_term_mod_
Definition: AASequence.h:578
const ResidueModification * c_term_mod_
Definition: AASequence.h:580
Iterator class for AASequence.
Definition: AASequence.h:253
const Residue * pointer
Definition: AASequence.h:262
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:206
const Residue & const_reference
Definition: AASequence.h:124
Iterator(std::vector< const Residue *> *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:274
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:195
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:338
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:69
const Residue * pointer
Definition: AASequence.h:129
const std::vector< const Residue * > * vector_
Definition: AASequence.h:242
int Int
Signed integer type.
Definition: Types.h:103
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
ConstIterator begin() const
Definition: AASequence.h:536
virtual ~Iterator()
destructor
Definition: AASequence.h:288
ConstIterator & operator++()
increment operator
Definition: AASequence.h:224

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13