86 consuming_possible_(true),
87 use_external_boundaries_(false),
88 correct_window_counter_(0)
90 use_external_boundaries_ = !swath_map_boundaries_.empty();
101 swath_map_boundaries_(swath_boundaries),
103 consuming_possible_(true),
104 use_external_boundaries_(false),
105 correct_window_counter_(0)
107 use_external_boundaries_ = !swath_map_boundaries_.empty();
128 consuming_possible_ =
false;
129 ensureMapsAreFilled_();
145 if (!use_external_boundaries_ && correct_window_counter_ != swath_maps_.size())
147 std::cout <<
"WARNING: Could not correctly read the upper/lower limits of the SWATH windows from your input file. Read " <<
148 correct_window_counter_ <<
" correct (non-zero) window limits (expected " << swath_maps_.size() <<
" windows)." << std::endl;
151 size_t nonempty_maps = 0;
152 for (
Size i = 0; i < swath_maps_.size(); i++)
156 map.
lower = swath_map_boundaries_[i].lower;
157 map.
upper = swath_map_boundaries_[i].upper;
158 map.
center = swath_map_boundaries_[i].center;
159 map.
imLower = swath_map_boundaries_[i].imLower;
160 map.
imUpper = swath_map_boundaries_[i].imUpper;
163 if (map.
sptr->getNrSpectra() > 0) {nonempty_maps++;}
166 if (nonempty_maps != swath_map_boundaries_.size())
168 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 (" <<
169 swath_map_boundaries_.size() <<
"). Please check your input." << std::endl;
177 std::cerr <<
"Read chromatogram while reading SWATH files, did not expect that!" << std::endl;
188 if (!consuming_possible_)
191 "FullSwathFileConsumer cannot consume any more spectra after retrieveSwathMaps has been called already");
196 consumeMS1Spectrum_(s);
203 "Swath scan does not provide a precursor.");
207 double center = prec[0].getMZ();
208 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
209 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
227 "Swath scan does not provide any precursor isolation information.");
231 for (
Size i = 0; i < swath_map_boundaries_.size(); i++)
236 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))
239 consumeSwathSpectrum_(s, i);
245 if (use_external_boundaries_)
248 String(
"Encountered SWATH scan with boundary ") + center +
" m/z which was not present in the provided windows.");
252 consumeSwathSpectrum_(s, swath_map_boundaries_.size());
255 if (lower > 0.0 && upper > 0.0)
256 {correct_window_counter_++;}
259 boundary.
lower = lower;
260 boundary.
upper = upper;
264 swath_map_boundaries_.push_back(boundary);
267 <<
" m/z with an isolation window of " << lower <<
" to " << upper
268 <<
" m/z and IM lower limit of " << lowerIm <<
" and upper limit of " << upperIm << std::endl;
345 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
346 swath_maps_.push_back(exp);
351 while (swath_maps_.size() <= swath_nr)
356 swath_maps_[swath_nr]->addSpectrum(s);
361 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
371 ms1_map_->addSpectrum(s);
396 ms1_consumer_(nullptr),
400 nr_ms1_spectra_(nr_ms1_spectra),
401 nr_ms2_spectra_(nr_ms2_spectra)
405 String cachedir,
String basename,
Size nr_ms1_spectra, std::vector<int> nr_ms2_spectra) :
407 ms1_consumer_(nullptr),
411 nr_ms1_spectra_(nr_ms1_spectra),
412 nr_ms2_spectra_(nr_ms2_spectra)
418 while (!swath_consumers_.empty())
420 delete swath_consumers_.back();
421 swath_consumers_.pop_back();
423 if (ms1_consumer_ !=
nullptr)
425 delete ms1_consumer_;
426 ms1_consumer_ =
nullptr;
433 String meta_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
434 String cached_file = meta_file +
".cached";
436 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
437 swath_consumers_.push_back(consumer);
440 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
441 swath_maps_.push_back(exp);
446 while (swath_maps_.size() <= swath_nr)
450 swath_consumers_[swath_nr]->consumeSpectrum(s);
451 swath_maps_[swath_nr]->addSpectrum(s);
456 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
457 String cached_file = meta_file +
".cached";
459 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
460 boost::shared_ptr<PeakMap > exp(
new PeakMap(settings_));
466 if (ms1_consumer_ ==
nullptr)
470 ms1_consumer_->consumeSpectrum(s);
471 ms1_map_->addSpectrum(s);
476 size_t swath_consumers_size = swath_consumers_.size();
477 bool have_ms1 = (ms1_consumer_ !=
nullptr);
487 while (!swath_consumers_.empty())
489 delete swath_consumers_.back();
490 swath_consumers_.pop_back();
492 if (ms1_consumer_ !=
nullptr)
494 delete ms1_consumer_;
495 ms1_consumer_ =
nullptr;
500 boost::shared_ptr<PeakMap > exp(
new PeakMap);
501 String meta_file = cachedir_ + basename_ +
"_ms1.mzML";
509 #pragma omp parallel for
511 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(swath_consumers_size); i++)
513 boost::shared_ptr<PeakMap > exp(
new PeakMap);
514 String meta_file = cachedir_ + basename_ +
"_" +
String(i) +
".mzML";
518 swath_maps_[i] = exp;
553 ms1_consumer_(nullptr),
557 nr_ms1_spectra_(nr_ms1_spectra),
558 nr_ms2_spectra_(nr_ms2_spectra)
562 const String& cachedir,
const String& basename,
Size nr_ms1_spectra,
const std::vector<int>& nr_ms2_spectra) :
564 ms1_consumer_(nullptr),
568 nr_ms1_spectra_(nr_ms1_spectra),
569 nr_ms2_spectra_(nr_ms2_spectra)
582 while (!swath_consumers_.empty())
584 delete swath_consumers_.back();
585 swath_consumers_.pop_back();
587 if (ms1_consumer_ !=
nullptr)
589 delete ms1_consumer_;
590 ms1_consumer_ =
nullptr;
596 String mzml_file = cachedir_ + basename_ +
"_" +
String(swath_consumers_.size()) +
".mzML";
599 consumer->
setExpectedSize(nr_ms2_spectra_[swath_consumers_.size()], 0);
600 swath_consumers_.push_back(consumer);
606 while (swath_consumers_.size() <= swath_nr)
610 swath_consumers_[swath_nr]->consumeSpectrum(s);
616 String mzml_file = cachedir_ + basename_ +
"_ms1.mzML";
618 ms1_consumer_->setExpectedSize(nr_ms1_spectra_, 0);
619 ms1_consumer_->getOptions().setCompression(
true);
624 if (ms1_consumer_ ==
nullptr)
628 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:388
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:464
std::vector< MSDataCachedConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:523
void addMS1Map_()
Definition: SwathFileConsumer.h:454
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:474
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:404
String basename_
Definition: SwathFileConsumer.h:526
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:393
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:528
~CachedSwathFileConsumer() override
Definition: SwathFileConsumer.h:415
MSDataCachedConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:522
PeakMap MapType
Definition: SwathFileConsumer.h:391
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:444
String cachedir_
Definition: SwathFileConsumer.h:525
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:392
CachedSwathFileConsumer(String cachedir, String basename, Size nr_ms1_spectra, std::vector< int > nr_ms2_spectra)
Definition: SwathFileConsumer.h:395
void addNewSwathMap_()
Definition: SwathFileConsumer.h:431
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:527
A method or algorithm argument contains illegal values.
Definition: Exception.h:629
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:316
Description of the experimental settings.
Definition: ExperimentalSettings.h:36
Facilitates file handling by file type recognition.
Definition: FileHandler.h:45
void loadExperiment(const String &filename, PeakMap &exp, const std::vector< FileTypes::Type > allowed_types=std::vector< FileTypes::Type >(), ProgressLogger::LogType log=ProgressLogger::NONE, const bool rewrite_source_file=false, const bool compute_hash=false)
Loads a file into an MSExperiment.
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file.
Definition: SwathFileConsumer.h:77
size_t correct_window_counter_
How many windows were correctly annotated (non-zero window limits)
Definition: SwathFileConsumer.h:318
FullSwathFileConsumer(std::vector< OpenSwath::SwathMap > swath_boundaries)
Constructor.
Definition: SwathFileConsumer.h:100
~FullSwathFileConsumer() override
Definition: SwathFileConsumer.h:110
bool consuming_possible_
Whether further spectra can still be consumed.
Definition: SwathFileConsumer.h:312
FullSwathFileConsumer()
Definition: SwathFileConsumer.h:84
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:82
std::vector< boost::shared_ptr< PeakMap > > swath_maps_
A list of SWATH maps and the MS1 map.
Definition: SwathFileConsumer.h:304
PeakMap settings_
The Experimental settings.
Definition: SwathFileConsumer.h:309
void setExpectedSize(Size, Size) override
Set expected size of spectra and chromatograms to be consumed.
Definition: SwathFileConsumer.h:112
virtual void consumeMS1Spectrum_(MapType::SpectrumType &s)=0
Consume an MS1 spectrum.
boost::shared_ptr< PeakMap > ms1_map_
Definition: SwathFileConsumer.h:305
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:80
void consumeChromatogram(MapType::ChromatogramType &) override
Consume a chromatogram -> should not happen when dealing with SWATH maps.
Definition: SwathFileConsumer.h:175
std::vector< OpenSwath::SwathMap > swath_map_boundaries_
A list of Swath map identifiers (lower/upper boundary and center)
Definition: SwathFileConsumer.h:301
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:126
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings (meta-data) of the data to be consumed.
Definition: SwathFileConsumer.h:113
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:185
bool use_external_boundaries_
Whether to use external input for SWATH boundaries.
Definition: SwathFileConsumer.h:315
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:81
virtual void ensureMapsAreFilled_()=0
Callback function after the reading is complete.
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:46
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:41
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:30
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.
On-disk mzML implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:545
std::vector< PlainMSDataWritingConsumer * > swath_consumers_
Definition: SwathFileConsumer.h:637
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:622
PlainMSDataWritingConsumer * ms1_consumer_
Definition: SwathFileConsumer.h:636
void addMS1Map_()
Definition: SwathFileConsumer.h:614
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:561
~MzMLSwathFileConsumer() override
Definition: SwathFileConsumer.h:572
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:631
MzMLSwathFileConsumer(const String &cachedir, const String &basename, Size nr_ms1_spectra, const std::vector< int > &nr_ms2_spectra)
Definition: SwathFileConsumer.h:552
String basename_
Definition: SwathFileConsumer.h:640
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:550
std::vector< int > nr_ms2_spectra_
Definition: SwathFileConsumer.h:642
PeakMap MapType
Definition: SwathFileConsumer.h:548
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:603
String cachedir_
Definition: SwathFileConsumer.h:639
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:549
void addNewSwathMap_()
Definition: SwathFileConsumer.h:594
int nr_ms1_spectra_
Definition: SwathFileConsumer.h:641
void deleteSetNull_()
Definition: SwathFileConsumer.h:579
void setCompression(bool compress)
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:215
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:330
void consumeMS1Spectrum_(MapType::SpectrumType &s) override
Consume an MS1 spectrum.
Definition: SwathFileConsumer.h:365
RegularSwathFileConsumer()
Definition: SwathFileConsumer.h:337
void addMS1Map_()
Definition: SwathFileConsumer.h:359
void ensureMapsAreFilled_() override
Callback function after the reading is complete.
Definition: SwathFileConsumer.h:374
MapType::ChromatogramType ChromatogramType
Definition: SwathFileConsumer.h:335
PeakMap MapType
Definition: SwathFileConsumer.h:333
void consumeSwathSpectrum_(MapType::SpectrumType &s, size_t swath_nr) override
Consume an MS2 spectrum belonging to SWATH "swath_nr".
Definition: SwathFileConsumer.h:349
MapType::SpectrumType SpectrumType
Definition: SwathFileConsumer.h:334
void addNewSwathMap_()
Definition: SwathFileConsumer.h:343
RegularSwathFileConsumer(std::vector< OpenSwath::SwathMap > known_window_boundaries)
Definition: SwathFileConsumer.h:339
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:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition: StandardTypes.h:34
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:21
bool ms1
Definition: SwathMap.h:28
double imUpper
Definition: SwathMap.h:27
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:22
double center
Definition: SwathMap.h:25
double lower
Definition: SwathMap.h:23
double imLower
Definition: SwathMap.h:26
double upper
Definition: SwathMap.h:24