ProteoWizard
Serializer_Text_Test.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Robert Burke <robert.burke@proteowizard.org>
6//
7// Copyright 2010 Spielberg Family Center for Applied Proteomics
8// University of Southern California, Los Angeles, California 90033
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23#define PWIZ_SOURCE
24
26#include "IdentData.hpp"
27#include "Serializer_Text.hpp"
28#include "TextWriter.hpp"
29#include "examples.hpp"
31
32using namespace pwiz::identdata;
33using namespace pwiz::identdata::examples;
34
35ostream* os_ = 0;
36
38{
39 if (os_)
40 (*os_) << "*** Beginning testSerializeRead() ***\n";
41
42 string testStr = "scan\trt\tmz\tscore\tscoretype\tpeptide\tprotein\n"
43 "1\t1.01\t100.1\t0.5\tmascot\tVAGWE\tvague protein\n"
44 "2\t2.02\t200.0\t0.9\tmascot\tCERTAIN\tcertain protein\n";
45
46 shared_ptr<istringstream> iss(new istringstream(testStr));
47
48 IdentData mzid;
49 Serializer_Text serializer;
50 serializer.read(iss, mzid);
51
52
53 if (os_)
54 {
55 (*os_) << "mzIdentML output:\n";
56 TextWriter tw(*os_);
57 tw(mzid);
58 }
59
60 if (os_)
61 (*os_) << "*** Ending testSerializeRead() ***\n";
62}
63
65{
66 if (os_)
67 (*os_) << "*** Beginning testSerializeWrite() ***\n";
68
69 ostringstream oss;
70 IdentData mzid;
72
73 Serializer_Text serializer;
74 serializer.write(oss, mzid);
75
76 if (os_)
77 (*os_) << oss.str() << endl;
78
79 if (os_)
80 (*os_) << "*** Ending testSerializeRead() ***\n";
81}
82
83void test()
84{
87}
88
89int main(int argc, char** argv)
90{
91 TEST_PROLOG(argc, argv)
92
93 try
94 {
95 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
96 test();
97 }
98 catch (exception& e)
99 {
100 TEST_FAILED(e.what())
101 }
102 catch (...)
103 {
104 TEST_FAILED("Caught unknown exception.")
105 }
106
108}
int main(int argc, char **argv)
void testSerializeWrite()
ostream * os_
void testSerializeRead()
void test()
Serializer_Text reads in and writes out an id file in tab format.
void write(std::ostream &os, const IdentData &mzid, const pwiz::util::IterationListenerRegistry *iterationListenerRegistry=0) const
writes IdentData object to ostream as a text table
void read(boost::shared_ptr< std::istream > is, IdentData &mzid) const
read in IdentData object from a delimited text fromat.
PWIZ_API_DECL void initializeBasicSpectrumIdentification(IdentData &mzid)
Implementation of the MzIdentMLType from the mzIdentML schema.
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175