ProteoWizard
ProteinList_DecoyGeneratorTest.cpp
Go to the documentation of this file.
1//
2// $Id$
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
31using namespace pwiz::proteome;
32using namespace pwiz::analysis;
33using namespace pwiz::util;
34
35
36ostream* 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
94
95
96int 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
int main(int argc, char *argv[])
void testShuffledList(ProteinListPtr pl)
void testReversedList(ProteinListPtr pl)
ProteinList decoy generator for creating decoy proteins on the fly.
virtual ProteinPtr protein(size_t index, bool getSequence=true) const
creates a reversed copy of every target protein with the specified decoy string prefixed to the id
creates a randomly shuffled copy of every target protein with the specified decoy string prefixed to ...
PWIZ_API_DECL void initializeTiny(MSData &msd)
boost::shared_ptr< Protein > ProteinPtr
boost::shared_ptr< ProteinList > ProteinListPtr
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175