|
OpenMS
2.5.0
|
Go to the documentation of this file.
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);
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);
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);
402 ms1_consumer_(nullptr),
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) :
413 ms1_consumer_(nullptr),
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_ !=
nullptr)
431 delete ms1_consumer_;
432 ms1_consumer_ =
nullptr;
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_ ==
nullptr)
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_ !=
nullptr);
493 while (!swath_consumers_.empty())
495 delete swath_consumers_.back();
496 swath_consumers_.pop_back();
498 if (ms1_consumer_ !=
nullptr)
500 delete ms1_consumer_;
501 ms1_consumer_ =
nullptr;
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;
559 ms1_consumer_(nullptr),
563 nr_ms1_spectra_(nr_ms1_spectra),
564 nr_ms2_spectra_(nr_ms2_spectra)
568 const String& cachedir,
const String& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
570 ms1_consumer_(nullptr),
574 nr_ms1_spectra_(nr_ms1_spectra),
575 nr_ms2_spectra_(nr_ms2_spectra)
588 while (!swath_consumers_.empty())
590 delete swath_consumers_.back();
591 swath_consumers_.pop_back();
593 if (ms1_consumer_ !=
nullptr)
595 delete ms1_consumer_;
596 ms1_consumer_ =
nullptr;
602 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
604 consumer->getOptions().setCompression(
true);
605 consumer->setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
606 swath_consumers_.push_back(consumer);
612 while (swath_consumers_.size() <= swath_nr)
616 swath_consumers_[swath_nr]->consumeSpectrum(s);
622 String mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
624 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
625 ms1_consumer_->getOptions().setCompression(
true);
630 if (ms1_consumer_ ==
nullptr)
634 ms1_consumer_->consumeSpectrum(s);
void addMS1Map_()
Definition: SwathFileConsumer.h:460
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:109
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
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:528
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:480
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:100
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:398
void addNewSwathMap_()
Definition: SwathFileConsumer.h:437
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:69
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:567
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:399
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:401
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
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:371
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:609
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:628
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
File adapter for MzML files.
Definition: MzMLFile.h:55
A more convenient string class.
Definition: String.h:58
void addMS1Map_()
Definition: SwathFileConsumer.h:620
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:529
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:334
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:196
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:533
String basename_
Definition: SwathFileConsumer.h:532
~FullSwathFileConsumer() override
Definition: SwathFileConsumer.h:135
String cachedir_
Definition: SwathFileConsumer.h:531
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:534
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:470
double lower
Definition: SwathMap.h:48
bool ms1
Definition: SwathMap.h:51
void addMS1Map_()
Definition: SwathFileConsumer.h:365
void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:380
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:647
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:343
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
String cachedir_
Definition: SwathFileConsumer.h:645
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:637
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:392
UInt getMSLevel() const
Returns the MS level.
void addNewSwathMap_()
Definition: SwathFileConsumer.h:349
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:642
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:137
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:106
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:54
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:648
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:125
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...
~MzMLSwathFileConsumer() override
Definition: SwathFileConsumer.h:578
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:556
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file.
Definition: SwathFileConsumer.h:100
double center
Definition: SwathMap.h:50
PeakMap MapType
Definition: SwathFileConsumer.h:105
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:107
#define OPENMS_LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:470
~CachedSwathFileConsumer() override
Definition: SwathFileConsumer.h:421
double upper
Definition: SwathMap.h:49
void clear(bool clear_meta_data)
Clears all data and meta data.
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:355
static OpenSwath::SpectrumAccessPtr getSpectrumAccessOpenMSPtr(boost::shared_ptr< OpenMS::PeakMap > exp)
Simple Factory method to get a SpectrumAccess Ptr from an MSExperiment.
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:61
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:345
void addNewSwathMap_()
Definition: SwathFileConsumer.h:600
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:340
On-disk mzML implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:549
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:324
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
String basename_
Definition: SwathFileConsumer.h:646
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
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:240
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:151
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:45
PeakMap MapType
Definition: SwathFileConsumer.h:339
The representation of a chromatogram.
Definition: MSChromatogram.h:54
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:311
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:315
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:341
PeakMap MapType
Definition: SwathFileConsumer.h:554
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:307
void deleteSetNull_()
Definition: SwathFileConsumer.h:585
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:47
PeakMap MapType
Definition: SwathFileConsumer.h:397
MzMLSwathFileConsumer(const String &cachedir, const String &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition: SwathFileConsumer.h:558
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:643
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:66
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:321
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:450
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:555