35 #ifndef OPENMS_FORMAT_SWATHFILE_H 36 #define OPENMS_FORMAT_SWATHFILE_H 48 #ifdef OPENMS_FORMAT_SWATHFILE_MZXMLSUPPORT 76 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
79 startProgress(0, file_list.size(),
"Loading data");
81 std::vector<OpenSwath::SwathMap> swath_maps(file_list.size());
83 #pragma omp parallel for 85 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(file_list.size()); ++i)
89 #pragma omp critical (OPENMS_SwathFile_loadSplit) 92 std::cout <<
"Loading file " << i <<
" with name " << file_list[i] <<
" using readoptions " << readoptions << std::endl;
95 String tmp_fname =
"openswath_tmpfile_" +
String(i) +
".mzML";
97 boost::shared_ptr<PeakMap > exp(
new PeakMap);
103 exp_meta = populateMetaData_(file_list[i]);
106 if (readoptions ==
"normal")
111 else if (readoptions ==
"cache")
114 spectra_ptr = doCacheFile_(file_list[i], tmp, tmp_fname, exp);
119 "Unknown option " + readoptions);
125 double upper = -1, lower = -1;
126 if (exp->size() == 0)
128 std::cerr <<
"WARNING: File " << file_list[i] <<
"\n does not have any scans - I will skip it" << std::endl;
131 if (exp->getSpectra()[0].getPrecursors().size() == 0)
133 std::cout <<
"NOTE: File " << file_list[i] <<
"\n does not have any precursors - I will assume it is the MS1 scan." << std::endl;
142 swath_map.
sptr = spectra_ptr;
143 swath_map.
lower = lower;
144 swath_map.
upper = upper;
147 #pragma omp critical (OPENMS_SwathFile_loadSplit) 150 LOG_DEBUG <<
"Adding Swath file " << file_list[i] <<
" with " << swath_map.
lower <<
" to " << swath_map.
upper << std::endl;
151 swath_maps[i] = swath_map;
152 setProgress(progress++);
161 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
163 std::cout <<
"Loading mzML file " << file <<
" using readoptions " << readoptions << std::endl;
164 String tmp_fname =
"openswath_tmpfile";
166 startProgress(0, 1,
"Loading metadata file " + file);
167 boost::shared_ptr<PeakMap> experiment_metadata = populateMetaData_(file);
168 exp_meta = experiment_metadata;
171 std::cout <<
"Will analyze the metadata first to determine the number of SWATH windows and the window sizes." << std::endl;
172 std::vector<int> swath_counter;
174 std::vector<OpenSwath::SwathMap> known_window_boundaries;
175 countScansInSwath_(experiment_metadata->getSpectra(), swath_counter, nr_ms1_spectra, known_window_boundaries);
176 std::cout <<
"Determined there to be " << swath_counter.size() <<
177 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
181 boost::shared_ptr<PeakMap> exp(
new PeakMap);
182 startProgress(0, 1,
"Loading data file " + file);
183 if (readoptions ==
"normal")
188 else if (readoptions ==
"cache")
190 dataConsumer =
new CachedSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
193 else if (readoptions ==
"split")
195 dataConsumer =
new MzMLSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
201 "Unknown or unsupported option " + readoptions);
203 LOG_DEBUG <<
"Finished parsing Swath file " << std::endl;
204 std::vector<OpenSwath::SwathMap> swath_maps;
214 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
216 std::cout <<
"Loading mzXML file " << file <<
" using readoptions " << readoptions << std::endl;
217 String tmp_fname =
"openswath_tmpfile";
219 startProgress(0, 1,
"Loading metadata file " + file);
220 boost::shared_ptr<PeakMap > experiment_metadata(
new PeakMap);
224 f.
load(file, *experiment_metadata);
225 exp_meta = experiment_metadata;
228 std::cout <<
"Will analyze the metadata first to determine the number of SWATH windows and the window sizes." << std::endl;
229 std::vector<int> swath_counter;
231 std::vector<OpenSwath::SwathMap> known_window_boundaries;
232 countScansInSwath_(experiment_metadata->getSpectra(), swath_counter, nr_ms1_spectra, known_window_boundaries);
233 std::cout <<
"Determined there to be " << swath_counter.size() <<
234 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
238 boost::shared_ptr<PeakMap > exp(
new PeakMap);
239 startProgress(0, 1,
"Loading data file " + file);
240 if (readoptions ==
"normal")
245 else if (readoptions ==
"cache")
247 dataConsumer =
new CachedSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
250 else if (readoptions ==
"split")
252 dataConsumer =
new MzMLSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
258 "Unknown or unsupported option " + readoptions);
260 LOG_DEBUG <<
"Finished parsing Swath file " << std::endl;
261 std::vector<OpenSwath::SwathMap> swath_maps;
273 boost::shared_ptr<PeakMap > experiment_metadata)
275 String cached_file = tmp + tmp_fname +
".cached";
276 String meta_file = tmp + tmp_fname;
282 delete cachedConsumer;
284 boost::shared_ptr<PeakMap > exp(
new PeakMap);
292 boost::shared_ptr<PeakMap > experiment_metadata(
new PeakMap);
296 f.
load(file, *experiment_metadata);
297 return experiment_metadata;
302 std::vector<int>& swath_counter,
int& nr_ms1_spectra,
303 std::vector<OpenSwath::SwathMap>& known_window_boundaries)
306 for (
Size i = 0; i < exp.size(); i++)
319 "Found SWATH scan (MS level 2 scan) without a precursor. Cannot determine SWATH window.");
322 double center = prec[0].getMZ();
324 for (
Size j = 0; j < known_window_boundaries.size(); j++)
328 if (std::fabs(center - known_window_boundaries[j].center) < 1e-6)
337 swath_counter.push_back(1);
338 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
339 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
341 boundary.
lower = lower;
342 boundary.
upper = upper;
344 known_window_boundaries.push_back(boundary);
346 LOG_DEBUG <<
"Adding Swath centered at " << center
347 <<
" m/z with an isolation window of " << lower <<
" to " << upper
348 <<
" m/z." << std::endl;
353 nr_ms1_spectra = ms1_counter;
355 std::cout <<
"Determined there to be " << swath_counter.size() <<
356 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
A more convenient string class.
Definition: String.h:57
File adapter for MzXML 3.1 files.
Definition: MzXMLFile.h:53
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:90
static OpenSwath::SpectrumAccessPtr getSpectrumAccessOpenMSPtr(boost::shared_ptr< OpenMS::PeakMap > exp)
Simple Factory method to get a SpectrumAccess Ptr from an MSExperiment.
std::vector< OpenSwath::SwathMap > loadMzML(String file, String tmp, boost::shared_ptr< ExperimentalSettings > &exp_meta, String readoptions="normal")
Loads a Swath run from a single mzML file.
Definition: SwathFile.h:160
OpenSwath::SpectrumAccessPtr doCacheFile_(String in, String tmp, String tmp_fname, boost::shared_ptr< PeakMap > experiment_metadata)
Cache a file to disk.
Definition: SwathFile.h:272
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
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:55
std::vector< OpenSwath::SwathMap > loadMzXML(String file, String tmp, boost::shared_ptr< ExperimentalSettings > &exp_meta, String readoptions="normal")
Loads a Swath run from a single mzXML file.
Definition: SwathFile.h:213
boost::shared_ptr< PeakMap > populateMetaData_(String file)
Only read the meta data from a file and use it to populate exp_meta.
Definition: SwathFile.h:290
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
#define LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:459
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file...
Definition: SwathFileConsumer.h:101
void load(const String &filename, MapType &map)
Loads a map from a MzXML file.
File adapter for MzML files.
Definition: MzMLFile.h:56
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
A method or algorithm argument contains illegal values.
Definition: Exception.h:649
File adapter for Swath files.
Definition: SwathFile.h:69
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 cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:392
Data structure to hold one SWATH map with information about upper / lower isolation window and whethe...
Definition: SwathMap.h:46
OpenSwath::SpectrumAccessPtr sptr
Definition: SwathMap.h:48
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
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
std::vector< OpenSwath::SwathMap > loadSplit(StringList file_list, String tmp, boost::shared_ptr< ExperimentalSettings > &exp_meta, String readoptions="normal")
Loads a Swath run from a list of split mzML files.
Definition: SwathFile.h:75
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:64
static void checkSwathMap(const OpenMS::PeakMap &swath_map, double &lower, double &upper)
Get the lower / upper offset for this SWATH map and do some sanity checks.
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
void transform(const String &filename_in, Interfaces::IMSDataConsumer *consumer, bool skip_full_count=false)
Transforms a map while loading using the supplied MSDataConsumer.
UInt getMSLevel() const
Returns the MS level.
void countScansInSwath_(const std::vector< MSSpectrum > exp, std::vector< int > &swath_counter, int &nr_ms1_spectra, std::vector< OpenSwath::SwathMap > &known_window_boundaries)
Counts the number of scans in a full Swath file (e.g. concatenated non-split file) ...
Definition: SwathFile.h:301
double center
Definition: SwathMap.h:51
void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
void setAlwaysAppendData(bool only)
sets whether or not to always append the data to the given map (even if a consumer is given) ...
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
void transform(const String &filename_in, Interfaces::IMSDataConsumer *consumer, bool skip_full_count=false, bool skip_first_pass=false)
Transforms a map while loading using the supplied MSDataConsumer.
double upper
Definition: SwathMap.h:50
void setFillData(bool only)
sets whether to fill the actual data into the container (spectrum/chromatogram)
bool ms1
Definition: SwathMap.h:52
double lower
Definition: SwathMap.h:49