ProteoWizard
Functions | Variables
SpectrumList_MZWindowTest.cpp File Reference
#include "SpectrumList_MZWindow.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Functions

void printSpectrumList (const SpectrumList &sl, ostream &os)
 
SpectrumListPtr createSpectrumList ()
 
void verifySpectrumSize (const SpectrumList &sl, size_t index, size_t size)
 
void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ printSpectrumList()

void printSpectrumList ( const SpectrumList sl,
ostream &  os 
)

Definition at line 38 of file SpectrumList_MZWindowTest.cpp.

39{
40 os << "size: " << sl.size() << endl;
41
42 for (size_t i=0, end=sl.size(); i<end; i++)
43 {
44 SpectrumPtr spectrum = sl.spectrum(i, false);
45 vector<MZIntensityPair> data;
46 spectrum->getMZIntensityPairs(data);
47
48 os << spectrum->index << " "
49 << spectrum->id << ": ";
50
51 copy(data.begin(), data.end(), ostream_iterator<MZIntensityPair>(os, " "));
52
53 os << endl;
54 }
55}
virtual size_t size() const =0
returns the number of spectra
virtual SpectrumPtr spectrum(size_t index, bool getBinaryData=false) const =0
retrieve a spectrum by index
boost::shared_ptr< Spectrum > SpectrumPtr
Definition MSData.hpp:573

References pwiz::msdata::SpectrumList::size(), and pwiz::msdata::SpectrumList::spectrum().

Referenced by createSpectrumList(), and test().

◆ createSpectrumList()

SpectrumListPtr createSpectrumList ( )

Definition at line 58 of file SpectrumList_MZWindowTest.cpp.

59{
61
62 for (size_t i=0; i<10; i++)
63 {
64 SpectrumPtr spectrum(new Spectrum);
65 spectrum->index = i;
66 spectrum->id = "scan=" + lexical_cast<string>(100+i);
67
68 // data: (i,1000) (i+1,1001) (i+2,1002) (i+3,1003) (i+4,1004)
69 vector<MZIntensityPair> data(5);
70 for (size_t j=0; j<5; j++) data[j] = MZIntensityPair(i+j, 1000+j);
71 spectrum->setMZIntensityPairs(data, MS_number_of_detector_counts);
72
73 sl->spectra.push_back(spectrum);
74 }
75
76 if (os_)
77 {
78 *os_ << "original spectrum list:\n";
79 printSpectrumList(*sl, *os_);
80 *os_ << endl;
81 }
82
83 return sl;
84}
void printSpectrumList(const SpectrumList &sl, ostream &os)
ostream * os_
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
boost::shared_ptr< SpectrumListSimple > SpectrumListSimplePtr
Definition MSData.hpp:731
The data point type of a mass spectrum.
Definition MSData.hpp:423
The structure that captures the generation of a peak list (including the underlying acquisitions)
Definition MSData.hpp:506
Simple writeable in-memory implementation of SpectrumList.
Definition MSData.hpp:717

References MS_number_of_detector_counts, os_, and printSpectrumList().

Referenced by test().

◆ verifySpectrumSize()

void verifySpectrumSize ( const SpectrumList sl,
size_t  index,
size_t  size 
)

Definition at line 87 of file SpectrumList_MZWindowTest.cpp.

88{
89 SpectrumPtr spectrum = sl.spectrum(index, true);
90 vector<MZIntensityPair> data;
91 spectrum->getMZIntensityPairs(data);
92 unit_assert(data.size() == size);
93}
#define unit_assert(x)
Definition unit.hpp:85

References pwiz::msdata::SpectrumList::spectrum(), and unit_assert.

Referenced by test().

◆ test()

void test ( )

Definition at line 96 of file SpectrumList_MZWindowTest.cpp.

97{
99 for (size_t i=0; i<sl->size(); i++)
100 verifySpectrumSize(*sl, i, 5);
101
102 SpectrumList_MZWindow window(sl, 4.20, 6.66);
103
104 if (os_)
105 {
106 *os_ << "filtered list:\n";
107 printSpectrumList(window, *os_);
108 *os_ << endl;
109 }
110
111 unit_assert(window.size() == sl->size());
112 verifySpectrumSize(window, 0, 0);
113 verifySpectrumSize(window, 1, 1);
114 verifySpectrumSize(window, 2, 2);
115 verifySpectrumSize(window, 3, 2);
116 verifySpectrumSize(window, 4, 2);
117 verifySpectrumSize(window, 5, 2);
118 verifySpectrumSize(window, 6, 1);
119 verifySpectrumSize(window, 7, 0);
120 verifySpectrumSize(window, 8, 0);
121 verifySpectrumSize(window, 9, 0);
122}
void verifySpectrumSize(const SpectrumList &sl, size_t index, size_t size)
SpectrumListPtr createSpectrumList()
SpectrumList filter, for creating Spectrum sub-lists.
boost::shared_ptr< SpectrumList > SpectrumListPtr
Definition MSData.hpp:711

References createSpectrumList(), os_, printSpectrumList(), pwiz::msdata::SpectrumListWrapper::size(), unit_assert, and verifySpectrumSize().

Referenced by main().

◆ main()

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

Definition at line 125 of file SpectrumList_MZWindowTest.cpp.

126{
127 TEST_PROLOG(argc, argv)
128
129 try
130 {
131 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
132 test();
133 }
134 catch (exception& e)
135 {
136 TEST_FAILED(e.what())
137 }
138 catch (...)
139 {
140 TEST_FAILED("Caught unknown exception.")
141 }
142
144}
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

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

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 35 of file SpectrumList_MZWindowTest.cpp.

Referenced by createSpectrumList(), main(), and test().