File: test_mzintegrationparams.cpp

package info (click to toggle)
libpappsomspp 0.11.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,032 kB
  • sloc: cpp: 78,332; xml: 44,164; python: 668; sql: 186; sh: 33; makefile: 31
file content (217 lines) | stat: -rw-r--r-- 9,428 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>


#include <QDebug>

#include <limits>
#include <pappsomspp/core/processing/filters/savgolfilter.h>
#include <pappsomspp/core/processing/combiners/mzintegrationparams.h>
#include <pappsomspp/core/utils.h>


using namespace pappso;


TEST_CASE("Constructing MzIntegrationParams objects.", "[MzIntegrationParams][constructors]")
{

  SECTION("Construct a MzIntegrationParams", "[MzIntegrationParams]")
  {
    MzIntegrationParams mz_integration_params1;
    PrecisionPtr precision_p = pappso::PrecisionFactory::getResInstance(40000);

    REQUIRE(mz_integration_params1.getBinningType() == MzIntegrationParams::BinningType::ARBITRARY);

    REQUIRE(precision_p == mz_integration_params1.getBinSizeModel());

    double smallestMz                            = 1800.373856;
    double greatestMz                            = 2600.956480;
    MzIntegrationParams::BinningType binningType = MzIntegrationParams::BinningType::ARBITRARY;
    int decimalPlaces                            = 3;
    bool binSizeDivisor                          = 6;
    bool removeZeroValDataPoints                 = true;


    MzIntegrationParams mz_integration_params2(smallestMz,
                                               greatestMz,
                                               binningType,
                                               precision_p,
                                               binSizeDivisor,
                                               decimalPlaces,
                                               removeZeroValDataPoints);

    REQUIRE(mz_integration_params2.getSmallestMz() == smallestMz);
    REQUIRE(mz_integration_params2.getGreatestMz() == greatestMz);
    REQUIRE(mz_integration_params2.getBinningType() == binningType);
    REQUIRE(mz_integration_params2.getBinSizeModel() == precision_p);
    REQUIRE(mz_integration_params2.getBinSizeDivisor() == binSizeDivisor);
    REQUIRE(mz_integration_params2.getDecimalPlaces() == decimalPlaces);
    REQUIRE(mz_integration_params2.isRemoveZeroValDataPoints() == removeZeroValDataPoints);
  }


  SECTION(
    "Construct a MzIntegrationParams from another "
    "MzIntegrationParams",
    "[MzIntegrationParams]")
  {

    double smallestMz                            = 1800.373856;
    double greatestMz                            = 2600.956480;
    MzIntegrationParams::BinningType binningType = MzIntegrationParams::BinningType::ARBITRARY;
    int decimalPlaces                            = 3;
    PrecisionPtr precision_p                     = pappso::PrecisionFactory::getPpmInstance(20);
    bool binSizeDivisor                          = 6;
    bool removeZeroValDataPoints                 = true;

    MzIntegrationParams mz_integration_params1(smallestMz,
                                               greatestMz,
                                               binningType,
                                               precision_p,
                                               binSizeDivisor,
                                               decimalPlaces,
                                               removeZeroValDataPoints);

    MzIntegrationParams mz_integration_params2;
    mz_integration_params2.initialize(mz_integration_params1);

    REQUIRE(mz_integration_params2.getSmallestMz() == smallestMz);
    REQUIRE(mz_integration_params2.getGreatestMz() == greatestMz);
    REQUIRE(mz_integration_params2.getBinningType() == binningType);
    REQUIRE(mz_integration_params2.getBinSizeModel() == precision_p);
    REQUIRE(mz_integration_params2.getBinSizeDivisor() == binSizeDivisor);
    REQUIRE(mz_integration_params2.getDecimalPlaces() == decimalPlaces);
    REQUIRE(mz_integration_params2.isRemoveZeroValDataPoints() == removeZeroValDataPoints);
  }
}


