OpenMS  2.4.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-2018.
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(), "Chromatogam 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  }
281 
282 
284 
285 
287  inline bool isInternallyConsistent() const
288  {
289  OPENMS_PRECONDITION(transitions_.size() == chromatograms_.size(), "Same number of transitions as chromatograms are required")
290  OPENMS_PRECONDITION(transition_map_.size() == chromatogram_map_.size(), "Same number of transitions as chromatograms mappings are required")
291  OPENMS_PRECONDITION(isMappingConsistent_(), "Mapping needs to be consistent")
292  return true;
293  }
294 
296  inline bool chromatogramIdsMatch() const
297  {
298  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
299  {
300  if (getChromatogram(it->first).getNativeID() != it->first)
301  {
302  return false;
303  }
304  }
305  for (std::map<String, int>::const_iterator it = precursor_chromatogram_map_.begin(); it != precursor_chromatogram_map_.end(); it++)
306  {
307  if (getPrecursorChromatogram(it->first).getNativeID() != it->first)
308  {
309  return false;
310  }
311  }
312  return true;
313  }
314 
315  void getLibraryIntensity(std::vector<double> & result) const
316  {
317  for (typename TransitionsType::const_iterator it = transitions_.begin(); it != transitions_.end(); ++it)
318  {
319  result.push_back(it->getLibraryIntensity());
320  }
321  for (Size i = 0; i < result.size(); i++)
322  {
323  // the library intensity should never be below zero
324  if (result[i] < 0.0)
325  {
326  result[i] = 0.0;
327  }
328  }
329  }
330 
331  MRMTransitionGroup subset(std::vector<std::string> tr_ids) const
332  {
333  MRMTransitionGroup transition_group_subset;
334  transition_group_subset.setTransitionGroupID(tr_gr_id_);
335 
336  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
337  {
338  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
339  {
340  if (this->hasTransition(tr_it->getNativeID()))
341  {
342  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
343  }
344  if (this->hasChromatogram(tr_it->getNativeID()))
345  {
346  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_.at(tr_it->getNativeID())], tr_it->getNativeID());
347  }
348  }
349  }
350 
351  for (typename std::vector<ChromatogramType>::const_iterator pr_it = precursor_chromatograms_.begin(); pr_it != precursor_chromatograms_.end(); ++pr_it)
352  {
353  // add precursor chromatograms if present
354  transition_group_subset.addPrecursorChromatogram(*pr_it,pr_it->getNativeID());
355  }
356 
357  for (std::vector< MRMFeature >::const_iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
358  {
359  MRMFeature mf;
360  mf.setIntensity(tgf_it->getIntensity());
361  mf.setRT(tgf_it->getRT());
362  std::vector<String> metavalues;
363  tgf_it->getKeys(metavalues);
364  for (std::vector<String>::iterator key_it = metavalues.begin(); key_it != metavalues.end(); ++key_it)
365  {
366  mf.setMetaValue(*key_it,tgf_it->getMetaValue(*key_it));
367  }
368  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
369  {
370  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
371  {
372  mf.addFeature(tgf_it->getFeature(tr_it->getNativeID()),tr_it->getNativeID());
373  }
374  }
375  std::vector<String> pf_ids;
376  tgf_it->getPrecursorFeatureIDs(pf_ids);
377  for (std::vector<String>::iterator pf_ids_it = pf_ids.begin(); pf_ids_it != pf_ids.end(); ++pf_ids_it)
378  {
379  mf.addPrecursorFeature(tgf_it->getPrecursorFeature(*pf_ids_it), *pf_ids_it);
380  }
381  transition_group_subset.addFeature(mf);
382  }
383 
384  return transition_group_subset;
385  }
386 
387  MRMTransitionGroup subsetDependent(std::vector<std::string> tr_ids) const
388  {
389  MRMTransitionGroup transition_group_subset;
390  transition_group_subset.setTransitionGroupID(tr_gr_id_);
391 
392  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
393  {
394  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
395  {
396  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
397  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_.at(tr_it->getNativeID())], tr_it->getNativeID());
398  }
399  }
400 
401  for (std::vector< MRMFeature >::const_iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
402  {
403  transition_group_subset.addFeature(*tgf_it);
404  }
405 
406  return transition_group_subset;
407  }
409 
417  const MRMFeature& getBestFeature() const
418  {
419  OPENMS_PRECONDITION(!getFeatures().empty(), "Cannot get best feature for empty transition group")
420 
421  // Find the feature with the highest score
422  Size bestf = 0;
423  double highest_score = getFeatures()[0].getOverallQuality();
424  for (Size it = 0; it < getFeatures().size(); it++)
425  {
426  if (getFeatures()[it].getOverallQuality() > highest_score)
427  {
428  bestf = it;
429  highest_score = getFeatures()[it].getOverallQuality();
430  }
431  }
432  return getFeatures()[bestf];
433  }
434 
435 protected:
436 
438  bool isMappingConsistent_() const
439  {
440  if (transition_map_.size() != chromatogram_map_.size())
441  {
442  return false;
443  }
444  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
445  {
446  if (!hasTransition(it->first))
447  {
448  return false;
449  }
450  }
451  return true;
452  }
453 
456 
459 
461  std::vector<ChromatogramType> chromatograms_;
462 
464  std::vector<ChromatogramType> precursor_chromatograms_;
465 
468 
469  std::map<String, int> chromatogram_map_;
470  std::map<String, int> precursor_chromatogram_map_;
471  std::map<String, int> transition_map_;
472 
473  };
474 }
475 
std::vector< TransitionType > TransitionsType
List of Reaction Monitoring transitions (meta data) type.
Definition: MRMTransitionGroup.h:77
MRMTransitionGroup(const MRMTransitionGroup &rhs)
Copy Constructor.
Definition: MRMTransitionGroup.h:91
MRMFeatureListType mrm_features_
feature list
Definition: MRMTransitionGroup.h:467
std::map< String, int > transition_map_
Definition: MRMTransitionGroup.h:471
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
bool hasTransition(String key) const
Definition: MRMTransitionGroup.h:158
TransitionsType transitions_
transition list
Definition: MRMTransitionGroup.h:458
String tr_gr_id_
transition group id (peak group id)
Definition: MRMTransitionGroup.h:455
A more convenient string class.
Definition: String.h:57
MRMTransitionGroup subsetDependent(std::vector< std::string > tr_ids) const
Definition: MRMTransitionGroup.h:387
const std::vector< MRMFeature > & getFeatures() const
Definition: MRMTransitionGroup.h:266
ChromatogramType & getChromatogram(const String &key)
Definition: MRMTransitionGroup.h:197
std::map< String, int > chromatogram_map_
Definition: MRMTransitionGroup.h:469
The representation of a chromatogram.
Definition: MSChromatogram.h:54
MRMTransitionGroup subset(std::vector< std::string > tr_ids) const
Definition: MRMTransitionGroup.h:331
const std::vector< TransitionType > & getTransitions() const
Definition: MRMTransitionGroup.h:142
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:106
Size size() const
Definition: MRMTransitionGroup.h:125
std::vector< ChromatogramType > precursor_chromatograms_
precursor chromatogram list
Definition: MRMTransitionGroup.h:464
const std::vector< ChromatogramType > & getPrecursorChromatograms() const
Definition: MRMTransitionGroup.h:220
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool isMappingConsistent_() const
Checks that the mapping between chromatograms and transitions is consistent.
Definition: MRMTransitionGroup.h:438
void addChromatogram(const ChromatogramType &chromatogram, const String &key)
Definition: MRMTransitionGroup.h:184
const ChromatogramType & getChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:204
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:172
void addFeature(const MRMFeature &feature)
Definition: MRMTransitionGroup.h:276
ChromatogramType::PeakType PeakType
Peak type.
Definition: MRMTransitionGroup.h:79
The representation of a group of transitions in a targeted proteomics experiment. ...
Definition: MRMTransitionGroup.h:67
const ChromatogramType & getPrecursorChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:255
MRMTransitionGroup & operator=(const MRMTransitionGroup &rhs)
Definition: MRMTransitionGroup.h:109
bool hasPrecursorChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:243
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition: MRMTransitionGroup.h:287
const std::vector< ChromatogramType > & getChromatograms() const
Definition: MRMTransitionGroup.h:179
std::vector< ChromatogramType > chromatograms_
chromatogram list
Definition: MRMTransitionGroup.h:461
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:214
std::vector< MRMFeature > MRMFeatureListType
Type definitions.
Definition: MRMTransitionGroup.h:75
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:174
const MRMFeature & getBestFeature() const
Returns the best feature by overall quality.
Definition: MRMTransitionGroup.h:417
std::vector< MRMFeature > & getFeaturesMuteable()
Definition: MRMTransitionGroup.h:271
const String & getTransitionGroupID() const
Definition: MRMTransitionGroup.h:130
bool chromatogramIdsMatch() const
Ensure that chromatogram native ids match their keys in the map.
Definition: MRMTransitionGroup.h:296
void addPrecursorFeature(const Feature &feature, const String &key)
Adds a precursor feature from a single chromatogram into the feature.
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:315
bool hasChromatogram(const String &key) const
Definition: MRMTransitionGroup.h:192
void addTransition(const TransitionType &transition, String key)
Definition: MRMTransitionGroup.h:152
void addFeature(const Feature &feature, const String &key)
Adds an feature from a single chromatogram into the feature.
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software. ...
void setTransitionGroupID(const String &tr_gr_id)
Definition: MRMTransitionGroup.h:135
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
ChromatogramType & getPrecursorChromatogram(const String &key)
Definition: MRMTransitionGroup.h:248
MRMTransitionGroup()
Default constructor.
Definition: MRMTransitionGroup.h:86
void addPrecursorChromatogram(const ChromatogramType &chromatogram, const String &key)
Definition: MRMTransitionGroup.h:235
std::vector< TransitionType > & getTransitionsMuteable()
Definition: MRMTransitionGroup.h:147
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:54
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition: MRMTransitionGroup.h:215
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:49
virtual ~MRMTransitionGroup()
Destructor.
Definition: MRMTransitionGroup.h:104
const TransitionType & getTransition(String key)
Definition: MRMTransitionGroup.h:163
std::map< String, int > precursor_chromatogram_map_
Definition: MRMTransitionGroup.h:470