OpenMS
OpenSwathHelper.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
17 
18 namespace OpenMS
19 {
23  class OPENMS_DLLAPI OpenSwathHelper
24  {
25 
26 public:
27 
40  static String computePrecursorId(const String& transition_group_id, int isotope)
41  {
42  return transition_group_id + "_Precursor_i" + String(isotope);
43  }
44 
56  static String computeTransitionGroupId(const String& precursor_id)
57  {
58  std::vector<String> substrings;
59  precursor_id.split("_", substrings);
60 
61  if (substrings.size() == 3) return substrings[0];
62  else if (substrings.size() > 3)
63  {
64  String r;
65  for (Size k = 0; k < substrings.size() - 2; k++) r += substrings[k] + "_";
66  return r.prefix(r.size() - 1);
67  }
68  return "";
69  }
70 
82  static void selectSwathTransitions(const OpenMS::TargetedExperiment& targeted_exp,
83  OpenMS::TargetedExperiment& selected_transitions,
84  double min_upper_edge_dist,
85  double lower, double upper);
86 
99  OpenSwath::LightTargetedExperiment& selected_transitions,
100  double min_upper_edge_dist,
101  double lower, double upper);
110  static void selectSwathTransitionsPasef(const OpenSwath::LightTargetedExperiment& transition_exp, std::vector<int>& tr_win_map,
111  double min_upper_edge_dist, const std::vector< OpenSwath::SwathMap > & swath_maps);
112 
131  static void checkSwathMap(const OpenMS::PeakMap& swath_map,
132  double& lower, double& upper, double& center);
133 
145  template <class TargetedExperimentT>
147  const TargetedExperimentT& targeted_exp,
148  TargetedExperimentT& selected_transitions,
149  double min_upper_edge_dist)
150  {
151  if (exp.empty() || exp[0].getPrecursors().empty())
152  {
153  std::cerr << "WARNING: File " << exp.getLoadedFilePath()
154  << " does not have any experiments or any precursors. Is it a SWATH map? "
155  << "I will move to the next map."
156  << std::endl;
157  return false;
158  }
159  double upper, lower, center;
160  OpenSwathHelper::checkSwathMap(exp, lower, upper, center);
161  OpenSwathHelper::selectSwathTransitions(targeted_exp, selected_transitions, min_upper_edge_dist, lower, upper);
162  if (selected_transitions.getTransitions().size() == 0)
163  {
164  std::cerr << "WARNING: For File " << exp.getLoadedFilePath()
165  << " no transition were within the precursor window of " << lower << " to " << upper
166  << std::endl;
167  return false;
168  }
169  return true;
170 
171  }
172 
182  static std::pair<double,double> estimateRTRange(const OpenSwath::LightTargetedExperiment & exp);
183 
198  static std::map<std::string, double> simpleFindBestFeature(const OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType & transition_group_map,
199  bool useQualCutoff = false,
200  double qualCutoff = 0.0);
201  };
202 
203 } // namespace OpenMS
204 
const String & getLoadedFilePath() const
get the file_name_ which is the absolute path to the file loaded from
std::map< String, MRMTransitionGroupType > TransitionGroupMapType
Definition: MRMFeatureFinderScoring.h:79
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
bool empty() const noexcept
Are there any spectra (does not consider chromatograms)
Definition: MSExperiment.h:133
A helper class that is used by several OpenSWATH tools.
Definition: OpenSwathHelper.h:24
static bool checkSwathMapAndSelectTransitions(const OpenMS::PeakMap &exp, const TargetedExperimentT &targeted_exp, TargetedExperimentT &selected_transitions, double min_upper_edge_dist)
Check the map and select transition in one function.
Definition: OpenSwathHelper.h:146
static String computePrecursorId(const String &transition_group_id, int isotope)
Compute unique precursor identifier.
Definition: OpenSwathHelper.h:40
static String computeTransitionGroupId(const String &precursor_id)
Compute transition group id.
Definition: OpenSwathHelper.h:56
static void selectSwathTransitions(const OpenMS::TargetedExperiment &targeted_exp, OpenMS::TargetedExperiment &selected_transitions, double min_upper_edge_dist, double lower, double upper)
Select transitions between lower and upper and write them into the new TargetedExperiment.
static std::map< std::string, double > simpleFindBestFeature(const OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType &transition_group_map, bool useQualCutoff=false, double qualCutoff=0.0)
Returns the feature with the highest score for each transition group.
static void selectSwathTransitions(const OpenSwath::LightTargetedExperiment &targeted_exp, OpenSwath::LightTargetedExperiment &selected_transitions, double min_upper_edge_dist, double lower, double upper)
Select transitions between lower and upper and write them into the new TargetedExperiment.
static std::pair< double, double > estimateRTRange(const OpenSwath::LightTargetedExperiment &exp)
Computes the min and max retention time value.
static void checkSwathMap(const OpenMS::PeakMap &swath_map, double &lower, double &upper, double &center)
Get the lower / upper offset for this SWATH map and do some sanity checks.
static void selectSwathTransitionsPasef(const OpenSwath::LightTargetedExperiment &transition_exp, std::vector< int > &tr_win_map, double min_upper_edge_dist, const std::vector< OpenSwath::SwathMap > &swath_maps)
Match transitions with their "best" window across m/z and ion mobility, save results in a vector.
A more convenient string class.
Definition: String.h:34
String prefix(SizeType length) const
returns the prefix of length length
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:39
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
const double k
Definition: Constants.h:132
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition: TransitionExperiment.h:185