TEST_CASE("Create bins with Da-based bin size", "[MzIntegrationParams]")
{
  double smallestMz                            = 1800.373856;
  double greatestMz                            = 1800.373856;
  MzIntegrationParams::BinningType binningType = MzIntegrationParams::BinningType::ARBITRARY;
  int decimalPlaces                            = 3;
  PrecisionPtr precision_p                     = pappso::PrecisionFactory::getDaltonInstance(0.05);
  bool binSizeDivisor                          = 6;
  bool removeZeroValDataPoints                 = true;

  MzIntegrationParams mz_integration_params(smallestMz,
                                            greatestMz,
                                            binningType,
                                            precision_p,
                                            binSizeDivisor,
                                            decimalPlaces,
                                            removeZeroValDataPoints);

  SECTION("Create bins in ARBITRARY mode", "[MzIntegrationParams]")
  {

    std::vector<double> bins = mz_integration_params.createBins();

    // Do not forget that we round to 3 decimal places:
    REQUIRE(bins.front() == 1800.374);

    // We create two bins: the first mz value (1800.374) and a new one that is
    // that mz value incremented by the delta (that is the size of the bin that
    // is created using an increment of 0.05).

    double manual_value = bins.front() + precision_p->delta(bins.front());

    // Below: if abs(1.0 - 1.2) is less or equal to 0.2 -> success
    // REQUIRE_THAT(1.0, Catch::Matchers::WithinAbs(1.2, 0.2)); // success
    // REQUIRE_THAT(1.2, Catch::Matchers::WithinAbs(1.1, 0.2)); // success
    // REQUIRE_THAT(1.0, Catch::Matchers::WithinAbs(1.3, 0.2)); // failure
    // REQUIRE_THAT(1.3, Catch::Matchers::WithinAbs(1.0, 0.2)); // failure

    REQUIRE(bins.back() == Catch::Approx(manual_value));
  }
}


TEST_CASE("Create bins with ppm-based bin sizes", "[MzIntegrationParams]")
{
  double smallestMz                            = 1800.373856;
  double greatestMz                            = 1800.373856;
  MzIntegrationParams::BinningType binningType = MzIntegrationParams::BinningType::ARBITRARY;
  int decimalPlaces                            = 3;
  PrecisionPtr precision_p                     = pappso::PrecisionFactory::getPpmInstance(20);
  bool binSizeDivisor                          = 6;
  bool removeZeroValDataPoints                 = true;

  MzIntegrationParams mz_integration_params(smallestMz,
                                            greatestMz,
                                            binningType,
                                            precision_p,
                                            binSizeDivisor,
                                            decimalPlaces,
                                            removeZeroValDataPoints);

  SECTION("Create bins in ARBITRARY mode", "[MzIntegrationParams]")
  {

    std::vector<double> bins = mz_integration_params.createBins();

    // Do not forget that we round to 3 decimal places:
    REQUIRE(bins.front() == 1800.374);

    // Check that the precision delta is computed correctly:
    double precision_delta = 1800.374 * 20 / 1000000;
    REQUIRE(pappso::Utils::almostEqual(
      precision_p->delta(1800.374), precision_delta, /*decimal_places*/ 15));

    double rounded_precision_delta =
      ceil((precision_delta * pow(10, decimalPlaces)) - 0.49) / pow(10, decimalPlaces);

    // We create two bins: the first mz value (1800.374) and a new one that is
    // that mz value incremented by the delta (that is the size of the bin that
    // is created using relative proportion of 20 ppm).

    REQUIRE(bins.back() == 1800.374 + rounded_precision_delta);
  }
}


TEST_CASE("Create bins with res-based bin sizes", "[MzIntegrationParams]")
{
  double smallestMz                            = 1800.373856;
  double greatestMz                            = 1800.373856;
  MzIntegrationParams::BinningType binningType = MzIntegrationParams::BinningType::ARBITRARY;
  int decimalPlaces                            = 3;
  PrecisionPtr precision_p                     = pappso::PrecisionFactory::getResInstance(20000);
  bool binSizeDivisor                          = 6;
  bool removeZeroValDataPoints                 = true;

  MzIntegrationParams mz_integration_params(smallestMz,
                                            greatestMz,
                                            binningType,
                                            precision_p,
                                            binSizeDivisor,
                                            decimalPlaces,
                                            removeZeroValDataPoints);

  SECTION("Create bins in ARBITRARY mode", "[MzIntegrationParams]")
  {

    std::vector<double> bins = mz_integration_params.createBins();

    // Do not forget that we round to 3 decimal places:
    REQUIRE(bins.front() == 1800.374);

    // Check that the precision delta is computed correctly:
    double precision_delta = 1800.374 / 20000;
    REQUIRE(pappso::Utils::almostEqual(
      precision_p->delta(1800.374), precision_delta, /*decimal_places*/ 15));

    double rounded_precision_delta =
      ceil((precision_delta * pow(10, decimalPlaces)) - 0.49) / pow(10, decimalPlaces);

    // We create two bins: the first mz value (1800.374) and a new one that is
    // that mz value incremented by the delta (that is the size of the bin that
    // is created using relative proportion of 20 ppm).

    REQUIRE(bins.back() == 1800.374 + rounded_precision_delta);
  }
}