ProteoWizard
ProteinList_DecoyGeneratorTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: ProteinList_DecoyGeneratorTest.cpp 4129 2012-11-20 00:05:37Z chambm $
3 //
4 //
5 // Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6 //
7 // Copyright 2010 Vanderbilt University - Nashville, TN 37232
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
26 #include "boost/random.hpp"
28 #include <cstring>
29 
30 
31 using namespace pwiz::proteome;
32 using namespace pwiz::analysis;
33 using namespace pwiz::util;
34 
35 
36 ostream* os_ = 0;
37 
38 
40 {
41  unit_assert(pl->size() == 3);
43  unit_assert(decoyList.size() == 6);
44  for (size_t i=0; i < pl->size(); ++i)
45  {
46  ProteinPtr target = decoyList.protein(i);
47  ProteinPtr decoy = decoyList.protein(i + pl->size());
48 
49  if (os_) *os_ << target->id << " " << target->sequence() << endl;
50  if (os_) *os_ << decoy->id << " " << decoy->sequence() << endl;
51 
52  unit_assert("reversed_" + target->id == decoy->id);
53  unit_assert(decoy->description.empty());
54  unit_assert(string(target->sequence().rbegin(), target->sequence().rend()) == decoy->sequence());
55  }
56 }
57 
58 
60 {
61  unit_assert(pl->size() == 3);
63  unit_assert(decoyList.size() == 6);
64 
65  boost::mt19937 engine(0);
66  boost::uniform_int<> distribution;
67  boost::variate_generator<boost::mt19937, boost::uniform_int<> > rng(engine, distribution);
68 
69  for (size_t i=0; i < pl->size(); ++i)
70  {
71  ProteinPtr target = decoyList.protein(i);
72  ProteinPtr decoy = decoyList.protein(i + pl->size());
73 
74  if (os_) *os_ << target->id << " " << target->sequence() << endl;
75  if (os_) *os_ << decoy->id << " " << decoy->sequence() << endl;
76 
77  unit_assert("shuffled_" + target->id == decoy->id);
78  unit_assert(decoy->description.empty());
79  string sequence = target->sequence();
80  random_shuffle(sequence.begin(), sequence.end(), rng);
81  unit_assert(sequence == decoy->sequence());
82  }
83 }
84 
85 
86 void test()
87 {
88  ProteomeData pd;
91  testReversedList(pl);
92  testShuffledList(pl);
93 }
94 
95 
96 int main(int argc, char* argv[])
97 {
98  TEST_PROLOG(argc, argv)
99 
100  try
101  {
102  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
103  test();
104  }
105  catch (exception& e)
106  {
107  TEST_FAILED(e.what())
108  }
109  catch (...)
110  {
111  TEST_FAILED("Caught unknown exception.")
112  }
113 
115 }
116 
117