OpenMS
FLASHHelperClasses.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Kyowon Jeong, Jihyung Kim $
6 // $Authors: Kyowon Jeong, Jihyung Kim $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
16 #include <boost/dynamic_bitset.hpp>
17 
18 namespace OpenMS
19 {
31 struct OPENMS_DLLAPI FLASHHelperClasses
32 {
34  class OPENMS_DLLAPI PrecalculatedAveragine
35  {
36  private:
38  std::vector<IsotopeDistribution> isotopes_;
40  std::vector<double> norms_;
42  std::vector<double> average_mono_mass_difference_;
44  std::vector<double> abundant_mono_mass_difference_;
45 
46  std::vector<double> snr_mul_factor_;
48  std::vector<int> left_count_from_apex_;
50  std::vector<int> right_count_from_apex_;
52  std::vector<Size> apex_index_;
53 
59  double min_mass_;
61  Size massToIndex_(double mass) const;
62 
63  public:
66 
77  PrecalculatedAveragine(double min_mass, double max_mass, double delta, CoarseIsotopePatternGenerator& generator, bool use_RNA_averagine, double decoy_iso_distance = -1, bool is_centroid = true);
78 
81 
83  PrecalculatedAveragine(PrecalculatedAveragine&& other) noexcept = default;
84 
87 
90 
93 
94 
96  IsotopeDistribution get(double mass) const;
97 
99  size_t getMaxIsotopeIndex() const;
100 
102  void setMaxIsotopeIndex(int index);
103 
106  Size getLeftCountFromApex(double mass) const;
107 
110  Size getRightCountFromApex(double mass) const;
111 
113  Size getApexIndex(double mass) const;
114 
116  Size getLastIndex(double mass) const;
117 
120  double getAverageMassDelta(double mass) const;
121 
124  double getMostAbundantMassDelta(double mass) const;
125 
126  double getSNRMultiplicationFactor(double mass) const;
127  };
128 
130  struct OPENMS_DLLAPI MassFeature
131  {
132  public:
134  uint index;
136  std::vector<float> per_charge_intensity;
137  std::vector<float> per_isotope_intensity;
139  int scan_number, min_scan_number, max_scan_number, rep_charge;
140  double avg_mass;
141  int min_charge, max_charge, charge_count;
142  double isotope_score, qscore;
143  double rep_mz;
144  bool is_decoy;
145  uint ms_level;
147  bool operator<(const MassFeature& a) const
148  {
149  return avg_mass < a.avg_mass;
150  }
151  bool operator>(const MassFeature& a) const
152  {
153  return avg_mass > a.avg_mass;
154  }
155  bool operator==(const MassFeature& other) const
156  {
157  return avg_mass == other.avg_mass;
158  }
159  };
160 
162  struct OPENMS_DLLAPI IsobaricQuantities
163  {
164  public:
165  int scan;
166  double rt;
167  double precursor_mz;
169  std::vector<double> quantities;
170  std::vector<double> merged_quantities;
171 
172  bool empty() const;
173  };
174 
176  class OPENMS_DLLAPI LogMzPeak
177  {
178  public:
180  double mz = 0;
182  float intensity = 0;
184  double logMz = -1000;
186  double mass = .0;
188  int abs_charge = 0;
190  bool is_positive = true;
192  int isotopeIndex = -1;
193 
195  LogMzPeak() = default;
196 
204  explicit LogMzPeak(const Peak1D& peak, bool positive);
205 
207  LogMzPeak(const LogMzPeak&) = default;
208 
210  ~LogMzPeak() = default;
211 
214  double getUnchargedMass() const;
215 
217  bool operator<(const LogMzPeak& a) const;
218  bool operator>(const LogMzPeak& a) const;
219  bool operator==(const LogMzPeak& other) const;
220  };
221 
223  class OPENMS_DLLAPI Tag
224  {
225  public:
227  explicit Tag(String seq, double n_mass, double c_mass, std::vector<double>& mzs, std::vector<int>& scores, int scan);
228 
230  Tag(const Tag&) = default;
231 
233  ~Tag() = default;
234 
235  bool operator<(const Tag& a) const;
236  bool operator>(const Tag& a) const;
237  bool operator==(const Tag& other) const;
238 
239  const String& getSequence() const;
240  const String& getUppercaseSequence() const;
241  double getNtermMass() const;
242  double getCtermMass() const;
243  Size getLength() const;
244  int getScore() const;
245  int getScore(int pos) const;
246  int getScan() const;
247  int getIndex() const
248  {
249  return index_;
250  }
251 
252  void setIndex(int i)
253  {
254  index_ = i;
255  }
256  float getRetentionTime() const
257  {
258  return rt_;
259  }
260 
261  void setRetentionTime(float i)
262  {
263  rt_ = i;
264  }
265 
266 
267  String toString() const;
268  const std::vector<double>& getMzs() const;
269 
270  private:
271  String seq_, upper_seq_;
272  double n_mass_ = -1, c_mass_ = -1;
273  float rt_ = -1;
274  std::vector<double> mzs_;
275  std::vector<int> scores_;
276  int scan_;
277  int index_;
279  };
280 
281  class OPENMS_DLLAPI DAG
282  {
283  public:
284  DAG()
285  {
286  }
287  explicit DAG(Size vertice_count): vertex_count_(vertice_count)
288  {
289  }
290 
291  Size size() const
292  {
293  return vertex_count_;
294  }
295 
296  bool addEdge(Size vertex1, Size vertex2, boost::dynamic_bitset<>& visited)
297  {
298  if (vertex1 >= vertex_count_ || vertex2 >= vertex_count_) return false;
299  if (! visited[vertex2]) return false;
300  visited[vertex1] = true;
301  adj_list_for_speed_up_[vertex2].insert(vertex1); //
302  return true;
303  }
304 
305  bool hasEdge(Size vertex1, Size vertex2) const
306  {
307  auto iter = adj_list_for_speed_up_.find(vertex2);
308  if (iter == adj_list_for_speed_up_.end()) return false;
309  return iter->second.find(vertex1) != iter->second.end();
310  }
311 
312  void findAllPaths(Size source, Size sink, std::vector<std::vector<Size>>& all_paths, Size max_count)
313  {
314  std::unordered_set<Size> visited;
315  std::vector<Size> path;
316 
317  if (adj_list_.empty())
318  {
319  for (const auto& [v2, vertices] : adj_list_for_speed_up_)
320  {
321  for (const auto& v1 : vertices)
322  {
323  adj_list_[v1].push_back(v2);
324  }
325  }
326  for (auto& v : adj_list_)
327  {
328  std::sort(v.second.begin(), v.second.end());
329  }
330  }
331 
332  findAllPaths_(source, sink, visited, path, all_paths, max_count); // reverse traveling
333  }
334 
335  private:
337  // 0, 1, 2, ... ,vertex_count - 1
338  std::map<Size, std::vector<Size>> adj_list_; //
339  std::unordered_map<Size, std::unordered_set<Size>> adj_list_for_speed_up_; // vertex swapped for fast stroing of edges
340  void findAllPaths_(Size current,
341  Size destination,
342  std::unordered_set<Size>& visited,
343  std::vector<Size>& path,
344  std::vector<std::vector<Size>>& all_paths,
345  Size max_count)
346  {
347  if (max_count > 0 && all_paths.size() >= max_count) return;
348 
349  visited.insert(current);
350  path.push_back(current);
351 
352  if (current == destination) { all_paths.push_back(path);}
353  else
354  {
355  for (Size i : adj_list_[current])
356  {
357  if (visited.find(i) == visited.end()) { findAllPaths_(i, destination, visited, path, all_paths, max_count); }
358  }
359  }
360 
361  // Backtrack
362  path.pop_back();
363  visited.erase(current);
364  }
365  };
366 
372  static double getLogMz(double mz, bool positive);
373 
378  static float getChargeMass(bool positive_ioniziation_mode);
379 };
380 } // namespace OpenMS
Isotope pattern generator for coarse isotope distributions.
Definition: CoarseIsotopePatternGenerator.h:79
Definition: FLASHHelperClasses.h:282
std::unordered_map< Size, std::unordered_set< Size > > adj_list_for_speed_up_
Definition: FLASHHelperClasses.h:339
void findAllPaths(Size source, Size sink, std::vector< std::vector< Size >> &all_paths, Size max_count)
Definition: FLASHHelperClasses.h:312
Size vertex_count_
Definition: FLASHHelperClasses.h:336
bool addEdge(Size vertex1, Size vertex2, boost::dynamic_bitset<> &visited)
Definition: FLASHHelperClasses.h:296
std::map< Size, std::vector< Size > > adj_list_
Definition: FLASHHelperClasses.h:338
bool hasEdge(Size vertex1, Size vertex2) const
Definition: FLASHHelperClasses.h:305
DAG(Size vertice_count)
Definition: FLASHHelperClasses.h:287
Size size() const
Definition: FLASHHelperClasses.h:291
DAG()
Definition: FLASHHelperClasses.h:284
void findAllPaths_(Size current, Size destination, std::unordered_set< Size > &visited, std::vector< Size > &path, std::vector< std::vector< Size >> &all_paths, Size max_count)
Definition: FLASHHelperClasses.h:340
log transformed peak. After deconvolution, all necessary information from deconvolution such as charg...
Definition: FLASHHelperClasses.h:177
bool operator>(const LogMzPeak &a) const
bool operator<(const LogMzPeak &a) const
log mz values are compared
LogMzPeak(const Peak1D &peak, bool positive)
constructor from Peak1D.
LogMzPeak()=default
default constructor
bool operator==(const LogMzPeak &other) const
LogMzPeak(const LogMzPeak &)=default
copy constructor
Averagine patterns pre-calculated for speed up. Other variables are also calculated for fast cosine c...
Definition: FLASHHelperClasses.h:35
Size getApexIndex(double mass) const
get index of most abundant isotope. If input mass exceeds the maximum mass (specified in constructor)...
double getSNRMultiplicationFactor(double mass) const
void setMaxIsotopeIndex(int index)
set max isotope index
std::vector< double > norms_
L2 norms_ for masses.
Definition: FLASHHelperClasses.h:40
std::vector< double > average_mono_mass_difference_
mass differences between average mass and monoisotopic mass
Definition: FLASHHelperClasses.h:42
PrecalculatedAveragine(double min_mass, double max_mass, double delta, CoarseIsotopePatternGenerator &generator, bool use_RNA_averagine, double decoy_iso_distance=-1, bool is_centroid=true)
constructor with parameters such as mass ranges and bin size.
PrecalculatedAveragine()=default
default constructor
Size max_isotope_index_
max isotope index
Definition: FLASHHelperClasses.h:55
PrecalculatedAveragine & operator=(PrecalculatedAveragine &&pc) noexcept=default
move assignment operator
size_t getMaxIsotopeIndex() const
get max isotope index
double min_mass_
min mass for calculation
Definition: FLASHHelperClasses.h:59
double mass_interval_
mass interval for calculation
Definition: FLASHHelperClasses.h:57
PrecalculatedAveragine & operator=(const PrecalculatedAveragine &pc)=default
copy assignment operator
Size massToIndex_(double mass) const
calculate the mass bin index from mass
std::vector< double > abundant_mono_mass_difference_
mass differences between most abundant mass and monoisotopic mass
Definition: FLASHHelperClasses.h:44
std::vector< double > snr_mul_factor_
Definition: FLASHHelperClasses.h:46
Size getLastIndex(double mass) const
get index of last isotope. If input mass exceeds the maximum mass (specified in constructor),...
IsotopeDistribution get(double mass) const
get distribution for input mass. If input mass exceeds the maximum mass (specified in constructor),...
std::vector< IsotopeDistribution > isotopes_
isotope distributions for different (binned) masses
Definition: FLASHHelperClasses.h:38
std::vector< Size > apex_index_
most abundant isotope index
Definition: FLASHHelperClasses.h:52
std::vector< int > left_count_from_apex_
Isotope start indices: isotopes of the indices less than them have very low intensities.
Definition: FLASHHelperClasses.h:48
PrecalculatedAveragine(PrecalculatedAveragine &&other) noexcept=default
move constructor
PrecalculatedAveragine(const PrecalculatedAveragine &)=default
copy constructor
std::vector< int > right_count_from_apex_
Isotope end indices: isotopes of the indices larger than them have very low intensities.
Definition: FLASHHelperClasses.h:50
Sequence tag. No mass gap is allowed in the seq. The mass gap containing tag should be enumerated int...
Definition: FLASHHelperClasses.h:224
int scan_
Definition: FLASHHelperClasses.h:276
String seq_
Definition: FLASHHelperClasses.h:271
int getIndex() const
Definition: FLASHHelperClasses.h:247
void setRetentionTime(float i)
Definition: FLASHHelperClasses.h:261
float getRetentionTime() const
Definition: FLASHHelperClasses.h:256
std::vector< int > scores_
Definition: FLASHHelperClasses.h:275
void setIndex(int i)
Definition: FLASHHelperClasses.h:252
Size length_
Definition: FLASHHelperClasses.h:278
const String & getUppercaseSequence() const
const std::vector< double > & getMzs() const
const String & getSequence() const
int index_
Definition: FLASHHelperClasses.h:277
Tag(const Tag &)=default
copy constructor
bool operator<(const Tag &a) const
std::vector< double > mzs_
Definition: FLASHHelperClasses.h:274
bool operator>(const Tag &a) const
bool operator==(const Tag &other) const
Tag(String seq, double n_mass, double c_mass, std::vector< double > &mzs, std::vector< int > &scores, int scan)
constructor
Definition: IsotopeDistribution.h:39
A container type that gathers peaks similar in m/z and moving along retention time.
Definition: MassTrace.h:36
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
FLASHIda C++ to C# (or vice versa) bridge functions The functions here are called in C# to invoke fun...
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Isobaric quantities.
Definition: FLASHHelperClasses.h:163
int scan
Definition: FLASHHelperClasses.h:165
std::vector< double > quantities
Definition: FLASHHelperClasses.h:169
std::vector< double > merged_quantities
Definition: FLASHHelperClasses.h:170
double precursor_mass
Definition: FLASHHelperClasses.h:168
double rt
Definition: FLASHHelperClasses.h:166
double precursor_mz
Definition: FLASHHelperClasses.h:167
Mass feature (Deconvolved masses in spectra are traced by Mass tracing to generate mass features - li...
Definition: FLASHHelperClasses.h:131
bool operator<(const MassFeature &a) const
features are compared
Definition: FLASHHelperClasses.h:147
double avg_mass
Definition: FLASHHelperClasses.h:140
std::vector< float > per_charge_intensity
Definition: FLASHHelperClasses.h:136
uint index
feature index;
Definition: FLASHHelperClasses.h:134
bool operator>(const MassFeature &a) const
Definition: FLASHHelperClasses.h:151
bool is_decoy
Definition: FLASHHelperClasses.h:144
int iso_offset
Definition: FLASHHelperClasses.h:138
std::vector< float > per_isotope_intensity
Definition: FLASHHelperClasses.h:137
uint ms_level
Definition: FLASHHelperClasses.h:145
double rep_mz
Definition: FLASHHelperClasses.h:143
MassTrace mt
Definition: FLASHHelperClasses.h:135
bool operator==(const MassFeature &other) const
Definition: FLASHHelperClasses.h:155
int charge_count
Definition: FLASHHelperClasses.h:141
double isotope_score
Definition: FLASHHelperClasses.h:142
int max_scan_number
Definition: FLASHHelperClasses.h:139
Wrapper struct for all the structs needed by the FLASHDeconv Three structures are defined: Precalcula...
Definition: FLASHHelperClasses.h:32
static double getLogMz(double mz, bool positive)
calculate log mzs from mzs
static float getChargeMass(bool positive_ioniziation_mode)
get charge carrier mass : positive mode mass of (Constants::PROTON_MASS_U) and negative mode mass of ...