ProteoWizard
Classes | Functions | Variables
ProteomeDataFileTest.cpp File Reference
#include "ProteomeDataFile.hpp"
#include "Diff.hpp"
#include "examples.hpp"
#include "Reader_FASTA.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Filesystem.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/copy.hpp>

Go to the source code of this file.

Classes

class  TestReader
 

Functions

void validateReadIndexed (const ProteomeDataFile::WriteConfig &writeConfig, const DiffConfig diffConfig)
 
void validateWriteRead (const ProteomeDataFile::WriteConfig &writeConfig, const DiffConfig diffConfig)
 
void test ()
 
void testReader ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
string filenameBase_ = "temp.ProteomeDataFileTest"
 

Function Documentation

◆ validateReadIndexed()

void validateReadIndexed ( const ProteomeDataFile::WriteConfig writeConfig,
const DiffConfig  diffConfig 
)

Definition at line 49 of file ProteomeDataFileTest.cpp.

51{
52 if (os_) *os_ << "validateReadIndexed()\n" << endl;
53
54 string filename1 = filenameBase_ + "1.fasta";
55
56 // create ProteomeData object in memory
57 ProteomeData tiny;
59
60 // write to file #1 (static)
61 ProteomeDataFile::write(tiny, filename1, writeConfig);
62
63 {
64 unit_assert(!bfs::exists(filename1 + ".index"));
65
67 config.indexed = true;
68 Reader_FASTA reader(config);
69
70 // read back into an ProteomeDataFile object
71 ProteomeDataFile pd1(filename1, reader);
72
73 unit_assert(bfs::exists(filename1));
74 unit_assert(bfs::exists(filename1 + ".index"));
75
76 // compare
77 Diff<ProteomeData, DiffConfig> diff(tiny, pd1, diffConfig);
78 if (diff && os_) *os_ << diff << endl;
80
81 // read back into an ProteomeDataFile object, this time should be indexed
82 ProteomeDataFile pd2(filename1, reader);
83
84 // compare
85 diff(tiny, pd2);
86 if (diff && os_) *os_ << diff << endl;
88
89 // now give the gzip read a workout
90 /*bio::filtering_istream tinyGZ(bio::gzip_compressor() | bio::file_descriptor_source(filename1));
91 bio::copy(tinyGZ, bio::file_descriptor_sink(filename1 + ".gz", ios::out | ios::binary));
92
93 ProteomeDataFile pd3(filename1 + ".gz", reader);
94
95 // compare
96 diff(tiny, pd3);
97 if (diff && os_) *os_ << diff << endl;
98 unit_assert(!diff);*/
99 }
100}
void diff(const string &filename1, const string &filename2)
string filename1
ostream * os_
string filenameBase_
FASTA -> ProteomeData stream serialization.
PWIZ_API_DECL void initializeTiny(ProteomeData &pd)
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
ProteomeData object plus file I/O.
static void write(const ProteomeData &pd, const std::string &uri, const WriteConfig &config=WriteConfig(), const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0)
static write function for any ProteomeData object; iterationListenerRegistry may be used for progress...
Reader_FASTA configuration.
bool indexed
read with a side-by-side index
#define unit_assert(x)
Definition unit.hpp:85

References diff(), filename1, filenameBase_, pwiz::proteome::Reader_FASTA::Config::indexed, pwiz::proteome::examples::initializeTiny(), os_, unit_assert, and pwiz::proteome::ProteomeDataFile::write().

Referenced by test().

◆ validateWriteRead()

void validateWriteRead ( const ProteomeDataFile::WriteConfig writeConfig,
const DiffConfig  diffConfig 
)

Definition at line 102 of file ProteomeDataFileTest.cpp.

