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

void initializeTinyMGF ( MSData msd)

Definition at line 40 of file Serializer_MGF_Test.cpp.

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_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::msdata::MSData::run, pwiz::msdata::Spectrum::scanList, pwiz::msdata::ScanList::scans, pwiz::msdata::Precursor::selectedIons, pwiz::data::ParamContainer::set(), pwiz::msdata::Spectrum::setMZIntensityArrays(), pwiz::msdata::Run::spectrumListPtr, and UO_second.

Referenced by testWriteRead().

{
//SourceFilePtr sourceFile(new SourceFile);
//sourceFile->set(MS_multiple_peak_list_nativeID_format);
// TODO: sourceFile->set(MS_Matrix_Science_MGF_file);
//msd.fileDescription.sourceFilePtrs.push_back(sourceFile);
shared_ptr<SpectrumListSimple> spectrumList(new SpectrumListSimple);
msd.run.spectrumListPtr = spectrumList;
spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
spectrumList->spectra.push_back(SpectrumPtr(new Spectrum));
Spectrum& s20 = *spectrumList->spectra[0];
s20.id = "index=0";
s20.index = 0;
s20.set(MS_ms_level, 2);
s20.set(MS_base_peak_m_z, 0.0);
s20.precursors.resize(1);
Precursor& s20precursor = s20.precursors.front();
s20precursor.selectedIons.resize(1);
s20precursor.selectedIons[0].set(MS_selected_ion_m_z, 445.34, MS_m_z);
s20precursor.selectedIons[0].set(MS_peak_intensity, 120053.0, MS_number_of_counts);
s20precursor.selectedIons[0].set(MS_charge_state, 2);
s20.scanList.scans.push_back(Scan());
Scan& s20scan = s20.scanList.scans.back();
s20.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_counts);
vector<double>& s20_mz = s20.getMZArray()->data;
vector<double>& s20_intensity = s20.getIntensityArray()->data;
for (int i=0; i<10; i++)
s20_mz.push_back(i*2);
for (int i=0; i<10; i++)
s20_intensity.push_back((10-i)*2);
s20.defaultArrayLength = s20_mz.size();
Spectrum& s21 = *spectrumList->spectra[1];
s21.id = "index=1";
s21.index = 1;
s21.set(MS_ms_level, 2);
s21.set(MS_base_peak_m_z, 3.0);
s21.precursors.resize(1);
Precursor& s21precursor = s21.precursors.front();
s21precursor.selectedIons.resize(1);
s21precursor.selectedIons[0].set(MS_selected_ion_m_z, 424.24, MS_m_z);
s21precursor.selectedIons[0].set(MS_peak_intensity, 4242.0, MS_number_of_counts);
s21precursor.selectedIons[0].cvParams.push_back(CVParam(MS_possible_charge_state, 2));
s21precursor.selectedIons[0].cvParams.push_back(CVParam(MS_possible_charge_state, 3));
s21.scanList.scans.push_back(Scan());
Scan& s21scan = s21.scanList.scans.back();
s21scan.set(MS_scan_start_time, 42.0, UO_second);
s21.setMZIntensityArrays(vector<double>(), vector<double>(), MS_number_of_counts);
vector<double>& s21_mz = s21.getMZArray()->data;
vector<double>& s21_intensity = s21.getIntensityArray()->data;
for (int i=1; i<=10; i++)
s21_mz.push_back(i*3);
for (int i=0; i<10; i++)
s21_intensity.push_back((10-i)*3);
s21.defaultArrayLength = s21_mz.size();
} // initializeTinyMGF()
void testWriteRead ( const MSData msd)

Definition at line 141 of file Serializer_MGF_Test.cpp.

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

Referenced by main(), testThreadSafetyWorker(), and testWriteRead().

{
Serializer_MGF serializer;
ostringstream oss;
serializer.write(oss, msd);
if (os_) *os_ << "oss:\n" << oss.str() << endl;
shared_ptr<istringstream> iss(new istringstream(oss.str()));
MSData msd2;
serializer.read(iss, msd2);
DiffConfig diffConfig;
diffConfig.ignoreIdentity = true;
diffConfig.ignoreChromatograms = true;
Diff<MSData, DiffConfig> diff(msd, msd2, diffConfig);
if (os_ && diff) *os_ << diff << endl;
if (os_)
{
*os_ << "msd2:\n";
Serializer_mzML mzmlSerializer;
mzmlSerializer.write(*os_, msd2);
*os_ << endl;
*os_ << "msd2::";
write(msd2);
*os_ << endl;
}
}
void testWriteRead ( )

Definition at line 178 of file Serializer_MGF_Test.cpp.

References initializeTinyMGF(), and testWriteRead().

{
MSData msd;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 187 of file Serializer_MGF_Test.cpp.

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

{
TEST_PROLOG(argc, argv)
try
{
if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
}
catch (exception& e)
{
TEST_FAILED(e.what())
}
catch (...)
{
TEST_FAILED("Caught unknown exception.")
}
}

Variable Documentation

ostream* os_ = 0

Definition at line 37 of file Serializer_MGF_Test.cpp.