87 consuming_possible_(true),
88 use_external_boundaries_(false),
89 correct_window_counter_(0)
91 use_external_boundaries_ = !swath_map_boundaries_.empty();
102 swath_map_boundaries_(swath_boundaries),
104 consuming_possible_(true),
105 use_external_boundaries_(false),
106 correct_window_counter_(0)
108 use_external_boundaries_ = !swath_map_boundaries_.empty();
129 consuming_possible_ =
false;
130 ensureMapsAreFilled_();
134 map.
sptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(ms1_map_);
146 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
148 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
149 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
152 size_t nonempty_maps = 0;
153 for (
Size i = 0; i < swath_maps_.size(); i++)
156 map.
sptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(swath_maps_[i]);
157 map.
lower = swath_map_boundaries_[i].lower;
158 map.
upper = swath_map_boundaries_[i].upper;
159 map.
center = swath_map_boundaries_[i].center;
160 map.
imLower = swath_map_boundaries_[i].imLower;
161 map.
imUpper = swath_map_boundaries_[i].imUpper;
164 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
167 if (nonempty_maps != swath_map_boundaries_.size())
169 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 (" <<
170 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
178 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
189 if (!consuming_possible_)
192 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
197 consumeMS1Spectrum_(s);
204 "Swath scan does not provide a precursor.");
208 double center = prec[0].getMZ();
209 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
210 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
218 lowerIm = (double)s.
getMetaValue(
"ion mobility lower limit");
219 upperIm = (double)s.
getMetaValue(
"ion mobility upper limit");
228 "Swath scan does not provide any precursor isolation information.");
232 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
237 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))
240 consumeSwathSpectrum_(s, i);
246 if (use_external_boundaries_)
249 std::string(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
253 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
256 if (lower > 0.0 && upper > 0.0)
257 {correct_window_counter_++;}
260 boundary.
lower = lower;
261 boundary.
upper = upper;
265 swath_map_boundaries_.push_back(boundary);
268 <<
" m/z with an isolation window of " << lower <<
" to " << upper
269 <<
" m/z and IM lower limit of " << lowerIm <<
" and upper limit of " << upperIm << std::endl;
346 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
347 swath_maps_.push_back(exp);
352 while (swath_maps_.size() <= swath_nr)
357 swath_maps_[swath_nr]->addSpectrum(s);
362 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
372 ms1_map_->addSpectrum(s);
397 ms1_consumer_(nullptr),
401 nr_ms1_spectra_(nr_ms1_spectra),
402 nr_ms2_spectra_(nr_ms2_spectra)
406 std::string cachedir, std::string basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
408 ms1_consumer_(nullptr),
412 nr_ms1_spectra_(nr_ms1_spectra),
413 nr_ms2_spectra_(nr_ms2_spectra)
419 while (!swath_consumers_.empty())
421 delete swath_consumers_.back();
422 swath_consumers_.pop_back();
424 if (ms1_consumer_ !=
nullptr)
426 delete ms1_consumer_;
427 ms1_consumer_ =
nullptr;
434 std::string meta_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(swath_consumers_.size()) +
".mzML";
435 std::string cached_file = meta_file +
".cached";
437 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
438 swath_consumers_.push_back(consumer);
441 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
442 swath_maps_.push_back(exp);
447 while (swath_maps_.size() <= swath_nr)
451 swath_consumers_[swath_nr]->consumeSpectrum(s);
452 swath_maps_[swath_nr]->addSpectrum(s);
457 std::string meta_file = cachedir_ + basename_ +
"_ms1.mzML";
458 std::string cached_file = meta_file +
".cached";
460 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
461 std::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
467 if (ms1_consumer_ ==
nullptr)
471 ms1_consumer_->consumeSpectrum(s);
472 ms1_map_->addSpectrum(s);
477 size_t swath_consumers_size = swath_consumers_.size();
478 bool have_ms1 = (ms1_consumer_ !=
nullptr);
488 while (!swath_consumers_.empty())
490 delete swath_consumers_.back();
491 swath_consumers_.pop_back();
493 if (ms1_consumer_ !=
nullptr)
495 delete ms1_consumer_;
496 ms1_consumer_ =
nullptr;
501 std::shared_ptr<PeakMap > exp(
new PeakMap);
502 std::string meta_file = cachedir_ + basename_ +
"_ms1.mzML";
510#pragma omp parallel for
512 for (
SignedSize i = 0; i < OpenMS::checkedCast<SignedSize>(swath_consumers_size); i++)
514 std::shared_ptr<PeakMap > exp(
new PeakMap);
515 std::string meta_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(i) +
".mzML";
519 swath_maps_[i] = exp;
553 MzMLSwathFileConsumer(
const std::string& cachedir,
const std::string& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
554 ms1_consumer_(nullptr),
558 nr_ms1_spectra_(nr_ms1_spectra),
559 nr_ms2_spectra_(nr_ms2_spectra)
563 const std::string& cachedir,
const std::string& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
565 ms1_consumer_(nullptr),
569 nr_ms1_spectra_(nr_ms1_spectra),
570 nr_ms2_spectra_(nr_ms2_spectra)
583 while (!swath_consumers_.empty())
585 delete swath_consumers_.back();
586 swath_consumers_.pop_back();
588 if (ms1_consumer_ !=
nullptr)
590 delete ms1_consumer_;
591 ms1_consumer_ =
nullptr;
597 std::string mzml_file = cachedir_ + basename_ +
"_" + StringUtils::toStr(swath_consumers_.size()) +
".mzML";
600 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
601 swath_consumers_.push_back(consumer);
607 while (swath_consumers_.size() <= swath_nr)
611 swath_consumers_[swath_nr]->consumeSpectrum(s);
617 std::string mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
619 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
620 ms1_consumer_->getOptions().setCompression(
true);
625 if (ms1_consumer_ ==
nullptr)
629 ms1_consumer_->consumeSpectrum(s);
#define OPENMS_LOG_DEBUG
Definition LogStream.h:714
On-disk cached implementation of FullSwathFileConsumer.
Definition SwathFileConsumer.h:389
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:465
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition SwathFileConsumer.h:524
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:405
void addMS1Map_()
Definition SwathFileConsumer.h:455
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:475
CachedSwathFileConsumer(std::string cachedir, std::string basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition SwathFileConsumer.h:396
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:394
std::string cachedir_
Definition SwathFileConsumer.h:526
std::string basename_
Definition SwathFileConsumer.h:527
std::vector< int > nr_ms2_spectra_
Definition SwathFileConsumer.h:529
~CachedSwathFileConsumer() override
Definition SwathFileConsumer.h:416
MSDataCachedConsumer * ms1_consumer_
Definition SwathFileConsumer.h:523
PeakMap MapType
Definition SwathFileConsumer.h:392
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:445
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:393
void addNewSwathMap_()
Definition SwathFileConsumer.h:432
int nr_ms1_spectra_
Definition SwathFileConsumer.h:528
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:48
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:78
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition SwathFileConsumer.h:319
std::vector< std::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition SwathFileConsumer.h:305
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition SwathFileConsumer.h:101
~FullSwathFileConsumer() override
Definition SwathFileConsumer.h:111
bool consuming_possible_
Whether further spectra can still be consumed.
Definition SwathFileConsumer.h:313
std::shared_ptr< PeakMap > ms1_map_
Definition SwathFileConsumer.h:306
FullSwathFileConsumer()
Definition SwathFileConsumer.h:85
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:83
PeakMap settings_
The Experimental settings.
Definition SwathFileConsumer.h:310
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition SwathFileConsumer.h:113
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:81
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition SwathFileConsumer.h:176
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition SwathFileConsumer.h:302
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition SwathFileConsumer.h:127
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition SwathFileConsumer.h:114
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:186
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition SwathFileConsumer.h:316
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:82
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:546
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition SwathFileConsumer.h:638
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:623
PlainMSDataWritingConsumer * ms1_consumer_
Definition SwathFileConsumer.h:637
void addMS1Map_()
Definition SwathFileConsumer.h:615
~MzMLSwathFileConsumer() override
Definition SwathFileConsumer.h:573
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:632
MzMLSwathFileConsumer(const std::string &cachedir, const std::string &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition SwathFileConsumer.h:553
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:551
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:562
std::string cachedir_
Definition SwathFileConsumer.h:640
std::string basename_
Definition SwathFileConsumer.h:641
std::vector< int > nr_ms2_spectra_
Definition SwathFileConsumer.h:643
PeakMap MapType
Definition SwathFileConsumer.h:549
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:604
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:550
void addNewSwathMap_()
Definition SwathFileConsumer.h:595
int nr_ms1_spectra_
Definition SwathFileConsumer.h:642
void deleteSetNull_()
Definition SwathFileConsumer.h:580
void setCompression(bool compress)
Consumer class that writes MS data to disk using the mzML format.
Definition MSDataWritingConsumer.h:219
In-memory implementation of FullSwathFileConsumer.
Definition SwathFileConsumer.h:331
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition SwathFileConsumer.h:366
RegularSwathFileConsumer()
Definition SwathFileConsumer.h:338
void addMS1Map_()
Definition SwathFileConsumer.h:360
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition SwathFileConsumer.h:375
MapType::ChromatogramType ChromatogramType
Definition SwathFileConsumer.h:336
PeakMap MapType
Definition SwathFileConsumer.h:334
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition SwathFileConsumer.h:350
MapType::SpectrumType SpectrumType
Definition SwathFileConsumer.h:335
void addNewSwathMap_()
Definition SwathFileConsumer.h:344
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition SwathFileConsumer.h:340
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
if none is found
Definition common-cmake-parameters.doxygen:88
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