104{
105 if (os_) *os_ << "validateWriteRead()\n " << writeConfig << endl;
106
107 string filename1 = filenameBase_ + "1.fasta";
108 string filename2 = filenameBase_ + "2.fasta";
109
110 {
111 // create ProteomeData object in memory
112 ProteomeData tiny;
114
115 // write to file #1 (static)
116 ProteomeDataFile::write(tiny, filename1, writeConfig);
117
118 shared_ptr<Reader> reader;
119 if (writeConfig.format == ProteomeDataFile::Format_FASTA)
120 {
121 // Reader_FASTA creates the index in the read() call
123 config.indexed = writeConfig.indexed;
124 reader.reset(new Reader_FASTA(config));
125 }
126
127 // read back into an ProteomeDataFile object
128 ProteomeDataFile pd1(filename1, *reader);
129
130 // compare
131 Diff<ProteomeData, DiffConfig> diff(tiny, pd1, diffConfig);
132 if (diff && os_) *os_ << diff << endl;
134
135 // write to file #2 (member)
136 pd1.write(filename2, writeConfig);
137
138 // read back into another ProteomeDataFile object
139 ProteomeDataFile pd2(filename2, *reader);
140
141 // compare
142 diff(tiny, pd2);
143 if (diff && os_) *os_ << diff << endl;
145
146 // now give the gzip read a workout
147 bio::filtering_istream tinyGZ(bio::gzip_compressor() | bio::file_descriptor_source(filename1));
148 bio::copy(tinyGZ, bio::file_descriptor_sink(filename1+".gz", ios::out|ios::binary));
149
150 ProteomeDataFile pd3(filename1+".gz", *reader);
151
152 // compare
153 diff(tiny, pd3);
154 if (diff && os_) *os_ << diff << endl;
156 }
157
158 // remove temp files
159 bfs::remove(filename1);
160 bfs::remove(filename2);
161 bfs::remove(filename1 + ".gz");
162
163 bool index1Exists = bfs::exists(filename1 + ".index");
164 bool index2Exists = bfs::exists(filename2 + ".index");
165 bool index3Exists = bfs::exists(filename1 + ".gz.index");
166
167 bool indexShouldExist = writeConfig.indexed;
168 unit_assert(!indexShouldExist || index1Exists);
169 unit_assert(!indexShouldExist || index2Exists);
170 unit_assert(!indexShouldExist || index3Exists);
171
172 if (index1Exists) bfs::remove(filename1 + ".index");
173 if (index2Exists) bfs::remove(filename2 + ".index");
174 if (index3Exists) bfs::remove(filename1 + ".gz.index");
175}

References diff(), filename1, filenameBase_, pwiz::proteome::ProteomeDataFile::WriteConfig::format, pwiz::proteome::ProteomeDataFile::WriteConfig::indexed, pwiz::proteome::Reader_FASTA::Config::indexed, pwiz::proteome::examples::initializeTiny(), os_, unit_assert, and pwiz::proteome::ProteomeDataFile::write().

Referenced by test().

◆ test()

void test ( )

Definition at line 177 of file ProteomeDataFileTest.cpp.

178{
180 DiffConfig diffConfig;
181
182 // test FASTA with binary stream index
183 validateWriteRead(writeConfig, diffConfig);
184
185 // test FASTA with pre-existing indexes
186 validateReadIndexed(writeConfig, diffConfig);
187
188 // test FASTA with memory index
189 writeConfig.indexed = false;
190 validateWriteRead(writeConfig, diffConfig);
191}
void validateWriteRead(const ProteomeDataFile::WriteConfig &writeConfig, const DiffConfig diffConfig)
void validateReadIndexed(const ProteomeDataFile::WriteConfig &writeConfig, const DiffConfig diffConfig)
configuration struct for diffs
Definition Diff.hpp:73

References pwiz::proteome::ProteomeDataFile::WriteConfig::indexed, validateReadIndexed(), and validateWriteRead().

Referenced by main().

◆ testReader()

void testReader ( )

Definition at line 228 of file ProteomeDataFileTest.cpp.

229{
230 // create a file
231 string filename = filenameBase_ + ".fAsTa";
232 ofstream os(filename.c_str());
233 os << ">Id Description\nSEQUENCE\n";
234 os.close();
235
236 // open the file with our Reader
237 TestReader reader;
238 ProteomeDataFile pd(filename, reader);
239
240 // verify that our reader got called properly
241 unit_assert(reader.count == 2);
242
243 // remove temp file
244 boost::filesystem::remove(filename);
245
246 if (os_) *os_ << endl;
247}

References TestReader::count, filenameBase_, os_, and unit_assert.

Referenced by main().

◆ main()

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

Definition at line 250 of file ProteomeDataFileTest.cpp.

251{
252 TEST_PROLOG(argc, argv)
253
254 try
255 {
256 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
257 test();
258 testReader();
259 }
260 catch (exception& e)
261 {
262 TEST_FAILED(e.what())
263 }
264 catch (...)
265 {
266 TEST_FAILED("Caught unknown exception.")
267 }
268
270}
void testReader()
void test()
#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, TEST_PROLOG, and testReader().

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 43 of file ProteomeDataFileTest.cpp.

Referenced by main(), testReader(), validateReadIndexed(), and validateWriteRead().

◆ filenameBase_

string filenameBase_ = "temp.ProteomeDataFileTest"

Definition at line 46 of file ProteomeDataFileTest.cpp.

Referenced by testReader(), validateReadIndexed(), and validateWriteRead().