37 #include <boost/cast.hpp> 111 consuming_possible_(true),
112 use_external_boundaries_(false),
113 correct_window_counter_(0)
115 use_external_boundaries_ = !swath_map_boundaries_.empty();
126 swath_map_boundaries_(swath_boundaries),
128 consuming_possible_(true),
129 use_external_boundaries_(false),
130 correct_window_counter_(0)
132 use_external_boundaries_ = !swath_map_boundaries_.empty();
153 consuming_possible_ =
false;
154 ensureMapsAreFilled_();
168 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
170 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
171 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
174 size_t nonempty_maps = 0;
175 for (
Size i = 0; i < swath_maps_.size(); i++)
179 map.
lower = swath_map_boundaries_[i].lower;
180 map.
upper = swath_map_boundaries_[i].upper;
181 map.
center = swath_map_boundaries_[i].center;
184 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
187 if (nonempty_maps != swath_map_boundaries_.size())
189 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 (" <<
190 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
198 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
208 if (!consuming_possible_)
211 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
216 consumeMS1Spectrum_(s);
223 "Swath scan does not provide a precursor.");
227 double center = prec[0].getMZ();
228 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
229 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
236 "Swath scan does not provide any precursor isolation information.");
240 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
244 if (std::fabs(center - swath_map_boundaries_[i].center) < 1e-6)
247 consumeSwathSpectrum_(s, i);
252 if (use_external_boundaries_)
255 String(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
259 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
262 if (lower > 0.0 && upper > 0.0)
263 {correct_window_counter_++;}
266 boundary.
lower = lower;
267 boundary.
upper = upper;
269 swath_map_boundaries_.push_back(boundary);
271 LOG_DEBUG <<
"Adding Swath centered at " << center
272 <<
" m/z with an isolation window of " << lower <<
" to " << upper
273 <<
" m/z." << std::endl;
303 virtual void ensureMapsAreFilled_() = 0;
350 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
351 swath_maps_.push_back(exp);
356 while (swath_maps_.size() <= swath_nr)
361 swath_maps_[swath_nr]->addSpectrum(s);
366 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
376 ms1_map_->addSpectrum(s);
401 ms1_consumer_(nullptr),
405 nr_ms1_spectra_(nr_ms1_spectra),
406 nr_ms2_spectra_(nr_ms2_spectra)
410 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
412 ms1_consumer_(nullptr),
416 nr_ms1_spectra_(nr_ms1_spectra),
417 nr_ms2_spectra_(nr_ms2_spectra)
423 while (!swath_consumers_.empty())
425 delete swath_consumers_.back();
426 swath_consumers_.pop_back();
428 if (ms1_consumer_ !=
nullptr)
430 delete ms1_consumer_;
431 ms1_consumer_ =
nullptr;
438 String meta_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
439 String cached_file = meta_file +
".cached";
441 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
442 swath_consumers_.push_back(consumer);
445 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
446 swath_maps_.push_back(exp);
451 while (swath_maps_.size() <= swath_nr)
455 swath_consumers_[swath_nr]->consumeSpectrum(s);
456 swath_maps_[swath_nr]->addSpectrum(s);
461 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
462 String cached_file = meta_file +
".cached";
464 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
465 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
471 if (ms1_consumer_ ==
nullptr)
475 ms1_consumer_->consumeSpectrum(s);
476 ms1_map_->addSpectrum(s);
481 size_t swath_consumers_size = swath_consumers_.size();
482 bool have_ms1 = (ms1_consumer_ !=
nullptr);
492 while (!swath_consumers_.empty())
494 delete swath_consumers_.back();
495 swath_consumers_.pop_back();
497 if (ms1_consumer_ !=
nullptr)
499 delete ms1_consumer_;
500 ms1_consumer_ =
nullptr;
505 boost::shared_ptr<PeakMap > exp(
new PeakMap);
506 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
514 #pragma omp parallel for 516 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(swath_consumers_size); i++)
518 boost::shared_ptr<PeakMap > exp(
new PeakMap);
519 String meta_file = cachedir_ + basename_ +
"_" +
String(i) +
".mzML";
523 swath_maps_[i] = exp;
555 ms1_consumer_(nullptr),
559 nr_ms1_spectra_(nr_ms1_spectra),
560 nr_ms2_spectra_(nr_ms2_spectra)
564 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
566 ms1_consumer_(nullptr),
570 nr_ms1_spectra_(nr_ms1_spectra),
571 nr_ms2_spectra_(nr_ms2_spectra)
584 while (!swath_consumers_.empty())
586 delete swath_consumers_.back();
587 swath_consumers_.pop_back();
589 if (ms1_consumer_ !=
nullptr)
591 delete ms1_consumer_;
592 ms1_consumer_ =
nullptr;
598 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
600 consumer->getOptions().setCompression(
true);
601 consumer->setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
602 swath_consumers_.push_back(consumer);
608 while (swath_consumers_.size() <= swath_nr)
612 swath_consumers_[swath_nr]->consumeSpectrum(s);
618 String mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
620 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
621 ms1_consumer_->getOptions().setCompression(
true);
622 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
628 if (ms1_consumer_ ==
nullptr)
632 ms1_consumer_->consumeSpectrum(s);
~MzMLSwathFileConsumer() override
Definition: SwathFileConsumer.h:574
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:626
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:641
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:409
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:320
bool consuming_possible_
Whether further spectra can still be consumed.
Definition: SwathFileConsumer.h:317
std::vector< boost::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition: SwathFileConsumer.h:309
A more convenient string class.
Definition: String.h:57
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:342
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:344
String basename_
Definition: SwathFileConsumer.h:645
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:479
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:240
static OpenSwath::SpectrumAccessPtr getSpectrumAccessOpenMSPtr(boost::shared_ptr< OpenMS::PeakMap > exp)
Simple Factory method to get a SpectrumAccess Ptr from an MSExperiment.
The representation of a chromatogram.
Definition: MSChromatogram.h:54
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:339
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:354
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:527
On-disk mzML implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:545
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:151
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:340
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:532
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:551
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:54
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:398
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:605
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:109
~FullSwathFileConsumer() override
Definition: SwathFileConsumer.h:135
MzMLSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:554
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:137
void addMS1Map_()
Definition: SwathFileConsumer.h:616
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:125
#define LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:458
PeakMap MapType
Definition: SwathFileConsumer.h:338
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:552
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file...
Definition: SwathFileConsumer.h:100
PeakMap MapType
Definition: SwathFileConsumer.h:396
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:533
File adapter for MzML files.
Definition: MzMLFile.h:55
PeakMap MapType
Definition: SwathFileConsumer.h:105
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
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:206
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:370
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:646
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...
PeakMap MapType
Definition: SwathFileConsumer.h:550
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:61
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:469
void addNewSwathMap_()
Definition: SwathFileConsumer.h:436
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:314
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:391
void deleteSetNull_()
Definition: SwathFileConsumer.h:581
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:306
String cachedir_
Definition: SwathFileConsumer.h:530
void addNewSwathMap_()
Definition: SwathFileConsumer.h:348
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:45
void addMS1Map_()
Definition: SwathFileConsumer.h:364
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:47
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:100
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:107
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition: SwathFileConsumer.h:138
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:347
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:333
void clear(bool clear_meta_data)
Clears all data and meta data.
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:397
void addMS1Map_()
Definition: SwathFileConsumer.h:459
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
void addNewSwathMap_()
Definition: SwathFileConsumer.h:596
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:379
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:310
void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:196
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:67
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:647
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:528
UInt getMSLevel() const
Returns the MS level.
double center
Definition: SwathMap.h:50
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:66
String cachedir_
Definition: SwathFileConsumer.h:644
MzMLSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries, String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:563
String basename_
Definition: SwathFileConsumer.h:531
double upper
Definition: SwathMap.h:49
bool ms1
Definition: SwathMap.h:51
Description of the experimental settings.
Definition: ExperimentalSettings.h:58
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:106
~CachedSwathFileConsumer() override
Definition: SwathFileConsumer.h:420
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:323
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:449
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:636
double lower
Definition: SwathMap.h:48
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:400
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:642