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 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

§ validateWriteRead()

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

Definition at line 49 of file ProteomeDataFileTest.cpp.

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

Referenced by test().

51 {
52  if (os_) *os_ << "validateWriteRead()\n " << writeConfig << endl;
53 
54  string filename1 = filenameBase_ + "1.fasta";
55  string filename2 = filenameBase_ + "2.fasta";
56 
57  {
58  // create ProteomeData object in memory
59  ProteomeData tiny;
61 
62  // write to file #1 (static)
63  ProteomeDataFile::write(tiny, filename1, writeConfig);
64 
65  shared_ptr<Reader> reader;
66  if (writeConfig.format == ProteomeDataFile::Format_FASTA)
67  {
68  // Reader_FASTA creates the index in the read() call
69  Reader_FASTA::Config config;
70  config.indexed = writeConfig.indexed;
71  reader.reset(new Reader_FASTA(config));
72  }
73 
74  // read back into an ProteomeDataFile object
75  ProteomeDataFile pd1(filename1, *reader);
76 
77  // compare
78  Diff<ProteomeData, DiffConfig> diff(tiny, pd1, diffConfig);
79  if (diff && os_) *os_ << diff << endl;
80  unit_assert(!diff);
81 
82  // write to file #2 (member)
83  pd1.write(filename2, writeConfig);
84 
85  // read back into another ProteomeDataFile object
86  ProteomeDataFile pd2(filename2, *reader);
87 
88  // compare
89  diff(tiny, pd2);
90  if (diff && os_) *os_ << diff << endl;
91  unit_assert(!diff);
92 
93  // now give the gzip read a workout
94  bio::filtering_istream tinyGZ(bio::gzip_compressor() | bio::file_descriptor_source(filename1));
95  bio::copy(tinyGZ, bio::file_descriptor_sink(filename1+".gz", ios::out|ios::binary));
96 
97  ProteomeDataFile pd3(filename1+".gz", *reader);
98 
99  // compare
100  diff(tiny, pd3);
101  if (diff && os_) *os_ << diff << endl;
102  unit_assert(!diff);
103  }
104 
105  // remove temp files
106  bfs::remove(filename1);
107  bfs::remove(filename2);
108  bfs::remove(filename1 + ".gz");
109 
110  bool index1Exists = bfs::exists(filename1 + ".index");
111  bool index2Exists = bfs::exists(filename2 + ".index");
112  bool index3Exists = bfs::exists(filename1 + ".gz.index");
113 
114  bool indexShouldExist = writeConfig.indexed;
115  unit_assert(!indexShouldExist || index1Exists);
116  unit_assert(!indexShouldExist || index2Exists);
117  unit_assert(!indexShouldExist || index3Exists);
118 
119  if (index1Exists) bfs::remove(filename1 + ".index");
120  if (index2Exists) bfs::remove(filename2 + ".index");
121  if (index3Exists) bfs::remove(filename1 + ".gz.index");
122 }
FASTA -> ProteomeData stream serialization.
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition: diff_std.hpp:142
string filename1
void diff(const string &filename1, const string &filename2)
ostream * os_
Format_FASTA
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
ProteomeData object plus file I/O.
PWIZ_API_DECL void initializeTiny(IdentData &mzid)
Reader_FASTA configuration.
bool indexed
read with a side-by-side index
string filenameBase_
#define unit_assert(x)
Definition: unit.hpp:85

§ test()

void test ( )

Definition at line 124 of file ProteomeDataFileTest.cpp.

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

Referenced by main().

125 {
126  ProteomeDataFile::WriteConfig writeConfig;
127  DiffConfig diffConfig;
128 
129  // test FASTA with binary stream index
130  validateWriteRead(writeConfig, diffConfig);
131 
132  // test FASTA with memory index
133  writeConfig.indexed = false;
134  validateWriteRead(writeConfig, diffConfig);
135 }
configuration struct for diffs
Definition: Diff.hpp:72
void validateWriteRead(const ProteomeDataFile::WriteConfig &writeConfig, const DiffConfig diffConfig)

§ testReader()

void testReader ( )

Definition at line 172 of file ProteomeDataFileTest.cpp.

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

173 {
174  // create a file
175  string filename = filenameBase_ + ".fAsTa";
176  ofstream os(filename.c_str());
177  os << ">Id Description\nSEQUENCE\n";
178  os.close();
179 
180  // open the file with our Reader
181  TestReader reader;
182  ProteomeDataFile pd(filename, reader);
183 
184  // verify that our reader got called properly
185  unit_assert(reader.count == 2);
186 
187  // remove temp file
188  boost::filesystem::remove(filename);
189 
190  if (os_) *os_ << endl;
191 }
ostream * os_
ProteomeData object plus file I/O.
string filenameBase_
#define unit_assert(x)
Definition: unit.hpp:85

§ main()

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

Definition at line 194 of file ProteomeDataFileTest.cpp.

References os_, test(), TEST_EPILOG, TEST_FAILED, TEST_PROLOG, and pwiz::util::testReader().

195 {
196  TEST_PROLOG(argc, argv)
197 
198  try
199  {
200  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
201  test();
202  testReader();
203  }
204  catch (exception& e)
205  {
206  TEST_FAILED(e.what())
207  }
208  catch (...)
209  {
210  TEST_FAILED("Caught unknown exception.")
211  }
212 
214 }
#define TEST_EPILOG
Definition: unit.hpp:182
ostream * os_
#define TEST_FAILED(x)
Definition: unit.hpp:176
void testReader()
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
void test()

Variable Documentation

§ os_

ostream* os_ = 0

Definition at line 43 of file ProteomeDataFileTest.cpp.

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

§ filenameBase_

string filenameBase_ = "temp.ProteomeDataFileTest"

Definition at line 46 of file ProteomeDataFileTest.cpp.

Referenced by testReader(), and validateWriteRead().