35 #ifndef OPENMS_FORMAT_DATAACCESS_SWATHFILECONSUMER_H 36 #define OPENMS_FORMAT_DATAACCESS_SWATHFILECONSUMER_H 38 #include <boost/cast.hpp> 112 consuming_possible_(true),
113 use_external_boundaries_(false),
114 correct_window_counter_(0)
116 use_external_boundaries_ = !swath_map_boundaries_.empty();
127 swath_map_boundaries_(swath_boundaries),
129 consuming_possible_(true),
130 use_external_boundaries_(false),
131 correct_window_counter_(0)
133 use_external_boundaries_ = !swath_map_boundaries_.empty();
154 consuming_possible_ =
false;
155 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;
185 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
188 if (nonempty_maps != swath_map_boundaries_.size())
190 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 (" <<
191 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
199 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
209 if (!consuming_possible_)
212 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
217 consumeMS1Spectrum_(s);
224 "Swath scan does not provide a precursor.");
228 double center = prec[0].getMZ();
229 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
230 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
237 "Swath scan does not provide any precursor isolation information.");
241 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
245 if (std::fabs(center - swath_map_boundaries_[i].center) < 1e-6)
248 consumeSwathSpectrum_(s, i);
253 if (use_external_boundaries_)
256 String(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
260 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
263 if (lower > 0.0 && upper > 0.0)
264 {correct_window_counter_++;}
267 boundary.
lower = lower;
268 boundary.
upper = upper;
270 swath_map_boundaries_.push_back(boundary);
272 LOG_DEBUG <<
"Adding Swath centered at " << center
273 <<
" m/z with an isolation window of " << lower <<
" to " << upper
274 <<
" m/z." << std::endl;
304 virtual void ensureMapsAreFilled_() = 0;
351 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
352 swath_maps_.push_back(exp);
357 while (swath_maps_.size() <= swath_nr)
362 swath_maps_[swath_nr]->addSpectrum(s);
367 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
377 ms1_map_->addSpectrum(s);
406 nr_ms1_spectra_(nr_ms1_spectra),
407 nr_ms2_spectra_(nr_ms2_spectra)
411 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
417 nr_ms1_spectra_(nr_ms1_spectra),
418 nr_ms2_spectra_(nr_ms2_spectra)
424 while (!swath_consumers_.empty())
426 delete swath_consumers_.back();
427 swath_consumers_.pop_back();
429 if (ms1_consumer_ != NULL)
431 delete ms1_consumer_;
432 ms1_consumer_ = NULL;
439 String meta_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
440 String cached_file = meta_file +
".cached";
442 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
443 swath_consumers_.push_back(consumer);
446 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
447 swath_maps_.push_back(exp);
452 while (swath_maps_.size() <= swath_nr)
456 swath_consumers_[swath_nr]->consumeSpectrum(s);
457 swath_maps_[swath_nr]->addSpectrum(s);
462 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
463 String cached_file = meta_file +
".cached";
465 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
466 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
472 if (ms1_consumer_ == NULL)
476 ms1_consumer_->consumeSpectrum(s);
477 ms1_map_->addSpectrum(s);
482 size_t swath_consumers_size = swath_consumers_.size();
483 bool have_ms1 = (ms1_consumer_ != NULL);
493 while (!swath_consumers_.empty())
495 delete swath_consumers_.back();
496 swath_consumers_.pop_back();
498 if (ms1_consumer_ != NULL)
500 delete ms1_consumer_;
501 ms1_consumer_ = NULL;
506 boost::shared_ptr<PeakMap > exp(
new PeakMap);
507 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
515 #pragma omp parallel for 517 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(swath_consumers_size); i++)
519 boost::shared_ptr<PeakMap > exp(
new PeakMap);
520 String meta_file = cachedir_ + basename_ +
"_" +
String(i) +
".mzML";
524 swath_maps_[i] = exp;
560 nr_ms1_spectra_(nr_ms1_spectra),
561 nr_ms2_spectra_(nr_ms2_spectra)
565 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
571 nr_ms1_spectra_(nr_ms1_spectra),
572 nr_ms2_spectra_(nr_ms2_spectra)
585 while (!swath_consumers_.empty())
587 delete swath_consumers_.back();
588 swath_consumers_.pop_back();
590 if (ms1_consumer_ != NULL)
592 delete ms1_consumer_;
593 ms1_consumer_ = NULL;
599 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
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 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
627 if (ms1_consumer_ == NULL)
631 ms1_consumer_->consumeSpectrum(s);
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:640
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:410
void ensureMapsAreFilled_()
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:380
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:321
bool consuming_possible_
Whether further spectra can still be consumed.
Definition: SwathFileConsumer.h:318
std::vector< boost::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition: SwathFileConsumer.h:310
A more convenient string class.
Definition: String.h:57
void setExperimentalSettings(const ExperimentalSettings &exp)
Set experimental settings (meta-data) of the data to be consumed.
Definition: SwathFileConsumer.h:139
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:343
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:345
String basename_
Definition: SwathFileConsumer.h:644
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:241
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:55
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr)
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:450
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:340
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:528
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr)
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:355
On-disk mzML implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:546
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:152
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:341
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:533
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
void consumeSpectrum(MapType::SpectrumType &s)
* Consume a spectrum which may belong either to an MS1 scan or one of n MS2 (SWATH) scans ...
Definition: SwathFileConsumer.h:207
void consumeMS1Spectrum_(MapType::SpectrumType &s)
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:625
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:552
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:55
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:399
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:110
MzMLSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:555
void addMS1Map_()
Definition: SwathFileConsumer.h:616
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:126
#define LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:459
PeakMap MapType
Definition: SwathFileConsumer.h:339
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:553
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file...
Definition: SwathFileConsumer.h:101
PeakMap MapType
Definition: SwathFileConsumer.h:397
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:534
File adapter for MzML files.
Definition: MzMLFile.h:56
PeakMap MapType
Definition: SwathFileConsumer.h:106
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
A method or algorithm argument contains illegal values.
Definition: Exception.h:649
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:645
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:551
void consumeChromatogram(MapType::ChromatogramType &)
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:197
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:59
void addNewSwathMap_()
Definition: SwathFileConsumer.h:437
~FullSwathFileConsumer()
Definition: SwathFileConsumer.h:136
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:315
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:392
void deleteSetNull_()
Definition: SwathFileConsumer.h:582
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:307
String cachedir_
Definition: SwathFileConsumer.h:531
void addNewSwathMap_()
Definition: SwathFileConsumer.h:349
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:46
void addMS1Map_()
Definition: SwathFileConsumer.h:365
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:48
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:108
void ensureMapsAreFilled_()
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:480
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:348
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:334
void consumeMS1Spectrum_(MapType::SpectrumType &s)
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:470
void clear(bool clear_meta_data)
Clears all data and meta data.
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:398
~CachedSwathFileConsumer()
Definition: SwathFileConsumer.h:421
void addMS1Map_()
Definition: SwathFileConsumer.h:460
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
void addNewSwathMap_()
Definition: SwathFileConsumer.h:597
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:311
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr)
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:605
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:68
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:646
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:529
UInt getMSLevel() const
Returns the MS level.
void setExpectedSize(Size, Size)
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:121
void ensureMapsAreFilled_()
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:635
void consumeMS1Spectrum_(MapType::SpectrumType &s)
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:371
double center
Definition: SwathMap.h:51
void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
String cachedir_
Definition: SwathFileConsumer.h:643
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:564
String basename_
Definition: SwathFileConsumer.h:532
double upper
Definition: SwathMap.h:50
bool ms1
Definition: SwathMap.h:52
~MzMLSwathFileConsumer()
Definition: SwathFileConsumer.h:575
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:107
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:324
void setExpectedSize(Size, Size)
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:138
double lower
Definition: SwathMap.h:49
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:401
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:641