ProteoWizard
Functions | Variables
Serializer_MGF_Test.cpp File Reference
#include "Serializer_MGF.hpp"
#include "Serializer_mzML.hpp"
#include "Diff.hpp"
#include "TextWriter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/utility/misc/Std.hpp"

Go to the source code of this file.

Functions

void initializeTinyMGF (MSData &msd)
 
void testWriteRead (const MSData &msd)
 
void testWriteRead ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ initializeTinyMGF()

void initializeTinyMGF ( MSData msd)

Definition at line 40 of file Serializer_MGF_Test.cpp.

41 {
43  fc.set(MS_MSn_spectrum);
45 
46  //SourceFilePtr sourceFile(new SourceFile);
47  //sourceFile->set(MS_multiple_peak_list_nativeID_format);
48  // TODO: sourceFile->set(MS_Matrix_Science_MGF_format);
49  //msd.fileDescription.sourceFilePtrs.push_back(sourceFile);
50 
51  shared_ptr<SpectrumListSimple> spectrumList(new SpectrumListSimple);
52  msd.run.spectrumListPtr = spectrumList;
53  spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
54  spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
55 
56  Spectrum& s20 = *spectrumList->spectra[0];
57  s20.id = "index=0";
58  s20.index = 0;
59  s20.set(MS_spectrum_title, s20.id);
60 
61  s20.set(MS_MSn_spectrum);
62  s20.set(MS_ms_level, 2);
63 
65  s20.set(MS_positive_scan);
66  s20.set(MS_lowest_observed_m_z, 0.0);
67  s20.set(MS_highest_observed_m_z, 18.0);
68  s20.set(MS_base_peak_m_z, 0.0);
69  s20.set(MS_base_peak_intensity, 20.0);
70  s20.set(MS_total_ion_current, 110.0);
71 
72  s20.precursors.resize(1);
73  Precursor& s20precursor = s20.precursors.front();
74  s20precursor.selectedIons.resize(1);
75  s20precursor.selectedIons[0].set(MS_selected_ion_m_z, 445.34, MS_m_z);
76  s20precursor.selectedIons[0].set(MS_peak_intensity, 120053.0, MS_number_of_detector_counts);
77  s20precursor.selectedIons[0].set(MS_charge_state, 2);
78 
80  s20.scanList.scans.push_back(Scan());
81  Scan& s20scan = s20.scanList.scans.back();
82  s20scan.set(MS_scan_start_time, 4.0, UO_second);
83 
84  s20.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_detector_counts);
85  BinaryData<double>& s20_mz = s20.getMZArray()->data;
86  BinaryData<double>& s20_intensity = s20.getIntensityArray()->data;
87 
88  for (int i=0; i<10; i++)
89  s20_mz.push_back(i*2);
90 
91  for (int i=0; i<10; i++)
92  s20_intensity.push_back((10-i)*2);
93 
94  s20.defaultArrayLength = s20_mz.size();
95 
96 
97  Spectrum& s21 = *spectrumList->spectra[1];
98  s21.id = "index=1";
99  s21.index = 1;
100  s21.set(MS_spectrum_title, s21.id);
101 
102  s21.set(MS_MSn_spectrum);
103  s21.set(MS_ms_level, 2);
104 
106  s21.set(MS_negative_scan);
107  s21.set(MS_lowest_observed_m_z, 3.0);
108  s21.set(MS_highest_observed_m_z, 30.0);
109  s21.set(MS_base_peak_m_z, 3.0);
110  s21.set(MS_base_peak_intensity, 30.0);
111  s21.set(MS_total_ion_current, 165.0);
112 
113  s21.precursors.resize(1);
114  Precursor& s21precursor = s21.precursors.front();
115  s21precursor.selectedIons.resize(1);
116  s21precursor.selectedIons[0].set(MS_selected_ion_m_z, 424.24, MS_m_z);
117  s21precursor.selectedIons[0].set(MS_peak_intensity, 4242.0, MS_number_of_detector_counts);
118  s21precursor.selectedIons[0].cvParams.push_back(CVParam(MS_possible_charge_state, 2));
119  s21precursor.selectedIons[0].cvParams.push_back(CVParam(MS_possible_charge_state, 3));
120 
122  s21.scanList.scans.push_back(Scan());
123  Scan& s21scan = s21.scanList.scans.back();
124  s21scan.set(MS_scan_start_time, 42.0, UO_second);
125 
126  s21.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_detector_counts);
127  BinaryData<double>& s21_mz = s21.getMZArray()->data;
128  BinaryData<double>& s21_intensity = s21.getIntensityArray()->data;
129 
130  for (int i=1; i<=10; i++)
131  s21_mz.push_back(i*3);
132 
133  for (int i=0; i<10; i++)
134  s21_intensity.push_back((10-i)*3);
135 
136  s21.defaultArrayLength = s21_mz.size();
137 
138 } // initializeTinyMGF()

