OpenMS
Loading...
Searching...
No Matches
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 <memory>
15#include <string>
16#include <vector>
17
18namespace OpenMS
19{
20 using SpectrumSequence = std::vector<OpenSwath::SpectrumPtr>;
21}
22namespace OpenSwath
23{
24
29 class OPENSWATHALGO_DLLAPI ISpectrumAccess
30 {
31public:
34
47 virtual std::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
58 virtual std::vector<std::size_t> getSpectraByRT(double RT, double deltaRT) const = 0;
60 virtual size_t getNrSpectra() const = 0;
62 virtual SpectrumMeta getSpectrumMetaById(int id) const = 0;
63
67 virtual std::size_t getNrChromatograms() const = 0;
69 virtual std::string getChromatogramNativeID(int id) const = 0;
70
71 /* @brief Fetches a spectrumSequence (multiple spectra pointers) closest to the given RT
72 *
73 * Returns the spectrum closest to @p RT plus up to @p nr_spectra_to_fetch / 2 neighbours
74 * on either side, in alternating order around the closest spectrum (the result is not
75 * sorted by RT). An odd @p nr_spectra_to_fetch yields at most that many spectra, an even
76 * value one more, and any value below 2 only the closest spectrum. If no spectrum lies
77 * at or after @p RT (e.g. @p RT is past the last spectrum), the sequence is empty.
78 *
79 * @p RT = target RT
80 * @p nr_spectra_to_fetch = # spectra around target RT to fetch (see above for the resulting sequence length)
81 */
82 SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch);
83
84 /* @brief Fetches a spectrumSequence (multiple spectra pointers) closest to the given RT. Filters all spectra by specified @p drift_start and @p drift_end
85 *
86 * The returned sequence is built as described for the driftless overload above: the
87 * closest spectrum plus up to @p nr_spectra_to_fetch / 2 neighbours per side, in
88 * alternating order (an even value yields one spectrum more, any value below 2 only
89 * the closest spectrum); if no spectrum lies at or after @p RT, the sequence is empty.
90 *
91 * @p RT = target RT
92 * @p nr_spectra_to_fetch = # spectra around target RT to fetch (see above for the resulting sequence length)
93 */
94 SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch, double drift_start, double drift_end);
95
97 static SpectrumPtr filterByDrift(const SpectrumPtr& input, double drift_start, double drift_end)
98 {
99 // NOTE: this function is very inefficient because filtering unsorted array
100 //OPENMS_PRECONDITION(drift_start <= 0, "Cannot filter by drift time if drift_start is not set");
101 //OPENMS_PRECONDITION(drift_end - drift_start < 0, "Cannot filter by drift time if range is empty");
102 //OPENMS_PRECONDITION(input->getDriftTimeArray() != nullptr, "Cannot filter by drift time if no drift time is available.");
103
104 //if (input->getDriftTimeArray() == nullptr)
105 //{
106 //throw Exception::NullPointer(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
107 //}
108
110
111 OpenSwath::BinaryDataArrayPtr mz_arr = input->getMZArray();
112 OpenSwath::BinaryDataArrayPtr int_arr = input->getIntensityArray();
113 OpenSwath::BinaryDataArrayPtr im_arr = input->getDriftTimeArray();
114
115 auto mz_it = mz_arr->data.cbegin();
116 auto int_it = int_arr->data.cbegin();
117 auto im_it = im_arr->data.cbegin();
118 auto mz_end = mz_arr->data.cend();
119
123 im_arr_out->description = im_arr->description;
124
125 while (mz_it != mz_end)
126 {
127 if ( (drift_start <= *im_it) && (drift_end >= *im_it) )
128 {
129 mz_arr_out->data.push_back( *mz_it );
130 intens_arr_out->data.push_back( *int_it );
131 im_arr_out->data.push_back( *im_it );
132 }
133 ++mz_it;
134 ++int_it;
135 ++im_it;
136 }
137 output->setMZArray(mz_arr_out);
138 output->setIntensityArray(intens_arr_out);
139 output->getDataArrays().push_back(im_arr_out);
140 return output;
141 }
142
143
144 };
145
146 typedef std::shared_ptr<ISpectrumAccess> SpectrumAccessPtr;
147}
148
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
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:97
SpectrumSequence getMultipleSpectra(double RT, int nr_spectra_to_fetch)
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)
virtual std::shared_ptr< ISpectrumAccess > lightClone() const =0
Light clone operator to produce a copy for concurrent read access.
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
std::shared_ptr< Chromatogram > ChromatogramPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:153
OpenMS::SpectrumSequence SpectrumSequence
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:25
std::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:146
std::shared_ptr< Spectrum > SpectrumPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:291
std::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:53
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:157
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:188