OpenMS
OpenSwathHelper.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-2023.
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 
43 
44 namespace OpenMS
45 {
49  class OPENMS_DLLAPI OpenSwathHelper
50  {
51 
52 public:
53 
66  static String computePrecursorId(const String& transition_group_id, int isotope)
67  {
68  return transition_group_id + "_Precursor_i" + String(isotope);
69  }
70 
82  static String computeTransitionGroupId(const String& precursor_id)
83  {
84  std::vector<String> substrings;
85  precursor_id.split("_", substrings);
86 
87  if (substrings.size() == 3) return substrings[0];
88  else if (substrings.size() > 3)
89  {
90  String r;
91  for (Size k = 0; k < substrings.size() - 2; k++) r += substrings[k] + "_";
92  return r.prefix(r.size() - 1);
93  }
94  return "";
95  }
96 
108  static void selectSwathTransitions(const OpenMS::TargetedExperiment& targeted_exp,
109  OpenMS::TargetedExperiment& selected_transitions,
110  double min_upper_edge_dist,
111  double lower, double upper);
112 
125  OpenSwath::LightTargetedExperiment& selected_transitions,
126  double min_upper_edge_dist,
127  double lower, double upper);
136  static void selectSwathTransitionsPasef(const OpenSwath::LightTargetedExperiment& transition_exp, std::vector<int>& tr_win_map,
137  double min_upper_edge_dist, const std::vector< OpenSwath::SwathMap > & swath_maps);
138 
156  static void checkSwathMap(const OpenMS::PeakMap& swath_map,
157  double& lower, double& upper, double& center);
158 
170  template <class TargetedExperimentT>
172  const TargetedExperimentT& targeted_exp,
173  TargetedExperimentT& selected_transitions,
174  double min_upper_edge_dist)
175  {
176  if (exp.empty() || exp[0].getPrecursors().empty())
177  {
178  std::cerr << "WARNING: File " << exp.getLoadedFilePath()
179  << " does not have any experiments or any precursors. Is it a SWATH map? "
180  << "I will move to the next map."
181  << std::endl;
182  return false;
183  }
184  double upper, lower, center;
185  OpenSwathHelper::checkSwathMap(exp, lower, upper, center);
186  OpenSwathHelper::selectSwathTransitions(targeted_exp, selected_transitions, min_upper_edge_dist, lower, upper);
187  if (selected_transitions.getTransitions().size() == 0)
188  {
189  std::cerr << "WARNING: For File " << exp.getLoadedFilePath()
190  << " no transition were within the precursor window of " << lower << " to " << upper
191  << std::endl;
192  return false;
193  }
194  return true;
195 
196  }
197 
207  static std::pair<double,double> estimateRTRange(const OpenSwath::LightTargetedExperiment & exp);
208 
223  static std::map<std::string, double> simpleFindBestFeature(const OpenMS::MRMFeatureFinderScoring::TransitionGroupMapType & transition_group_map,
224  bool useQualCutoff = false,
225  double qualCutoff = 0.0);
226  };
227 
228 } // namespace OpenMS
229 
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:105
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
bool empty() const
Are there any spectra (does not consider chromatograms)
Definition: MSExperiment.h:159
A helper class that is used by several OpenSWATH tools.
Definition: OpenSwathHelper.h:50
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:171
static String computePrecursorId(const String &transition_group_id, int isotope)
Compute unique precursor identifier.
Definition: OpenSwathHelper.h:66
static String computeTransitionGroupId(const String &precursor_id)
Compute transition group id.
Definition: OpenSwathHelper.h:82
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:60
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:65
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
const double k
Definition: Constants.h:158
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Definition: TransitionExperiment.h:219