35 #ifndef OPENMS_FORMAT_SWATHFILE_H
36 #define OPENMS_FORMAT_SWATHFILE_H
41 #ifdef OPENMS_FORMAT_SWATHFILE_MZXMLSUPPORT
69 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
72 startProgress(0, file_list.size(),
"Loading data");
74 std::vector<OpenSwath::SwathMap> swath_maps(file_list.size());
76 #pragma omp parallel for
78 for (
SignedSize i = 0; i < boost::numeric_cast<SignedSize>(file_list.size()); ++i)
82 #pragma omp critical (OPENMS_SwathFile_loadSplit)
85 std::cout <<
"Loading file " << i <<
" with name " << file_list[i] <<
" using readoptions " << readoptions << std::endl;
88 String tmp_fname =
"openswath_tmpfile_" +
String(i) +
".mzML";
96 exp_meta = populateMetaData_(file_list[i]);
99 if (readoptions ==
"normal")
104 else if (readoptions ==
"cache")
107 spectra_ptr = doCacheFile_(file_list[i], tmp, tmp_fname, exp);
112 "Unknown option " + readoptions);
118 double upper = -1, lower = -1;
119 if (exp->size() == 0)
121 std::cerr <<
"WARNING: File " << file_list[i] <<
"\n does not have any scans - I will skip it" << std::endl;
124 if (exp->getSpectra()[0].getPrecursors().size() == 0)
126 std::cout <<
"NOTE: File " << file_list[i] <<
"\n does not have any precursors - I will assume it is the MS1 scan." << std::endl;
135 swath_map.
sptr = spectra_ptr;
136 swath_map.
lower = lower;
137 swath_map.
upper = upper;
140 #pragma omp critical (OPENMS_SwathFile_loadSplit)
143 LOG_DEBUG <<
"Adding Swath file " << file_list[i] <<
" with " << swath_map.
lower <<
" to " << swath_map.
upper << std::endl;
144 swath_maps[i] = swath_map;
145 setProgress(progress++);
154 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
156 std::cout <<
"Loading mzML file " << file <<
" using readoptions " << readoptions << std::endl;
157 String tmp_fname =
"openswath_tmpfile";
159 startProgress(0, 1,
"Loading metadata file " + file);
160 boost::shared_ptr<MSExperiment<Peak1D> > experiment_metadata = populateMetaData_(file);
161 exp_meta = experiment_metadata;
164 std::cout <<
"Will analyze the metadata first to determine the number of SWATH windows and the window sizes." << std::endl;
165 std::vector<int> swath_counter;
167 std::vector<OpenSwath::SwathMap> known_window_boundaries;
168 countScansInSwath_(experiment_metadata->getSpectra(), swath_counter, nr_ms1_spectra, known_window_boundaries);
169 std::cout <<
"Determined there to be " << swath_counter.size() <<
170 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
175 startProgress(0, 1,
"Loading data file " + file);
176 if (readoptions ==
"normal")
181 else if (readoptions ==
"cache")
183 dataConsumer =
new CachedSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
189 "Unknown or unsupported option " + readoptions);
191 LOG_DEBUG <<
"Finished parsing Swath file " << std::endl;
192 std::vector<OpenSwath::SwathMap> swath_maps;
202 boost::shared_ptr<ExperimentalSettings>& exp_meta,
String readoptions =
"normal")
204 std::cout <<
"Loading mzXML file " << file <<
" using readoptions " << readoptions << std::endl;
205 String tmp_fname =
"openswath_tmpfile";
207 startProgress(0, 1,
"Loading metadata file " + file);
212 f.
load(file, *experiment_metadata);
213 exp_meta = experiment_metadata;
216 std::cout <<
"Will analyze the metadata first to determine the number of SWATH windows and the window sizes." << std::endl;
217 std::vector<int> swath_counter;
219 std::vector<OpenSwath::SwathMap> known_window_boundaries;
220 countScansInSwath_(experiment_metadata->getSpectra(), swath_counter, nr_ms1_spectra, known_window_boundaries);
221 std::cout <<
"Determined there to be " << swath_counter.size() <<
222 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
227 startProgress(0, 1,
"Loading data file " + file);
228 if (readoptions ==
"normal")
233 else if (readoptions ==
"cache")
235 dataConsumer =
new CachedSwathFileConsumer(known_window_boundaries, tmp, tmp_fname, nr_ms1_spectra, swath_counter);
241 "Unknown or unsupported option " + readoptions);
243 LOG_DEBUG <<
"Finished parsing Swath file " << std::endl;
244 std::vector<OpenSwath::SwathMap> swath_maps;
258 String cached_file = tmp + tmp_fname +
".cached";
259 String meta_file = tmp + tmp_fname;
265 delete cachedConsumer;
279 f.
load(file, *experiment_metadata);
280 return experiment_metadata;
285 std::vector<int>& swath_counter,
int& nr_ms1_spectra,
286 std::vector<OpenSwath::SwathMap>& known_window_boundaries)
289 for (
Size i = 0; i < exp.size(); i++)
302 "Found SWATH scan (MS level 2 scan) without a precursor. Cannot determine SWATH window.");
305 double center = prec[0].getMZ();
307 for (
Size j = 0; j < known_window_boundaries.size(); j++)
311 if (std::fabs(center - known_window_boundaries[j].center) < 1e-6)
320 swath_counter.push_back(1);
321 double lower = prec[0].getMZ() - prec[0].getIsolationWindowLowerOffset();
322 double upper = prec[0].getMZ() + prec[0].getIsolationWindowUpperOffset();
324 boundary.
lower = lower;
325 boundary.
upper = upper;
327 known_window_boundaries.push_back(boundary);
329 LOG_DEBUG <<
"Adding Swath centered at " << center
330 <<
" m/z with an isolation window of " << lower <<
" to " << upper
331 <<
" m/z." << std::endl;
336 nr_ms1_spectra = ms1_counter;
338 std::cout <<
"Determined there to be " << swath_counter.size() <<
339 " SWATH windows and in total " << nr_ms1_spectra <<
" MS1 spectra" << std::endl;
static OpenSwath::SpectrumAccessPtr getSpectrumAccessOpenMSPtr(boost::shared_ptr< OpenMS::MSExperiment< OpenMS::Peak1D > > exp)
Simple Factory method to get a SpectrumAccess Ptr from an MSExperiment.
A more convenient string class.
Definition: String.h:57
File adapter for MzXML 2.1 files.
Definition: MzXMLFile.h:53
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:259
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:90
void load(const String &filename, MapType &map)
Loads a map from a MzXML file.
Definition: MzXMLFile.h:81
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:153
void retrieveSwathMaps(std::vector< OpenSwath::SwathMap > &maps)
Populate the vector of swath maps after consuming all spectra.
Definition: SwathFileConsumer.h:150
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:128
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:51
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:201
#define LOG_DEBUG
Macro for general debugging information.
Definition: LogStream.h:459
boost::shared_ptr< MSExperiment< Peak1D > > populateMetaData_(String file)
Only read the meta data from a file and use it to populate exp_meta.
Definition: SwathFile.h:273
Abstract base class which can consume spectra coming from SWATH experiment stored in a single file...
Definition: SwathFileConsumer.h:99
void transform(const String &filename_in, Interfaces::IMSDataConsumer< MapType > *consumer, bool skip_full_count=false)
Transforms a map while loading using the supplied MSDataConsumer.
Definition: MzXMLFile.h:127
File adapter for MzML files.
Definition: MzMLFile.h:55
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
File adapter for Swath files.
Definition: SwathFile.h:62
On-disk cached implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:391
void load(const String &filename, MapType &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
Definition: MzMLFile.h:83
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
OpenSwath::SpectrumAccessPtr doCacheFile_(String in, String tmp, String tmp_fname, boost::shared_ptr< MSExperiment< Peak1D > > experiment_metadata)
Cache a file to disk.
Definition: SwathFile.h:255
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:284
In-memory implementation of FullSwathFileConsumer.
Definition: SwathFileConsumer.h:333
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
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:68
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:62
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.
double center
Definition: SwathMap.h:51
void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
void transform(const String &filename_in, Interfaces::IMSDataConsumer< MapType > *consumer, bool skip_full_count=false)
Transforms a map while loading using the supplied MSDataConsumer.
Definition: MzMLFile.h:135
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.
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
static void checkSwathMap(const OpenMS::MSExperiment< Peak1D > &swath_map, double &lower, double &upper)
Get the lower / upper offset for this SWATH map and do some sanity checks.