OpenMS
openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.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, Witold Wolski $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <OpenMS/OPENSWATHALGO/OpenSwathAlgoConfig.h>
12 
14 #include <boost/shared_ptr.hpp>
15 #include <string>
16 #include <vector>
17 
18 namespace OpenMS
19 {
20  using SpectrumSequence = std::vector<OpenSwath::SpectrumPtr>;
21 }
22 namespace OpenSwath
23 {
24 
29  class OPENSWATHALGO_DLLAPI ISpectrumAccess
30  {
31 public:
33  virtual ~ISpectrumAccess();
34 
47  virtual boost::shared_ptr<ISpectrumAccess> lightClone() const = 0;
48 
50  virtual SpectrumPtr getSpectrumById(int id) = 0;
51 
53  SpectrumPtr getSpectrumById(int id, double drift_start, double drift_end );
54 
56  virtual std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const = 0;
58  virtual size_t getNrSpectra() const = 0;
60  virtual SpectrumMeta getSpectrumMetaById(int id) const = 0;
61 
63  virtual ChromatogramPtr getChromatogramById(int id) = 0;
65  virtual std::size_t getNrChromatograms() const = 0;
67  virtual std::string getChromatogramNativeID(int id) const = 0;
68 
69  /* @brief Fetches a spectrumSequence (multiple spectra pointers) closest to the given RT
70  * @p RT = target RT
71  * @p nr_spectra_to_fetch = # spectra around target RT to fetch (length of the spectrum sequence)
72  */
73  SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch);
74 
75  /* @brief Fetches a spectrumSequence (multiple spectra pointers) closest to the given RT. Filters all spectra by specified @p drift_start and @p drift_end
76  * @p RT = target RT
77  * @p nr_spectra_to_fetch = # spectra around target RT to fetch (length of the spectrum sequence)
78  */
79  SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch, double drift_start, double drift_end);
80 
82  static SpectrumPtr filterByDrift(const SpectrumPtr& input, double drift_start, double drift_end)
83  {
84  // NOTE: this function is very inefficient because filtering unsorted array
85  //OPENMS_PRECONDITION(drift_start <= 0, "Cannot filter by drift time if drift_start is not set");
86  //OPENMS_PRECONDITION(drift_end - drift_start < 0, "Cannot filter by drift time if range is empty");
87  //OPENMS_PRECONDITION(input->getDriftTimeArray() != nullptr, "Cannot filter by drift time if no drift time is available.");
88 
89  //if (input->getDriftTimeArray() == nullptr)
90  //{
91  //throw Exception::NullPointer(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
92  //}
93 
95 
96  OpenSwath::BinaryDataArrayPtr mz_arr = input->getMZArray();
97  OpenSwath::BinaryDataArrayPtr int_arr = input->getIntensityArray();
98  OpenSwath::BinaryDataArrayPtr im_arr = input->getDriftTimeArray();
99 
100  auto mz_it = mz_arr->data.cbegin();
101  auto int_it = int_arr->data.cbegin();
102  auto im_it = im_arr->data.cbegin();
103  auto mz_end = mz_arr->data.cend();
104 
108  im_arr_out->description = im_arr->description;
109 
110  while (mz_it != mz_end)
111  {
112  if ( (drift_start <= *im_it) && (drift_end >= *im_it) )
113  {
114  mz_arr_out->data.push_back( *mz_it );
115  intens_arr_out->data.push_back( *int_it );
116  im_arr_out->data.push_back( *im_it );
117  }
118  ++mz_it;
119  ++int_it;
120  ++im_it;
121  }
122  output->setMZArray(mz_arr_out);
123  output->setIntensityArray(intens_arr_out);
124  output->getDataArrays().push_back(im_arr_out);
125  return output;
126  }
127 
128 
129  };
130 
131  typedef boost::shared_ptr<ISpectrumAccess> SpectrumAccessPtr;
132 }
133 
The interface of a mass spectrometry experiment.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:30
SpectrumPtr getSpectrumById(int id, double drift_start, double drift_end)
Return pointer to a spectrum at the given id, the spectrum will be filtered by drift time.
virtual ChromatogramPtr getChromatogramById(int id)=0
Return a pointer to a chromatogram at the given id.
virtual std::vector< std::size_t > getSpectraByRT(double RT, double deltaRT) const =0
Return a vector of ids of spectra that are within RT +/- deltaRT.
virtual ~ISpectrumAccess()
Destructor.
static SpectrumPtr filterByDrift(const SpectrumPtr &input, double drift_start, double drift_end)
filters a spectrum by drift time, spectrum pointer returned is a copy
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:82
SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch)
virtual boost::shared_ptr< ISpectrumAccess > lightClone() const =0
Light clone operator to produce a copy for concurrent read access.
virtual SpectrumMeta getSpectrumMetaById(int id) const =0
Returns the meta information for a spectrum.
virtual SpectrumPtr getSpectrumById(int id)=0
Return a pointer to a spectrum at the given id.
virtual std::size_t getNrChromatograms() const =0
Returns the number of chromatograms available.
virtual size_t getNrSpectra() const =0
Returns the number of spectra available.
virtual std::string getChromatogramNativeID(int id) const =0
Returns the native id of the chromatogram at the given id.
SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch, double drift_start, double drift_end)
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::vector< OpenSwath::SpectrumPtr > SpectrumSequence
a vector of spectrum pointers that DIA scores can operate on, allows for clever integration of only t...
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:20
Definition: Scoring.h:18
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:146
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:53
OpenMS::SpectrumSequence SpectrumSequence
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:25
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:276
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:131
The datastructures used by the OpenSwath interfaces.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:42
Identifying information for a spectrum.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:150
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:181