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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
|
/////////////////////// Qt includes
#include <QDebug>
#include <QString>
#include <QDir>
/////////////////////// Catch2 includes
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
/////////////////////// Local includes
#include "TestUtils.hpp"
#include <libXpertMass/FragmentationPathway.hpp>
namespace MsXpS
{
namespace libXpertMassCore
{
TestUtils test_utils_fragmentation_pathway_1_letter("protein-1-letter", 1);
TestUtils test_utils_fragmentation_pathway_3_letters("protein-3-letters", 1);
ErrorList error_list_fragmentation_pathway;
SCENARIO(
"FragmentationPathway objects can be constructed empty and then initialized "
"piecemeal "
"until they are valid",
"[FragmentationPathway]")
{
test_utils_fragmentation_pathway_1_letter.initializeXpertmassLibrary();
PolChemDefCstSPtr pol_chem_def_csp =
test_utils_fragmentation_pathway_1_letter.msp_polChemDef;
GIVEN("A FragmentationPathway constructed with no parameter at all")
{
FragmentationPathway fragmentation_pathway;
REQUIRE_FALSE(fragmentation_pathway.isValid());
REQUIRE_FALSE(
fragmentation_pathway.validate(error_list_fragmentation_pathway));
// <fgs>
// <name>a</name>
// <end>LE</end>
// <formula>-C1O1</formula>
// <comment>opt_comment</comment>
// <fgr>
// <name>one_rule</name>
// <formula>+H2O</formula>
// <prev-mnm-code>M</prev-mnm-code>
// <this-mnm-code>Y</this-mnm-code>
// <next-mnm-code>T</next-mnm-code>
// <comment>opt_comment</comment>
// </fgr>
// other fgr allowed, none possible also
// </fgs>
WHEN("The PolChemDef is set with the setter")
{
fragmentation_pathway.setPolchemDefCstSPtr(pol_chem_def_csp);
THEN(
"The FragmentationPathway is still invalid and does not validate "
"successfully")
{
REQUIRE_FALSE(fragmentation_pathway.isValid());
REQUIRE_FALSE(
fragmentation_pathway.validate(error_list_fragmentation_pathway));
}
AND_WHEN("The name is set with the setter")
{
fragmentation_pathway.setName("a");
THEN(
"The FragmentationPathway is still invalid and does not validate "
"successfully")
{
REQUIRE_FALSE(fragmentation_pathway.isValid());
REQUIRE_FALSE(
fragmentation_pathway.validate(error_list_fragmentation_pathway));
AND_THEN("A FragmentationPathway can be gotten from the PolChemDef")
{
FragmentationPathwayCstSPtr fragmentation_pathway_csp =
fragmentation_pathway.getFromPolChemDefByName();
REQUIRE(fragmentation_pathway_csp != nullptr);
REQUIRE(fragmentation_pathway.isKnownByNameInPolChemDef() ==
Enums::PolChemDefEntityStatus::ENTITY_KNOWN);
}
}
AND_WHEN("The end is set with the setter")
{
fragmentation_pathway.setFragEnd(Enums::FragEnd::LE);
THEN(
"The FragmentationPathway is still invalid and does not validate "
"successfully")
{
REQUIRE_FALSE(fragmentation_pathway.isValid());
REQUIRE_FALSE(
fragmentation_pathway.validate(error_list_fragmentation_pathway));
}
AND_WHEN("The formula is set with one of the setters")
{
fragmentation_pathway.setFormula("-C1O1");
THEN(
"The FragmentationPathway is valid and does validate "
"successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(
error_list_fragmentation_pathway));
}
AND_WHEN("The formula is set with other of the setters")
{
fragmentation_pathway.setFormula(Formula("-C1O1"));
THEN(
"The FragmentationPathway is valid and does validate "
"successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(
error_list_fragmentation_pathway));
}
AND_WHEN("The comment is set with the setter")
{
fragmentation_pathway.setComment("opt_comment");
THEN(
"The FragmentationPathway is still valid and does validate "
"successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(
error_list_fragmentation_pathway));
}
AND_WHEN("A correct FragmentationRule is added")
{
// <fgr>
// <name>one_rule</name>
// <formula>+H2O</formula>
// <prev-mnm-code>M</prev-mnm-code>
// <this-mnm-code>Y</this-mnm-code>
// <next-mnm-code>T</next-mnm-code>
// <comment>opt_comment</comment>
// </fgr>
FragmentationRuleSPtr frag_rule_sp =
std::make_shared<FragmentationRule>(pol_chem_def_csp,
"one_rule",
"F",
"D",
"E",
"opt_comment",
"+H2O");
fragmentation_pathway.addRule(frag_rule_sp);
THEN(
"The FragmentationPathway is still valid and does validate "
"successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(
error_list_fragmentation_pathway));
REQUIRE(fragmentation_pathway.getName().toStdString() ==
"a");
REQUIRE(fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "one_rule");
}
}
}
}
}
}
}
}
}
}
SCENARIO(
"FragmentationPathway objects can get as many FragmentationRule instances "
"as "
"necessary",
"[FragmentationPathway]")
{
test_utils_fragmentation_pathway_1_letter.initializeXpertmassLibrary();
PolChemDefCstSPtr pol_chem_def_csp =
test_utils_fragmentation_pathway_1_letter.msp_polChemDef;
GIVEN(
"A FragmentationPathway constructed with full parameters (with "
"FragmentationRules)")
{
FragmentationPathway fragmentation_pathway(
pol_chem_def_csp, "a", "-C1O1", Enums::FragEnd::LE, "opt_comment");
FragmentationRuleSPtr frag_rule_1_sp = std::make_shared<FragmentationRule>(
pol_chem_def_csp, "one_rule", "F", "D", "E", "opt1_comment", "+H2O");
FragmentationRuleSPtr frag_rule_2_sp = std::make_shared<FragmentationRule>(
pol_chem_def_csp, "two_rule", "G", "E", "F", "opt2_comment", "+H4O2");
FragmentationRuleSPtr frag_rule_3_sp = std::make_shared<FragmentationRule>(
pol_chem_def_csp, "three_rule", "H", "F", "G", "opt3_comment", "+H6O9");
fragmentation_pathway.addRule(frag_rule_1_sp);
fragmentation_pathway.addRule(frag_rule_2_sp);
fragmentation_pathway.insertRuleAt(frag_rule_3_sp, 1);
THEN("The FragmentationPathway is valid and does validate successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 3);
REQUIRE(
fragmentation_pathway.getRulesCstRef().at(0)->getName().toStdString() ==
"one_rule");
REQUIRE(
fragmentation_pathway.getRulesCstRef().at(1)->getName().toStdString() ==
"three_rule");
REQUIRE(
fragmentation_pathway.getRulesCstRef().at(2)->getName().toStdString() ==
"two_rule");
}
WHEN("Copy-constructing a new FragmentationPathway")
{
FragmentationPathway new_fragmentation_pathway(fragmentation_pathway);
THEN(
"The new FragmentationPathway is valid, does validate successfully "
"and operator==() returns proper result")
{
REQUIRE(new_fragmentation_pathway.isValid());
REQUIRE(
new_fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(new_fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(new_fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(new_fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(new_fragmentation_pathway.getRulesCstRef().size() == 3);
REQUIRE(new_fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "one_rule");
REQUIRE(new_fragmentation_pathway.getRulesCstRef()
.at(1)
->getName()
.toStdString() == "three_rule");
REQUIRE(new_fragmentation_pathway.getRulesCstRef()
.at(2)
->getName()
.toStdString() == "two_rule");
REQUIRE(new_fragmentation_pathway == fragmentation_pathway);
}
}
WHEN("One FragmentationRule is removed")
{
fragmentation_pathway.removeRuleAt(0);
THEN("The container changes")
{
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 2);
REQUIRE(fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "three_rule");
REQUIRE(fragmentation_pathway.getRulesCstRef()
.at(1)
->getName()
.toStdString() == "two_rule");
}
WHEN("One FragmentationRule is removed")
{
fragmentation_pathway.removeRuleAt(1);
THEN("The container changes")
{
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "three_rule");
}
}
}
}
}
SCENARIO(
"FragmentationPathway objects can be copy- or assignment-constructed and "
"compared",
"[FragmentationPathway]")
{
test_utils_fragmentation_pathway_1_letter.initializeXpertmassLibrary();
PolChemDefCstSPtr pol_chem_def_csp =
test_utils_fragmentation_pathway_1_letter.msp_polChemDef;
GIVEN(
"A FragmentationPathway constructed with full parameters (with "
"FragmentationRules)")
{
FragmentationPathway fragmentation_pathway(
pol_chem_def_csp, "a", "-C1O1", Enums::FragEnd::LE, "opt_comment");
FragmentationRuleSPtr frag_rule_sp = std::make_shared<FragmentationRule>(
pol_chem_def_csp, "one_rule", "F", "D", "E", "opt_comment", "+H2O");
fragmentation_pathway.addRule(frag_rule_sp);
THEN("The FragmentationPathway is valid and does validate successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(
fragmentation_pathway.getRulesCstRef().at(0)->getName().toStdString() ==
"one_rule");
}
WHEN("Another FragmentationPathway is copy-constructed")
{
FragmentationPathway new_fragmentation_pathway(fragmentation_pathway);
THEN("It is identical to the original one")
{
REQUIRE(new_fragmentation_pathway.isValid());
REQUIRE(
new_fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(new_fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(new_fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(new_fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(new_fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(new_fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "one_rule");
}
THEN("The comparison operators work")
{
REQUIRE(new_fragmentation_pathway == fragmentation_pathway);
REQUIRE_FALSE(new_fragmentation_pathway != fragmentation_pathway);
REQUIRE(new_fragmentation_pathway == new_fragmentation_pathway);
REQUIRE_FALSE(new_fragmentation_pathway != new_fragmentation_pathway);
}
}
WHEN("Another FragmentationPathway is assignment-initialized")
{
FragmentationPathway new_fragmentation_pathway;
new_fragmentation_pathway = fragmentation_pathway;
THEN("It is identical to the original one")
{
REQUIRE(new_fragmentation_pathway.isValid());
REQUIRE(
new_fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(new_fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(new_fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(new_fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(new_fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(new_fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "one_rule");
}
THEN("The comparison operators work")
{
REQUIRE(new_fragmentation_pathway == fragmentation_pathway);
REQUIRE_FALSE(new_fragmentation_pathway != fragmentation_pathway);
REQUIRE(new_fragmentation_pathway == new_fragmentation_pathway);
REQUIRE_FALSE(new_fragmentation_pathway != new_fragmentation_pathway);
}
}
}
}
SCENARIO(
"FragmentationPathway objects from version 1 XML element can be "
"initialized "
"from an <fgs> XML element and can export themselves as such also",
"[FragmentationPathway]")
{
PolChemDefCstSPtr pol_chem_def_csp =
test_utils_fragmentation_pathway_1_letter.msp_polChemDef;
// int fgs_element_index = 0;
// //
// int name_element_index = 1;
// int name_text_index = 2;
// int frag_end_element_index = 3;
// int frag_end_text_index = 4;
// int formula_element_index = 5;
// int formula_text_index = 6;
// int side_chain_element_index = 7;
// int side_chain_text_index = 8;
// int comment_element_index = 9;
// int comment_text_index = 10;
// //
// int fgr_element_index = 11;
// //
// int fgr_name_element_index = 12;
// int fgr_name_text_index = 13;
// int fgr_formula_element_index = 14;
// int fgr_formula_text_index = 15;
// int prev_code_element_index = 16;
// int prev_code_text_index = 17;
// int curr_code_element_index = 18;
// int curr_code_text_index = 19;
// int next_code_element_index = 20;
// int next_code_text_index = 21;
// int fgr_comment_element_index = 22;
// int fgr_comment_text_index = 23;
// <fgs>
// <name>a</name>
// <end>LE</end>
// <formula>-C1O1</formula>
// <sidechaincontrib>0</sidechaincontrib>
// <comment>opt_comment</comment>
// <fgr>
// <name>one_rule</name>
// <formula>+H2O</formula>
// <prev-mnm-code>M</prev-mnm-code>
// <curr-mnm-code>Y</curr-mnm-code>
// <next-mnm-code>T</next-mnm-code>
// <comment>opt_comment</comment>
// </fgr>
// other fgr allowed, none possible also
// </fgs>
QStringList dom_strings{"fgs", // 0
"name", // 1
"a", // 2
"end", // 3
"LE", // 4
"formula", // 5
"-C1O1", // 6
"sidechaincontrib", // 7
"0", // 8
"comment", // 9
"opt_comment", // 10
"fgr", // 11
"name", // 12
"one_rule", // 13
"formula", // 14
"+H2O", // 15
"prev-mnm-code", // 16
"M", // 17
"curr-mnm-code", // 18
"Y", // 19
"next-mnm-code", // 20
"T", // 21
"comment", // 22
"opt_comment"}; // 23
QDomDocument document =
test_utils_fragmentation_pathway_1_letter.craftFgsDomDocument(dom_strings);
QDomElement fragmentation_pathway_element =
document.elementsByTagName(dom_strings[0]).item(0).toElement();
// Use indentation 1 to mimick what happens in XpertMass.
// qDebug().noquote() << "The document:\n'"
// << document.toString(/*indentation*/ 1) << "'";
// We need to remove all spaces from the strings to be able to compare
// them. There must be a bug somewhere because with the original output, at
// the screen everything seems correct, but test FAILED.
QString document_string = document.toString(/*indentation*/ 0);
document_string = Utils::unspacify(document_string);
QString expected_fgs_string =
"<fgs><name>a</name><end>LE</end><formula>-C1O1</formula>"
"<sidechaincontrib>0</sidechaincontrib><comment>opt_comment</comment>"
"<fgr><name>one_rule</name><formula>+H2O</formula>"
"<prev-mnm-code>M</prev-mnm-code><curr-mnm-code>Y</curr-mnm-code>"
"<next-mnm-code>T</next-mnm-code><comment>opt_comment</comment>"
"</fgr></fgs>";
expected_fgs_string = Utils::unspacify(expected_fgs_string);
QString expected_fgp_string =
"<fgp><name>a</name><end>LE</end><formula>-C1O1</formula>"
"<sidechaincontrib>0</sidechaincontrib><comment>opt_comment</comment>"
"<fgr><name>one_rule</name><formula>+H2O</formula>"
"<prev-mnm-code>M</prev-mnm-code><curr-mnm-code>Y</curr-mnm-code>"
"<next-mnm-code>T</next-mnm-code><comment>opt_comment</comment>"
"</fgr></fgp>";
expected_fgp_string = Utils::unspacify(expected_fgp_string);
REQUIRE(document_string.toStdString() == expected_fgs_string.toStdString());
WHEN("Creating a FragmentationPathway only with PolChemDef")
{
FragmentationPathway fragmentation_pathway(pol_chem_def_csp);
AND_WHEN("Initializing it with an XML <fgs> element")
{
REQUIRE(fragmentation_pathway.renderXmlFgsElement(
fragmentation_pathway_element, /*version*/ 1));
THEN(
"The initalized FragmentationPathway is valid and validates "
"successfully")
{
THEN("The FragmentationPathway is valid and validates successfully")
{
REQUIRE(fragmentation_pathway.isValid());
REQUIRE(
fragmentation_pathway.validate(error_list_fragmentation_pathway));
REQUIRE(fragmentation_pathway.getName().toStdString() == "a");
REQUIRE(fragmentation_pathway.getFragEnd() == Enums::FragEnd::LE);
REQUIRE(fragmentation_pathway.getFormulaCstRef()
.getActionFormula()
.toStdString() == "-C1O1");
REQUIRE(fragmentation_pathway.getRulesCstRef().size() == 1);
REQUIRE(fragmentation_pathway.getRulesCstRef()
.at(0)
->getName()
.toStdString() == "one_rule");
}
}
AND_WHEN("Exporting itself as a <fgp> XML element")
{
QString xml_text =
fragmentation_pathway.formatXmlFgpElement(/*offset*/ 1);
xml_text = Utils::unspacify(xml_text);
THEN("The text must be identical to the initial XML <fgs> string")
{
REQUIRE(xml_text.toStdString() == expected_fgp_string.toStdString());
}
}
}
}
}
} // namespace libXpertMassCore
} // namespace MsXpS
|