OpenMS  2.5.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-2020.
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 
113  class OPENMS_DLLAPI AASequence
114  {
115 public:
116 
117  class Iterator;
118 
123  class OPENMS_DLLAPI ConstIterator
124  {
125 public:
126 
127  // TODO Iterator constructor for ConstIterator
128 
129  typedef const Residue& const_reference;
130  typedef Residue& reference;
131  typedef const Residue* const_pointer;
132  typedef std::vector<const Residue*>::difference_type difference_type;
134  typedef const Residue* pointer;
135  typedef std::random_access_iterator_tag iterator_category;
136 
140  ConstIterator()
142  {
143  }
144 
146  ConstIterator(const std::vector<const Residue*>* vec_ptr, difference_type position)
147  {
148  vector_ = vec_ptr;
149  position_ = position;
150  }
151 
154  vector_(rhs.vector_),
155  position_(rhs.position_)
156  {
157  }
158 
161  vector_(rhs.vector_),
162  position_(rhs.position_)
163  {
164  }
165 
167  virtual ~ConstIterator()
168  {
169  }
170 
172 
175  {
176  if (this != &rhs)
177  {
178  position_ = rhs.position_;
179  vector_ = rhs.vector_;
180  }
181  return *this;
182  }
183 
187  const_reference operator*() const
189  {
190  return *(*vector_)[position_];
191  }
192 
194  const_pointer operator->() const
195  {
196  return (*vector_)[position_];
197  }
198 
201  {
202  return ConstIterator(vector_, position_ + diff);
203  }
204 
206  {
207  return position_ - rhs.position_;
208  }
209 
212  {
213  return ConstIterator(vector_, position_ - diff);
214  }
215 
217  bool operator==(const ConstIterator& rhs) const
218  {
219  return vector_ == rhs.vector_ && position_ == rhs.position_;
220  }
221 
223  bool operator!=(const ConstIterator& rhs) const
224  {
225  return vector_ != rhs.vector_ || position_ != rhs.position_;
226  }
227 
230  {
231  ++position_;
232  return *this;
233  }
234 
237  {
238  --position_;
239  return *this;
240  }
241 
243 
244 protected:
245 
246  // pointer to the AASequence vector
247  const std::vector<const Residue*>* vector_;
248 
249  // position in the AASequence vector
251  };
252 
253 
258  class OPENMS_DLLAPI Iterator
259  {
260 public:
261 
263 
264  typedef const Residue& const_reference;
265  typedef Residue& reference;
266  typedef const Residue* const_pointer;
267  typedef const Residue* pointer;
268  typedef std::vector<const Residue*>::difference_type difference_type;
269 
273  Iterator()
275  {
276  }
277 
279  Iterator(std::vector<const Residue*>* vec_ptr, difference_type position)
280  {
281  vector_ = vec_ptr;
282  position_ = position;
283  }
284 
286  Iterator(const Iterator& rhs) :
287  vector_(rhs.vector_),
288  position_(rhs.position_)
289  {
290  }
291 
293  virtual ~Iterator()
294  {
295  }
296 
298 
301  {
302  if (this != &rhs)
303  {
304  position_ = rhs.position_;
305  vector_ = rhs.vector_;
306  }
307  return *this;
308  }
309 
313  const_reference operator*() const
315  {
316  return *(*vector_)[position_];
317  }
318 
320  const_pointer operator->() const
321  {
322  return (*vector_)[position_];
323  }
324 
326  pointer operator->()
327  {
328  return (*vector_)[position_];
329  }
330 
333  {
334  return Iterator(vector_, position_ + diff);
335  }
336 
338  {
339  return position_ - rhs.position_;
340  }
341 
344  {
345  return Iterator(vector_, position_ - diff);
346  }
347 
349  bool operator==(const Iterator& rhs) const
350  {
351  return vector_ == rhs.vector_ && position_ == rhs.position_;
352  }
353 
355  bool operator!=(const Iterator& rhs) const
356  {
357  return vector_ != rhs.vector_ || position_ != rhs.position_;
358  }
359 
362  {
363  ++position_;
364  return *this;
365  }
366 
369  {
370  --position_;
371  return *this;
372  }
373 
375 
376 protected:
377 
378  // pointer to the AASequence vector
379  std::vector<const Residue*>* vector_;
380 
381  // position in the AASequence vector
383  };
384 
388 
390  AASequence();
391 
393  AASequence(const AASequence&) = default;
394 
396  AASequence(AASequence&&) noexcept = default;
397 
399  virtual ~AASequence();
401 
403  AASequence& operator=(const AASequence&) = default;
404 
406  AASequence& operator=(AASequence&&) = default; // TODO: add noexcept (gcc 4.8 bug)
407 
409  bool empty() const;
410 
414 
426  String toString() const;
427 
429  String toUnmodifiedString() const;
430 
439  String toUniModString() const;
440 
459  String toBracketString(bool integer_mass = true,
460  bool mass_delta = false,
461  const std::vector<String> & fixed_modifications = std::vector<String>()) const;
462 
465  void setModification(Size index, const String& modification);
466 
467  // sets the (potentially modified) residue
468  void setModification(Size index, const Residue* modification) { peptide_[index] = modification; }
469 
472  void setNTerminalModification(const String& modification);
473 
475  void setNTerminalModification(const ResidueModification* modification);
476 
478  const String& getNTerminalModificationName() const;
479 
481  const ResidueModification* getNTerminalModification() const;
482 
485  void setCTerminalModification(const String& modification);
486 
488  void setCTerminalModification(const ResidueModification* modification);
489 
491  const String& getCTerminalModificationName() const;
492 
494  const ResidueModification* getCTerminalModification() const;
495 
497  const Residue& getResidue(Size index) const;
498 
500  EmpiricalFormula getFormula(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
501 
503  double getAverageWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
504 
509  double getMonoWeight(Residue::ResidueType type = Residue::Full, Int charge = 0) const;
510 
512  const Residue& operator[](Size index) const;
513 
515  AASequence operator+(const AASequence& peptide) const;
516 
518  AASequence& operator+=(const AASequence&);
519 
521  AASequence operator+(const Residue* residue) const;
522 
524  AASequence& operator+=(const Residue*);
525 
527  Size size() const;
528 
530  AASequence getPrefix(Size index) const;
531 
533  AASequence getSuffix(Size index) const;
534 
536  AASequence getSubsequence(Size index, UInt number) const;
537 
539  void getAAFrequencies(Map<String, Size>& frequency_table) const;
540 
542 
546  bool has(const Residue& residue) const;
548 
551  bool hasSubsequence(const AASequence& peptide) const;
552 
555  bool hasPrefix(const AASequence& peptide) const;
556 
559  bool hasSuffix(const AASequence& peptide) const;
560 
562  bool hasNTerminalModification() const;
563 
565  bool hasCTerminalModification() const;
566 
568  bool isModified() const;
569 
571  bool operator==(const AASequence& rhs) const;
572 
574  bool operator<(const AASequence& rhs) const;
575 
577  bool operator!=(const AASequence& rhs) const;
579 
583  inline Iterator begin() { return Iterator(&peptide_, 0); }
584 
585  inline ConstIterator begin() const { return ConstIterator(&peptide_, 0); }
586 
587  inline Iterator end() { return Iterator(&peptide_, (Int) peptide_.size()); }
588 
589  inline ConstIterator end() const { return ConstIterator(&peptide_, (Int) peptide_.size()); }
591 
595  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
597 
599  friend OPENMS_DLLAPI std::istream& operator>>(std::istream& is, const AASequence& peptide);
601 
610  static AASequence fromString(const String& s,
611  bool permissive = true);
612 
621  static AASequence fromString(const char* s,
622  bool permissive = true);
623 
624  protected:
625 
626  std::vector<const Residue*> peptide_;
627 
629 
631 
646  static String::ConstIterator parseModRoundBrackets_(const String::ConstIterator str_it,
647  const String& str,
648  AASequence& aas,
649  const ResidueModification::TermSpecificity& specificity);
650 
664  static String::ConstIterator parseModSquareBrackets_(const String::ConstIterator str_it,
665  const String& str,
666  AASequence& aas,
667  const ResidueModification::TermSpecificity& specificity);
668 
669  static void parseString_(const String& peptide, AASequence& aas,
670  bool permissive = true);
671  };
672 
673  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const AASequence& peptide);
674 
675  OPENMS_DLLAPI std::istream& operator>>(std::istream& os, const AASequence& peptide);
676 
677 } // namespace OpenMS
678 
679 
OpenMS::AASequence::Iterator::operator=
Iterator & operator=(const Iterator &rhs)
assignment operator
Definition: AASequence.h:300
OpenMS::AASequence::ConstIterator
ConstIterator for AASequence.
Definition: AASequence.h:123
OpenMS::AASequence::peptide_
std::vector< const Residue * > peptide_
Definition: AASequence.h:626
OpenMS::AASequence::ConstIterator::difference_type
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:132
OpenMS::ResidueModification
Representation of a modification.
Definition: ResidueModification.h:76
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:427
OpenMS::AASequence::end
Iterator end()
Definition: AASequence.h:587
OpenMS::AASequence::c_term_mod_
const ResidueModification * c_term_mod_
Definition: AASequence.h:630
OpenMS::String
A more convenient string class.
Definition: String.h:58
KDTree::operator!=
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
OpenMS::AASequence::Iterator::position_
difference_type position_
Definition: AASequence.h:382
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:379
OpenMS::Residue::Full
with N-terminus and C-terminus
Definition: Residue.h:152
OpenMS::AASequence::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &rhs)
assignment operator
Definition: AASequence.h:174
OpenMS::AASequence::ConstIterator::const_reference
const typedef Residue & const_reference
Definition: AASequence.h:129
Map.h
OpenMS::operator<
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
OpenMS::AASequence::ConstIterator::operator+
const ConstIterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:200
OpenMS::AASequence::ConstIterator::operator->
const_pointer operator->() const
dereference operator
Definition: AASequence.h:194
OpenMS::AASequence::Iterator
Iterator class for AASequence.
Definition: AASequence.h:258
OpenMS::AASequence::ConstIterator::pointer
const typedef Residue * pointer
Definition: AASequence.h:134
OpenMS::AASequence::Iterator::operator-
difference_type operator-(Iterator rhs) const
Definition: AASequence.h:337
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::AASequence::Iterator::operator->
const_pointer operator->() const
dereference operator
Definition: AASequence.h:320
OpenMS::AASequence::ConstIterator::operator--
ConstIterator & operator--()
decrement operator
Definition: AASequence.h:236
OpenMS::Residue
Representation of a residue.
Definition: Residue.h:61
OpenMS::ResidueModification::TermSpecificity
TermSpecificity
Position where the modification is allowed to occur.
Definition: ResidueModification.h:95
OpenMS::AASequence::ConstIterator::operator==
bool operator==(const ConstIterator &rhs) const
equality comparator
Definition: AASequence.h:217
OpenMS::AASequence::ConstIterator::operator++
ConstIterator & operator++()
increment operator
Definition: AASequence.h:229
int
OpenMS::AASequence::Iterator::operator->
pointer operator->()
mutable dereference operator
Definition: AASequence.h:326
OpenMS::AASequence::ConstIterator::const_pointer
const typedef Residue * const_pointer
Definition: AASequence.h:131
OpenMS::AASequence::ConstIterator::ConstIterator
ConstIterator(const AASequence::Iterator &rhs)
copy constructor from Iterator
Definition: AASequence.h:160
OpenMS::AASequence::Iterator::Iterator
Iterator(const Iterator &rhs)
copy constructor
Definition: AASequence.h:286
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:146
OpenMS::AASequence::Iterator::operator!=
bool operator!=(const Iterator &rhs) const
inequality operator
Definition: AASequence.h:355
OpenMS::AASequence::Iterator::reference
Residue & reference
Definition: AASequence.h:265
OpenMS::AASequence::Iterator::operator++
Iterator & operator++()
increment operator
Definition: AASequence.h:361
OpenMS::AASequence::ConstIterator::operator-
const ConstIterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:211
OpenMS::AASequence::begin
ConstIterator begin() const
Definition: AASequence.h:585
OpenMS::AASequence::Iterator::const_reference
const typedef Residue & const_reference
Definition: AASequence.h:264
OpenMS::Residue::ResidueType
ResidueType
Definition: Residue.h:150
OpenMS::AASequence::ConstIterator::operator-
difference_type operator-(ConstIterator rhs) const
Definition: AASequence.h:205
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:247
OpenMS::AASequence::ConstIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: AASequence.h:135
OpenMS::AASequence::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &rhs)
copy constructor
Definition: AASequence.h:153
OpenMS::AASequence::Iterator::difference_type
std::vector< const Residue * >::difference_type difference_type
Definition: AASequence.h:268
Residue.h
OpenMS::StringConversions::toString
String toString(const T &i)
fallback template for general purpose using Boost::Karma; more specializations below
Definition: StringUtils.h:85
OpenMS::AASequence::ConstIterator::~ConstIterator
virtual ~ConstIterator()
destructor
Definition: AASequence.h:167
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
EmpiricalFormula.h
OpenMS::AASequence::Iterator::operator==
bool operator==(const Iterator &rhs) const
equality comparator
Definition: AASequence.h:349
OpenMS::EmpiricalFormula
Representation of an empirical formula.
Definition: EmpiricalFormula.h:82
OpenMS::AASequence::ConstIterator::reference
Residue & reference
Definition: AASequence.h:130
OpenMS::AASequence::Iterator::const_pointer
const typedef Residue * const_pointer
Definition: AASequence.h:266
OpenMS::AASequence::end
ConstIterator end() const
Definition: AASequence.h:589
String.h
OpenMS::AASequence::ConstIterator::operator!=
bool operator!=(const ConstIterator &rhs) const
inequality operator
Definition: AASequence.h:223
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:279
OpenMS::AASequence::Iterator::operator--
Iterator & operator--()
decrement operator
Definition: AASequence.h:368
OpenMS::AASequence::begin
Iterator begin()
Definition: AASequence.h:583
OpenMS::AASequence::Iterator::operator+
const Iterator operator+(difference_type diff) const
forward jump operator
Definition: AASequence.h:332
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:113
OpenMS::Map
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
OpenMS::operator>>
std::istream & operator>>(std::istream &os, const AASequence &peptide)
OpenMS::AASequence::ConstIterator::value_type
Residue value_type
Definition: AASequence.h:133
seqan::position
Size< TNeedle >::Type position(const PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:561
OpenMS::String::ConstIterator
const_iterator ConstIterator
Const Iterator.
Definition: String.h:72
OpenMS::AASequence::Iterator::pointer
const typedef Residue * pointer
Definition: AASequence.h:267
OpenMS::AASequence::Iterator::operator-
const Iterator operator-(difference_type diff) const
backward jump operator
Definition: AASequence.h:343
OpenMS::AASequence::ConstIterator::position_
difference_type position_
Definition: AASequence.h:250
OpenMS::AASequence::Iterator::~Iterator
virtual ~Iterator()
destructor
Definition: AASequence.h:293
OpenMS::AASequence::n_term_mod_
const ResidueModification * n_term_mod_
Definition: AASequence.h:628