References pwiz::msdata::Spectrum::defaultArrayLength, pwiz::msdata::FileDescription::fileContent, pwiz::msdata::MSData::fileDescription, pwiz::msdata::Spectrum::getIntensityArray(), pwiz::msdata::Spectrum::getMZArray(), pwiz::msdata::SpectrumIdentity::id, pwiz::msdata::SpectrumIdentity::index, MS_base_peak_intensity, MS_base_peak_m_z, MS_centroid_spectrum, MS_charge_state, MS_highest_observed_m_z, MS_lowest_observed_m_z, MS_m_z, MS_ms_level, MS_MSn_spectrum, MS_negative_scan, MS_no_combination, MS_number_of_detector_counts, MS_peak_intensity, MS_positive_scan, MS_possible_charge_state, MS_scan_start_time, MS_selected_ion_m_z, MS_spectrum_title, MS_total_ion_current, pwiz::msdata::Spectrum::precursors, pwiz::util::BinaryData< T >::push_back(), pwiz::msdata::MSData::run, pwiz::msdata::Spectrum::scanList, pwiz::msdata::ScanList::scans, pwiz::msdata::Precursor::selectedIons, pwiz::data::ParamContainer::set(), pwiz::msdata::Spectrum::setMZIntensityArrays(), pwiz::util::BinaryData< T >::size(), pwiz::msdata::Run::spectrumListPtr, and UO_second.

Referenced by testWriteRead().

◆ testWriteRead() [1/2]

void testWriteRead ( const MSData msd)

Definition at line 141 of file Serializer_MGF_Test.cpp.

142 {
143  Serializer_MGF serializer;
144 
145  ostringstream oss;
146  serializer.write(oss, msd);
147 
148  if (os_) *os_ << "oss:\n" << oss.str() << endl;
149 
150  shared_ptr<istringstream> iss(new istringstream(oss.str()));
151  MSData msd2;
152  serializer.read(iss, msd2);
153 
154  DiffConfig diffConfig;
155  diffConfig.ignoreIdentity = true;
156  diffConfig.ignoreChromatograms = true;
157 
158  Diff<MSData, DiffConfig> diff(msd, msd2, diffConfig);
159  if (os_ && diff) *os_ << diff << endl;
160  unit_assert(!diff);
161 
162  if (os_)
163  {
164  *os_ << "msd2:\n";
165  Serializer_mzML mzmlSerializer;
166  mzmlSerializer.write(*os_, msd2);
167  *os_ << endl;
168 
169  *os_ << "msd2::";
170  TextWriter write(*os_);
171  write(msd2);
172 
173  *os_ << endl;
174  }
175 }

References diff(), pwiz::msdata::DiffConfig::ignoreChromatograms, pwiz::msdata::DiffConfig::ignoreIdentity, os_, pwiz::msdata::Serializer_MGF::read(), unit_assert, pwiz::identdata::IO::write(), pwiz::msdata::Serializer_MGF::write(), and pwiz::msdata::Serializer_mzML::write().

Referenced by main(), and testWriteRead().

◆ testWriteRead() [2/2]

void testWriteRead ( )

Definition at line 178 of file Serializer_MGF_Test.cpp.

179 {
180  MSData msd;
181  initializeTinyMGF(msd);
182 
183  testWriteRead(msd);
184 }

References initializeTinyMGF(), and testWriteRead().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 187 of file Serializer_MGF_Test.cpp.

188 {
189  TEST_PROLOG(argc, argv)
190 
191  try
192  {
193  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
194  testWriteRead();
195  }
196  catch (exception& e)
197  {
198  TEST_FAILED(e.what())
199  }
200  catch (...)
201  {
202  TEST_FAILED("Caught unknown exception.")
203  }
204 
206 }

References os_, TEST_EPILOG, TEST_FAILED, TEST_PROLOG, and testWriteRead().

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 37 of file Serializer_MGF_Test.cpp.

