OpenMS
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-2023.
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, Timo Sachsenberg $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/CONCEPT/Types.h>
42 
43 #include <vector>
44 #include <iosfwd>
45 #include <map>
46 
47 namespace OpenMS
48 {
49 
111  class OPENMS_DLLAPI AASequence
112  {
113 public:
114 
115  class Iterator;
116 
121  class OPENMS_DLLAPI ConstIterator
122  {
123  public:
124  // TODO Iterator constructor for ConstIterator
125 
126  typedef const Residue& const_reference;
127  typedef Residue& reference;
128  typedef const Residue* const_pointer;
129  typedef std::vector<const Residue*>::difference_type difference_type;
131  typedef const Residue* pointer;
132  typedef std::random_access_iterator_tag iterator_category;
133 
138  ConstIterator() = default;
139 
141  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
142  : vector_{vec_ptr},
143  position_{position}
144  {
145  }
146 
148  ConstIterator(const ConstIterator& rhs) = default;
149 
152  vector_(rhs.vector_),
153  position_(rhs.position_)
154  {
155  }
156 
158  virtual ~ConstIterator() = default;
159 
161 
163  ConstIterator& operator=(const ConstIterator& rhs) = default;
164 
170  {
171  return *(*vector_)[position_];
172  }
173 
176  {
177  return (*vector_)[position_];
178  }
179 
182  {
183  return ConstIterator(vector_, position_ + diff);
184  }
185 
187  {
188  return position_ - rhs.position_;
189  }
190 
193  {
194  return ConstIterator(vector_, position_ - diff);
195  }
196 
198  bool operator==(const ConstIterator& rhs) const
199  {
200  return vector_ == rhs.vector_ && position_ == rhs.position_;
201  }
202 
204  bool operator!=(const ConstIterator& rhs) const
205  {
206  return vector_ != rhs.vector_ || position_ != rhs.position_;
207  }
208 
211  {
212  ++position_;
213  return *this;
214  }
215 
218  {
219  --position_;
220  return *this;
221  }
222 
224 
225 protected:
226 
227  // pointer to the AASequence vector
228  const std::vector<const Residue*>* vector_ {};
229 
230  // position in the AASequence vector
231  difference_type position_ {};
232  };
233 
234 
239  class OPENMS_DLLAPI Iterator
240  {
241 public:
242 
244 
245  typedef const Residue& const_reference;
246  typedef Residue& reference;
247  typedef const Residue* const_pointer;
248  typedef const Residue* pointer;
249  typedef std::vector<const Residue*>::difference_type difference_type;
250 
255  Iterator() = default;
256 
258  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
259  : vector_ {vec_ptr},
260  position_{position}
261  {
262  }
263 
265  Iterator(const Iterator& rhs) = default;
266 
268  virtual ~Iterator() = default;
269 
271 
274  {
275  if (this != &rhs)
276  {
277  position_ = rhs.position_;
278  vector_ = rhs.vector_;
279  }
280  return *this;
281  }
282 
288  {
289  return *(*vector_)[position_];
290  }
291 
294  {
295  return (*vector_)[position_];
296  }
297 
300  {
301  return (*vector_)[position_];
302  }
303 
306  {
307  return Iterator(vector_, position_ + diff);
308  }
309 
311  {
312  return position_ - rhs.position_;
313  }
314 
317  {
318  return Iterator(vector_, position_ - diff);
319  }
320 
322  bool operator==(const Iterator& rhs) const
323  {
324  return vector_ == rhs.vector_ && position_ == rhs.position_;
325  }
326 
328  bool operator!=(const Iterator& rhs) const
329  {
330  return vector_ != rhs.vector_ || position_ != rhs.position_;
331  }
332 
335  {
336  ++position_;
337  return *this;
338  }
339 
342  {
343  --position_;
344  return *this;
345  }
346 
348 
349 protected:
350 
351  // pointer to the AASequence vector
352  std::vector<const Residue*>* vector_ {};
353 
354  // position in the AASequence vector
355  difference_type position_ {};
356  };
357 
361 
364 
366  AASequence(const AASequence&) = default;
367 
369  AASequence(AASequence&&) noexcept = default;
370 
372  virtual ~AASequence();
374 
376  AASequence& operator=(const AASequence&) = default;
377 
379  AASequence& operator=(AASequence&&) = default; // TODO: add noexcept (gcc 4.8 bug)
380 
382  bool empty() const;
383 
387 
399  String toString() const;
400 
402  String toUnmodifiedString() const;
403 
412  String toUniModString() const;
413 
432  String toBracketString(bool integer_mass = true,
433  bool mass_delta = false,
434  const std::vector<String> & fixed_modifications = std::vector<String>()) const;
435 
438  void setModification(Size index, const String& modification);
439 
441  void setModification(Size index, const Residue* modification);
442 
444  void setModification(Size index, const ResidueModification* modification);
445 
448  void setModification(Size index, const ResidueModification& modification);
449 
451  void setModificationByDiffMonoMass(Size index, double diffMonoMass);
452 
455  void setNTerminalModification(const String& modification);
456 
458  void setNTerminalModification(const ResidueModification* modification);
459 
461  void setNTerminalModification(const ResidueModification& mod);
462 
464  void setNTerminalModificationByDiffMonoMass(double diffMonoMass, bool protein_term);
465 
467  const String& getNTerminalModificationName() const;
468 
470  const ResidueModification* getNTerminalModification() const;
471 
474  void setCTerminalModification(const String& modification);
475 
477  void setCTerminalModification(const ResidueModification* modification);
478 
480  void setCTerminalModification(const ResidueModification& mod);
481 
483  void setCTerminalModificationByDiffMonoMass(double diffMonoMass, bool protein_term);
484 
486  const String& getCTerminalModificationName() const;
487 
489  const ResidueModification* getCTerminalModification() const;
490 
492  const Residue& getResidue(Size index) const;
493 
495  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
496 
498  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
499 
504  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
505 
511  double getMZ(Int charge, Residue::ResidueType type = Residue::Full) const;
512 
514  const Residue& operator[](Size index) const;
515 
517  AASequence operator+(const AASequence& peptide) const;
518 
520  AASequence& operator+=(const AASequence&);
521 
523  AASequence operator+(const Residue* residue) const;
524 
526  AASequence& operator+=(const Residue*);
527 
529  Size size() const;
530 
532  AASequence getPrefix(Size index) const;
533 
535  AASequence getSuffix(Size index) const;
536 
538  AASequence getSubsequence(Size index, UInt number) const;
539 
541  void getAAFrequencies(std::map<String, Size>& frequency_table) const;
542 
544 
549  bool has(const Residue& residue) const;
550 
553  bool hasSubsequence(const AASequence& peptide) const;
554 
557  bool hasPrefix(const AASequence& peptide) const;
558 
561  bool hasSuffix(const AASequence& peptide) const;
562 
564  bool hasNTerminalModification() const;
565 
567  bool hasCTerminalModification() const;
568 
570  bool isModified() const;
571 
573  bool operator==(const AASequence& rhs) const;
574 
576  bool operator<(const AASequence& rhs) const;
577 
579  bool operator!=(const AASequence& rhs) const;
581 
585  inline Iterator begin() { return Iterator(&peptide_, 0); }
586 
587  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
588 
589  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
590 
591  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
593 
598  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
599 
601  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
603 
612  static AASequence fromString(const String& s,
613  bool permissive = true);
614 
623  static AASequence fromString(const char* s,
624  bool permissive = true);
625 
626  protected:
627 
628  std::vector<const Residue*> peptide_;
629 
631 
633 
648  const String& str,
649  AASequence& aas,
650  const ResidueModification::TermSpecificity& specificity);
651 
666  const String& str,
667  AASequence& aas,
668  const ResidueModification::TermSpecificity& specificity);
669 
670  static void parseString_(const String& peptide, AASequence& aas,
671  bool permissive = true);
672  };
673 
674  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
675 
676  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
677 
678 } // namespace OpenMS
679 
680 
ConstIterator for AASequence.
Definition: AASequence.h:122
const_pointer operator->() const
dereference operator
Definition: AASequence.h:175
ConstIterator(const ConstIterator &rhs)=default
copy constructor
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:192
Residue value_type
Definition: AASequence.h:130
virtual ~ConstIterator()=default
destructor
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
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:204
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:151
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:181
ConstIterator()=default
default constructor
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:217
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:132
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:198
const std::vector< const Residue * > * vector_
Definition: AASequence.h:228
ConstIterator & operator++()
increment operator
Definition: AASequence.h:210
const Residue * const_pointer
Definition: AASequence.h:128
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:129
difference_type position_
Definition: AASequence.h:231
const Residue * pointer
Definition: AASequence.h:131
Residue & reference
Definition: AASequence.h:127
const Residue & const_reference
Definition: AASequence.h:126
const_reference operator*() const
dereference operator
Definition: AASequence.h:169
ConstIterator & operator=(const ConstIterator &rhs)=default
assignment operator
difference_type operator-(ConstIterator rhs) const
Definition: AASequence.h:186
Iterator class for AASequence.
Definition: AASequence.h:240
const_pointer operator->() const
dereference operator
Definition: AASequence.h:293
Iterator()=default
default constructor
pointer operator->()
mutable dereference operator
Definition: AASequence.h:299
virtual ~Iterator()=default
destructor
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:305
Iterator & operator--()
decrement operator
Definition: AASequence.h:341
Iterator(const Iterator &rhs)=default
copy constructor
std::vector< const Residue * > * vector_
Definition: AASequence.h:352
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:310
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:273
Iterator(std::vector< const Residue * > *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:258
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:322
const Residue * const_pointer
Definition: AASequence.h:247
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:249
difference_type position_
Definition: AASequence.h:355
const Residue * pointer
Definition: AASequence.h:248
Residue & reference
Definition: AASequence.h:246
const Residue & const_reference
Definition: AASequence.h:245
const_reference operator*() const
dereference operator
Definition: AASequence.h:287
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:328
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:316
Iterator & operator++()
increment operator
Definition: AASequence.h:334
Representation of a peptide/protein sequence.
Definition: AASequence.h:112
std::vector< const Residue * > peptide_
Definition: AASequence.h:628
AASequence(const AASequence &)=default
Copy constructor.
static String::ConstIterator parseModSquareBrackets_(const String::ConstIterator str_it, const String &str, AASequence &aas, const ResidueModification::TermSpecificity &specificity)
Parses modifications in square brackets (a mass)
ConstIterator end() const
Definition: AASequence.h:591
static AASequence fromString(const char *s, bool permissive=true)
create AASequence object by parsing a C string (character array)
static String::ConstIterator parseModRoundBrackets_(const String::ConstIterator str_it, const String &str, AASequence &aas, const ResidueModification::TermSpecificity &specificity)
Parses modifications in round brackets (an identifier)
static void parseString_(const String &peptide, AASequence &aas, bool permissive=true)
friend std::ostream & operator<<(std::ostream &os, const AASequence &peptide)
writes a peptide to an output stream
const ResidueModification * c_term_mod_
Definition: AASequence.h:632
static AASequence fromString(const String &s, bool permissive=true)
create AASequence object by parsing an OpenMS string
Iterator end()
Definition: AASequence.h:589
AASequence(AASequence &&) noexcept=default
Move constructor.
const ResidueModification * n_term_mod_
Definition: AASequence.h:630
ConstIterator begin() const
Definition: AASequence.h:587
AASequence()
Default constructor.
friend std::istream & operator>>(std::istream &is, const AASequence &peptide)
reads a peptide from an input stream
Representation of an empirical formula.
Definition: EmpiricalFormula.h:85
Representation of a modification on an amino acid residue.
Definition: ResidueModification.h:79
TermSpecificity
Position where the modification is allowed to occur.
Definition: ResidueModification.h:98
Representation of an amino acid residue.
Definition: Residue.h:63
A more convenient string class.
Definition: String.h:60
const_iterator ConstIterator
Const Iterator.
Definition: String.h:72
int Int
Signed integer type.
Definition: Types.h:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
static bool hasPrefix(const String &this_s, const String &string)
Definition: StringUtilsSimple.h:111
static bool hasSuffix(const String &this_s, const String &string)
Definition: StringUtilsSimple.h:124
static String number(double d, UInt n)
Definition: StringUtils.h:217
static bool has(const String &this_s, Byte byte)
Definition: StringUtilsSimple.h:142
void setModification(int location, int max_size, const String &modification, OpenMS::AASequence &aas)
helper function that sets a modification on a AASequence object
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
std::istream & operator>>(std::istream &os, const AASequence &peptide)
const std::string & toString(const DriftTimeUnit value)