110 consuming_possible_(true),
111 use_external_boundaries_(false),
112 correct_window_counter_(0)
114 use_external_boundaries_ = !swath_map_boundaries_.empty();
125 swath_map_boundaries_(swath_boundaries),
127 consuming_possible_(true),
128 use_external_boundaries_(false),
129 correct_window_counter_(0)
131 use_external_boundaries_ = !swath_map_boundaries_.empty();
152 consuming_possible_ =
false;
153 ensureMapsAreFilled_();
169 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
171 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
172 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
175 size_t nonempty_maps = 0;
176 for (
Size i = 0; i < swath_maps_.size(); i++)
180 map.
lower = swath_map_boundaries_[i].lower;
181 map.
upper = swath_map_boundaries_[i].upper;
182 map.
center = swath_map_boundaries_[i].center;
183 map.
imLower = swath_map_boundaries_[i].imLower;
184 map.
imUpper = swath_map_boundaries_[i].imUpper;
187 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
190 if (nonempty_maps != swath_map_boundaries_.size())
192 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 (" <<
193 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
201 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
212 if (!consuming_possible_)
215 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
220 consumeMS1Spectrum_(s);
227 "Swath scan does not provide a precursor.");
231 double center = prec[0].getMZ();
232 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
233 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
251 "Swath scan does not provide any precursor isolation information.");
255 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
260 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))
263 consumeSwathSpectrum_(s, i);
269 if (use_external_boundaries_)
272 String(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
276 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
279 if (lower > 0.0 && upper > 0.0)
280 {correct_window_counter_++;}
283 boundary.
lower = lower;
284 boundary.
upper = upper;
288 swath_map_boundaries_.push_back(boundary);
291 <<
" m/z with an isolation window of " << lower <<
" to " << upper
292 <<
" m/z and IM lower limit of " << lowerIm <<
" and upper limit of " << upperIm << std::endl;
369 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
370 swath_maps_.push_back(exp);
375 while (swath_maps_.size() <= swath_nr)
380 swath_maps_[swath_nr]->addSpectrum(s);
385 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
395 ms1_map_->addSpectrum(s);
420 ms1_consumer_(nullptr),
424 nr_ms1_spectra_(nr_ms1_spectra),
425 nr_ms2_spectra_(nr_ms2_spectra)
429 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
431 ms1_consumer_(nullptr),
435 nr_ms1_spectra_(nr_ms1_spectra),
436 nr_ms2_spectra_(nr_ms2_spectra)
442 while (!swath_consumers_.empty())
444 delete swath_consumers_.back();
445 swath_consumers_.pop_back();
447 if (ms1_consumer_ !=
nullptr)
449 delete ms1_consumer_;
450 ms1_consumer_ =
nullptr;
457 String meta_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
458 String cached_file = meta_file +
".cached";
460 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
461 swath_consumers_.push_back(consumer);
464 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
465 swath_maps_.push_back(exp);
470 while (swath_maps_.size() <= swath_nr)
474 swath_consumers_[swath_nr]->consumeSpectrum(s);
475 swath_maps_[swath_nr]->addSpectrum(s);
480 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
481 String cached_file = meta_file +
".cached";
483 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
484 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
490 if (ms1_consumer_ ==
nullptr)
494 ms1_consumer_->consumeSpectrum(s);
495 ms1_map_->addSpectrum(s);
500 size_t swath_consumers_size = swath_consumers_.size();
501 bool have_ms1 = (ms1_consumer_ !=
nullptr);
511 while (!swath_consumers_.empty())
513 delete swath_consumers_.back();
514 swath_consumers_.pop_back();
516 if (ms1_consumer_ !=
nullptr)
518 delete ms1_consumer_;
519 ms1_consumer_ =
nullptr;
524 boost::shared_ptr<PeakMap > exp(
new PeakMap);
525 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
533 #pragma omp parallel for
535 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(swath_consumers_size); i++)
537 boost::shared_ptr<PeakMap > exp(
new PeakMap);
538 String meta_file = cachedir_ + basename_ +
"_" +
String(i) +
".mzML";
542 swath_maps_[i] = exp;
577 ms1_consumer_(nullptr),
581 nr_ms1_spectra_(nr_ms1_spectra),
582 nr_ms2_spectra_(nr_ms2_spectra)
586 const String& cachedir,
const String& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
588 ms1_consumer_(nullptr),
592 nr_ms1_spectra_(nr_ms1_spectra),
593 nr_ms2_spectra_(nr_ms2_spectra)
606 while (!swath_consumers_.empty())
608 delete swath_consumers_.back();
609 swath_consumers_.pop_back();
611 if (ms1_consumer_ !=
nullptr)
613 delete ms1_consumer_;
614 ms1_consumer_ =
nullptr;
620 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
623 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
624 swath_consumers_.push_back(consumer);
630 while (swath_consumers_.size() <= swath_nr)
634 swath_consumers_[swath_nr]->consumeSpectrum(s);
640 String mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
642 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
643 ms1_consumer_->getOptions().setCompression(
true);
648 if (ms1_consumer_ ==
nullptr)
652 ms1_consumer_->consumeSpectrum(s);
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:480
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:412
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:488
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:547
void addMS1Map_()
Definition: SwathFileConsumer.h:478
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:498
CachedSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries, String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:428
String basename_
Definition: SwathFileConsumer.h:550
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:417
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:552
~CachedSwathFileConsumer() override
Definition: SwathFileConsumer.h:439
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:546
PeakMap MapType
Definition: SwathFileConsumer.h:415
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:468
String cachedir_
Definition: SwathFileConsumer.h:549
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:416
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:419
void addNewSwathMap_()
Definition: SwathFileConsumer.h:455
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:551
A method or algorithm argument contains illegal values.
Definition: Exception.h:650
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:341
Description of the experimental settings.
Definition: ExperimentalSettings.h:62
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file.
Definition: SwathFileConsumer.h:101
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:342
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:124
~FullSwathFileConsumer() override
Definition: SwathFileConsumer.h:134
bool consuming_possible_
Whether further spectra can still be consumed.
Definition: SwathFileConsumer.h:336
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:108
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:106
std::vector< boost::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition: SwathFileConsumer.h:328
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:333
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:136
virtual void consumeMS1Spectrum_(MapType::SpectrumType &s)=0
Consume an MS1 spectrum.
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:329
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:104
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:199
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:325
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:150
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition: SwathFileConsumer.h:137
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:209
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:339
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:105
virtual void ensureMapsAreFilled_()=0
Callback function after the reading is complete.
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:70
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:68
void writeMetadata(MapType exp, const 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:57
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:57
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:100
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:72
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
UInt getMSLevel() const
Returns the MS level.
void clear(bool clear_meta_data)
Clears all data and meta data.
File adapter for MzML files.
Definition: MzMLFile.h:60
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
On-disk mzML implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:569
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:661
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:646
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:660
void addMS1Map_()
Definition: SwathFileConsumer.h:638
MzMLSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries, const String &cachedir, const String &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition: SwathFileConsumer.h:585
~MzMLSwathFileConsumer() override
Definition: SwathFileConsumer.h:596
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:655
MzMLSwathFileConsumer(const String &cachedir, const String &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition: SwathFileConsumer.h:576
String basename_
Definition: SwathFileConsumer.h:664
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:574
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:666
PeakMap MapType
Definition: SwathFileConsumer.h:572
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:627
String cachedir_
Definition: SwathFileConsumer.h:663
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:573
void addNewSwathMap_()
Definition: SwathFileConsumer.h:618
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:665
void deleteSetNull_()
Definition: SwathFileConsumer.h:603
void setCompression(bool compress)
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:242
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:354
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:389
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:361
void addMS1Map_()
Definition: SwathFileConsumer.h:383
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:398
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:359
PeakMap MapType
Definition: SwathFileConsumer.h:357
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:373
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:358
void addNewSwathMap_()
Definition: SwathFileConsumer.h:367
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:363
static OpenSwath::SpectrumAccessPtr getSpectrumAccessOpenMSPtr(const boost::shared_ptr< OpenMS::PeakMap > &exp)
Simple Factory method to get a SpectrumAccess Ptr from an MSExperiment.
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
A more convenient string class.
Definition: String.h:60
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:61
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:46
bool ms1
Definition: SwathMap.h:53
double imUpper
Definition: SwathMap.h:52
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:47
double center
Definition: SwathMap.h:50
double lower
Definition: SwathMap.h:48
double imLower
Definition: SwathMap.h:51
double upper
Definition: SwathMap.h:49