Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2017.
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 const std::vector<ChromatogramType> & getChromatograms() const
175  {
176  return chromatograms_;
177  }
178 
179  inline std::vector<ChromatogramType> & getChromatograms()
180  {
181  return chromatograms_;
182  }
183 
184  inline void addChromatogram(ChromatogramType & chromatogram, 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(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  }
204 
205 
207 
208  inline const std::vector<ChromatogramType> & getPrecursorChromatograms() const
209  {
211  }
212 
213  inline std::vector<ChromatogramType> & getPrecursorChromatograms()
214  {
216  }
217 
228  inline void addPrecursorChromatogram(ChromatogramType & chromatogram, String key)
229  {
230  precursor_chromatograms_.push_back(chromatogram);
231  precursor_chromatogram_map_[key] = boost::numeric_cast<int>(precursor_chromatograms_.size()) - 1;
232 
233  // OPENMS_POSTCONDITION(chromatogramIdsMatch(), "Chromatogram ids do not match")
234  }
235 
236  inline bool hasPrecursorChromatogram(String key) const
237  {
239  }
240 
242  {
243  OPENMS_PRECONDITION(hasPrecursorChromatogram(key), "Cannot retrieve precursor chromatogram that does not exist")
244  OPENMS_PRECONDITION(precursor_chromatograms_.size() > (size_t)precursor_chromatogram_map_[key], "Mapping needs to be accurate")
246  }
248 
249 
251 
252  inline const std::vector<MRMFeature> & getFeatures() const
253  {
254  return mrm_features_;
255  }
256 
257  inline std::vector<MRMFeature> & getFeaturesMuteable()
258  {
259  return mrm_features_;
260  }
261 
262  inline void addFeature(MRMFeature & feature)
263  {
264  mrm_features_.push_back(feature);
265  }
267 
268 
270 
271 
273  inline bool isInternallyConsistent() const
274  {
275  OPENMS_PRECONDITION(transitions_.size() == chromatograms_.size(), "Same number of transitions as chromatograms are required")
276  OPENMS_PRECONDITION(transition_map_.size() == chromatogram_map_.size(), "Same number of transitions as chromatograms mappings are required")
277  OPENMS_PRECONDITION(isMappingConsistent_(), "Mapping needs to be consistent")
278  return true;
279  }
280 
282  inline bool chromatogramIdsMatch()
283  {
284  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
285  {
286  if (getChromatogram(it->first).getNativeID() != it->first)
287  {
288  return false;
289  }
290  }
291  for (std::map<String, int>::const_iterator it = precursor_chromatogram_map_.begin(); it != precursor_chromatogram_map_.end(); it++)
292  {
293  if (getPrecursorChromatogram(it->first).getNativeID() != it->first)
294  {
295  return false;
296  }
297  }
298  return true;
299  }
300 
301  void getLibraryIntensity(std::vector<double> & result) const
302  {
303  for (typename TransitionsType::const_iterator it = transitions_.begin(); it != transitions_.end(); ++it)
304  {
305  result.push_back(it->getLibraryIntensity());
306  }
307  for (Size i = 0; i < result.size(); i++)
308  {
309  // the library intensity should never be below zero
310  if (result[i] < 0.0)
311  {
312  result[i] = 0.0;
313  }
314  }
315  }
316 
317  MRMTransitionGroup subset(std::vector<std::string> tr_ids)
318  {
319  MRMTransitionGroup transition_group_subset;
320  transition_group_subset.setTransitionGroupID(tr_gr_id_);
321 
322  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
323  {
324  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
325  {
326  if (this->hasTransition(tr_it->getNativeID()))
327  {
328  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
329  }
330  if (this->hasChromatogram(tr_it->getNativeID()))
331  {
332  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_[tr_it->getNativeID()]], tr_it->getNativeID());
333  }
334  }
335  }
336 
337  for (typename std::vector<ChromatogramType>::iterator pr_it = precursor_chromatograms_.begin(); pr_it != precursor_chromatograms_.end(); ++pr_it)
338  {
339  // add precursor chromatograms if present
340  transition_group_subset.addPrecursorChromatogram(*pr_it,pr_it->getNativeID());
341  }
342 
343  for (std::vector< MRMFeature >::iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
344  {
345  MRMFeature mf;
346  mf.setIntensity(tgf_it->getIntensity());
347  mf.setRT(tgf_it->getRT());
348  std::vector<String> metavalues;
349  tgf_it->getKeys(metavalues);
350  for (std::vector<String>::iterator key_it = metavalues.begin(); key_it != metavalues.end(); ++key_it)
351  {
352  mf.setMetaValue(*key_it,tgf_it->getMetaValue(*key_it));
353  }
354  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
355  {
356  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
357  {
358  mf.addFeature(tgf_it->getFeature(tr_it->getNativeID()),tr_it->getNativeID());
359  }
360  }
361  std::vector<String> pf_ids;
362  tgf_it->getPrecursorFeatureIDs(pf_ids);
363  for (std::vector<String>::iterator pf_ids_it = pf_ids.begin(); pf_ids_it != pf_ids.end(); ++pf_ids_it)
364  {
365  mf.addPrecursorFeature(tgf_it->getPrecursorFeature(*pf_ids_it),*pf_ids_it);
366  }
367  transition_group_subset.addFeature(mf);
368  }
369 
370  return transition_group_subset;
371  }
372 
373  MRMTransitionGroup subsetDependent(std::vector<std::string> tr_ids)
374  {
375  MRMTransitionGroup transition_group_subset;
376  transition_group_subset.setTransitionGroupID(tr_gr_id_);
377 
378  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
379  {
380  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
381  {
382  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
383  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_[tr_it->getNativeID()]], tr_it->getNativeID());
384  }
385  }
386 
387  for (std::vector< MRMFeature >::iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
388  {
389  transition_group_subset.addFeature(*tgf_it);
390  }
391 
392  return transition_group_subset;
393  }
395 
396 
404  const MRMFeature& getBestFeature() const
405  {
406  OPENMS_PRECONDITION(!getFeatures().empty(), "Cannot get best feature for empty transition group")
407 
408  // Find the feature with the highest score
409  Size bestf = 0;
410  double highest_score = getFeatures()[0].getOverallQuality();
411  for (Size it = 0; it < getFeatures().size(); it++)
412  {
413  if (getFeatures()[it].getOverallQuality() > highest_score)
414  {
415  bestf = it;
416  highest_score = getFeatures()[it].getOverallQuality();
417  }
418  }
419  return getFeatures()[bestf];
420  }
421 
422 protected:
423 
425  bool isMappingConsistent_() const
426  {
427  if (transition_map_.size() != chromatogram_map_.size())
428  {
429  return false;
430  }
431  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
432  {
433  if (!hasTransition(it->first))
434  {
435  return false;
436  }
437  }
438  return true;
439  }
440 
443 
446 
448  std::vector<ChromatogramType> chromatograms_;
449 
451  std::vector<ChromatogramType> precursor_chromatograms_;
452 
455 
456  std::map<String, int> chromatogram_map_;
457  std::map<String, int> precursor_chromatogram_map_;
458  std::map<String, int> transition_map_;
459 
460  };
461 }
462 
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:454
std::map< String, int > transition_map_
Definition: MRMTransitionGroup.h:458
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:445
String tr_gr_id_
transition group id (peak group id)
Definition: MRMTransitionGroup.h:442
A more convenient string class.
Definition: String.h:57
const std::vector< MRMFeature > & getFeatures() const
Definition: MRMTransitionGroup.h:252
void addChromatogram(ChromatogramType &chromatogram, String key)
Definition: MRMTransitionGroup.h:184
std::map< String, int > chromatogram_map_
Definition: MRMTransitionGroup.h:456
The representation of a chromatogram.
Definition: MSChromatogram.h:54
MRMTransitionGroup subset(std::vector< std::string > tr_ids)
Definition: MRMTransitionGroup.h:317
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:451
bool hasPrecursorChromatogram(String key) const
Definition: MRMTransitionGroup.h:236
const std::vector< ChromatogramType > & getPrecursorChromatograms() const
Definition: MRMTransitionGroup.h:208
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool isMappingConsistent_() const
Checks that the mapping between chromatograms and transitions is consistent.
Definition: MRMTransitionGroup.h:425
ChromatogramType & getChromatogram(String key)
Definition: MRMTransitionGroup.h:197
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
MRMTransitionGroup subsetDependent(std::vector< std::string > tr_ids)
Definition: MRMTransitionGroup.h:373
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
MRMTransitionGroup & operator=(const MRMTransitionGroup &rhs)
Definition: MRMTransitionGroup.h:109
void addFeature(Feature &feature, const String &key)
Adds an feature from a single chromatogram into the feature.
bool isInternallyConsistent() const
Check whether internal state is consistent, e.g. same number of chromatograms and transitions are pre...
Definition: MRMTransitionGroup.h:273
bool hasChromatogram(String key) const
Definition: MRMTransitionGroup.h:192
const std::vector< ChromatogramType > & getChromatograms() const
Definition: MRMTransitionGroup.h:174
std::vector< ChromatogramType > chromatograms_
chromatogram list
Definition: MRMTransitionGroup.h:448
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:179
const MRMFeature & getBestFeature() const
Returns the best feature by overall quality.
Definition: MRMTransitionGroup.h:404
std::vector< MRMFeature > & getFeaturesMuteable()
Definition: MRMTransitionGroup.h:257
const String & getTransitionGroupID() const
Definition: MRMTransitionGroup.h:130
ChromatogramType & getPrecursorChromatogram(String key)
Definition: MRMTransitionGroup.h:241
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:301
void addTransition(const TransitionType &transition, String key)
Definition: MRMTransitionGroup.h:152
void addFeature(MRMFeature &feature)
Definition: MRMTransitionGroup.h:262
void addPrecursorFeature(Feature &feature, const String &key)
Adds a precursor 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
bool chromatogramIdsMatch()
Ensure that chromatogram native ids match their keys in the map.
Definition: MRMTransitionGroup.h:282
MRMTransitionGroup()
Default constructor.
Definition: MRMTransitionGroup.h:86
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:213
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:49
void addPrecursorChromatogram(ChromatogramType &chromatogram, String key)
Definition: MRMTransitionGroup.h:228
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:457

OpenMS / TOPP release 2.3.0 Documentation generated on Wed Apr 18 2018 19:29:06 using doxygen 1.8.14