84 consuming_possible_(true),
85 use_external_boundaries_(false),
86 correct_window_counter_(0)
88 use_external_boundaries_ = !swath_map_boundaries_.empty();
99 swath_map_boundaries_(swath_boundaries),
101 consuming_possible_(true),
102 use_external_boundaries_(false),
103 correct_window_counter_(0)
105 use_external_boundaries_ = !swath_map_boundaries_.empty();
126 consuming_possible_ =
false;
127 ensureMapsAreFilled_();
143 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
145 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
146 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
149 size_t nonempty_maps = 0;
150 for (
Size i = 0; i < swath_maps_.size(); i++)
154 map.
lower = swath_map_boundaries_[i].lower;
155 map.
upper = swath_map_boundaries_[i].upper;
156 map.
center = swath_map_boundaries_[i].center;
157 map.
imLower = swath_map_boundaries_[i].imLower;
158 map.
imUpper = swath_map_boundaries_[i].imUpper;
161 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
164 if (nonempty_maps != swath_map_boundaries_.size())
166 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 (" <<
167 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
175 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
186 if (!consuming_possible_)
189 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
194 consumeMS1Spectrum_(s);
201 "Swath scan does not provide a precursor.");
205 double center = prec[0].getMZ();
206 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
207 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
225 "Swath scan does not provide any precursor isolation information.");
229 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
234 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))
237 consumeSwathSpectrum_(s, i);
243 if (use_external_boundaries_)
246 String(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
250 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
253 if (lower > 0.0 && upper > 0.0)
254 {correct_window_counter_++;}
257 boundary.
lower = lower;
258 boundary.
upper = upper;
262 swath_map_boundaries_.push_back(boundary);
265 <<
" m/z with an isolation window of " << lower <<
" to " << upper
266 <<
" m/z and IM lower limit of " << lowerIm <<
" and upper limit of " << upperIm << std::endl;
343 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
344 swath_maps_.push_back(exp);
349 while (swath_maps_.size() <= swath_nr)
354 swath_maps_[swath_nr]->addSpectrum(s);
359 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
369 ms1_map_->addSpectrum(s);
394 ms1_consumer_(nullptr),
398 nr_ms1_spectra_(nr_ms1_spectra),
399 nr_ms2_spectra_(nr_ms2_spectra)
403 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
405 ms1_consumer_(nullptr),
409 nr_ms1_spectra_(nr_ms1_spectra),
410 nr_ms2_spectra_(nr_ms2_spectra)
416 while (!swath_consumers_.empty())
418 delete swath_consumers_.back();
419 swath_consumers_.pop_back();
421 if (ms1_consumer_ !=
nullptr)
423 delete ms1_consumer_;
424 ms1_consumer_ =
nullptr;
431 String meta_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
432 String cached_file = meta_file +
".cached";
434 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
435 swath_consumers_.push_back(consumer);
438 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
439 swath_maps_.push_back(exp);
444 while (swath_maps_.size() <= swath_nr)
448 swath_consumers_[swath_nr]->consumeSpectrum(s);
449 swath_maps_[swath_nr]->addSpectrum(s);
454 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
455 String cached_file = meta_file +
".cached";
457 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
458 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
464 if (ms1_consumer_ ==
nullptr)
468 ms1_consumer_->consumeSpectrum(s);
469 ms1_map_->addSpectrum(s);
474 size_t swath_consumers_size = swath_consumers_.size();
475 bool have_ms1 = (ms1_consumer_ !=
nullptr);
485 while (!swath_consumers_.empty())
487 delete swath_consumers_.back();
488 swath_consumers_.pop_back();
490 if (ms1_consumer_ !=
nullptr)
492 delete ms1_consumer_;
493 ms1_consumer_ =
nullptr;
498 boost::shared_ptr<PeakMap > exp(
new PeakMap);
499 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
507 #pragma omp parallel for
509 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(swath_consumers_size); i++)
511 boost::shared_ptr<PeakMap > exp(
new PeakMap);
512 String meta_file = cachedir_ + basename_ +
"_" +
String(i) +
".mzML";
516 swath_maps_[i] = exp;
551 ms1_consumer_(nullptr),
555 nr_ms1_spectra_(nr_ms1_spectra),
556 nr_ms2_spectra_(nr_ms2_spectra)
560 const String& cachedir,
const String& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
562 ms1_consumer_(nullptr),
566 nr_ms1_spectra_(nr_ms1_spectra),
567 nr_ms2_spectra_(nr_ms2_spectra)
580 while (!swath_consumers_.empty())
582 delete swath_consumers_.back();
583 swath_consumers_.pop_back();
585 if (ms1_consumer_ !=
nullptr)
587 delete ms1_consumer_;
588 ms1_consumer_ =
nullptr;
594 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
597 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
598 swath_consumers_.push_back(consumer);
604 while (swath_consumers_.size() <= swath_nr)
608 swath_consumers_[swath_nr]->consumeSpectrum(s);
614 String mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
616 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
617 ms1_consumer_->getOptions().setCompression(
true);
622 if (ms1_consumer_ ==
nullptr)
626 ms1_consumer_->consumeSpectrum(s);
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:454
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:386
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:462
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:521
void addMS1Map_()
Definition: SwathFileConsumer.h:452
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:472
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:402
String basename_
Definition: SwathFileConsumer.h:524
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:391
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:526
~CachedSwathFileConsumer() override
Definition: SwathFileConsumer.h:413
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:520
PeakMap MapType
Definition: SwathFileConsumer.h:389
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:442
String cachedir_
Definition: SwathFileConsumer.h:523
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:390
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:393
void addNewSwathMap_()
Definition: SwathFileConsumer.h:429
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:525
A method or algorithm argument contains illegal values.
Definition: Exception.h:624
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:315
Description of the experimental settings.
Definition: ExperimentalSettings.h:36
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file.
Definition: SwathFileConsumer.h:75
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:316
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:98
~FullSwathFileConsumer() override
Definition: SwathFileConsumer.h:108
bool consuming_possible_
Whether further spectra can still be consumed.
Definition: SwathFileConsumer.h:310
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:82
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:80
std::vector< boost::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition: SwathFileConsumer.h:302
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:307
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:110
virtual void consumeMS1Spectrum_(MapType::SpectrumType &s)=0
Consume an MS1 spectrum.
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:303
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:78
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:173
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:299
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:124
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition: SwathFileConsumer.h:111
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:183
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:313
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:79
virtual void ensureMapsAreFilled_()=0
Callback function after the reading is complete.
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:44
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:42
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:31
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:46
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.
File adapter for MzML files.
Definition: MzMLFile.h:34
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:543
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:635
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:620
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:634
void addMS1Map_()
Definition: SwathFileConsumer.h:612
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:559
~MzMLSwathFileConsumer() override
Definition: SwathFileConsumer.h:570
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:629
MzMLSwathFileConsumer(const String &cachedir, const String &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition: SwathFileConsumer.h:550
String basename_
Definition: SwathFileConsumer.h:638
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:548
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:640
PeakMap MapType
Definition: SwathFileConsumer.h:546
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:601
String cachedir_
Definition: SwathFileConsumer.h:637
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:547
void addNewSwathMap_()
Definition: SwathFileConsumer.h:592
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:639
void deleteSetNull_()
Definition: SwathFileConsumer.h:577
void setCompression(bool compress)
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:216
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:328
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:363
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:335
void addMS1Map_()
Definition: SwathFileConsumer.h:357
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:372
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:333
PeakMap MapType
Definition: SwathFileConsumer.h:331
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:347
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:332
void addNewSwathMap_()
Definition: SwathFileConsumer.h:341
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:337
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:34
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:35
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:20
bool ms1
Definition: SwathMap.h:27
double imUpper
Definition: SwathMap.h:26
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:21
double center
Definition: SwathMap.h:24
double lower
Definition: SwathMap.h:22
double imLower
Definition: SwathMap.h:25
double upper
Definition: SwathMap.h:23