OpenMS  2.6.0
MRMTransitionGroup.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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Macros.h>
39 #include <boost/numeric/conversion/cast.hpp>
40 
41 namespace OpenMS
42 {
43 
66  template <typename ChromatogramType, typename TransitionType>
68  {
69 
70 public:
71 
73 
74  typedef std::vector<MRMFeature> MRMFeatureListType;
77  typedef std::vector<TransitionType> TransitionsType;
81 
87  {
88  }
89 
92  tr_gr_id_(rhs.tr_gr_id_),
100  {
101  }
102 
105  {
106  }
108 
110  {
111  if (&rhs != this)
112  {
113  tr_gr_id_ = rhs.tr_gr_id_;
121  }
122  return *this;
123  }
124 
125  inline Size size() const
126  {
127  return chromatograms_.size();
128  }
129 
130  inline const String & getTransitionGroupID() const
131  {
132  return tr_gr_id_;
133  }
134 
135  inline void setTransitionGroupID(const String & tr_gr_id)
136  {
137  tr_gr_id_ = tr_gr_id;
138  }
139 
141 
142  inline const std::vector<TransitionType> & getTransitions() const
143  {
144  return transitions_;
145  }
146 
147  inline std::vector<TransitionType> & getTransitionsMuteable()
148  {
149  return transitions_;
150  }
151 
152  inline void addTransition(const TransitionType & transition, String key)
153  {
154  transitions_.push_back(transition);
155  transition_map_[key] = boost::numeric_cast<int>(transitions_.size()) - 1;
156  }
157 
158  inline bool hasTransition(String key) const
159  {
160  return transition_map_.find(key) != transition_map_.end();
161  }
162 
163  inline const TransitionType & getTransition(String key)
164  {
165  OPENMS_PRECONDITION(hasTransition(key), "Cannot retrieve transitions that does not exist")
166  OPENMS_PRECONDITION(transitions_.size() > (size_t)transition_map_[key], "Mapping needs to be accurate")
167  return transitions_[transition_map_[key]];
168  }
170 
171 
173 
174  inline std::vector<ChromatogramType> & getChromatograms()
175  {
176  return chromatograms_;
177  }
178 
179  inline const std::vector<ChromatogramType> & getChromatograms() const
180  {
181  return chromatograms_;
182  }
183 
184  inline void addChromatogram(const ChromatogramType & chromatogram, const String& key)
185  {
186  chromatograms_.push_back(chromatogram);
187  chromatogram_map_[key] = boost::numeric_cast<int>(chromatograms_.size()) - 1;
188 
189  // OPENMS_POSTCONDITION(chromatogramIdsMatch(), "Chromatogram ids do not match")
190  }
191 
192  inline bool hasChromatogram(const String& key) const
193  {
194  return chromatogram_map_.find(key) != chromatogram_map_.end();
195  }
196 
198  {
199  OPENMS_PRECONDITION(hasChromatogram(key), "Cannot retrieve chromatogram that does not exist")
200  OPENMS_PRECONDITION(chromatograms_.size() > (size_t)chromatogram_map_[key], "Mapping needs to be accurate")
201  return chromatograms_[chromatogram_map_[key]];
202  }
203 
204  inline const ChromatogramType & getChromatogram(const String& key) const
205  {
206  OPENMS_PRECONDITION(hasChromatogram(key), "Cannot retrieve chromatogram that does not exist")
207  OPENMS_PRECONDITION(chromatograms_.size() > (size_t)chromatogram_map_.at(key), "Mapping needs to be accurate")
208  return chromatograms_[chromatogram_map_.at(key)];
209  }
211 
212 
214 
215  inline std::vector<ChromatogramType> & getPrecursorChromatograms()
216  {
218  }
219 
220  inline const std::vector<ChromatogramType> & getPrecursorChromatograms() const
221  {
223  }
224 
235  inline void addPrecursorChromatogram(const ChromatogramType & chromatogram, const String& key)
236  {
237  precursor_chromatograms_.push_back(chromatogram);
238  precursor_chromatogram_map_[key] = boost::numeric_cast<int>(precursor_chromatograms_.size()) - 1;
239 
240  // OPENMS_POSTCONDITION(chromatogramIdsMatch(), "Chromatogram ids do not match")
241  }
242 
243  inline bool hasPrecursorChromatogram(const String& key) const
244  {
246  }
247 
249  {
250  OPENMS_PRECONDITION(hasPrecursorChromatogram(key), "Cannot retrieve precursor chromatogram that does not exist")
251  OPENMS_PRECONDITION(precursor_chromatograms_.size() > (size_t)precursor_chromatogram_map_.at(key), "Mapping needs to be accurate")
253  }
254 
255  inline const ChromatogramType & getPrecursorChromatogram(const String& key) const
256  {
257  OPENMS_PRECONDITION(hasPrecursorChromatogram(key), "Cannot retrieve precursor chromatogram that does not exist")
258  OPENMS_PRECONDITION(precursor_chromatograms_.size() > (size_t)precursor_chromatogram_map_.at(key), "Mapping needs to be accurate")
260  }
262 
263 
265 
266  inline const std::vector<MRMFeature> & getFeatures() const
267  {
268  return mrm_features_;
269  }
270 
271  inline std::vector<MRMFeature> & getFeaturesMuteable()
272  {
273  return mrm_features_;
274  }
275 
276  inline void addFeature(const MRMFeature & feature)
277  {
278  mrm_features_.push_back(feature);
279  }
280 
281  inline void addFeature(MRMFeature && feature)
282  {
283  mrm_features_.push_back(std::move(feature));
284  }
286 
287 
289 
290 
292  inline bool isInternallyConsistent() const
293  {
294  OPENMS_PRECONDITION(transitions_.size() == chromatograms_.size(), "Same number of transitions as chromatograms are required")
295  OPENMS_PRECONDITION(transition_map_.size() == chromatogram_map_.size(), "Same number of transitions as chromatograms mappings are required")
296  OPENMS_PRECONDITION(isMappingConsistent_(), "Mapping needs to be consistent")
297  return true;
298  }
299 
301  inline bool chromatogramIdsMatch() const
302  {
303  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
304  {
305  if (getChromatogram(it->first).getNativeID() != it->first)
306  {
307  return false;
308  }
309  }
310  for (std::map<String, int>::const_iterator it = precursor_chromatogram_map_.begin(); it != precursor_chromatogram_map_.end(); it++)
311  {
312  if (getPrecursorChromatogram(it->first).getNativeID() != it->first)
313  {
314  return false;
315  }
316  }
317  return true;
318  }
319 
320  void getLibraryIntensity(std::vector<double> & result) const
321  {
322  for (typename TransitionsType::const_iterator it = transitions_.begin(); it != transitions_.end(); ++it)
323  {
324  result.push_back(it->getLibraryIntensity());
325  }
326  for (Size i = 0; i < result.size(); i++)
327  {
328  // the library intensity should never be below zero
329  if (result[i] < 0.0)
330  {
331  result[i] = 0.0;
332  }
333  }
334  }
335 
336  MRMTransitionGroup subset(std::vector<std::string> tr_ids) const
337  {
338  MRMTransitionGroup transition_group_subset;
339  transition_group_subset.setTransitionGroupID(tr_gr_id_);
340 
341  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
342  {
343  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
344  {
345  if (this->hasTransition(tr_it->getNativeID()))
346  {
347  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
348  }
349  if (this->hasChromatogram(tr_it->getNativeID()))
350  {
351  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_.at(tr_it->getNativeID())], tr_it->getNativeID());
352  }
353  }
354  }
355 
356  for (typename std::vector<ChromatogramType>::const_iterator pr_it = precursor_chromatograms_.begin(); pr_it != precursor_chromatograms_.end(); ++pr_it)
357  {
358  // add precursor chromatograms if present
359  transition_group_subset.addPrecursorChromatogram(*pr_it,pr_it->getNativeID());
360  }
361 
362  for (std::vector< MRMFeature >::const_iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
363  {
364  MRMFeature mf;
365  mf.setIntensity(tgf_it->getIntensity());
366  mf.setRT(tgf_it->getRT());
367  std::vector<String> metavalues;
368  tgf_it->getKeys(metavalues);
369  for (std::vector<String>::iterator key_it = metavalues.begin(); key_it != metavalues.end(); ++key_it)
370  {
371  mf.setMetaValue(*key_it,tgf_it->getMetaValue(*key_it));
372  }
373  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
374  {
375  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
376  {
377  mf.addFeature(tgf_it->getFeature(tr_it->getNativeID()),tr_it->getNativeID());
378  }
379  }
380  std::vector<String> pf_ids;
381  tgf_it->getPrecursorFeatureIDs(pf_ids);
382  for (std::vector<String>::iterator pf_ids_it = pf_ids.begin(); pf_ids_it != pf_ids.end(); ++pf_ids_it)
383  {
384  mf.addPrecursorFeature(tgf_it->getPrecursorFeature(*pf_ids_it), *pf_ids_it);
385  }
386  transition_group_subset.addFeature(mf);
387  }
388 
389  return transition_group_subset;
390  }
391 
392  MRMTransitionGroup subsetDependent(std::vector<std::string> tr_ids) const
393  {
394  MRMTransitionGroup transition_group_subset;
395  transition_group_subset.setTransitionGroupID(tr_gr_id_);
396 
397  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
398  {
399  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
400  {
401  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
402  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_.at(tr_it->getNativeID())], tr_it->getNativeID());
403  }
404  }
405 
406  for (std::vector< MRMFeature >::const_iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
407  {
408  transition_group_subset.addFeature(*tgf_it);
409  }
410 
411  return transition_group_subset;
412  }
414 
422  const MRMFeature& getBestFeature() const
423  {
424  OPENMS_PRECONDITION(!getFeatures().empty(), "Cannot get best feature for empty transition group")
425 
426  // Find the feature with the highest score
427  Size bestf = 0;
428  double highest_score = getFeatures()[0].getOverallQuality();
429  for (Size it = 0; it < getFeatures().size(); it++)
430  {
431  if (getFeatures()[it].getOverallQuality() > highest_score)
432  {
433  bestf = it;
434  highest_score = getFeatures()[it].getOverallQuality();
435  }
436  }
437  return getFeatures()[bestf];
438  }
439 
440 protected:
441 
443  bool isMappingConsistent_() const
444  {
445  if (transition_map_.size() != chromatogram_map_.size())
446  {
447  return false;
448  }
449  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
450  {
451  if (!hasTransition(it->first))
452  {
453  return false;
454  }
455  }
456  return true;
457  }
458 
461 
464 
466  std::vector<ChromatogramType> chromatograms_;
467 
469  std::vector<ChromatogramType> precursor_chromatograms_;
470 
473 
474  std::map<String, int> chromatogram_map_;
475  std::map<String, int> precursor_chromatogram_map_;
476  std::map<String, int> transition_map_;
477 
478  };
479 }
480 
OpenMS::MRMTransitionGroup::getPrecursorChromatogram
const ChromatogramType & getPrecursorChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:255
OpenMS::MRMTransitionGroup::isInternallyConsistent
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition: MRMTransitionGroup.h:292
OpenMS::MRMTransitionGroup::addPrecursorChromatogram
void addPrecursorChromatogram(const ChromatogramType &chromatogram, const String &key)
Definition: MRMTransitionGroup.h:235
OpenMS::MRMTransitionGroup::chromatograms_
std::vector< ChromatogramType > chromatograms_
chromatogram list
Definition: MRMTransitionGroup.h:466
OpenMS::MRMTransitionGroup::setTransitionGroupID
void setTransitionGroupID(const String &tr_gr_id)
Definition: MRMTransitionGroup.h:135
OpenMS::ChromatogramSettings::getNativeID
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software.
OpenMS::MRMTransitionGroup::getChromatograms
const std::vector< ChromatogramType > & getChromatograms() const
Definition: MRMTransitionGroup.h:179
OpenMS::MRMTransitionGroup::getBestFeature
const MRMFeature & getBestFeature() const
Returns the best feature by overall quality.
Definition: MRMTransitionGroup.h:422
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::MRMTransitionGroup::hasPrecursorChromatogram
bool hasPrecursorChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:243
OpenMS::MRMTransitionGroup::getFeaturesMuteable
std::vector< MRMFeature > & getFeaturesMuteable()
Definition: MRMTransitionGroup.h:271
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::MRMTransitionGroup::TransitionsType
std::vector< TransitionType > TransitionsType
List of Reaction Monitoring transitions (meta data) type.
Definition: MRMTransitionGroup.h:77
OPENMS_PRECONDITION
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:136
OpenMS::Peak2D::setIntensity
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:172
OpenMS::MRMFeature
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:50
OpenMS::MRMFeature::addFeature
void addFeature(const Feature &feature, const String &key)
Adds an feature from a single chromatogram into the feature.
OpenMS::MRMTransitionGroup::MRMTransitionGroup
MRMTransitionGroup(const MRMTransitionGroup &rhs)
Copy Constructor.
Definition: MRMTransitionGroup.h:91
Macros.h
OpenMS::Peak2D::setRT
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:214
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::MRMTransitionGroup::hasTransition
bool hasTransition(String key) const
Definition: MRMTransitionGroup.h:158
OpenMS::MRMTransitionGroup::hasChromatogram
bool hasChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:192
MRMFeature.h
OpenMS::MetaInfoInterface::setMetaValue
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
OpenMS::MRMTransitionGroup::getTransitionsMuteable
std::vector< TransitionType > & getTransitionsMuteable()
Definition: MRMTransitionGroup.h:147
OpenMS::MRMTransitionGroup::getChromatogram
ChromatogramType & getChromatogram(const String &key)
Definition: MRMTransitionGroup.h:197
OpenMS::MRMFeature::addPrecursorFeature
void addPrecursorFeature(const Feature &feature, const String &key)
Adds a precursor feature from a single chromatogram into the feature.
OpenMS::ChromatogramPeak
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:53
OpenMS::MRMTransitionGroup::chromatogram_map_
std::map< String, int > chromatogram_map_
Definition: MRMTransitionGroup.h:474
OpenMS::MRMTransitionGroup::getPrecursorChromatograms
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition: MRMTransitionGroup.h:215
OpenMS::MRMTransitionGroup::getPrecursorChromatogram
ChromatogramType & getPrecursorChromatogram(const String &key)
Definition: MRMTransitionGroup.h:248
OpenMS::MRMTransitionGroup::MRMTransitionGroup
MRMTransitionGroup()
Default constructor.
Definition: MRMTransitionGroup.h:86
OpenMS::MRMTransitionGroup::isMappingConsistent_
bool isMappingConsistent_() const
Checks that the mapping between chromatograms and transitions is consistent.
Definition: MRMTransitionGroup.h:443
OpenMS::MRMTransitionGroup::~MRMTransitionGroup
virtual ~MRMTransitionGroup()
Destructor.
Definition: MRMTransitionGroup.h:104
seqan::find
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
OpenMS::MRMTransitionGroup::precursor_chromatogram_map_
std::map< String, int > precursor_chromatogram_map_
Definition: MRMTransitionGroup.h:475
OpenMS::MRMTransitionGroup::transition_map_
std::map< String, int > transition_map_
Definition: MRMTransitionGroup.h:476
OpenMS::MRMTransitionGroup::operator=
MRMTransitionGroup & operator=(const MRMTransitionGroup &rhs)
Definition: MRMTransitionGroup.h:109
OpenMS::MRMTransitionGroup::mrm_features_
MRMFeatureListType mrm_features_
feature list
Definition: MRMTransitionGroup.h:472
OpenMS::MRMTransitionGroup::getChromatogram
const ChromatogramType & getChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:204
OpenMS::MRMTransitionGroup::transitions_
TransitionsType transitions_
transition list
Definition: MRMTransitionGroup.h:463
OpenMS::MRMTransitionGroup::getTransition
const TransitionType & getTransition(String key)
Definition: MRMTransitionGroup.h:163
OpenMS::MRMTransitionGroup::addFeature
void addFeature(const MRMFeature &feature)
Definition: MRMTransitionGroup.h:276
OpenMS::MRMTransitionGroup::PeakType
ChromatogramType::PeakType PeakType
Peak type.
Definition: MRMTransitionGroup.h:79
OpenMS::MRMTransitionGroup::getFeatures
const std::vector< MRMFeature > & getFeatures() const
Definition: MRMTransitionGroup.h:266
OpenMS::MRMTransitionGroup
The representation of a group of transitions in a targeted proteomics experiment.
Definition: MRMTransitionGroup.h:67
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::MRMTransitionGroup::tr_gr_id_
String tr_gr_id_
transition group id (peak group id)
Definition: MRMTransitionGroup.h:460
OpenMS::MRMTransitionGroup::subsetDependent
MRMTransitionGroup subsetDependent(std::vector< std::string > tr_ids) const
Definition: MRMTransitionGroup.h:392
OpenMS::MRMTransitionGroup::addFeature
void addFeature(MRMFeature &&feature)
Definition: MRMTransitionGroup.h:281
OpenMS::MRMTransitionGroup::MRMFeatureListType
std::vector< MRMFeature > MRMFeatureListType
Type definitions.
Definition: MRMTransitionGroup.h:75
OpenMS::MRMTransitionGroup::chromatogramIdsMatch
bool chromatogramIdsMatch() const
Ensure that chromatogram native ids match their keys in the map.
Definition: MRMTransitionGroup.h:301
OpenMS::MRMTransitionGroup::subset
MRMTransitionGroup subset(std::vector< std::string > tr_ids) const
Definition: MRMTransitionGroup.h:336
OpenMS::MRMTransitionGroup::getChromatograms
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:174
OpenMS::MRMTransitionGroup::getLibraryIntensity
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:320
OpenMS::MRMTransitionGroup::getTransitions
const std::vector< TransitionType > & getTransitions() const
Definition: MRMTransitionGroup.h:142
OpenMS::MRMTransitionGroup::precursor_chromatograms_
std::vector< ChromatogramType > precursor_chromatograms_
precursor chromatogram list
Definition: MRMTransitionGroup.h:469
OpenMS::MRMTransitionGroup::size
Size size() const
Definition: MRMTransitionGroup.h:125
OpenMS::MRMTransitionGroup::getTransitionGroupID
const String & getTransitionGroupID() const
Definition: MRMTransitionGroup.h:130
OpenMS::MRMTransitionGroup::getPrecursorChromatograms
const std::vector< ChromatogramType > & getPrecursorChromatograms() const
Definition: MRMTransitionGroup.h:220
OpenMS::MRMTransitionGroup::addTransition
void addTransition(const TransitionType &transition, String key)
Definition: MRMTransitionGroup.h:152
OpenMS::MRMTransitionGroup::addChromatogram
void addChromatogram(const ChromatogramType &chromatogram, const String &key)
Definition: MRMTransitionGroup.h:184