forked from OpenMS/OpenMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial_FileIO_Consumer.cpp
More file actions
48 lines (39 loc) · 1.62 KB
/
Copy pathTutorial_FileIO_Consumer.cpp
File metadata and controls
48 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
// SPDX-License-Identifier: BSD-3-Clause
//
#include <OpenMS/FORMAT/MzMLFile.h>
#include <OpenMS/FORMAT/DATAACCESS/MSDataWritingConsumer.h>
#include <OpenMS/SYSTEM/File.h>
#include <OpenMS/openms_data_path.h> // exotic header for path to tutorial data
#include <iostream>
using namespace OpenMS;
using namespace std;
class TICWritingConsumer : public MSDataWritingConsumer
{
// Inheriting from MSDataWritingConsumer allows to change the data before
// they are written to disk (to "filename") using the processSpectrum_ and
// processChromatogram_ functions.
public:
double TIC {};
int nr_spectra {};
// Create new consumer
TICWritingConsumer(const String& filename) : MSDataWritingConsumer(filename)
{}
// Add a data processing step for spectra before they are written to disk
void processSpectrum_(MSDataWritingConsumer::SpectrumType & s) override
{
for (const auto& p : s) TIC += p.getIntensity();
nr_spectra++;
}
// Empty chromatogram data processing
void processChromatogram_(MSDataWritingConsumer::ChromatogramType& /* c */) override {}
};
int main(int argc, const char** argv)
{
auto file_mzXML = OPENMS_DOC_PATH + String("/code_examples/data/Tutorial_FileIO_indexed.mzML");
// Create the consumer, set output file name, transform
TICWritingConsumer consumer("Tutorial_FileIO_output.mzML");
MzMLFile().transform(file_mzXML, &consumer);
std::cout << "There are " << consumer.nr_spectra << " spectra in the input file.\n";
std::cout << "The total ion current is " << consumer.TIC << std::endl;
} //end of main