ProteoWizard
IPIFASTADatabaseTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: IPIFASTADatabaseTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2006 Louis Warschaw Prostate Cancer Center
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
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 
24 #include "IPIFASTADatabase.hpp"
26 #include <boost/filesystem/operations.hpp>
28 #include <cstring>
29 
30 
31 using namespace pwiz::util;
32 using namespace pwiz::proteome;
33 
34 
35 ostream* os_ = 0;
36 
37 
38 void writeTestEntries(ostream& os)
39 {
40  os << ">IPI:IPI00000001.2|SWISS-PROT:O95793-1|..." << endl;
41  os << "MSQVQVQVQNPSAALSGSQILNKNQSLLSQPLMSIPSTTSSLPSENAGRPIQNSALPSAS" << endl;
42  os << "ITSTSAAAESITPTVELNALCMKLGKKPMYKPVDPYSRMQSTYNYNMRGGAYPPRYFYPF" << endl;
43  os << "PVPPLLYQVELSVGGQQFNGKGKTRQAAKHDAAAKALRILQNEPLPERLEVNGRESEEEN" << endl;
44  os << "LNKSEISQVFEIALKRNLPVNFEVARESGPPHMKNFVTKVSVGEFVGEGEGKSKKISKKN" << endl;
45  os << "AAIAVLEELKKLPPLPAVERVKPRIKKKTKPIVKPQTSPEYGQGINPISRLAQIQQAKKE" << endl;
46  os << "KEPEYTLLTERGLPRRREFVMQVKVGNHTAEGTGTNKKVAKRNAAENMLEILGFKVPQAQ" << endl;
47  os << "PTKPALKSEEKTPIKKPGDGRKVTFFEPGSGDENGTSNKEDEFRMPYLSHQQLPAGILPM" << endl;
48  os << "VPEVAQAVGVSQGHHTKDFTRAAPNPAKATVTAMIARELLYGGTSPTAETILKNNISSGH" << endl;
49  os << "VPHGPLTRPSEQLDYLSRVQGFQVEYKDFPKNNKNEFVSLINCSSQPPLISHGIGKDVES" << endl;
50  os << "CHDMAALNILKLLSELDQQSTEMPRTGNGPMSVCGRC" << endl;
51  os << ">IPI:IPI00000005.1|SWISS-PROT:P01111|..." << endl;
52  os << "MTEYKLVVVGAGGVGKSALTIQLIQNHFVDEYDPTIEDSYRKQVVIDGETCLLDILDTAG" << endl;
53  os << "QEEYSAMRDQYMRTGEGFLCVFAINNSKSFADINLYREQIKRVKDSDDVPMVLVGNKCDL" << endl;
54  os << "PTRTVDTKQAHELAKSYGIPFIETSAKTRQGVEDAFYTLVREIRQYRMKKLNSSDDGTQG" << endl;
55  os << "CMGLPCVVM" << endl;
56 }
57 
58 
59 void test()
60 {
61  string filename = "IPIFASTADatabaseTest.test.txt";
62  ofstream os(filename.c_str());
63  writeTestEntries(os);
64  os.close();
65 
66  IPIFASTADatabase db(filename);
67  unit_assert(db.records().size() == 2);
68 
69  IPIFASTADatabase::const_iterator it = db.records().begin();
70  unit_assert(it->id == 1);
71  unit_assert(it->faID == "IPI:IPI00000001.2");
72  unit_assert(it->sequence.size() == 577);
73  unit_assert(it->sequence.find("PVPPLL") == 120);
74  if (os_) *os_ << *it << endl;
75 
76  ++it;
77  unit_assert(it->id == 5);
78  unit_assert(it->faID == "IPI:IPI00000005.1");
79  unit_assert(it->sequence.size() == 189);
80  unit_assert(it->sequence.find("PTRTVD") == 120);
81  if (os_) *os_ << *it << endl;
82 
83  boost::filesystem::remove(filename);
84 }
85 
86 
88 {
89  IPIFASTADatabase db("ipi.HUMAN.fasta");
90  cout << "record count: " << db.records().size() << endl;
91 
92  if (!db.records().empty())
93  {
94  const IPIFASTADatabase::Record* record = &db.records().back();
95  cout << *record << endl;
96  }
97 }
98 
99 
100 int main(int argc, char* argv[])
101 {
102  TEST_PROLOG(argc, argv)
103 
104  try
105  {
106  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
107  if (os_) *os_ << "IPIFASTADatabaseTest\n";
108  test();
109  //testRealDatabase();
110  }
111  catch (exception& e)
112  {
113  TEST_FAILED(e.what())
114  }
115  catch (...)
116  {
117  TEST_FAILED("Caught unknown exception.")
118  }
119 
121 }
122