35 #ifndef OPENMS_ANALYSIS_OPENSWATH_CACHEDMZML_H
36 #define OPENMS_ANALYSIS_OPENSWATH_CACHEDMZML_H
48 #define MAGIC_NUMBER 8093
110 void writeMemdump(MapType& exp,
String out)
113 std::ofstream ofs(out.c_str(), std::ios::binary);
114 Size exp_size = exp.size();
115 Size chrom_size = exp.getChromatograms().size();
117 ofs.write((
char*)&magic_number,
sizeof(magic_number));
118 ofs.write((
char*)&exp_size,
sizeof(exp_size));
119 ofs.write((
char*)&chrom_size,
sizeof(chrom_size));
121 startProgress(0, exp.size() + exp.getChromatograms().size(),
"storing binary spectra");
122 for (
Size i = 0; i < exp.size(); i++)
125 writeSpectrum_(exp[i], ofs);
128 for (
Size i = 0; i < exp.getChromatograms().size(); i++)
131 writeChromatogram_(exp.getChromatograms()[i], ofs);
141 std::ifstream ifs(filename.c_str(), std::ios::binary);
142 Size exp_size, chrom_size;
146 ifs.read((
char*)&magic_number,
sizeof(magic_number));
149 throw "wrong file, does not start with MAGIC_NUMBER";
152 ifs.read((
char*)&exp_size,
sizeof(exp_size));
153 ifs.read((
char*)&chrom_size,
sizeof(chrom_size));
156 startProgress(0, exp_size + chrom_size,
"reading binary spectra");
157 for (
Size i = 0; i < exp_size; i++)
161 readSpectrum_(spectrum, ifs);
164 std::vector<ChromatogramType> chromatograms;
165 for (
Size i = 0; i < chrom_size; i++)
169 readChromatogram_(chromatogram, ifs);
170 chromatograms.push_back(chromatogram);
187 std::ifstream ifs(filename.c_str(), std::ios::binary);
188 readSingleSpectrum(spectrum, ifs, idx);
196 readSpectrum_(spectrum, ifs);
206 return spectra_index_;
219 std::ifstream ifs(filename.c_str(), std::ios::binary);
220 Size exp_size, chrom_size;
223 spectra_index_.clear();
224 chrom_index_.clear();
226 int extra_offset =
sizeof(dbl_field_) +
sizeof(int_field_);
227 int chrom_offset = 0;
229 ifs.read((
char*)&magic_number,
sizeof(magic_number));
232 throw "wrong file, does not start with MAGIC_NUMBER";
238 ifs.read((
char*)&exp_size,
sizeof(exp_size));
239 ifs.read((
char*)&chrom_size,
sizeof(chrom_size));
240 startProgress(0, exp_size + chrom_size,
"Creating index for binary spectra");
241 for (
Size i = 0; i < exp_size; i++)
246 spectra_index_.push_back(ifs.tellg());
247 ifs.read((
char*)&spec_size,
sizeof(spec_size));
248 ifs.seekg((
int)ifs.tellg() + extra_offset + (
sizeof(
DatumSingleton)) * 2 * (spec_size));
252 for (
Size i = 0; i < chrom_size; i++)
257 chrom_index_.push_back(ifs.tellg());
258 ifs.read((
char*)&chrom_size,
sizeof(chrom_size));
259 ifs.seekg((
int)ifs.tellg() + chrom_offset + (
sizeof(
DatumSingleton)) * 2 * (chrom_size));
271 std::vector<MSChromatogram<ChromatogramPeak> > chromatograms = exp.
getChromatograms();
272 for (
Size i = 0; i < exp.
size(); i++)
280 chromatograms[i].clear(
false);
286 f.
store(out_meta, exp);
295 ifs.read((
char*) &spec_size,
sizeof(spec_size));
296 ifs.read((
char*) &ms_level,
sizeof(ms_level));
297 ifs.read((
char*) &rt,
sizeof(rt));
299 data1->data.resize(spec_size);
300 data2->data.resize(spec_size);
301 ifs.read((
char*) &(data1->data)[0], spec_size *
sizeof(
double));
302 ifs.read((
char*) &(data2->data)[0], spec_size *
sizeof(
double));
310 ifs.read((
char*) &spec_size,
sizeof(spec_size));
311 data1->data.resize(spec_size);
313 data2->data.resize(spec_size);
314 ifs.read((
char*) &(data1->data)[0], spec_size *
sizeof(
double));
315 ifs.read((
char*) &(data2->data)[0], spec_size *
sizeof(
double));
324 ifs.read((
char*)&spec_size,
sizeof(spec_size));
325 ifs.read((
char*)&ms_level,
sizeof(ms_level));
326 ifs.read((
char*)&rt,
sizeof(rt));
328 data1.resize(spec_size);
329 data2.resize(spec_size);
338 ifs.read((
char*)&spec_size,
sizeof(spec_size));
339 data1.resize(spec_size);
340 data2.resize(spec_size);
353 readSpectrum_(mz_data, int_data, ifs, ms_level, rt);
354 spectrum.reserve(mz_data.size());
358 for (
Size j = 0; j < mz_data.size(); j++)
363 spectrum.push_back(p);
373 readChromatogram_(rt_data, int_data, ifs);
374 chromatogram.reserve(rt_data.size());
376 for (
Size j = 0; j < rt_data.size(); j++)
381 chromatogram.push_back(p);
389 Size exp_size = spectrum.size();
390 ofs.write((
char*)&exp_size,
sizeof(exp_size));
392 ofs.write((
char*)&int_field_,
sizeof(int_field_));
393 dbl_field_ = spectrum.
getRT();
394 ofs.write((
char*)&dbl_field_,
sizeof(dbl_field_));
397 ofs.write((
char*)&exp[i].front(), exp[i].size() *
sizeof(exp[i].front()));
398 std::cout <<
" storing spectrum " << i <<
" with size " << exp[i].size() << std::endl;
402 for (
Size j = 0; j < spectrum.size(); j++)
404 mz_data.push_back(spectrum[j].getMZ());
405 int_data.push_back(spectrum[j].getIntensity());
407 ofs.write((
char*)&mz_data.front(), mz_data.size() *
sizeof(mz_data.front()));
408 ofs.write((
char*)&int_data.front(), int_data.size() *
sizeof(int_data.front()));
416 Size exp_size = chromatogram.size();
417 ofs.write((
char*)&exp_size,
sizeof(exp_size));
420 for (
Size j = 0; j < chromatogram.size(); j++)
422 rt_data.push_back(chromatogram[j].getRT());
423 int_data.push_back(chromatogram[j].getIntensity());
425 ofs.write((
char*)&rt_data.front(), rt_data.size() *
sizeof(rt_data.front()));
426 ofs.write((
char*)&int_data.front(), int_data.size() *
sizeof(int_data.front()));
void setRT(CoordinateType rt)
Mutable access to RT.
Definition: ChromatogramPeak.h:117
MSSpectrum< Peak1D > SpectrumType
Definition: CachedmzML.h:69
A more convenient string class.
Definition: String.h:56
void createMemdumpIndex(String filename)
Create an index on the location of all the spectra and chromatograms.
Definition: CachedmzML.h:217
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:231
Size size() const
Definition: MSExperiment.h:117
std::vector< Size > spectra_index_
Definition: CachedmzML.h:429
The representation of a chromatogram.
Definition: MSChromatogram.h:53
void writeChromatogram_(const ChromatogramType &chromatogram, std::ofstream &ofs)
Definition: CachedmzML.h:414
double DatumSingleton
Definition: CachedmzML.h:73
void readSingleSpectrum(MSSpectrum< Peak1D > &spectrum, std::ifstream &ifs, const Size &idx) const
Definition: CachedmzML.h:192
MSChromatogram< ChromatogramPeak > ChromatogramType
Definition: CachedmzML.h:70
MSExperiment< Peak1D > MapType
Definition: CachedmzML.h:68
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:114
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: Peak1D.h:105
File adapter for MzML files.
Definition: MzMLFile.h:58
void readChromatogram_(ChromatogramType &chromatogram, std::ifstream &ifs) const
Definition: CachedmzML.h:369
void readMemdump(MapType &exp_reading, String filename) const
Read all spectra from a dump from the disk.
Definition: CachedmzML.h:139
void reserve(Size s)
Definition: MSExperiment.h:132
const std::vector< Size > & getSpectraIndex() const
Definition: CachedmzML.h:204
CachedmzML & operator=(const CachedmzML &rhs)
Assignment operator.
Definition: CachedmzML.h:94
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
void setMSLevel(UInt ms_level)
Sets the MS level.
Definition: MSSpectrum.h:237
void store(const String &filename, const MapType &map) const
Stores a map in a MzML file.
Definition: MzMLFile.h:126
const std::vector< Size > & getChromatogramIndex() const
Definition: CachedmzML.h:209
OPENSWATHALGO_DLLAPI typedef boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/DataStructures.h:77
std::vector< DatumSingleton > Datavector
Definition: CachedmzML.h:78
void addSpectrum(const MSSpectrum< PeakT > &spectrum)
adds a spectra to the list
Definition: MSExperiment.h:738
#define MAGIC_NUMBER
Definition: CachedmzML.h:48
void readSpectrum_(SpectrumType &spectrum, std::ifstream &ifs) const
Definition: CachedmzML.h:346
void setChromatograms(const std::vector< MSChromatogram< ChromatogramPeakType > > &chromatograms)
sets the chromatogram list
Definition: MSExperiment.h:756
void writeSpectrum_(const SpectrumType &spectrum, std::ofstream &ofs)
Definition: CachedmzML.h:387
void setIntensity(IntensityType intensity)
Mutable access to the data point intensity (height)
Definition: ChromatogramPeak.h:108
void setRT(DoubleReal rt)
Sets the absolute retention time (is seconds)
Definition: MSSpectrum.h:221
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedmzML.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
static void readChromatogramFast(OpenSwath::BinaryDataArrayPtr data1, OpenSwath::BinaryDataArrayPtr data2, std::ifstream &ifs)
fast access without copying
Definition: CachedmzML.h:306
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSExperiment.h:809
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
static void readSpectrumFast(OpenSwath::BinaryDataArrayPtr data1, OpenSwath::BinaryDataArrayPtr data2, std::ifstream &ifs, int ms_level, double rt)
fast access without copying
Definition: CachedmzML.h:290
void readSpectrum_(Datavector &data1, Datavector &data2, std::ifstream &ifs, int &ms_level, double &rt) const
Definition: CachedmzML.h:321
double dbl_field_
Definition: CachedmzML.h:64
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:55
int int_field_
Definition: CachedmzML.h:63
void readChromatogram_(Datavector &data1, Datavector &data2, std::ifstream &ifs) const
Definition: CachedmzML.h:335
DoubleReal getRT() const
Definition: MSSpectrum.h:215
std::vector< Size > chrom_index_
Definition: CachedmzML.h:430
~CachedmzML()
Default destructor.
Definition: CachedmzML.h:89
void writeMetadata(MapType exp, String out_meta)
Write only the meta data of an MSExperiment.
Definition: CachedmzML.h:268
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:768