OpenMS  3.0.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-2022.
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 
125  // TODO Iterator constructor for ConstIterator
126 
127  typedef const Residue& const_reference;
128  typedef Residue& reference;
129  typedef const Residue* const_pointer;
130  typedef std::vector<const Residue*>::difference_type difference_type;
132  typedef const Residue* pointer;
133  typedef std::random_access_iterator_tag iterator_category;
134 
138  ConstIterator()
140  {
141  }
142 
144  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
145  {
146  vector_ = vec_ptr;
147  position_ = position;
148  }
149 
152  vector_(rhs.vector_),
153  position_(rhs.position_)
154  {
155  }
156 
159  vector_(rhs.vector_),
160  position_(rhs.position_)
161  {
162  }
163 
165  virtual ~ConstIterator()
166  {
167  }
168 
170 
173  {
174  if (this != &rhs)
175  {
176  position_ = rhs.position_;
177  vector_ = rhs.vector_;
178  }
179  return *this;
180  }
181 
185  const_reference operator*() const
187  {
188  return *(*vector_)[position_];
189  }
190 
192  const_pointer operator->() const
193  {
194  return (*vector_)[position_];
195  }
196 
199  {
200  return ConstIterator(vector_, position_ + diff);
201  }
202 
204  {
205  return position_ - rhs.position_;
206  }
207 
210  {
211  return ConstIterator(vector_, position_ - diff);
212  }
213 
215  bool operator==(const ConstIterator& rhs) const
216  {
217  return vector_ == rhs.vector_ && position_ == rhs.position_;
218  }
219 
221  bool operator!=(const ConstIterator& rhs) const
222  {
223  return vector_ != rhs.vector_ || position_ != rhs.position_;
224  }
225 
228  {
229  ++position_;
230  return *this;
231  }
232 
235  {
236  --position_;
237  return *this;
238  }
239 
241 
242 protected:
243 
244  // pointer to the AASequence vector
245  const std::vector<const Residue*>* vector_;
246 
247  // position in the AASequence vector
249  };
250 
251 
256  class OPENMS_DLLAPI Iterator
257  {
258 public:
259 
261 
262  typedef const Residue& const_reference;
263  typedef Residue& reference;
264  typedef const Residue* const_pointer;
265  typedef const Residue* pointer;
266  typedef std::vector<const Residue*>::difference_type difference_type;
267 
271  Iterator()
273  {
274  }
275 
277  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
278  {
279  vector_ = vec_ptr;
280  position_ = position;
281  }
282 
284  Iterator(const Iterator& rhs) :
285  vector_(rhs.vector_),
286  position_(rhs.position_)
287  {
288  }
289 
291  virtual ~Iterator()
292  {
293  }
294 
296 
299  {
300  if (this != &rhs)
301  {
302  position_ = rhs.position_;
303  vector_ = rhs.vector_;
304  }
305  return *this;
306  }
307 
311  const_reference operator*() const
313  {
314  return *(*vector_)[position_];
315  }
316 
318  const_pointer operator->() const
319  {
320  return (*vector_)[position_];
321  }
322 
324  pointer operator->()
325  {
326  return (*vector_)[position_];
327  }
328 
331  {
332  return Iterator(vector_, position_ + diff);
333  }
334 
336  {
337  return position_ - rhs.position_;
338  }
339 
342  {
343  return Iterator(vector_, position_ - diff);
344  }
345 
347  bool operator==(const Iterator& rhs) const
348  {
349  return vector_ == rhs.vector_ && position_ == rhs.position_;
350  }
351 
353  bool operator!=(const Iterator& rhs) const
354  {
355  return vector_ != rhs.vector_ || position_ != rhs.position_;
356  }
357 
360  {
361  ++position_;
362  return *this;
363  }
364 
367  {
368  --position_;
369  return *this;
370  }
371 
373 
374 protected:
375 
376  // pointer to the AASequence vector
377  std::vector<const Residue*>* vector_;
378 
379  // position in the AASequence vector
381  };
382 
386 
388  AASequence();
389 
391  AASequence(const AASequence&) = default;
392 
394  AASequence(AASequence&&) noexcept = default;
395 
397  virtual ~AASequence();
399 
401  AASequence& operator=(const AASequence&) = default;
402 
404  AASequence& operator=(AASequence&&) = default; // TODO: add noexcept (gcc 4.8 bug)
405 
407  bool empty() const;
408 
412 
424  String toString() const;
425 
427  String toUnmodifiedString() const;
428 
437  String toUniModString() const;
438 
457  String toBracketString(bool integer_mass = true,
458  bool mass_delta = false,
459  const std::vector<String> & fixed_modifications = std::vector<String>()) const;
460 
463  void setModification(Size index, const String& modification);
464 
466  void setModification(Size index, const Residue* modification);
467 
469  void setModification(Size index, const ResidueModification* modification);
470 
473  void setModification(Size index, const ResidueModification& modification);
474 
476  void setModificationByDiffMonoMass(Size index, double diffMonoMass);
477 
480  void setNTerminalModification(const String& modification);
481 
483  void setNTerminalModification(const ResidueModification* modification);
484 
486  void setNTerminalModification(const ResidueModification& mod);
487 
489  void setNTerminalModificationByDiffMonoMass(double diffMonoMass, bool protein_term);
490 
492  const String& getNTerminalModificationName() const;
493 
495  const ResidueModification* getNTerminalModification() const;
496 
499  void setCTerminalModification(const String& modification);
500 
502  void setCTerminalModification(const ResidueModification* modification);
503 
505  void setCTerminalModification(const ResidueModification& mod);
506 
508  void setCTerminalModificationByDiffMonoMass(double diffMonoMass, bool protein_term);
509 
511  const String& getCTerminalModificationName() const;
512 
514  const ResidueModification* getCTerminalModification() const;
515 
517  const Residue& getResidue(Size index) const;
518 
520  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
521 
523  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
524 
529  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
530 
536  double getMZ(Int charge, Residue::ResidueType type = Residue::Full) const;
537 
539  const Residue& operator[](Size index) const;
540 
542  AASequence operator+(const AASequence& peptide) const;
543 
545  AASequence& operator+=(const AASequence&);
546 
548  AASequence operator+(const Residue* residue) const;
549 
551  AASequence& operator+=(const Residue*);
552 
554  Size size() const;
555 
557  AASequence getPrefix(Size index) const;
558 
560  AASequence getSuffix(Size index) const;
561 
563  AASequence getSubsequence(Size index, UInt number) const;
564 
566  void getAAFrequencies(std::map<String, Size>& frequency_table) const;
567 
569 
573  bool has(const Residue& residue) const;
575 
578  bool hasSubsequence(const AASequence& peptide) const;
579 
582  bool hasPrefix(const AASequence& peptide) const;
583 
586  bool hasSuffix(const AASequence& peptide) const;
587 
589  bool hasNTerminalModification() const;
590 
592  bool hasCTerminalModification() const;
593 
595  bool isModified() const;
596 
598  bool operator==(const AASequence& rhs) const;
599 
601  bool operator<(const AASequence& rhs) const;
602 
604  bool operator!=(const AASequence& rhs) const;
606 
610  inline Iterator begin() { return Iterator(&peptide_, 0); }
611 
612  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
613 
614  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
615 
616  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
618 
622  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
624 
626  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
628 
637  static AASequence fromString(const String& s,
638  bool permissive = true);
639 
648  static AASequence fromString(const char* s,
649  bool permissive = true);
650 
651  protected:
652 
653  std::vector<const Residue*> peptide_;
654 
656 
658 
672  static String::ConstIterator parseModRoundBrackets_(const String::ConstIterator str_it,
673  const String& str,
674  AASequence& aas,
675  const ResidueModification::TermSpecificity& specificity);
676 
690  static String::ConstIterator parseModSquareBrackets_(const String::ConstIterator str_it,
691  const String& str,
692  AASequence& aas,
693  const ResidueModification::TermSpecificity& specificity);
694 
695  static void parseString_(const String& peptide, AASequence& aas,
696  bool permissive = true);
697  };
698 
699  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
700 
701  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
702 
703 } // namespace OpenMS
704 
705 
OpenMS::AASequence::Iterator::operator=
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:298
OpenMS::AASequence::ConstIterator
ConstIterator for AASequence.
Definition: AASequence.h:121
OpenMS::AASequence::peptide_
std::vector< const Residue * > peptide_
Definition: AASequence.h:653
OpenMS::toString
const std::string & toString(const DriftTimeUnit value)
OpenMS::AASequence::ConstIterator::difference_type
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:130
OpenMS::ResidueModification
Representation of a modification on an amino acid residue.
Definition: ResidueModification.h:78
Types.h
OpenMS::operator*
DPosition< D, TCoordinateType > operator*(DPosition< D, TCoordinateType > position, typename DPosition< D, TCoordinateType >::CoordinateType scalar)
Scalar multiplication (a bit inefficient)
Definition: DPosition.h:426
OpenMS::AASequence::end
Iterator end()
Definition: AASequence.h:614
OpenMS::AASequence::c_term_mod_
const ResidueModification * c_term_mod_
Definition: AASequence.h:657
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::AASequence::Iterator::position_
difference_type position_
Definition: AASequence.h:380
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::AASequence::Iterator::vector_
std::vector< const Residue * > * vector_
Definition: AASequence.h:377
OpenMS::AASequence::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &rhs)
assignment operator
Definition: AASequence.h:172
OpenMS::AASequence::ConstIterator::const_reference
const typedef Residue & const_reference
Definition: AASequence.h:127
OpenMS::StringUtils::hasSuffix
static bool hasSuffix(const String &this_s, const String &string)
Definition: StringUtilsSimple.h:124
OpenMS::AASequence::ConstIterator::operator+
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:198
OpenMS::AASequence::ConstIterator::operator->
const_pointer operator->() const
dereference operator
Definition: AASequence.h:192
OpenMS::StringUtils::hasPrefix
static bool hasPrefix(const String &this_s, const String &string)
Definition: StringUtilsSimple.h:111
OpenMS::AASequence::Iterator
Iterator class for AASequence.
Definition: AASequence.h:256
OpenMS::AASequence::ConstIterator::pointer
const typedef Residue * pointer
Definition: AASequence.h:132
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS::AASequence::Iterator::operator-
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:335
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::AASequence::Iterator::operator->
const_pointer operator->() const
dereference operator
Definition: AASequence.h:318
OpenMS::AASequence::ConstIterator::operator--
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:234
OpenMS::Residue
Representation of an amino acid residue.
Definition: Residue.h:62
OpenMS::ResidueModification::TermSpecificity
TermSpecificity
Position where the modification is allowed to occur.
Definition: ResidueModification.h:97
OpenMS::AASequence::ConstIterator::operator==
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:215
OpenMS::AASequence::ConstIterator::operator++
ConstIterator & operator++()
increment operator
Definition: AASequence.h:227
OpenMS::AASequence::Iterator::operator->
pointer operator->()
mutable dereference operator
Definition: AASequence.h:324
OpenMS::AASequence::ConstIterator::const_pointer
const typedef Residue * const_pointer
Definition: AASequence.h:129
OpenMS::AASequence::ConstIterator::ConstIterator
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:158
OpenMS::AASequence::Iterator::Iterator
Iterator(const Iterator &rhs)
copy constructor
Definition: AASequence.h:284
OpenMS::AASequence::ConstIterator::ConstIterator
ConstIterator(const std::vector< const Residue * > *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:144
OpenMS::AASequence::Iterator::operator!=
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:353
OpenMS::AASequence::Iterator::reference
Residue & reference
Definition: AASequence.h:263
OpenMS::AASequence::Iterator::operator++
Iterator & operator++()
increment operator
Definition: AASequence.h:359
OpenMS::AASequence::ConstIterator::operator-
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:209
OpenMS::AASequence::begin
ConstIterator begin() const
Definition: AASequence.h:612
OpenMS::AASequence::Iterator::const_reference
const typedef Residue & const_reference
Definition: AASequence.h:262
OpenMS::AASequence::ConstIterator::operator-
difference_type operator-(ConstIterator rhs) const
Definition: AASequence.h:203
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::TargetedExperimentHelper::setModification
void setModification(int location, int max_size, String modification, OpenMS::AASequence &aas)
helper function that sets a modification on a AASequence object
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::AASequence::ConstIterator::vector_
const std::vector< const Residue * > * vector_
Definition: AASequence.h:245
OpenMS::AASequence::ConstIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:133
OpenMS::AASequence::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &rhs)
copy constructor
Definition: AASequence.h:151
OpenMS::AASequence::Iterator::difference_type
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:266
Residue.h
OpenMS::AASequence::ConstIterator::~ConstIterator
virtual ~ConstIterator()
destructor
Definition: AASequence.h:165
EmpiricalFormula.h
OpenMS::AASequence::Iterator::operator==
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:347
OpenMS::EmpiricalFormula
Representation of an empirical formula.
Definition: EmpiricalFormula.h:84
OpenMS::AASequence::ConstIterator::reference
Residue & reference
Definition: AASequence.h:128
OpenMS::AASequence::Iterator::const_pointer
const typedef Residue * const_pointer
Definition: AASequence.h:264
OpenMS::StringUtils::has
static bool has(const String &this_s, Byte byte)
Definition: StringUtilsSimple.h:142
OpenMS::StringUtils::number
static String number(double d, UInt n)
Definition: StringUtils.h:196
OpenMS::AASequence::end
ConstIterator end() const
Definition: AASequence.h:616
String.h
OpenMS::AASequence::ConstIterator::operator!=
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:221
OpenMS::AASequence::Iterator::Iterator
Iterator(std::vector< const Residue * > *vec_ptr, difference_type position)
detailed constructor with pointer to the vector and offset position
Definition: AASequence.h:277
OpenMS::AASequence::Iterator::operator--
Iterator & operator--()
decrement operator
Definition: AASequence.h:366
OpenMS::AASequence::Iterator::operator+
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:330
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:111
ResidueModification.h
OpenMS::operator>>
std::istream & operator>>(std::istream &os, const AASequence &peptide)
OpenMS::AASequence::ConstIterator::value_type
Residue value_type
Definition: AASequence.h:131
OpenMS::String::ConstIterator
const_iterator ConstIterator
Const Iterator.
Definition: String.h:72
OpenMS::AASequence::Iterator::pointer
const typedef Residue * pointer
Definition: AASequence.h:265
OpenMS::AASequence::Iterator::operator-
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:341
OpenMS::AASequence::ConstIterator::position_
difference_type position_
Definition: AASequence.h:248
OpenMS::AASequence::Iterator::~Iterator
virtual ~Iterator()
destructor
Definition: AASequence.h:291
OpenMS::AASequence::n_term_mod_
const ResidueModification * n_term_mod_
Definition: AASequence.h:655