Referenced by main(), and testWriteRead().

pwiz::msdata::Spectrum::getIntensityArray
BinaryDataArrayPtr getIntensityArray() const
get intensity array (may be null)
MS_charge_state
MS_charge_state
charge state: The charge state of the ion, single or multiple and positive or negatively charged.
Definition: cv.hpp:396
MS_number_of_detector_counts
MS_number_of_detector_counts
number of detector counts: The number of counted events observed in one or a group of elements of a d...
Definition: cv.hpp:741
pwiz::msdata::Spectrum
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition: MSData.hpp:505
pwiz::msdata::SpectrumIdentity::index
size_t index
the zero-based, consecutive index of the spectrum in the SpectrumList.
Definition: MSData.hpp:473
MS_base_peak_m_z
MS_base_peak_m_z
base peak m/z: M/z value of the signal of highest intensity in the mass spectrum.
Definition: cv.hpp:2118
pwiz::util::BinaryData::size
size_t size() const
Definition: BinaryData.hpp:145
MS_scan_start_time
MS_scan_start_time
scan start time: The time that an analyzer started a scan, relative to the start of the MS run.
Definition: cv.hpp:309
MS_MSn_spectrum
MS_MSn_spectrum
MSn spectrum: MSn refers to multi-stage MS2 experiments designed to record product ion spectra where ...
Definition: cv.hpp:2364
pwiz::msdata::Serializer_mzML
MSData <-> mzML stream serialization.
Definition: Serializer_mzML.hpp:39
pwiz::msdata::Spectrum::setMZIntensityArrays
void setMZIntensityArrays(const std::vector< double > &mzArray, const std::vector< double > &intensityArray, CVID intensityUnits)
set m/z and intensity arrays separately (they must be the same size)
pwiz::msdata::MSData::run
Run run
a run in mzML should correspond to a single, consecutive and coherent set of scans on an instrument.
Definition: MSData.hpp:886
MS_total_ion_current
MS_total_ion_current
total ion current: The sum of all the separate ion currents carried by the ions of different m/z cont...
Definition: cv.hpp:1407
MS_negative_scan
MS_negative_scan
negative scan: Polarity of the scan is negative.
Definition: cv.hpp:735
MS_positive_scan
MS_positive_scan
positive scan: Polarity of the scan is positive.
Definition: cv.hpp:738
UO_second
UO_second
second: A time unit which is equal to the duration of 9 192 631 770 periods of the radiation correspo...
Definition: cv.hpp:13833
pwiz::msdata::Serializer_MGF
MSData <-> MGF stream serialization.
Definition: Serializer_MGF.hpp:37
pwiz::msdata::Spectrum::getMZArray
BinaryDataArrayPtr getMZArray() const
get m/z array (may be null)
pwiz::msdata::Serializer_MGF::read
void read(boost::shared_ptr< std::istream > is, MSData &msd) const
read in MSData object from an MGF istream note: istream may be managed by MSData's SpectrumList,...
pwiz::identdata::IO::write
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
pwiz::data::Diff
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
pwiz::msdata::SpectrumIdentity::id
std::string id
a unique identifier for this spectrum. It should be expected that external files may use this identif...
Definition: MSData.hpp:476
pwiz::msdata::DiffConfig::ignoreChromatograms
bool ignoreChromatograms
Definition: Diff.hpp:220
TEST_EPILOG
#define TEST_EPILOG
Definition: unit.hpp:183
testWriteRead
void testWriteRead(const MSData &msd)
Definition: Serializer_MGF_Test.cpp:141
pwiz::msdata::FileDescription::fileContent
FileContent fileContent
this summarizes the different types of spectra that can be expected in the file. This is expected to ...
Definition: MSData.hpp:87
pwiz::msdata::MSData::fileDescription
FileDescription fileDescription
information pertaining to the entire mzML file (i.e. not specific to any part of the data set) is sto...
Definition: MSData.hpp:862
pwiz::util::BinaryData::push_back
void push_back(const T &value)
Definition: BinaryData.hpp:362
MS_no_combination
MS_no_combination
no combination: Use this term if only one scan was recorded or there is no information about scans av...
Definition: cv.hpp:3072
diff
void diff(const string &filename1, const string &filename2)
Definition: FrequencyDataTest.cpp:40
pwiz::msdata::TextWriter
Definition: TextWriter.hpp:40
initializeTinyMGF
void initializeTinyMGF(MSData &msd)
Definition: Serializer_MGF_Test.cpp:40
pwiz::msdata::SpectrumPtr
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: MSData.hpp:573
MS_selected_ion_m_z
MS_selected_ion_m_z
selected ion m/z: Mass-to-charge ratio of an selected ion.
Definition: cv.hpp:2901
pwiz::util::BinaryData< double >
pwiz::msdata::SpectrumListSimple
Simple writeable in-memory implementation of SpectrumList.
Definition: MSData.hpp:716
pwiz::msdata::Spectrum::scanList
ScanList scanList
list of scans
Definition: MSData.hpp:517
pwiz::msdata::Scan
Scan or acquisition from original raw file used to create this peak list, as specified in sourceFile.
Definition: MSData.hpp:369
pwiz::msdata::Run::spectrumListPtr
SpectrumListPtr spectrumListPtr
all mass spectra and the acquisitions underlying them are described and attached here....
Definition: MSData.hpp:827
pwiz::msdata::ScanList::scans
std::vector< Scan > scans
Definition: MSData.hpp:397
TEST_FAILED
#define TEST_FAILED(x)
Definition: unit.hpp:177
pwiz::msdata::FileContent
This summarizes the different types of spectra that can be expected in the file. This is expected to ...
Definition: MSData.hpp:50
TEST_PROLOG
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:175
MS_ms_level
MS_ms_level
ms level: Stages of ms achieved in a multi stage mass spectrometry experiment.
Definition: cv.hpp:2139
pwiz::data::ParamContainer::set
void set(CVID cvid, const std::string &value="", CVID units=CVID_Unknown)
set/add a CVParam (not recursive)
MS_m_z
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition: cv.hpp:384
MS_centroid_spectrum
MS_centroid_spectrum
centroid spectrum: Processing of profile data to produce spectra that contains discrete peaks of zero...
Definition: cv.hpp:720
os_
ostream * os_
Definition: Serializer_MGF_Test.cpp:37
MS_peak_intensity
MS_peak_intensity
peak intensity: Intensity of ions as measured by the height or area of a peak in a mass spectrum.
Definition: cv.hpp:402
MS_highest_observed_m_z
MS_highest_observed_m_z
highest observed m/z: Highest m/z value observed in the m/z array.
Definition: cv.hpp:2187
MS_base_peak_intensity
MS_base_peak_intensity
base peak intensity: The intensity of the greatest peak in the mass spectrum.
Definition: cv.hpp:2121
pwiz::msdata::Spectrum::precursors
std::vector< Precursor > precursors
list and descriptions of precursors to the spectrum currently being described.
Definition: MSData.hpp:520
pwiz::msdata::MSData
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
pwiz::msdata::DiffConfig
configuration struct for diffing MSData types
Definition: Diff.hpp:205
pwiz::msdata::Precursor::selectedIons
std::vector< SelectedIon > selectedIons
this list of precursor ions that were selected.
Definition: MSData.hpp:329
pwiz::msdata::Serializer_MGF::write
void write(std::ostream &os, const MSData &msd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
write MSData object to ostream as MGF; iterationListenerRegistry may be used to receive progress upda...
unit_assert
#define unit_assert(x)
Definition: unit.hpp:85
MS_lowest_observed_m_z
MS_lowest_observed_m_z
lowest observed m/z: Lowest m/z value observed in the m/z array.
Definition: cv.hpp:2190
pwiz::msdata::Precursor
The method of precursor ion selection and activation.
Definition: MSData.hpp:311
pwiz::msdata::Spectrum::defaultArrayLength
size_t defaultArrayLength
default length of binary data arrays contained in this element.
Definition: MSData.hpp:508
MS_possible_charge_state
MS_possible_charge_state
possible charge state: A possible charge state of the ion in a situation where the charge of an ion i...
Definition: cv.hpp:2571
pwiz::msdata::DiffConfig::ignoreIdentity
bool ignoreIdentity
ignore members of SpectrumIdentity and ChromatogramIdentity
Definition: Diff.hpp:208
pwiz::data::CVParam
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44
pwiz::msdata::Serializer_mzML::write
void write(std::ostream &os, const MSData &msd, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
write MSData object to ostream as mzML; iterationListenerRegistry may be used to receive progress upd...
MS_spectrum_title
MS_spectrum_title
spectrum title: A free-form text title describing a spectrum.
Definition: cv.hpp:3075