90 consuming_possible_(true),
91 use_external_boundaries_(false),
92 correct_window_counter_(0)
94 use_external_boundaries_ = !swath_map_boundaries_.empty();
105 swath_map_boundaries_(swath_boundaries),
107 consuming_possible_(true),
108 use_external_boundaries_(false),
109 correct_window_counter_(0)
111 use_external_boundaries_ = !swath_map_boundaries_.empty();
132 consuming_possible_ =
false;
133 ensureMapsAreFilled_();
137 map.
sptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(ms1_map_);
149 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
151 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
152 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
159 std::vector<OpenSwath::SpectrumAccessPtr> map_access(swath_maps_.size());
160 std::exception_ptr access_error;
162#pragma omp parallel for
164 for (
SignedSize i = 0; i < static_cast<SignedSize>(swath_maps_.size()); i++)
168 map_access[i] = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(swath_maps_[i]);
173#pragma omp critical (FullSwathFileConsumer_retrieveSwathMaps)
176 if (!access_error) access_error = std::current_exception();
182 std::rethrow_exception(access_error);
185 size_t nonempty_maps = 0;
186 for (
Size i = 0; i < swath_maps_.size(); i++)
189 map.
sptr = map_access[i];
190 map.
lower = swath_map_boundaries_[i].lower;
191 map.
upper = swath_map_boundaries_[i].upper;
192 map.
center = swath_map_boundaries_[i].center;
193 map.
imLower = swath_map_boundaries_[i].imLower;
194 map.
imUpper = swath_map_boundaries_[i].imUpper;
197 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
200 if (nonempty_maps != swath_map_boundaries_.size())
202 std::cout <<
"WARNING: The number nonempty maps found in the input file (" << nonempty_maps <<
") is not equal to the number of provided swath window boundaries (" <<
203 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
211 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
222 if (!consuming_possible_)
225 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
230 consumeMS1Spectrum_(s);
237 "Swath scan does not provide a precursor.");
241 double center = prec[0].getMZ();
242 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
243 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
251 lowerIm = (double)s.
getMetaValue(
"ion mobility lower limit");
252 upperIm = (double)s.
getMetaValue(
"ion mobility upper limit");
261 "Swath scan does not provide any precursor isolation information.");
265 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
270 if ( (std::fabs(center - swath_map_boundaries_[i].center) < 1e-6) && (std::fabs(lowerIm - swath_map_boundaries_[i].imLower) < 1e-6) && ( std::fabs(upperIm - swath_map_boundaries_[i].imUpper) < 1e-6))
273 consumeSwathSpectrum_(s, i);
279 if (use_external_boundaries_)
282 std::string(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
286 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
289 if (lower > 0.0 && upper > 0.0)
290 {correct_window_counter_++;}
293 boundary.
lower = lower;
294 boundary.
upper = upper;
298 swath_map_boundaries_.push_back(boundary);
301 <<
" m/z with an isolation window of " << lower <<
" to " << upper
302 <<
" m/z and IM lower limit of " << lowerIm <<
" and upper limit of " << upperIm << std::endl;
379 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
380 swath_maps_.push_back(exp);
385 while (swath_maps_.size() <= swath_nr)
390 swath_maps_[swath_nr]->addSpectrum(s);
395 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
405 ms1_map_->addSpectrum(s);
430 ms1_consumer_(nullptr),
434 nr_ms1_spectra_(nr_ms1_spectra),
435 nr_ms2_spectra_(nr_ms2_spectra)
439 std::string cachedir, std::string basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
441 ms1_consumer_(nullptr),
445 nr_ms1_spectra_(nr_ms1_spectra),
446 nr_ms2_spectra_(nr_ms2_spectra)
452 while (!swath_consumers_.empty())
454 delete swath_consumers_.back();
455 swath_consumers_.pop_back();
457 if (ms1_consumer_ !=
nullptr)
459 delete ms1_consumer_;
460 ms1_consumer_ =
nullptr;
467 std::string meta_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(swath_consumers_.size()) +
".mzML";
468 std::string cached_file = meta_file +
".cached";
470 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
471 swath_consumers_.push_back(consumer);
474 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
475 swath_maps_.push_back(exp);
480 while (swath_maps_.size() <= swath_nr)
484 swath_consumers_[swath_nr]->consumeSpectrum(s);
485 swath_maps_[swath_nr]->addSpectrum(s);
490 std::string meta_file = cachedir_ + basename_ +
"_ms1.mzML";
491 std::string cached_file = meta_file +
".cached";
493 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
494 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
500 if (ms1_consumer_ ==
nullptr)
504 ms1_consumer_->consumeSpectrum(s);
505 ms1_map_->addSpectrum(s);
510 size_t swath_consumers_size = swath_consumers_.size();
511 bool have_ms1 = (ms1_consumer_ !=
nullptr);
521 while (!swath_consumers_.empty())
523 delete swath_consumers_.back();
524 swath_consumers_.pop_back();
526 if (ms1_consumer_ !=
nullptr)
528 delete ms1_consumer_;
529 ms1_consumer_ =
nullptr;
534 std::shared_ptr<PeakMap > exp(
new PeakMap);
535 std::string meta_file = cachedir_ + basename_ +
"_ms1.mzML";
543#pragma omp parallel for
545 for (
SignedSize i = 0; i < OpenMS::checkedCast<SignedSize>(swath_consumers_size); i++)
547 std::shared_ptr<PeakMap > exp(
new PeakMap);
548 std::string meta_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(i) +
".mzML";
552 swath_maps_[i] = exp;
586 MzMLSwathFileConsumer(
const std::string& cachedir,
const std::string& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
587 ms1_consumer_(nullptr),
591 nr_ms1_spectra_(nr_ms1_spectra),
592 nr_ms2_spectra_(nr_ms2_spectra)
596 const std::string& cachedir,
const std::string& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
598 ms1_consumer_(nullptr),
602 nr_ms1_spectra_(nr_ms1_spectra),
603 nr_ms2_spectra_(nr_ms2_spectra)
616 while (!swath_consumers_.empty())
618 delete swath_consumers_.back();
619 swath_consumers_.pop_back();
621 if (ms1_consumer_ !=
nullptr)
623 delete ms1_consumer_;
624 ms1_consumer_ =
nullptr;
630 std::string mzml_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(swath_consumers_.size()) +
".mzML";
633 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
634 swath_consumers_.push_back(consumer);
640 while (swath_consumers_.size() <= swath_nr)
644 swath_consumers_[swath_nr]->consumeSpectrum(s);
650 std::string mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
652 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
653 ms1_consumer_->getOptions().setCompression(
true);
658 if (ms1_consumer_ ==
nullptr)
662 ms1_consumer_->consumeSpectrum(s);
#define OPENMS_LOG_DEBUG
Definition LogStream.h:714
On-disk cached implementation of FullSwathFileConsumer.
Definition SwathFileConsumer.h:422
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:498
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition SwathFileConsumer.h:557
CachedSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries, std::string cachedir, std::string basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition SwathFileConsumer.h:438
void addMS1Map_()
Definition SwathFileConsumer.h:488
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:508
CachedSwathFileConsumer(std::string cachedir, std::string basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition SwathFileConsumer.h:429
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:427
std::string cachedir_
Definition SwathFileConsumer.h:559
std::string basename_
Definition SwathFileConsumer.h:560
std::vector< int > nr_ms2_spectra_
Definition SwathFileConsumer.h:562
~CachedSwathFileConsumer() override
Definition SwathFileConsumer.h:449
MSDataCachedConsumer * ms1_consumer_
Definition SwathFileConsumer.h:556
PeakMap MapType
Definition SwathFileConsumer.h:425
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:478
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:426
void addNewSwathMap_()
Definition SwathFileConsumer.h:465
int nr_ms1_spectra_
Definition SwathFileConsumer.h:561
A method or algorithm argument contains illegal values.
Definition Exception.h:633
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition Exception.h:317
Description of the experimental settings.
Definition ExperimentalSettings.h:37
Facilitates file handling by file type recognition.
Definition FileHandler.h:52
void loadExperiment(const std::string &filename, PeakMap &exp, const std::vector< FileTypes::Type > allowed_types=std::vector< FileTypes::Type >(), ProgressLogger::LogType log=ProgressLogger::NONE, const bool rewrite_source_file=false, const bool compute_hash=false)
Loads a file into an MSExperiment.
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file.
Definition SwathFileConsumer.h:81
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition SwathFileConsumer.h:352
std::vector< std::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition SwathFileConsumer.h:338
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition SwathFileConsumer.h:104
~FullSwathFileConsumer() override
Definition SwathFileConsumer.h:114
bool consuming_possible_
Whether further spectra can still be consumed.
Definition SwathFileConsumer.h:346
std::shared_ptr< PeakMap > ms1_map_
Definition SwathFileConsumer.h:339
FullSwathFileConsumer()
Definition SwathFileConsumer.h:88
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:86
PeakMap settings_
The Experimental settings.
Definition SwathFileConsumer.h:343
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition SwathFileConsumer.h:116
virtual void consumeMS1Spectrum_(MapType::SpectrumType &s)=0
Consume an MS1 spectrum.
virtual void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr)=0
Consume an MS2 spectrum belonging to SWATH "swath_nr".
PeakMap MapType
Definition SwathFileConsumer.h:84
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition SwathFileConsumer.h:209
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition SwathFileConsumer.h:335
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition SwathFileConsumer.h:130
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition SwathFileConsumer.h:117
void consumeSpectrum(MapType::SpectrumType &s) override
Consume a spectrum which may belong either to an MS1 scan or one of n MS2 (SWATH) scans
Definition SwathFileConsumer.h:219
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition SwathFileConsumer.h:349
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:85
virtual void ensureMapsAreFilled_()=0
Callback function after the reading is complete.
The interface of a consumer of spectra and chromatograms.
Definition IMSDataConsumer.h:46
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition CachedMzMLHandler.h:41
void writeMetadata(MapType exp, const std::string &out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
PeakFileOptions & getOptions()
Get the peak file options.
The representation of a chromatogram.
Definition MSChromatogram.h:33
Transforming and cached writing consumer of MS data.
Definition MSDataCachedConsumer.h:31
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition MSDataCachedConsumer.h:74
void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override
Set expected size of spectra and chromatograms to be written.
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
UInt getMSLevel() const
Returns the MS level.
void clear(bool clear_meta_data)
Clears all data and meta data.
On-disk mzML implementation of FullSwathFileConsumer.
Definition SwathFileConsumer.h:579
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition SwathFileConsumer.h:671
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:656
PlainMSDataWritingConsumer * ms1_consumer_
Definition SwathFileConsumer.h:670
void addMS1Map_()
Definition SwathFileConsumer.h:648
~MzMLSwathFileConsumer() override
Definition SwathFileConsumer.h:606
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:665
MzMLSwathFileConsumer(const std::string &cachedir, const std::string &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition SwathFileConsumer.h:586
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:584
MzMLSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries, const std::string &cachedir, const std::string &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition SwathFileConsumer.h:595
std::string cachedir_
Definition SwathFileConsumer.h:673
std::string basename_
Definition SwathFileConsumer.h:674
std::vector< int > nr_ms2_spectra_
Definition SwathFileConsumer.h:676
PeakMap MapType
Definition SwathFileConsumer.h:582
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:637
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:583
void addNewSwathMap_()
Definition SwathFileConsumer.h:628
int nr_ms1_spectra_
Definition SwathFileConsumer.h:675
void deleteSetNull_()
Definition SwathFileConsumer.h:613
void setCompression(bool compress)
Consumer class that writes MS data to disk using the mzML format.
Definition MSDataWritingConsumer.h:237
In-memory implementation of FullSwathFileConsumer.
Definition SwathFileConsumer.h:364
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:399
RegularSwathFileConsumer()
Definition SwathFileConsumer.h:371
void addMS1Map_()
Definition SwathFileConsumer.h:393
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:408
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:369
PeakMap MapType
Definition SwathFileConsumer.h:367
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:383
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:368
void addNewSwathMap_()
Definition SwathFileConsumer.h:377
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition SwathFileConsumer.h:373
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
if none is found
Definition common-cmake-parameters.doxygen:76
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition SwathMap.h:21
bool ms1
Definition SwathMap.h:28
double imUpper
Definition SwathMap.h:27
OpenSwath::SpectrumAccessPtr sptr
Definition SwathMap.h:22
double center
Definition SwathMap.h:25
double lower
Definition SwathMap.h:23
double imLower
Definition SwathMap.h:26
double upper
Definition SwathMap.h:24