ProteoWizard
DemuxDebugReadWriteTest.cpp
Go to the documentation of this file.
1 //
2 // DemuxDebugReadWriteTest.cpp
3 //
4 //
5 // Original author: Austin Keller <atkeller .@. uw.edu>
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 
24 #include <boost/make_shared.hpp>
25 
26 using namespace pwiz::analysis;
27 using namespace pwiz::util;
28 using namespace DemuxTypes;
29 
31 
32 public:
33 
34  void Run()
35  {
36  SetUp();
37  ReadWriteTest();
38  TearDown();
39  }
40 
41 protected:
42 
44  {
45  { // Use scope to ensure deletion of debug writer to close output file
46  DemuxDebugWriter debugWriter("DemuxDebugOutput_TestOut.log");
47  unit_assert(debugWriter.IsOpen());
48 
49  for (size_t i = 0; i < spectrumList_.size(); i += 3)
50  {
51  debugWriter.WriteDeconvBlock(i, spectrumList_.at(i), spectrumList_.at(i + 1), spectrumList_.at(i + 2));
52  }
53  }
54 
55  vector<MatrixPtr> readSpectrumList;
56 
57  DemuxDebugReader debugReader("DemuxDebugOutput_TestOut.log");
58  unit_assert(debugReader.IsOpen());
59  unit_assert_operator_equal(3 * debugReader.NumBlocks(), spectrumList_.size());
60 
61  uint64_t spectrumIndex;
62  for (size_t i = 0; i < debugReader.NumBlocks(); ++i)
63  {
64  debugReader.ReadDeconvBlock(spectrumIndex, A_, B_, C_);
65  readSpectrumList.push_back(A_);
66  readSpectrumList.push_back(B_);
67  readSpectrumList.push_back(C_);
68  }
69 
70  unit_assert_operator_equal(readSpectrumList.size(), spectrumList_.size());
71 
72  for (size_t i = 0; i < readSpectrumList.size(); ++i)
73  {
74  unit_assert(spectrumList_.at(i)->isApprox(*readSpectrumList.at(i)));
75  }
76  }
77 
78  void SetUp() {
79  // Generate a list of spectra
80  A_ = boost::make_shared<MatrixType>(3, 4);
81  B_ = boost::make_shared<MatrixType>(4, 3);
82  C_ = boost::make_shared<MatrixType>(3, 3);
83  *A_ << -14.834628974133, -15.729764770592, 56.292839002858, 30.766363712773,
84  79.595747995303, -8.356622426449, 20.840197237638, 83.801095382748,
85  87.889866880787, 13.75327399942, 86.730656404499, -0.46420627108677;
86 
87  *B_ << 23.588885367543, 49.667231605868, -86.700220187964,
88  51.392601274063, -77.511392742378, 23.389497301117,
89  -78.475202879706, -62.60684915327, -42.39206607192,
90  59.595164405161, 2.1025961854091, 65.787705013259;
91 
92  *C_ = *A_ * *B_;
93 
94  spectrumList_.push_back(A_);
95  spectrumList_.push_back(B_);
96  spectrumList_.push_back(C_);
97 
98  MatrixPtr D = boost::make_shared<MatrixType>(3, 4);
99  MatrixPtr E = boost::make_shared<MatrixType>(4, 3);
100  MatrixPtr F = boost::make_shared<MatrixType>(3, 3);
101 
102  *D = 5 * A_->eval();
103  *E = 3 * B_->eval();
104  *F = *A_ * *B_;
105 
106  spectrumList_.push_back(A_);
107  spectrumList_.push_back(B_);
108  spectrumList_.push_back(C_);
109  }
110 
111  void TearDown()
112  {
113  remove("DemuxDebugOutput_TestOut.log");
114  }
115 
116  vector<MatrixPtr> spectrumList_;
120 };
121 
122 
123 int main(int argc, char* argv[])
124 {
125  TEST_PROLOG(argc, argv)
126 
127  try
128  {
129  DemuxDebugRWTest tester;
130  tester.Run();
131  }
132  catch (exception& e)
133  {
134  TEST_FAILED(e.what())
135  }
136  catch (...)
137  {
138  TEST_FAILED("Caught unknown exception.")
139  }
140 
142 }
vector< MatrixPtr > spectrumList_
A class for reading demux matrices from file.
#define TEST_EPILOG
Definition: unit.hpp:182
boost::shared_ptr< MatrixType > MatrixPtr
Definition: DemuxTypes.hpp:39
bool IsOpen() const
Should be called after construction to verify that the file was opened successfully.
A class for writing demux matrices to file.
#define D
F
Definition: Chemistry.hpp:80
#define unit_assert_operator_equal(expected, actual)
Definition: unit.hpp:92
void ReadDeconvBlock(uint64_t &spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Can be used to read through the blocks sequntially.
void WriteDeconvBlock(uint64_t spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Writes a set of matrices with the given spectrum index to file.
bool IsOpen() const
Should be called after construction to verify that the file was opened successfully.
#define TEST_FAILED(x)
Definition: unit.hpp:176
int main(int argc, char *argv[])
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174
size_t NumBlocks() const
Number of blocks (sets of matrices) that are contained in the file.
#define unit_assert(x)
Definition: unit.hpp:85