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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
#include <iostream>
#include <iomanip>
#include <catch2/catch_test_macros.hpp>
#include <QDebug>
#include <pappsomspp/core/utils.h>
#include <pappsomspp/core/trace/datapoint.h>
#include <pappsomspp/core/trace/trace.h>
#include <pappsomspp/core/trace/maptrace.h>
#include <pappsomspp/core/massspectrum/massspectrum.h>
#include <pappsomspp/core/processing/combiners/massdatacombinerinterface.h>
#include <pappsomspp/core/processing/combiners/massspectrumpluscombiner.h>
#include <pappsomspp/core/processing/combiners/mzintegrationparams.h>
namespace pappso
{
TEST_CASE("Constructing MassSpectrumPlusCombiner objects.",
"[MassSpectrumPlusCombiner][constructors]")
{
SECTION("Construct a MassSpectrumPlusCombiner", "[MassSpectrumPlusCombiner]")
{
MassSpectrumPlusCombiner mass_spectrum_combiner1;
REQUIRE(mass_spectrum_combiner1.getDecimalPlaces() == -1);
int decimal_places = 3;
MassSpectrumPlusCombiner mass_spectrum_combiner2(decimal_places);
REQUIRE(mass_spectrum_combiner2.getDecimalPlaces() == decimal_places);
}
SECTION(
"Construct a MassSpectrumPlusCombiner from another "
"MassSpectrumPlusCombiner",
"[MassSpectrumPlusCombiner]")
{
int decimal_places = 3;
MassSpectrumPlusCombiner mass_spectrum_combiner(decimal_places);
MassSpectrumPlusCombiner mass_spectrum_combiner1(mass_spectrum_combiner);
REQUIRE(mass_spectrum_combiner1.getDecimalPlaces() == decimal_places);
// Test the handling of the bins.
// Create the bins
std::vector<double> bins{0.001, 0.002, 0.003, 0.004, 0.005};
MassSpectrumPlusCombiner mass_spectrum_combiner2(decimal_places);
mass_spectrum_combiner2.setBins(bins);
MassSpectrumPlusCombiner mass_spectrum_combiner3(mass_spectrum_combiner2);
REQUIRE(mass_spectrum_combiner3.getBins().size() == 5);
REQUIRE(mass_spectrum_combiner3.getBins().front() == 0.001);
REQUIRE(mass_spectrum_combiner3.getBins().back() == 0.005);
}
}
#if !defined(__i386__)
// This test unbelievable does not pass on i386...
TEST_CASE("Performing combinations with MassSpectrumPlusCombiner",
"[MassSpectrumPlusCombiner][combinations]")
{
SECTION("Combine two complementary MassSpectrum objects into a MapTrace.",
"[MassSpectrumPlusCombiner]")
{
// Create a MassSpectrum that looks like something real.
std::vector<DataPoint> data_point_vector;
// clang-format off
data_point_vector.push_back(DataPoint("610.02000 12963.5715942383"));
data_point_vector.push_back(DataPoint("610.07000 15639.6568298340"));
data_point_vector.push_back(DataPoint("610.12000 55999.7628784180"));
data_point_vector.push_back(DataPoint("610.17000 9335990.3578681946"));
data_point_vector.push_back(DataPoint("610.2200000 635674266.1611375809"));
data_point_vector.push_back(DataPoint("610.27000 54459.4762458801"));
data_point_vector.push_back(DataPoint("610.32000 205580.6580276489"));
data_point_vector.push_back(DataPoint("610.37000 84627.3196716309"));
data_point_vector.push_back(DataPoint("610.42000 51061.7636718750"));
data_point_vector.push_back(DataPoint("610.47000 0.0000000000"));
data_point_vector.push_back(DataPoint("610.52000 29848.3424072266"));
data_point_vector.push_back(DataPoint("610.57000 27266.8031616211"));
data_point_vector.push_back(DataPoint("610.62000 36922.3937377930"));
data_point_vector.push_back(DataPoint("610.67000 44082.4265441895"));
data_point_vector.push_back(DataPoint("610.72000 32580.1677703857"));
data_point_vector.push_back(DataPoint("610.77000 39453.8380126953"));
data_point_vector.push_back(DataPoint("610.82000 63698.7124328613"));
data_point_vector.push_back(DataPoint("610.87000 34406.7755126953"));
data_point_vector.push_back(DataPoint("610.92000 33385.7486267090"));
data_point_vector.push_back(DataPoint("610.97000 22105.9357604980"));
// clang-format on
REQUIRE(20 == data_point_vector.size());
MassSpectrum mass_spectrum1(data_point_vector);
REQUIRE(20 == mass_spectrum1.size());
data_point_vector.clear();
// Create another mass spectrum that is the "continuation" of the first one.
// clang-format off
data_point_vector.push_back(DataPoint("611.02000 12963.5715942383"));
data_point_vector.push_back(DataPoint("611.07000 15639.6568298340"));
data_point_vector.push_back(DataPoint("611.12000 55999.7628784180"));
data_point_vector.push_back(DataPoint("611.17000 9335990.3578681946"));
data_point_vector.push_back(DataPoint("611.2200000 635674266.1611375809"));
data_point_vector.push_back(DataPoint("611.27000 54459.4762458801"));
data_point_vector.push_back(DataPoint("611.32000 205580.6580276489"));
data_point_vector.push_back(DataPoint("611.37000 84627.3196716309"));
data_point_vector.push_back(DataPoint("611.42000 51061.7636718750"));
data_point_vector.push_back(DataPoint("611.47000 0.00000000"));
data_point_vector.push_back(DataPoint("611.52000 29848.3424072266"));
data_point_vector.push_back(DataPoint("611.57000 27266.8031616211"));
data_point_vector.push_back(DataPoint("611.62000 36922.3937377930"));
data_point_vector.push_back(DataPoint("611.67000 44082.4265441895"));
data_point_vector.push_back(DataPoint("611.72000 32580.1677703857"));
data_point_vector.push_back(DataPoint("611.77000 39453.8380126953"));
data_point_vector.push_back(DataPoint("611.82000 63698.7124328613"));
data_point_vector.push_back(DataPoint("611.87000 34406.7755126953"));
data_point_vector.push_back(DataPoint("611.92000 33385.7486267090"));
data_point_vector.push_back(DataPoint("611.97000 22105.9357604980"));
// clang-format on
REQUIRE(20 == data_point_vector.size());
MassSpectrum mass_spectrum2(data_point_vector);
REQUIRE(20 == mass_spectrum2.size());
// Prepare the bins on the basis of the spectrum.
int decimal_places = 5;
pappso::PrecisionPtr precision_p =
pappso::PrecisionFactory::getDaltonInstance(0.05);
bool binSizeDivisor = 6;
MzIntegrationParams mz_integration_params(610.02,
611.97,
MzIntegrationParams::BinningType::ARBITRARY,
precision_p,
binSizeDivisor,
decimal_places,
true);
// Check that it does not compute bins, since BinningType::NONE.
std::vector<double> bins = mz_integration_params.createBins();
// Creation of the same number of data points plus a last one bin.
REQUIRE(bins.size() == mass_spectrum1.size() + mass_spectrum2.size() + 1);
REQUIRE(bins[0] == 610.02000);
// The last bin matches the last DataPoint of the second spectrum + one bin
// size.
REQUIRE(bins.back() == 612.02000);
// Now compute the combination without binning.
MassSpectrumPlusCombiner mass_spectrum_combiner(decimal_places);
mass_spectrum_combiner.setBins(bins);
MapTrace map_trace;
mass_spectrum_combiner.combine(map_trace, mass_spectrum1);
// std::cout << std::setprecision(10)
//<< "First map item x: " << map_trace.begin()->first
//<< " y: " << map_trace.begin()->second << std::endl;
REQUIRE(map_trace.size() == 20);
REQUIRE(map_trace[610.02000] == 12963.5715942383);
REQUIRE(map_trace[610.27000] == 54459.4762458801);
REQUIRE(map_trace[610.97000] == 22105.9357604980);
// Now combine the second mass spectrum.
mass_spectrum_combiner.combine(map_trace, mass_spectrum2);
REQUIRE(map_trace.size() == 40);
REQUIRE(map_trace[610.02000] == 12963.5715942383);
REQUIRE(map_trace[610.27000] == 54459.4762458801);
REQUIRE(map_trace[610.97000] == 22105.9357604980);
}
SECTION("Combine two intermixed MassSpectrum objects into a MapTrace.",
"[MassSpectrumPlusCombiner]")
{
// Create a MassSpectrum that looks like something real.
std::vector<DataPoint> data_point_vector;
// clang-format off
data_point_vector.push_back(DataPoint("610.02000 12963.5715942383"));
data_point_vector.push_back(DataPoint("610.07000 15639.6568298340"));
data_point_vector.push_back(DataPoint("610.12000 55999.7628784180"));
data_point_vector.push_back(DataPoint("610.17000 9335990.3578681946"));
data_point_vector.push_back(DataPoint("610.2200000 635674266.1611375809"));
data_point_vector.push_back(DataPoint("610.27000 54459.4762458801"));
data_point_vector.push_back(DataPoint("610.32000 205580.6580276489"));
data_point_vector.push_back(DataPoint("610.37000 84627.3196716309"));
data_point_vector.push_back(DataPoint("610.42000 51061.7636718750"));
data_point_vector.push_back(DataPoint("610.47000 0.0000000000"));
data_point_vector.push_back(DataPoint("610.52000 29848.3424072266"));
data_point_vector.push_back(DataPoint("610.57000 27266.8031616211"));
data_point_vector.push_back(DataPoint("610.62000 36922.3937377930"));
data_point_vector.push_back(DataPoint("610.67000 44082.4265441895"));
data_point_vector.push_back(DataPoint("610.72000 32580.1677703857"));
data_point_vector.push_back(DataPoint("610.77000 39453.8380126953"));
data_point_vector.push_back(DataPoint("610.82000 63698.7124328613"));
data_point_vector.push_back(DataPoint("610.87000 34406.7755126953"));
data_point_vector.push_back(DataPoint("610.92000 33385.7486267090"));
data_point_vector.push_back(DataPoint("610.97000 22105.9357604980"));
// clang-format on
REQUIRE(20 == data_point_vector.size());
MassSpectrum mass_spectrum1(data_point_vector);
REQUIRE(20 == mass_spectrum1.size());
data_point_vector.clear();
// Create another mass spectrum that intermixes with the first one by adding
// 0.005 to the previous m/z values.
// clang-format off
data_point_vector.push_back(DataPoint("610.02500 12963.5715942383"));
data_point_vector.push_back(DataPoint("610.07500 15639.6568298340"));
data_point_vector.push_back(DataPoint("610.12500 55999.7628784180"));
data_point_vector.push_back(DataPoint("610.17500 9335990.3578681946"));
data_point_vector.push_back(DataPoint("610.2200000 635674266.1611375809"));
data_point_vector.push_back(DataPoint("610.27500 54459.4762458801"));
data_point_vector.push_back(DataPoint("610.32500 205580.6580276489"));
data_point_vector.push_back(DataPoint("610.37500 84627.3196716309"));
data_point_vector.push_back(DataPoint("610.42500 51061.7636718750"));
data_point_vector.push_back(DataPoint("610.47500 0.0000000000"));
data_point_vector.push_back(DataPoint("610.52500 29848.3424072266"));
data_point_vector.push_back(DataPoint("610.57500 27266.8031616211"));
data_point_vector.push_back(DataPoint("610.62500 36922.3937377930"));
data_point_vector.push_back(DataPoint("610.67500 44082.4265441895"));
data_point_vector.push_back(DataPoint("610.72500 32580.1677703857"));
data_point_vector.push_back(DataPoint("610.77500 39453.8380126953"));
data_point_vector.push_back(DataPoint("610.82500 63698.7124328613"));
data_point_vector.push_back(DataPoint("610.87500 34406.7755126953"));
data_point_vector.push_back(DataPoint("610.92500 33385.7486267090"));
data_point_vector.push_back(DataPoint("610.97500 22105.9357604980"));
// clang-format on
REQUIRE(20 == data_point_vector.size());
MassSpectrum mass_spectrum2(data_point_vector);
REQUIRE(20 == mass_spectrum2.size());
// Prepare the bins on the basis of the spectrum.
int decimal_places = 5;
pappso::PrecisionPtr precision_p =
pappso::PrecisionFactory::getDaltonInstance(0.05);
bool binSizeDivisor = 6;
MzIntegrationParams mz_integration_params(610.02,
610.975,
MzIntegrationParams::BinningType::ARBITRARY,
precision_p,
binSizeDivisor,
decimal_places,
true);
// Check that it does not compute bins, since BinningType::NONE.
std::vector<double> bins = mz_integration_params.createBins();
REQUIRE(bins.size() == 21);
REQUIRE(bins[0] == 610.02000);
REQUIRE(bins.back() == 610.97000 + 0.05);
MassSpectrumPlusCombiner mass_spectrum_combiner(decimal_places);
mass_spectrum_combiner.setBins(bins);
MapTrace map_trace;
mass_spectrum_combiner.combine(map_trace, mass_spectrum1);
REQUIRE(map_trace.size() == 20);
}
}
#endif
} // namespace pappso
|