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 #ifndef OPENMS_KERNEL_MRMTRANSITIONGROUP_H
36 #define OPENMS_KERNEL_MRMTRANSITIONGROUP_H
37 
38 #include <OpenMS/CONCEPT/Macros.h>
40 #include <boost/numeric/conversion/cast.hpp>
41 
42 namespace OpenMS
43 {
44 
67  template <typename ChromatogramType, typename TransitionType>
69  {
70 
71 public:
72 
74 
75  typedef std::vector<MRMFeature> MRMFeatureListType;
78  typedef std::vector<TransitionType> TransitionsType;
82 
88  {
89  }
90 
93  tr_gr_id_(rhs.tr_gr_id_),
101  {
102  }
103 
106  {
107  }
109 
111  {
112  if (&rhs != this)
113  {
114  tr_gr_id_ = rhs.tr_gr_id_;
122  }
123  return *this;
124  }
125 
126  inline Size size() const
127  {
128  return chromatograms_.size();
129  }
130 
131  inline const String & getTransitionGroupID() const
132  {
133  return tr_gr_id_;
134  }
135 
136  inline void setTransitionGroupID(const String & tr_gr_id)
137  {
138  tr_gr_id_ = tr_gr_id;
139  }
140 
142 
143  inline const std::vector<TransitionType> & getTransitions() const
144  {
145  return transitions_;
146  }
147 
148  inline std::vector<TransitionType> & getTransitionsMuteable()
149  {
150  return transitions_;
151  }
152 
153  inline void addTransition(const TransitionType & transition, String key)
154  {
155  transitions_.push_back(transition);
156  transition_map_[key] = boost::numeric_cast<int>(transitions_.size()) - 1;
157  }
158 
159  inline bool hasTransition(String key) const
160  {
161  return transition_map_.find(key) != transition_map_.end();
162  }
163 
164  inline const TransitionType & getTransition(String key)
165  {
166  OPENMS_PRECONDITION(hasTransition(key), "Cannot retrieve transitions that does not exist")
167  OPENMS_PRECONDITION(transitions_.size() > (size_t)transition_map_[key], "Mapping needs to be accurate")
168  return transitions_[transition_map_[key]];
169  }
171 
172 
174 
175  inline const std::vector<ChromatogramType> & getChromatograms() const
176  {
177  return chromatograms_;
178  }
179 
180  inline std::vector<ChromatogramType> & getChromatograms()
181  {
182  return chromatograms_;
183  }
184 
185  inline void addChromatogram(ChromatogramType & chromatogram, String key)
186  {
187  chromatograms_.push_back(chromatogram);
188  chromatogram_map_[key] = boost::numeric_cast<int>(chromatograms_.size()) - 1;
189 
190  // OPENMS_POSTCONDITION(chromatogramIdsMatch(), "Chromatogam ids do not match")
191  }
192 
193  inline bool hasChromatogram(String key) const
194  {
195  return chromatogram_map_.find(key) != chromatogram_map_.end();
196  }
197 
199  {
200  OPENMS_PRECONDITION(hasChromatogram(key), "Cannot retrieve chromatogram that does not exist")
201  OPENMS_PRECONDITION(chromatograms_.size() > (size_t)chromatogram_map_[key], "Mapping needs to be accurate")
202  return chromatograms_[chromatogram_map_[key]];
203  }
205 
206 
208 
209  inline const std::vector<ChromatogramType> & getPrecursorChromatograms() const
210  {
212  }
213 
214  inline std::vector<ChromatogramType> & getPrecursorChromatograms()
215  {
217  }
218 
229  inline void addPrecursorChromatogram(ChromatogramType & chromatogram, String key)
230  {
231  precursor_chromatograms_.push_back(chromatogram);
232  precursor_chromatogram_map_[key] = boost::numeric_cast<int>(precursor_chromatograms_.size()) - 1;
233 
234  // OPENMS_POSTCONDITION(chromatogramIdsMatch(), "Chromatogam ids do not match")
235  }
236 
237  inline bool hasPrecursorChromatogram(String key) const
238  {
240  }
241 
243  {
244  OPENMS_PRECONDITION(hasPrecursorChromatogram(key), "Cannot retrieve precursor chromatogram that does not exist")
245  OPENMS_PRECONDITION(precursor_chromatograms_.size() > (size_t)precursor_chromatogram_map_[key], "Mapping needs to be accurate")
247  }
249 
250 
252 
253  inline const std::vector<MRMFeature> & getFeatures() const
254  {
255  return mrm_features_;
256  }
257 
258  inline std::vector<MRMFeature> & getFeaturesMuteable()
259  {
260  return mrm_features_;
261  }
262 
263  inline void addFeature(MRMFeature & feature)
264  {
265  mrm_features_.push_back(feature);
266  }
268 
269 
271 
272 
274  inline bool isInternallyConsistent() const
275  {
276  OPENMS_PRECONDITION(transitions_.size() == chromatograms_.size(), "Same number of transitions as chromatograms are required")
277  OPENMS_PRECONDITION(transition_map_.size() == chromatogram_map_.size(), "Same number of transitions as chromatograms mappings are required")
278  OPENMS_PRECONDITION(isMappingConsistent_(), "Mapping needs to be consistent")
279  return true;
280  }
281 
283  inline bool chromatogramIdsMatch()
284  {
285  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
286  {
287  if (getChromatogram(it->first).getNativeID() != it->first)
288  {
289  return false;
290  }
291  }
292  for (std::map<String, int>::const_iterator it = precursor_chromatogram_map_.begin(); it != precursor_chromatogram_map_.end(); it++)
293  {
294  if (getPrecursorChromatogram(it->first).getNativeID() != it->first)
295  {
296  return false;
297  }
298  }
299  return true;
300  }
301 
302  void getLibraryIntensity(std::vector<double> & result) const
303  {
304  for (typename TransitionsType::const_iterator it = transitions_.begin(); it != transitions_.end(); ++it)
305  {
306  result.push_back(it->getLibraryIntensity());
307  }
308  for (Size i = 0; i < result.size(); i++)
309  {
310  // the library intensity should never be below zero
311  if (result[i] < 0.0)
312  {
313  result[i] = 0.0;
314  }
315  }
316  }
317 
318  MRMTransitionGroup subset(std::vector<std::string> tr_ids)
319  {
320  MRMTransitionGroup transition_group_subset;
321  transition_group_subset.setTransitionGroupID(tr_gr_id_);
322 
323  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
324  {
325  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
326  {
327  if (this->hasTransition(tr_it->getNativeID()))
328  {
329  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
330  }
331  if (this->hasChromatogram(tr_it->getNativeID()))
332  {
333  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_[tr_it->getNativeID()]], tr_it->getNativeID());
334  }
335  }
336  }
337 
338  for (typename std::vector<ChromatogramType>::iterator pr_it = precursor_chromatograms_.begin(); pr_it != precursor_chromatograms_.end(); ++pr_it)
339  {
340  // add precursor chromatograms if present
341  transition_group_subset.addPrecursorChromatogram(*pr_it,pr_it->getNativeID());
342  }
343 
344  for (std::vector< MRMFeature >::iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
345  {
346  MRMFeature mf;
347  mf.setIntensity(tgf_it->getIntensity());
348  mf.setRT(tgf_it->getRT());
349  std::vector<String> metavalues;
350  tgf_it->getKeys(metavalues);
351  for (std::vector<String>::iterator key_it = metavalues.begin(); key_it != metavalues.end(); ++key_it)
352  {
353  mf.setMetaValue(*key_it,tgf_it->getMetaValue(*key_it));
354  }
355  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
356  {
357  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
358  {
359  mf.addFeature(tgf_it->getFeature(tr_it->getNativeID()),tr_it->getNativeID());
360  }
361  }
362  std::vector<String> pf_ids;
363  tgf_it->getPrecursorFeatureIDs(pf_ids);
364  for (std::vector<String>::iterator pf_ids_it = pf_ids.begin(); pf_ids_it != pf_ids.end(); ++pf_ids_it)
365  {
366  mf.addPrecursorFeature(tgf_it->getPrecursorFeature(*pf_ids_it),*pf_ids_it);
367  }
368  transition_group_subset.addFeature(mf);
369  }
370 
371  return transition_group_subset;
372  }
373 
374  MRMTransitionGroup subsetDependent(std::vector<std::string> tr_ids)
375  {
376  MRMTransitionGroup transition_group_subset;
377  transition_group_subset.setTransitionGroupID(tr_gr_id_);
378 
379  for (typename TransitionsType::const_iterator tr_it = transitions_.begin(); tr_it != transitions_.end(); ++tr_it)
380  {
381  if (std::find(tr_ids.begin(), tr_ids.end(), tr_it->getNativeID()) != tr_ids.end())
382  {
383  transition_group_subset.addTransition(*tr_it, tr_it->getNativeID());
384  transition_group_subset.addChromatogram(chromatograms_[chromatogram_map_[tr_it->getNativeID()]], tr_it->getNativeID());
385  }
386  }
387 
388  for (std::vector< MRMFeature >::iterator tgf_it = mrm_features_.begin(); tgf_it != mrm_features_.end(); ++tgf_it)
389  {
390  transition_group_subset.addFeature(*tgf_it);
391  }
392 
393  return transition_group_subset;
394  }
396 
397 
405  const MRMFeature& getBestFeature() const
406  {
407  OPENMS_PRECONDITION(!getFeatures().empty(), "Cannot get best feature for empty transition group")
408 
409  // Find the feature with the highest score
410  Size bestf = 0;
411  double highest_score = getFeatures()[0].getOverallQuality();
412  for (Size it = 0; it < getFeatures().size(); it++)
413  {
414  if (getFeatures()[it].getOverallQuality() > highest_score)
415  {
416  bestf = it;
417  highest_score = getFeatures()[it].getOverallQuality();
418  }
419  }
420  return getFeatures()[bestf];
421  }
422 
423 protected:
424 
426  bool isMappingConsistent_() const
427  {
428  if (transition_map_.size() != chromatogram_map_.size())
429  {
430  return false;
431  }
432  for (std::map<String, int>::const_iterator it = chromatogram_map_.begin(); it != chromatogram_map_.end(); it++)
433  {
434  if (!hasTransition(it->first))
435  {
436  return false;
437  }
438  }
439  return true;
440  }
441 
444 
446  TransitionsType transitions_;
447 
449  std::vector<ChromatogramType> chromatograms_;
450 
452  std::vector<ChromatogramType> precursor_chromatograms_;
453 
455  MRMFeatureListType mrm_features_;
456 
457  std::map<String, int> chromatogram_map_;
458  std::map<String, int> precursor_chromatogram_map_;
459  std::map<String, int> transition_map_;
460 
461  };
462 }
463 #endif // OPENMS_KERNEL_MRMTRANSITIONGROUP_H
464 
std::vector< TransitionType > TransitionsType
List of Reaction Monitoring transitions (meta data) type.
Definition: MRMTransitionGroup.h:78
MRMTransitionGroup(const MRMTransitionGroup &rhs)
Copy Constructor.
Definition: MRMTransitionGroup.h:92
MRMFeatureListType mrm_features_
feature list
Definition: MRMTransitionGroup.h:455
std::map< String, int > transition_map_
Definition: MRMTransitionGroup.h:459
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
bool hasTransition(String key) const
Definition: MRMTransitionGroup.h:159
TransitionsType transitions_
transition list
Definition: MRMTransitionGroup.h:446
String tr_gr_id_
transition group id (peak group id)
Definition: MRMTransitionGroup.h:443
A more convenient string class.
Definition: String.h:57
const std::vector< MRMFeature > & getFeatures() const
Definition: MRMTransitionGroup.h:253
void addChromatogram(ChromatogramType &chromatogram, String key)
Definition: MRMTransitionGroup.h:185
std::map< String, int > chromatogram_map_
Definition: MRMTransitionGroup.h:457
The representation of a chromatogram.
Definition: MSChromatogram.h:55
MRMTransitionGroup subset(std::vector< std::string > tr_ids)
Definition: MRMTransitionGroup.h:318
const std::vector< TransitionType > & getTransitions() const
Definition: MRMTransitionGroup.h:143
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
Size size() const
Definition: MRMTransitionGroup.h:126
std::vector< ChromatogramType > precursor_chromatograms_
precursor chromatogram list
Definition: MRMTransitionGroup.h:452
bool hasPrecursorChromatogram(String key) const
Definition: MRMTransitionGroup.h:237
const std::vector< ChromatogramType > & getPrecursorChromatograms() const
Definition: MRMTransitionGroup.h:209
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool isMappingConsistent_() const
Checks that the mapping between chromatograms and transitions is consistent.
Definition: MRMTransitionGroup.h:426
ChromatogramType & getChromatogram(String key)
Definition: MRMTransitionGroup.h:198
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height)
Definition: Peak2D.h:173
MRMTransitionGroup subsetDependent(std::vector< std::string > tr_ids)
Definition: MRMTransitionGroup.h:374
ChromatogramType::PeakType PeakType
Peak type.
Definition: MRMTransitionGroup.h:80
The representation of a group of transitions in a targeted proteomics experiment. ...
Definition: MRMTransitionGroup.h:68
MRMTransitionGroup & operator=(const MRMTransitionGroup &rhs)
Definition: MRMTransitionGroup.h:110
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:274
bool hasChromatogram(String key) const
Definition: MRMTransitionGroup.h:193
const std::vector< ChromatogramType > & getChromatograms() const
Definition: MRMTransitionGroup.h:175
std::vector< ChromatogramType > chromatograms_
chromatogram list
Definition: MRMTransitionGroup.h:449
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0)
Definition: Peak2D.h:215
std::vector< MRMFeature > MRMFeatureListType
Type definitions.
Definition: MRMTransitionGroup.h:76
std::vector< ChromatogramType > & getChromatograms()
Definition: MRMTransitionGroup.h:180
const MRMFeature & getBestFeature() const
Returns the best feature by overall quality.
Definition: MRMTransitionGroup.h:405
std::vector< MRMFeature > & getFeaturesMuteable()
Definition: MRMTransitionGroup.h:258
const String & getTransitionGroupID() const
Definition: MRMTransitionGroup.h:131
ChromatogramType & getPrecursorChromatogram(String key)
Definition: MRMTransitionGroup.h:242
void getLibraryIntensity(std::vector< double > &result) const
Definition: MRMTransitionGroup.h:302
void addTransition(const TransitionType &transition, String key)
Definition: MRMTransitionGroup.h:153
void addFeature(MRMFeature &feature)
Definition: MRMTransitionGroup.h:263
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:136
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
bool chromatogramIdsMatch()
Ensure that chromatogram native ids match their keys in the map.
Definition: MRMTransitionGroup.h:283
MRMTransitionGroup()
Default constructor.
Definition: MRMTransitionGroup.h:87
std::vector< TransitionType > & getTransitionsMuteable()
Definition: MRMTransitionGroup.h:148
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:55
std::vector< ChromatogramType > & getPrecursorChromatograms()
Definition: MRMTransitionGroup.h:214
A multi-chromatogram MRM feature.
Definition: MRMFeature.h:50
void addPrecursorChromatogram(ChromatogramType &chromatogram, String key)
Definition: MRMTransitionGroup.h:229
virtual ~MRMTransitionGroup()
Destructor.
Definition: MRMTransitionGroup.h:105
const TransitionType & getTransition(String key)
Definition: MRMTransitionGroup.h:164
std::map< String, int > precursor_chromatogram_map_
Definition: MRMTransitionGroup.h:458

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13