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 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
|
//Copyright 2015 Ryan Wick
//This file is part of Bandage.
//Bandage is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//Bandage is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Bandage. If not, see <http://www.gnu.org/licenses/>.
#include <QtTest/QtTest>
#include <QDebug>
#include "ogdf/basic/Graph.h"
#include "ogdf/basic/GraphAttributes.h"
#include "../graph/assemblygraph.h"
#include "../program/settings.h"
#include "../blast/blastsearch.h"
#include "../ui/mygraphicsview.h"
#include "../program/memory.h"
#include "../graph/debruijnnode.h"
#include "../graph/debruijnedge.h"
#include "../program/globals.h"
#include "../command_line/commoncommandlinefunctions.h"
class BandageTests : public QObject
{
Q_OBJECT
private slots:
void loadFastg();
void loadLastGraph();
void loadTrinity();
void pathFunctionsOnLastGraph();
void pathFunctionsOnFastg();
void pathFunctionsOnGfaSequencesInGraph();
void pathFunctionsOnGfaSequencesInFasta();
void graphLocationFunctions();
void loadCsvData();
void loadCsvDataTrinity();
void blastSearch();
void blastSearchFilters();
void graphScope();
void commandLineSettings();
void sciNotComparisons();
void graphEdits();
void velvetToGfa();
void spadesToGfa();
void mergeNodesOnGfa();
void changeNodeNames();
void changeNodeDepths();
void blastQueryPaths();
void bandageInfo();
private:
void createGlobals();
bool createBlastTempDirectory();
void deleteBlastTempDirectory();
QString getTestDirectory();
DeBruijnEdge * getEdgeFromNodeNames(QString startingNodeName,
QString endingNodeName);
bool doCircularSequencesMatch(QByteArray s1, QByteArray s2);
};
void BandageTests::loadFastg()
{
createGlobals();
bool fastgGraphLoaded = g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
//Check that the graph loaded properly.
QCOMPARE(fastgGraphLoaded, true);
//Check that the appropriate number of nodes/edges are present.
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 88);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphEdges.size(), 118);
//Check the length of a couple nodes.
DeBruijnNode * node1 = g_assemblyGraph->m_deBruijnGraphNodes["1+"];
DeBruijnNode * node28 = g_assemblyGraph->m_deBruijnGraphNodes["28-"];
QCOMPARE(node1->getLength(), 6070);
QCOMPARE(node28->getLength(), 79);
}
void BandageTests::loadLastGraph()
{
createGlobals();
bool lastGraphLoaded = g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.LastGraph");
//Check that the graph loaded properly.
QCOMPARE(lastGraphLoaded, true);
//Check that the appropriate number of nodes/edges are present.
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 34);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphEdges.size(), 32);
//Check the length of a couple nodes.
DeBruijnNode * node1 = g_assemblyGraph->m_deBruijnGraphNodes["1+"];
DeBruijnNode * node14 = g_assemblyGraph->m_deBruijnGraphNodes["14-"];
QCOMPARE(node1->getLength(), 2000);
QCOMPARE(node14->getLength(), 60);
}
void BandageTests::loadTrinity()
{
createGlobals();
bool trinityLoaded = g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.Trinity.fasta");
//Check that the graph loaded properly.
QCOMPARE(trinityLoaded, true);
//Check that the appropriate number of nodes/edges are present.
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 1170);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphEdges.size(), 1056);
//Check the length of a couple nodes.
DeBruijnNode * node10241 = g_assemblyGraph->m_deBruijnGraphNodes["4|c4_10241+"];
DeBruijnNode * node3901 = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3901-"];
QCOMPARE(node10241->getLength(), 1186);
QCOMPARE(node3901->getLength(), 1);
}
//LastGraph files have no overlap in the edges, so these tests look at paths
//where the connections are simple.
void BandageTests::pathFunctionsOnLastGraph()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.LastGraph");
QString pathStringFailure;
Path testPath1 = Path::makeFromString("(1996) 9+, 13+ (5)", false, &pathStringFailure);
Path testPath2 = Path::makeFromString("(1996) 9+, 13+ (5)", false, &pathStringFailure);
Path testPath3 = Path::makeFromString("(1996) 9+, 13+ (6)", false, &pathStringFailure);
Path testPath4 = Path::makeFromString("9+, 13+, 14-", false, &pathStringFailure);
DeBruijnNode * node4Minus = g_assemblyGraph->m_deBruijnGraphNodes["4-"];
DeBruijnNode * node9Plus = g_assemblyGraph->m_deBruijnGraphNodes["9+"];
DeBruijnNode * node13Plus = g_assemblyGraph->m_deBruijnGraphNodes["13+"];
DeBruijnNode * node14Minus = g_assemblyGraph->m_deBruijnGraphNodes["14+"];
DeBruijnNode * node7Plus = g_assemblyGraph->m_deBruijnGraphNodes["7+"];
QCOMPARE(testPath1.getLength(), 10);
QCOMPARE(testPath1.getPathSequence(), QByteArray("GACCTATAGA"));
QCOMPARE(testPath1.isEmpty(), false);
QCOMPARE(testPath1.isCircular(), false);
QCOMPARE(testPath1 == testPath2, true);
QCOMPARE(testPath1 == testPath3, false);
QCOMPARE(testPath1.haveSameNodes(testPath3), true);
QCOMPARE(testPath1.hasNodeSubset(testPath4), true);
QCOMPARE(testPath4.hasNodeSubset(testPath1), false);
QCOMPARE(testPath1.getString(true), QString("(1996) 9+, 13+ (5)"));
QCOMPARE(testPath1.getString(false), QString("(1996)9+,13+(5)"));
QCOMPARE(testPath4.getString(true), QString("9+, 13+, 14-"));
QCOMPARE(testPath4.getString(false), QString("9+,13+,14-"));
QCOMPARE(testPath1.containsEntireNode(node13Plus), false);
QCOMPARE(testPath4.containsEntireNode(node13Plus), true);
QCOMPARE(testPath4.isInMiddleOfPath(node13Plus), true);
QCOMPARE(testPath4.isInMiddleOfPath(node14Minus), false);
QCOMPARE(testPath4.isInMiddleOfPath(node9Plus), false);
Path testPath4Extended;
QCOMPARE(testPath4.canNodeFitOnEnd(node7Plus, &testPath4Extended), true);
QCOMPARE(testPath4Extended.getString(true), QString("9+, 13+, 14-, 7+"));
QCOMPARE(testPath4.canNodeFitAtStart(node4Minus, &testPath4Extended), true);
QCOMPARE(testPath4Extended.getString(true), QString("4-, 9+, 13+, 14-"));
}
//FASTG files have overlaps in the edges, so these tests look at paths where
//the overlap has to be removed from the path sequence.
void BandageTests::pathFunctionsOnFastg()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
QString pathStringFailure;
Path testPath1 = Path::makeFromString("(50234) 6+, 26+, 23+, 26+, 24+ (200)", false, &pathStringFailure);
Path testPath2 = Path::makeFromString("26+, 23+", true, &pathStringFailure);
QCOMPARE(testPath1.getLength(), 1764);
QCOMPARE(testPath2.getLength(), 1387);
QCOMPARE(testPath1.isCircular(), false);
QCOMPARE(testPath2.isCircular(), true);
}
//This function tests paths on a GFA file which keeps its sequences in the GFA
//file.
void BandageTests::pathFunctionsOnGfaSequencesInGraph()
{
createGlobals();
bool gfaLoaded = g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test_plasmids.gfa");
QCOMPARE(gfaLoaded, true);
//Check that the number of nodes/edges.
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 18);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphEdges.size(), 24);
//Check a couple short paths.
QString pathStringFailure;
Path testPath1 = Path::makeFromString("232+, 277+", false, &pathStringFailure);
QByteArray testPath1Sequence = "CCTTATACGAAGCCCAGGTTAATCCTGGGCTTTTTGTTGAATCTGATCATTGGTAGCAAACAGATCAGGATTGGTAATTTTGATGTTTTCCTGACAACTCCTGCAAAGCATCAGCCCAGCAAAAAGTTGTACATGTTCCGTTGATTCACAGAAGGCACATGGCTTAGGAAAAGAGATGATATTGGCTGAATTGACTAATTCTGTTGACATAAGAAGTAACCTTGGATTGTACATATTTATTTTTAATAAATTTCAATACTTTATACCTAATTTAGCCACTAAAATTTGTACATTATTGTATAATCCATGTGTACATATTATTTTTTATAATTTTCATTCACTTAGACCCAAAATAGTATTTATTTTTGTACAACACCATGTACAGAACAATAATCATATAAATCAAATTTTTAGCATAAAAAAGTCCATTAATTTTGTACACAATTCTGAAACTTAAAAATCTAAACTTTCATCAATTTTTTTCATAATTTCAATAAATTAACCTTAATTTTAAGATATATTCTGAAATTTGGTTTGAAAGCTGTTTTTACATTATATTTCAATACTTTAAATCAAAAAATTGGATATTTTTTGAAAAACTCAATGAAAGTTTATTTTTTATTTAAAAACAACTAGTTATATTAGTTTTTATCCATTTTTTTGAAACAGTTTCTATATGATAAAAAAACCTATAAAAACCATATCTAGCAAAGGTTTGAGGGTTATCATCTTTAGATGCGTGGTGTGTGACAAAAAAATCCCGGCATGTGCCGGATTCTGGATTAGAAAATTGGCTAAAGTGACGTAGGACTGGTGCTTGGTTTTACATGGAAAAAAGTATTTATTTTCTGGTTTATAAAAACGTAAAAAGATCAGTTTTTGTTCATTCATCCAGGTTAAAAATTTCAACCTAAAACTTTAATTATGAAAAGCTTCACAGAAAGCATTCAAATGCGATTTAAGAGCCTTTATCTAAAAAACATAGATCTTATAGCGAAAAACAGAAAACAGCTCAAAAAACGCAAAAGAGAGTGAAGTAAAGAGATGTTTTGACTTTAGATAGCTGCATAGAGCGAGTGTCTACGAGCGAACTATCAAAATTTGCGTCTAGACTCTCTGAAAAACATTTTTTTGCCCTCTTTAGCCTAAGAAAGCTTAATTTTCATGCAGAAATTTGCTCCTGGACCGAGCGTAGCGAGAAAAAAAGCTCATGAGCGAAGCGAATTCCGAGTTGCTTTTGCTTTTTCTTAAAGTCACGCAAGTATTAACCAAAAAATTGCCCCGACGAACTGAGCGAAAGCGAAGTTCAATAGAGTTTGAGCGAAGCGAAAACCAAGGGC";
Path testPath2 = Path::makeFromString("277-, 232-", false, &pathStringFailure);
QByteArray testPath2Sequence = "GCCCTTGGTTTTCGCTTCGCTCAAACTCTATTGAACTTCGCTTTCGCTCAGTTCGTCGGGGCAATTTTTTGGTTAATACTTGCGTGACTTTAAGAAAAAGCAAAAGCAACTCGGAATTCGCTTCGCTCATGAGCTTTTTTTCTCGCTACGCTCGGTCCAGGAGCAAATTTCTGCATGAAAATTAAGCTTTCTTAGGCTAAAGAGGGCAAAAAAATGTTTTTCAGAGAGTCTAGACGCAAATTTTGATAGTTCGCTCGTAGACACTCGCTCTATGCAGCTATCTAAAGTCAAAACATCTCTTTACTTCACTCTCTTTTGCGTTTTTTGAGCTGTTTTCTGTTTTTCGCTATAAGATCTATGTTTTTTAGATAAAGGCTCTTAAATCGCATTTGAATGCTTTCTGTGAAGCTTTTCATAATTAAAGTTTTAGGTTGAAATTTTTAACCTGGATGAATGAACAAAAACTGATCTTTTTACGTTTTTATAAACCAGAAAATAAATACTTTTTTCCATGTAAAACCAAGCACCAGTCCTACGTCACTTTAGCCAATTTTCTAATCCAGAATCCGGCACATGCCGGGATTTTTTTGTCACACACCACGCATCTAAAGATGATAACCCTCAAACCTTTGCTAGATATGGTTTTTATAGGTTTTTTTATCATATAGAAACTGTTTCAAAAAAATGGATAAAAACTAATATAACTAGTTGTTTTTAAATAAAAAATAAACTTTCATTGAGTTTTTCAAAAAATATCCAATTTTTTGATTTAAAGTATTGAAATATAATGTAAAAACAGCTTTCAAACCAAATTTCAGAATATATCTTAAAATTAAGGTTAATTTATTGAAATTATGAAAAAAATTGATGAAAGTTTAGATTTTTAAGTTTCAGAATTGTGTACAAAATTAATGGACTTTTTTATGCTAAAAATTTGATTTATATGATTATTGTTCTGTACATGGTGTTGTACAAAAATAAATACTATTTTGGGTCTAAGTGAATGAAAATTATAAAAAATAATATGTACACATGGATTATACAATAATGTACAAATTTTAGTGGCTAAATTAGGTATAAAGTATTGAAATTTATTAAAAATAAATATGTACAATCCAAGGTTACTTCTTATGTCAACAGAATTAGTCAATTCAGCCAATATCATCTCTTTTCCTAAGCCATGTGCCTTCTGTGAATCAACGGAACATGTACAACTTTTTGCTGGGCTGATGCTTTGCAGGAGTTGTCAGGAAAACATCAAAATTACCAATCCTGATCTGTTTGCTACCAATGATCAGATTCAACAAAAAGCCCAGGATTAACCTGGGCTTCGTATAAGG";
QCOMPARE(testPath1.getPathSequence(), testPath1Sequence);
QCOMPARE(testPath2.getPathSequence(), testPath2Sequence);
}
//This function tests paths on a GFA file which keeps its sequences in a
//separate FASTA file.
void BandageTests::pathFunctionsOnGfaSequencesInFasta()
{
createGlobals();
bool gfaLoaded = g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test_plasmids_separate_sequences.gfa");
QCOMPARE(gfaLoaded, true);
//Check that the number of nodes/edges.
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 18);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphEdges.size(), 24);
//Since a node sequence hasn't be required yet, the nodes should still have
//just '*' for their sequence. But they should still report the correct
//length.
DeBruijnNode * node282Plus = g_assemblyGraph->m_deBruijnGraphNodes["282+"];
DeBruijnNode * node282Minus = g_assemblyGraph->m_deBruijnGraphNodes["282-"];
QCOMPARE(node282Plus->sequenceIsMissing(), true);
QCOMPARE(node282Minus->sequenceIsMissing(), true);
QCOMPARE(node282Plus->getLength(), 1819);
QCOMPARE(node282Minus->getLength(), 1819);
//Check a couple short paths.
QString pathStringFailure;
Path testPath1 = Path::makeFromString("232+, 277+", false, &pathStringFailure);
QByteArray testPath1Sequence = "CCTTATACGAAGCCCAGGTTAATCCTGGGCTTTTTGTTGAATCTGATCATTGGTAGCAAACAGATCAGGATTGGTAATTTTGATGTTTTCCTGACAACTCCTGCAAAGCATCAGCCCAGCAAAAAGTTGTACATGTTCCGTTGATTCACAGAAGGCACATGGCTTAGGAAAAGAGATGATATTGGCTGAATTGACTAATTCTGTTGACATAAGAAGTAACCTTGGATTGTACATATTTATTTTTAATAAATTTCAATACTTTATACCTAATTTAGCCACTAAAATTTGTACATTATTGTATAATCCATGTGTACATATTATTTTTTATAATTTTCATTCACTTAGACCCAAAATAGTATTTATTTTTGTACAACACCATGTACAGAACAATAATCATATAAATCAAATTTTTAGCATAAAAAAGTCCATTAATTTTGTACACAATTCTGAAACTTAAAAATCTAAACTTTCATCAATTTTTTTCATAATTTCAATAAATTAACCTTAATTTTAAGATATATTCTGAAATTTGGTTTGAAAGCTGTTTTTACATTATATTTCAATACTTTAAATCAAAAAATTGGATATTTTTTGAAAAACTCAATGAAAGTTTATTTTTTATTTAAAAACAACTAGTTATATTAGTTTTTATCCATTTTTTTGAAACAGTTTCTATATGATAAAAAAACCTATAAAAACCATATCTAGCAAAGGTTTGAGGGTTATCATCTTTAGATGCGTGGTGTGTGACAAAAAAATCCCGGCATGTGCCGGATTCTGGATTAGAAAATTGGCTAAAGTGACGTAGGACTGGTGCTTGGTTTTACATGGAAAAAAGTATTTATTTTCTGGTTTATAAAAACGTAAAAAGATCAGTTTTTGTTCATTCATCCAGGTTAAAAATTTCAACCTAAAACTTTAATTATGAAAAGCTTCACAGAAAGCATTCAAATGCGATTTAAGAGCCTTTATCTAAAAAACATAGATCTTATAGCGAAAAACAGAAAACAGCTCAAAAAACGCAAAAGAGAGTGAAGTAAAGAGATGTTTTGACTTTAGATAGCTGCATAGAGCGAGTGTCTACGAGCGAACTATCAAAATTTGCGTCTAGACTCTCTGAAAAACATTTTTTTGCCCTCTTTAGCCTAAGAAAGCTTAATTTTCATGCAGAAATTTGCTCCTGGACCGAGCGTAGCGAGAAAAAAAGCTCATGAGCGAAGCGAATTCCGAGTTGCTTTTGCTTTTTCTTAAAGTCACGCAAGTATTAACCAAAAAATTGCCCCGACGAACTGAGCGAAAGCGAAGTTCAATAGAGTTTGAGCGAAGCGAAAACCAAGGGC";
Path testPath2 = Path::makeFromString("277-, 232-", false, &pathStringFailure);
QByteArray testPath2Sequence = "GCCCTTGGTTTTCGCTTCGCTCAAACTCTATTGAACTTCGCTTTCGCTCAGTTCGTCGGGGCAATTTTTTGGTTAATACTTGCGTGACTTTAAGAAAAAGCAAAAGCAACTCGGAATTCGCTTCGCTCATGAGCTTTTTTTCTCGCTACGCTCGGTCCAGGAGCAAATTTCTGCATGAAAATTAAGCTTTCTTAGGCTAAAGAGGGCAAAAAAATGTTTTTCAGAGAGTCTAGACGCAAATTTTGATAGTTCGCTCGTAGACACTCGCTCTATGCAGCTATCTAAAGTCAAAACATCTCTTTACTTCACTCTCTTTTGCGTTTTTTGAGCTGTTTTCTGTTTTTCGCTATAAGATCTATGTTTTTTAGATAAAGGCTCTTAAATCGCATTTGAATGCTTTCTGTGAAGCTTTTCATAATTAAAGTTTTAGGTTGAAATTTTTAACCTGGATGAATGAACAAAAACTGATCTTTTTACGTTTTTATAAACCAGAAAATAAATACTTTTTTCCATGTAAAACCAAGCACCAGTCCTACGTCACTTTAGCCAATTTTCTAATCCAGAATCCGGCACATGCCGGGATTTTTTTGTCACACACCACGCATCTAAAGATGATAACCCTCAAACCTTTGCTAGATATGGTTTTTATAGGTTTTTTTATCATATAGAAACTGTTTCAAAAAAATGGATAAAAACTAATATAACTAGTTGTTTTTAAATAAAAAATAAACTTTCATTGAGTTTTTCAAAAAATATCCAATTTTTTGATTTAAAGTATTGAAATATAATGTAAAAACAGCTTTCAAACCAAATTTCAGAATATATCTTAAAATTAAGGTTAATTTATTGAAATTATGAAAAAAATTGATGAAAGTTTAGATTTTTAAGTTTCAGAATTGTGTACAAAATTAATGGACTTTTTTATGCTAAAAATTTGATTTATATGATTATTGTTCTGTACATGGTGTTGTACAAAAATAAATACTATTTTGGGTCTAAGTGAATGAAAATTATAAAAAATAATATGTACACATGGATTATACAATAATGTACAAATTTTAGTGGCTAAATTAGGTATAAAGTATTGAAATTTATTAAAAATAAATATGTACAATCCAAGGTTACTTCTTATGTCAACAGAATTAGTCAATTCAGCCAATATCATCTCTTTTCCTAAGCCATGTGCCTTCTGTGAATCAACGGAACATGTACAACTTTTTGCTGGGCTGATGCTTTGCAGGAGTTGTCAGGAAAACATCAAAATTACCAATCCTGATCTGTTTGCTACCAATGATCAGATTCAACAAAAAGCCCAGGATTAACCTGGGCTTCGTATAAGG";
//Check the paths sequences. Doing so will trigger the loading of node
//sequences from the FASTA file.
QCOMPARE(testPath1.getPathSequence(), testPath1Sequence);
QCOMPARE(testPath2.getPathSequence(), testPath2Sequence);
//Now that the paths have been accessed, the node sequences should be
//loaded (even the ones not in the path).
QCOMPARE(node282Plus->sequenceIsMissing(), false);
QCOMPARE(node282Minus->sequenceIsMissing(), false);
QCOMPARE(node282Plus->getLength(), 1819);
QCOMPARE(node282Minus->getLength(), 1819);
}
void BandageTests::graphLocationFunctions()
{
//First do some tests with a FASTG, where the overlap results in a simpler
//sitations: all positions have a reverse complement position in the
//reverse complement node.
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
DeBruijnNode * node12Plus = g_assemblyGraph->m_deBruijnGraphNodes["12+"];
DeBruijnNode * node3Plus = g_assemblyGraph->m_deBruijnGraphNodes["3+"];
GraphLocation location1(node12Plus, 1);
GraphLocation revCompLocation1 = location1.reverseComplementLocation();
QCOMPARE(location1.getBase(), 'C');
QCOMPARE(revCompLocation1.getBase(), 'G');
QCOMPARE(revCompLocation1.getPosition(), 394);
GraphLocation location2 = GraphLocation::endOfNode(node3Plus);
QCOMPARE(location2.getPosition(), 5869);
location2.moveLocation(-1);
QCOMPARE(location2.getPosition(), 5868);
location2.moveLocation(2);
QCOMPARE(location2.getNode()->getName(), QString("38-"));
QCOMPARE(location2.getPosition(), 1);
GraphLocation location3;
QCOMPARE(location2.isNull(), false);
QCOMPARE(location3.isNull(), true);
//Now look at a LastGraph file which is more complex. Because of the
//offset, reverse complement positions can be in different nodes and may
//not even exist.
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.LastGraph");
int kmer = g_assemblyGraph->m_kmer;
DeBruijnNode * node13Plus = g_assemblyGraph->m_deBruijnGraphNodes["13+"];
DeBruijnNode * node8Minus = g_assemblyGraph->m_deBruijnGraphNodes["8-"];
GraphLocation location4 = GraphLocation::startOfNode(node13Plus);
QCOMPARE(location4.getBase(), 'A');
QCOMPARE(location4.getPosition(), 1);
GraphLocation revCompLocation4 = location4.reverseComplementLocation();
QCOMPARE(revCompLocation4.getBase(), 'T');
QCOMPARE(revCompLocation4.getNode()->getName(), QString("13-"));
QCOMPARE(revCompLocation4.getPosition(), node13Plus->getLength() - kmer + 1);
GraphLocation location5 = GraphLocation::endOfNode(node8Minus);
GraphLocation location6 = location5;
location6.moveLocation(-60);
GraphLocation revCompLocation5 = location5.reverseComplementLocation();
GraphLocation revCompLocation6 = location6.reverseComplementLocation();
QCOMPARE(revCompLocation5.isNull(), true);
QCOMPARE(revCompLocation6.isNull(), false);
QCOMPARE(revCompLocation6.getNode()->getName(), QString("8+"));
QCOMPARE(revCompLocation6.getPosition(), 1);
}
void BandageTests::loadCsvData()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
QString errormsg;
QStringList columns;
bool coloursLoaded = false;
g_assemblyGraph->loadCSV(getTestDirectory() + "test.csv", &columns, &errormsg, &coloursLoaded);
DeBruijnNode * node6Plus = g_assemblyGraph->m_deBruijnGraphNodes["6+"];
DeBruijnNode * node6Minus = g_assemblyGraph->m_deBruijnGraphNodes["6-"];
DeBruijnNode * node7Plus = g_assemblyGraph->m_deBruijnGraphNodes["7+"];
DeBruijnNode * node4Plus = g_assemblyGraph->m_deBruijnGraphNodes["4+"];
DeBruijnNode * node4Minus = g_assemblyGraph->m_deBruijnGraphNodes["4-"];
DeBruijnNode * node3Plus = g_assemblyGraph->m_deBruijnGraphNodes["3+"];
DeBruijnNode * node5Minus = g_assemblyGraph->m_deBruijnGraphNodes["5-"];
DeBruijnNode * node8Plus = g_assemblyGraph->m_deBruijnGraphNodes["8+"];
DeBruijnNode * node9Plus = g_assemblyGraph->m_deBruijnGraphNodes["9+"];
QCOMPARE(columns.size(), 3);
QCOMPARE(errormsg, QString("There were 2 unmatched entries in the CSV."));
QCOMPARE(node6Plus->getCsvLine(0), QString("SIX_PLUS"));
QCOMPARE(node6Plus->getCsvLine(1), QString("6plus"));
QCOMPARE(node6Plus->getCsvLine(2), QString("plus6"));
QCOMPARE(node9Plus->getCsvLine(3), QString(""));
QCOMPARE(node9Plus->getCsvLine(25), QString(""));
QCOMPARE(node6Minus->getCsvLine(0), QString("SIX_MINUS"));
QCOMPARE(node6Minus->getCsvLine(1), QString("6minus"));
QCOMPARE(node6Minus->getCsvLine(2), QString("minus6"));
QCOMPARE(node7Plus->getCsvLine(0), QString("SEVEN_PLUS"));
QCOMPARE(node7Plus->getCsvLine(1), QString("7plus"));
QCOMPARE(node7Plus->getCsvLine(2), QString("plus7"));
QCOMPARE(node4Plus->getCsvLine(0), QString("FOUR_PLUS"));
QCOMPARE(node4Plus->getCsvLine(1), QString("4plus"));
QCOMPARE(node4Plus->getCsvLine(2), QString("plus4"));
QCOMPARE(node4Minus->getCsvLine(0), QString("FOUR_MINUS"));
QCOMPARE(node4Minus->getCsvLine(1), QString("4minus"));
QCOMPARE(node4Minus->getCsvLine(2), QString("minus4"));
QCOMPARE(node3Plus->getCsvLine(0), QString("THREE_PLUS"));
QCOMPARE(node3Plus->getCsvLine(1), QString("3plus"));
QCOMPARE(node3Plus->getCsvLine(2), QString("plus3"));
QCOMPARE(node5Minus->getCsvLine(0), QString("FIVE_MINUS"));
QCOMPARE(node5Minus->getCsvLine(1), QString(""));
QCOMPARE(node5Minus->getCsvLine(2), QString(""));
QCOMPARE(node8Plus->getCsvLine(0), QString("EIGHT_PLUS"));
QCOMPARE(node8Plus->getCsvLine(1), QString("8plus"));
QCOMPARE(node8Plus->getCsvLine(2), QString("plus8"));
QCOMPARE(node9Plus->getCsvLine(0), QString("NINE_PLUS"));
QCOMPARE(node9Plus->getCsvLine(1), QString("9plus"));
QCOMPARE(node9Plus->getCsvLine(2), QString("plus9"));
QCOMPARE(node9Plus->getCsvLine(3), QString(""));
QCOMPARE(node9Plus->getCsvLine(4), QString(""));
QCOMPARE(node9Plus->getCsvLine(5), QString(""));
}
void BandageTests::loadCsvDataTrinity()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.Trinity.fasta");
QString errormsg;
QStringList columns;
bool coloursLoaded = false;
g_assemblyGraph->loadCSV(getTestDirectory() + "test.Trinity.csv", &columns, &errormsg, &coloursLoaded);
DeBruijnNode * node3912Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3912+"];
DeBruijnNode * node3912Minus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3912-"];
DeBruijnNode * node3914Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3914+"];
DeBruijnNode * node3915Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3915+"];
DeBruijnNode * node3923Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3923+"];
DeBruijnNode * node3924Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3924+"];
DeBruijnNode * node3940Plus = g_assemblyGraph->m_deBruijnGraphNodes["19|c0_3940+"];
QCOMPARE(columns.size(), 1);
QCOMPARE(node3912Plus->getCsvLine(0), QString("3912PLUS"));
QCOMPARE(node3912Minus->getCsvLine(0), QString("3912MINUS"));
QCOMPARE(node3914Plus->getCsvLine(0), QString("3914PLUS"));
QCOMPARE(node3915Plus->getCsvLine(0), QString("3915PLUS"));
QCOMPARE(node3923Plus->getCsvLine(0), QString("3923PLUS"));
QCOMPARE(node3924Plus->getCsvLine(0), QString("3924PLUS"));
QCOMPARE(node3940Plus->getCsvLine(0), QString("3940PLUS"));
}
void BandageTests::blastSearch()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
g_settings->blastQueryFilename = getTestDirectory() + "test_queries1.fasta";
createBlastTempDirectory();
g_blastSearch->doAutoBlastSearch();
BlastQuery * exact = g_blastSearch->m_blastQueries.getQueryFromName("test_query_exact");
BlastQuery * one_mismatch = g_blastSearch->m_blastQueries.getQueryFromName("test_query_one_mismatch");
BlastQuery * one_insertion = g_blastSearch->m_blastQueries.getQueryFromName("test_query_one_insertion");
BlastQuery * one_deletion = g_blastSearch->m_blastQueries.getQueryFromName("test_query_one_deletion");
QCOMPARE(exact->getLength(), 100);
QCOMPARE(one_mismatch->getLength(), 100);
QCOMPARE(one_insertion->getLength(), 101);
QCOMPARE(one_deletion->getLength(), 99);
QSharedPointer<BlastHit> exactHit = exact->getHits().at(0);
QSharedPointer<BlastHit> one_mismatchHit = one_mismatch->getHits().at(0);
QSharedPointer<BlastHit> one_insertionHit = one_insertion->getHits().at(0);
QSharedPointer<BlastHit> one_deletionHit = one_deletion->getHits().at(0);
QCOMPARE(exactHit->m_numberMismatches, 0);
QCOMPARE(exactHit->m_numberGapOpens, 0);
QCOMPARE(one_mismatchHit->m_numberMismatches, 1);
QCOMPARE(one_mismatchHit->m_numberGapOpens, 0);
QCOMPARE(one_insertionHit->m_numberMismatches, 0);
QCOMPARE(one_insertionHit->m_numberGapOpens, 1);
QCOMPARE(one_deletionHit->m_numberMismatches, 0);
QCOMPARE(one_deletionHit->m_numberGapOpens, 1);
QCOMPARE(exactHit->m_percentIdentity < 100.0, false);
QCOMPARE(one_mismatchHit->m_percentIdentity < 100.0, true);
QCOMPARE(one_insertionHit->m_percentIdentity < 100.0, true);
QCOMPARE(one_deletionHit->m_percentIdentity < 100.0, true);
deleteBlastTempDirectory();
}
void BandageTests::blastSearchFilters()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
g_settings->blastQueryFilename = getTestDirectory() + "test_queries2.fasta";
createBlastTempDirectory();
//First do the search with no filters
g_blastSearch->doAutoBlastSearch();
int unfilteredHitCount = g_blastSearch->m_allHits.size();
//Now filter by e-value.
g_settings->blastEValueFilter.on = true;
g_settings->blastEValueFilter = SciNot(1.0, -5);
g_blastSearch->doAutoBlastSearch();
QCOMPARE(g_blastSearch->m_allHits.size(), 14);
QCOMPARE(g_blastSearch->m_allHits.size() < unfilteredHitCount, true);
//Now add a bit score filter.
g_settings->blastBitScoreFilter.on = true;
g_settings->blastBitScoreFilter = 100.0;
g_blastSearch->doAutoBlastSearch();
QCOMPARE(g_blastSearch->m_allHits.size(), 9);
//Now add an alignment length filter.
g_settings->blastAlignmentLengthFilter.on = true;
g_settings->blastAlignmentLengthFilter = 100;
g_blastSearch->doAutoBlastSearch();
QCOMPARE(g_blastSearch->m_allHits.size(), 8);
//Now add an identity filter.
g_settings->blastIdentityFilter.on = true;
g_settings->blastIdentityFilter = 50.0;
g_blastSearch->doAutoBlastSearch();
QCOMPARE(g_blastSearch->m_allHits.size(), 7);
//Now add a query coverage filter.
g_settings->blastQueryCoverageFilter.on = true;
g_settings->blastQueryCoverageFilter = 90.0;
g_blastSearch->doAutoBlastSearch();
QCOMPARE(g_blastSearch->m_allHits.size(), 5);
deleteBlastTempDirectory();
}
void BandageTests::graphScope()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
QString errorTitle;
QString errorMessage;
int drawnNodes;
std::vector<DeBruijnNode *> startingNodes;
g_settings->graphScope = WHOLE_GRAPH;
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 44);
g_settings->graphScope = WHOLE_GRAPH;
g_settings->nodeDistance = 0;
g_settings->doubleMode = true;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 88);
g_settings->graphScope = AROUND_NODE;
g_settings->startingNodes = "1";
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 1);
g_settings->graphScope = AROUND_NODE;
g_settings->startingNodes = "1";
g_settings->nodeDistance = 0;
g_settings->doubleMode = true;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 2);
g_settings->graphScope = AROUND_NODE;
g_settings->startingNodes = "1+";
g_settings->nodeDistance = 0;
g_settings->doubleMode = true;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 1);
g_settings->graphScope = AROUND_NODE;
g_settings->startingNodes = "1";
g_settings->nodeDistance = 1;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 3);
g_settings->graphScope = AROUND_NODE;
g_settings->startingNodes = "1";
g_settings->nodeDistance = 2;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 10);
g_settings->graphScope = DEPTH_RANGE;
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
g_settings->minDepthRange = 0.0;
g_settings->maxDepthRange = 211.0;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 43);
g_settings->graphScope = DEPTH_RANGE;
g_settings->nodeDistance = 10;
g_settings->doubleMode = false;
g_settings->minDepthRange = 0.0;
g_settings->maxDepthRange = 211.0;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 43);
g_settings->graphScope = DEPTH_RANGE;
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
g_settings->minDepthRange = 211.0;
g_settings->maxDepthRange = 1000.0;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 1);
g_settings->graphScope = DEPTH_RANGE;
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
g_settings->minDepthRange = 40.0;
g_settings->maxDepthRange = 211.0;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 42);
createBlastTempDirectory();
g_settings->blastQueryFilename = getTestDirectory() + "test_queries1.fasta";
g_blastSearch->doAutoBlastSearch();
g_settings->graphScope = AROUND_BLAST_HITS;
g_settings->nodeDistance = 0;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "all");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 1);
g_settings->graphScope = AROUND_BLAST_HITS;
g_settings->nodeDistance = 1;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "all");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 3);
g_settings->graphScope = AROUND_BLAST_HITS;
g_settings->nodeDistance = 2;
g_settings->doubleMode = false;
startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage, g_settings->doubleMode, g_settings->startingNodes, "all");
g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
g_assemblyGraph->layoutGraph();
drawnNodes = g_assemblyGraph->getDrawnNodeCount();
QCOMPARE(drawnNodes, 9);
deleteBlastTempDirectory();
}
void BandageTests::commandLineSettings()
{
createGlobals();
QStringList commandLineSettings;
commandLineSettings = QString("--scope entire").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->graphScope, WHOLE_GRAPH);
commandLineSettings = QString("--scope aroundnodes").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->graphScope, AROUND_NODE);
commandLineSettings = QString("--scope aroundblast").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->graphScope, AROUND_BLAST_HITS);
commandLineSettings = QString("--scope depthrange").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->graphScope, DEPTH_RANGE);
commandLineSettings = QString("--nodes 5+").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->startingNodes, QString("5+"));
commandLineSettings = QString("--nodes 1,2,3").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->startingNodes, QString("1,2,3"));
QCOMPARE(g_settings->startingNodesExactMatch, true);
commandLineSettings = QString("--partial").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->startingNodesExactMatch, false);
commandLineSettings = QString("--distance 12").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeDistance.val, 12);
commandLineSettings = QString("--mindepth 1.2").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minDepthRange.val, 1.2);
commandLineSettings = QString("--maxdepth 2.1").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxDepthRange.val, 2.1);
QCOMPARE(g_settings->doubleMode, false);
commandLineSettings = QString("--double").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->doubleMode, true);
QCOMPARE(g_settings->nodeLengthMode, AUTO_NODE_LENGTH);
commandLineSettings = QString("--nodelen 10000").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeLengthMode, MANUAL_NODE_LENGTH);
QCOMPARE(g_settings->manualNodeLengthPerMegabase.val, 10000.0);
commandLineSettings = QString("--iter 1").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->graphLayoutQuality.val, 1);
commandLineSettings = QString("--nodewidth 4.2").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->averageNodeWidth.val, 4.2);
commandLineSettings = QString("--depwidth 0.222").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->depthEffectOnWidth.val, 0.222);
commandLineSettings = QString("--deppower 0.72").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->depthPower.val, 0.72);
QCOMPARE(g_settings->displayNodeNames, false);
commandLineSettings = QString("--names").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->displayNodeNames, true);
QCOMPARE(g_settings->displayNodeLengths, false);
commandLineSettings = QString("--lengths").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->displayNodeLengths, true);
QCOMPARE(g_settings->displayNodeDepth, false);
commandLineSettings = QString("--depth").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->displayNodeDepth, true);
QCOMPARE(g_settings->displayBlastHits, false);
commandLineSettings = QString("--blasthits").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->displayBlastHits, true);
commandLineSettings = QString("--fontsize 5").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->labelFont.pointSize(), 5);
commandLineSettings = QString("--edgecol #00ff00").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->edgeColour.name(), QString("#00ff00"));
commandLineSettings = QString("--edgewidth 5.5").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->edgeWidth.val, 5.5);
commandLineSettings = QString("--outcol #ff0000").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->outlineColour.name(), QString("#ff0000"));
commandLineSettings = QString("--outline 0.123").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->outlineThickness.val, 0.123);
commandLineSettings = QString("--selcol tomato").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->selectionColour.name(), QString("#ff6347"));
QCOMPARE(g_settings->antialiasing, true);
commandLineSettings = QString("--noaa").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->antialiasing, false);
commandLineSettings = QString("--textcol #550000ff").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->textColour.name(), QString("#0000ff"));
QCOMPARE(g_settings->textColour.alpha(), 85);
commandLineSettings = QString("--toutcol steelblue").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->textOutlineColour), QString("steelblue"));
commandLineSettings = QString("--toutline 0.321").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->textOutlineThickness.val, 0.321);
QCOMPARE(g_settings->positionTextNodeCentre, false);
commandLineSettings = QString("--centre").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->positionTextNodeCentre, true);
commandLineSettings = QString("--colour random").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeColourScheme, RANDOM_COLOURS);
commandLineSettings = QString("--colour uniform").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeColourScheme, UNIFORM_COLOURS);
commandLineSettings = QString("--colour depth").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeColourScheme, DEPTH_COLOUR);
commandLineSettings = QString("--colour blastsolid").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeColourScheme, BLAST_HITS_SOLID_COLOUR);
commandLineSettings = QString("--colour blastrainbow").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->nodeColourScheme, BLAST_HITS_RAINBOW_COLOUR);
commandLineSettings = QString("--ransatpos 12").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourPositiveSaturation.val, 12);
commandLineSettings = QString("--ransatneg 23").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourNegativeSaturation.val, 23);
commandLineSettings = QString("--ranligpos 34").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourPositiveLightness.val, 34);
commandLineSettings = QString("--ranligneg 45").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourNegativeLightness.val, 45);
commandLineSettings = QString("--ranopapos 56").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourPositiveOpacity.val, 56);
commandLineSettings = QString("--ranopaneg 67").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->randomColourNegativeOpacity.val, 67);
commandLineSettings = QString("--unicolpos springgreen").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->uniformPositiveNodeColour), QString("springgreen"));
commandLineSettings = QString("--unicolneg teal").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->uniformNegativeNodeColour), QString("teal"));
commandLineSettings = QString("--unicolspe papayawhip").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->uniformNodeSpecialColour), QString("papayawhip"));
commandLineSettings = QString("--depcollow mediumorchid").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->lowDepthColour), QString("mediumorchid"));
commandLineSettings = QString("--depcolhi linen").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(getColourName(g_settings->highDepthColour), QString("linen"));
QCOMPARE(g_settings->autoDepthValue, true);
commandLineSettings = QString("--depvallow 56.7").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->lowDepthValue.val, 56.7);
QCOMPARE(g_settings->autoDepthValue, false);
commandLineSettings = QString("--depvalhi 67.8").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->highDepthValue.val, 67.8);
commandLineSettings = QString("--depvalhi 67.8").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->highDepthValue.val, 67.8);
commandLineSettings = QString("--query queries.fasta").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastQueryFilename, QString("queries.fasta"));
commandLineSettings = QString("--blastp --abc").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastSearchParameters, QString("--abc"));
QCOMPARE(g_settings->blastAlignmentLengthFilter.on, false);
commandLineSettings = QString("--alfilter 543").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastAlignmentLengthFilter.on, true);
QCOMPARE(g_settings->blastAlignmentLengthFilter.val, 543);
QCOMPARE(g_settings->blastQueryCoverageFilter.on, false);
commandLineSettings = QString("--qcfilter 67.8").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastQueryCoverageFilter.on, true);
QCOMPARE(g_settings->blastQueryCoverageFilter.val, 67.8);
QCOMPARE(g_settings->blastIdentityFilter.on, false);
commandLineSettings = QString("--ifilter 12.3").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastIdentityFilter.on, true);
QCOMPARE(g_settings->blastIdentityFilter.val, 12.3);
QCOMPARE(g_settings->blastEValueFilter.on, false);
commandLineSettings = QString("--evfilter 8.5e-14").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastEValueFilter.on, true);
QCOMPARE(g_settings->blastEValueFilter.val, SciNot(8.5, -14));
QCOMPARE(g_settings->blastEValueFilter.val.getCoefficient(), 8.5);
QCOMPARE(g_settings->blastEValueFilter.val.getExponent(), -14);
QCOMPARE(g_settings->blastBitScoreFilter.on, false);
commandLineSettings = QString("--bsfilter 1234.5").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->blastBitScoreFilter.on, true);
QCOMPARE(g_settings->blastBitScoreFilter.val, 1234.5);
commandLineSettings = QString("--pathnodes 3").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxQueryPathNodes.val, 3);
commandLineSettings = QString("--minpatcov 0.543").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minQueryCoveredByPath.val, 0.543);
commandLineSettings = QString("--minhitcov 0.654").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minQueryCoveredByHits.val, 0.654);
QCOMPARE(g_settings->minQueryCoveredByHits.on, true);
commandLineSettings = QString("--minhitcov off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minQueryCoveredByHits.on, false);
commandLineSettings = QString("--minmeanid 0.765").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minMeanHitIdentity.val, 0.765);
QCOMPARE(g_settings->minMeanHitIdentity.on, true);
commandLineSettings = QString("--minmeanid off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minMeanHitIdentity.on, false);
commandLineSettings = QString("--minpatlen 0.97").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minLengthPercentage.val, 0.97);
QCOMPARE(g_settings->minLengthPercentage.on, true);
commandLineSettings = QString("--minpatlen off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minLengthPercentage.on, false);
commandLineSettings = QString("--maxpatlen 1.03").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxLengthPercentage.val, 1.03);
QCOMPARE(g_settings->maxLengthPercentage.on, true);
commandLineSettings = QString("--maxpatlen off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxLengthPercentage.on, false);
commandLineSettings = QString("--minlendis -1234").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minLengthBaseDiscrepancy.val, -1234);
QCOMPARE(g_settings->minLengthBaseDiscrepancy.on, true);
commandLineSettings = QString("--minlendis off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->minLengthBaseDiscrepancy.on, false);
commandLineSettings = QString("--maxlendis 4321").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxLengthBaseDiscrepancy.val, 4321);
QCOMPARE(g_settings->maxLengthBaseDiscrepancy.on, true);
commandLineSettings = QString("--maxlendis off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxLengthBaseDiscrepancy.on, false);
commandLineSettings = QString("--maxevprod 4e-500").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxEValueProduct.val.getCoefficient(), 4.0);
QCOMPARE(g_settings->maxEValueProduct.val.getExponent(), -500);
QCOMPARE(g_settings->maxEValueProduct.on, true);
commandLineSettings = QString("--maxevprod off").split(" ");
parseSettings(commandLineSettings);
QCOMPARE(g_settings->maxEValueProduct.on, false);
}
void BandageTests::sciNotComparisons()
{
SciNot sn01(1.0, 10);
SciNot sn02(10.0, 9);
SciNot sn03(0.1, 11);
SciNot sn04(5.0, 10);
SciNot sn05(-5.0, 15);
SciNot sn06(-6.0, 15);
SciNot sn07(-3.0, 3);
SciNot sn08(-0.3, 4);
SciNot sn09(-3.0, -3);
SciNot sn10(-0.3, -2);
SciNot sn11(1.4, 2);
SciNot sn12("1.4e2");
SciNot sn13("140");
QCOMPARE(sn01 == sn02, true);
QCOMPARE(sn01 == sn03, true);
QCOMPARE(sn01 == sn03, true);
QCOMPARE(sn01 >= sn03, true);
QCOMPARE(sn01 <= sn03, true);
QCOMPARE(sn01 != sn03, false);
QCOMPARE(sn01 < sn04, true);
QCOMPARE(sn01 <= sn04, true);
QCOMPARE(sn01 > sn04, false);
QCOMPARE(sn01 >= sn04, false);
QCOMPARE(sn04 > sn05, true);
QCOMPARE(sn04 < sn05, false);
QCOMPARE(sn06 < sn05, true);
QCOMPARE(sn06 <= sn05, true);
QCOMPARE(sn06 > sn05, false);
QCOMPARE(sn06 >= sn05, false);
QCOMPARE(sn07 == sn08, true);
QCOMPARE(sn07 != sn08, false);
QCOMPARE(sn09 == sn10, true);
QCOMPARE(sn09 != sn10, false);
QCOMPARE(sn11 == sn12, true);
QCOMPARE(sn11 == sn13, true);
QCOMPARE(sn01.asString(true), QString("1e10"));
QCOMPARE(sn01.asString(false), QString("1e10"));
QCOMPARE(sn11.asString(true), QString("1.4e2"));
QCOMPARE(sn11.asString(false), QString("140"));
}
void BandageTests::graphEdits()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 88);
QCOMPARE(int(g_assemblyGraph->m_deBruijnGraphEdges.size()), 118);
//Get the path sequence now to compare to the merged node sequence at the
//end.
QString pathStringFailure;
Path path = Path::makeFromString("6+, 26+, 23+, 26+, 24+", false, &pathStringFailure);
QByteArray pathSequence = path.getPathSequence();
g_assemblyGraph->duplicateNodePair(g_assemblyGraph->m_deBruijnGraphNodes["26+"], 0);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 90);
QCOMPARE(int(g_assemblyGraph->m_deBruijnGraphEdges.size()), 126);
std::vector<DeBruijnEdge *> edgesToRemove;
edgesToRemove.push_back(getEdgeFromNodeNames("26_copy+", "24+"));
edgesToRemove.push_back(getEdgeFromNodeNames("6+", "26+"));
edgesToRemove.push_back(getEdgeFromNodeNames("26+", "23+"));
edgesToRemove.push_back(getEdgeFromNodeNames("23+", "26_copy+"));
g_assemblyGraph->deleteEdges(&edgesToRemove);
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 90);
QCOMPARE(int(g_assemblyGraph->m_deBruijnGraphEdges.size()), 118);
g_assemblyGraph->mergeAllPossible();
QCOMPARE(g_assemblyGraph->m_deBruijnGraphNodes.size(), 82);
QCOMPARE(int(g_assemblyGraph->m_deBruijnGraphEdges.size()), 110);
DeBruijnNode * mergedNode = g_assemblyGraph->m_deBruijnGraphNodes["6_26_copy_23_26_24+"];
QCOMPARE(pathSequence, mergedNode->getSequence());
}
//Saving a Velvet graph to GFA is a bit complex because the node sequence offset
//must be filled in. This function tests aspects of that process.
void BandageTests::velvetToGfa()
{
//First load the graph as a LastGraph and pull out some information and a
//circular path sequence.
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "big_test.LastGraph");
int lastGraphNodeCount = g_assemblyGraph->m_nodeCount;
int lastGraphEdgeCount= g_assemblyGraph->m_edgeCount;
long long lastGraphTotalLength = g_assemblyGraph->m_totalLength;
long long lastGraphShortestContig = g_assemblyGraph->m_shortestContig;
long long lastGraphLongestContig = g_assemblyGraph->m_longestContig;
QString pathStringFailure;
Path lastGraphTestPath1 = Path::makeFromString("3176-, 3176+, 4125+, 3178-, 3283+, 3180+, 3177-", true, &pathStringFailure);
Path lastGraphTestPath2 = Path::makeFromString("3368+, 3369+, 3230+, 3231+, 3370-, 3143+, 3144+, 3145+, 3240+, 3241+, 3788-, 3787-, 3231+, 3252+, 3241-, 3240-, 3145-, 4164-, 4220+, 3368-, 3367+", true, &pathStringFailure);
QByteArray lastGraphTestPath1Sequence = lastGraphTestPath1.getPathSequence();
QByteArray lastGraphTestPath2Sequence = lastGraphTestPath2.getPathSequence();
//Now save the graph as a GFA and reload it and grab the same information.
g_assemblyGraph->saveEntireGraphToGfa(getTestDirectory() + "big_test_temp.gfa");
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "big_test_temp.gfa");
int gfaNodeCount = g_assemblyGraph->m_nodeCount;
int gfaEdgeCount= g_assemblyGraph->m_edgeCount;
long long gfaTotalLength = g_assemblyGraph->m_totalLength;
long long gfaShortestContig = g_assemblyGraph->m_shortestContig;
long long gfaLongestContig = g_assemblyGraph->m_longestContig;
Path gfaTestPath1 = Path::makeFromString("3176-, 3176+, 4125+, 3178-, 3283+, 3180+, 3177-", true, &pathStringFailure);
Path gfaTestPath2 = Path::makeFromString("3368+, 3369+, 3230+, 3231+, 3370-, 3143+, 3144+, 3145+, 3240+, 3241+, 3788-, 3787-, 3231+, 3252+, 3241-, 3240-, 3145-, 4164-, 4220+, 3368-, 3367+", true, &pathStringFailure);
QByteArray gfaTestPath1Sequence = gfaTestPath1.getPathSequence();
QByteArray gfaTestPath2Sequence = gfaTestPath2.getPathSequence();
//Now we compare the LastGraph info to the GFA info to make sure they are
//the same (or appropriately different). The k-mer size for this graph is
//51, so we expect each node to get 50 base pairs longer.
QCOMPARE(lastGraphNodeCount, gfaNodeCount);
QCOMPARE(lastGraphEdgeCount, gfaEdgeCount);
QCOMPARE(lastGraphTotalLength + 50 * lastGraphNodeCount, gfaTotalLength);
QCOMPARE(lastGraphShortestContig + 50, gfaShortestContig);
QCOMPARE(lastGraphLongestContig + 50, gfaLongestContig);
QCOMPARE(lastGraphTestPath1Sequence, gfaTestPath1Sequence);
QCOMPARE(lastGraphTestPath2Sequence, gfaTestPath2Sequence);
//Finally, delete the gfa file.
QFile::remove(getTestDirectory() + "big_test_temp.gfa");
}
void BandageTests::spadesToGfa()
{
//First load the graph as a FASTG and pull out some information and a
//path sequence.
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
int fastgNodeCount = g_assemblyGraph->m_nodeCount;
int fastgEdgeCount= g_assemblyGraph->m_edgeCount;
long long fastgTotalLength = g_assemblyGraph->m_totalLength;
long long fastgShortestContig = g_assemblyGraph->m_shortestContig;
long long fastgLongestContig = g_assemblyGraph->m_longestContig;
QString pathStringFailure;
Path fastgTestPath1 = Path::makeFromString("24+, 14+, 39-, 43-, 42-, 2-, 4+, 33+, 35-, 31-, 44-, 27+, 9-, 28-, 44+, 31+, 36+", false, &pathStringFailure);
Path fastgTestPath2 = Path::makeFromString("16+, 7+, 13+, 37+, 41-, 40-, 42+, 43+, 39+, 14-, 22-, 20+, 7-, 25-, 32-, 38+, 3-", false, &pathStringFailure);
QByteArray fastgTestPath1Sequence = fastgTestPath1.getPathSequence();
QByteArray fastgTestPath2Sequence = fastgTestPath2.getPathSequence();
//Now save the graph as a GFA and reload it and grab the same information.
g_assemblyGraph->saveEntireGraphToGfa(getTestDirectory() + "test_temp.gfa");
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test_temp.gfa");
int gfaNodeCount = g_assemblyGraph->m_nodeCount;
int gfaEdgeCount= g_assemblyGraph->m_edgeCount;
long long gfaTotalLength = g_assemblyGraph->m_totalLength;
long long gfaShortestContig = g_assemblyGraph->m_shortestContig;
long long gfaLongestContig = g_assemblyGraph->m_longestContig;
Path gfaTestPath1 = Path::makeFromString("24+, 14+, 39-, 43-, 42-, 2-, 4+, 33+, 35-, 31-, 44-, 27+, 9-, 28-, 44+, 31+, 36+", false, &pathStringFailure);
Path gfaTestPath2 = Path::makeFromString("16+, 7+, 13+, 37+, 41-, 40-, 42+, 43+, 39+, 14-, 22-, 20+, 7-, 25-, 32-, 38+, 3-", false, &pathStringFailure);
QByteArray gfaTestPath1Sequence = gfaTestPath1.getPathSequence();
QByteArray gfaTestPath2Sequence = gfaTestPath2.getPathSequence();
//Now we compare the LastGraph info to the GFA info to make sure they are
//the same (or appropriately different). The k-mer size for this graph is
//51, so we expect each node to get 50 base pairs longer.
QCOMPARE(fastgNodeCount, gfaNodeCount);
QCOMPARE(fastgEdgeCount, gfaEdgeCount);
QCOMPARE(fastgTotalLength, gfaTotalLength);
QCOMPARE(fastgShortestContig, gfaShortestContig);
QCOMPARE(fastgLongestContig, gfaLongestContig);
QCOMPARE(fastgTestPath1Sequence, gfaTestPath1Sequence);
QCOMPARE(fastgTestPath2Sequence, gfaTestPath2Sequence);
//Finally, delete the gfa file.
QFile::remove(getTestDirectory() + "test_temp.gfa");
}
void BandageTests::mergeNodesOnGfa()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test_plasmids.gfa");
DeBruijnNode * node6Plus = g_assemblyGraph->m_deBruijnGraphNodes["6+"];
DeBruijnNode * node280Plus = g_assemblyGraph->m_deBruijnGraphNodes["280+"];
DeBruijnNode * node232Minus = g_assemblyGraph->m_deBruijnGraphNodes["232-"];
DeBruijnNode * node333Plus = g_assemblyGraph->m_deBruijnGraphNodes["333+"];
DeBruijnNode * node289Plus = g_assemblyGraph->m_deBruijnGraphNodes["289+"];
DeBruijnNode * node283Plus = g_assemblyGraph->m_deBruijnGraphNodes["283+"];
DeBruijnNode * node277Plus = g_assemblyGraph->m_deBruijnGraphNodes["277+"];
DeBruijnNode * node297Plus = g_assemblyGraph->m_deBruijnGraphNodes["297+"];
DeBruijnNode * node282Plus = g_assemblyGraph->m_deBruijnGraphNodes["282+"];
//Create a path before merging the nodes.
QString pathStringFailure;
Path testPath1 = Path::makeFromString("6+, 280+, 232-, 333+, 289+, 283+", true, &pathStringFailure);
QByteArray path1Sequence = testPath1.getPathSequence();
int path1Length = testPath1.getLength();
int nodeTotalLength = node6Plus->getLength() + node280Plus->getLength() + node232Minus->getLength() +
node333Plus->getLength() + node289Plus->getLength() + node283Plus->getLength();
//The k-mer size in this test is 81, so the path should remove all of those overlaps.
QCOMPARE(path1Length, nodeTotalLength - 6 * 81);
//Now remove excess nodes.
std::vector<DeBruijnNode*> nodesToDelete;
nodesToDelete.push_back(node277Plus);
nodesToDelete.push_back(node297Plus);
nodesToDelete.push_back(node282Plus);
g_assemblyGraph->deleteNodes(&nodesToDelete);
//There should now be six nodes in the graph (plus complements).
QCOMPARE(12, g_assemblyGraph->m_deBruijnGraphNodes.size());
//After a merge, there should be only one node (and its complement).
g_assemblyGraph->mergeAllPossible();
QCOMPARE(2, g_assemblyGraph->m_deBruijnGraphNodes.size());
//That last node should have a length of its six constituent nodes, minus
//the overlaps.
DeBruijnNode * lastNode = g_assemblyGraph->m_deBruijnGraphNodes.first();
QCOMPARE(lastNode->getLength(), nodeTotalLength - 5 * 81);
//If we make a circular path with this node, its length should be equal to
//the length of the path made before.
Path testPath2 = Path::makeFromString(lastNode->getName(), true, &pathStringFailure);
QCOMPARE(path1Length, testPath2.getLength());
//The sequence of this second path should also match the sequence of the
//first path.
QByteArray path2Sequence = testPath2.getPathSequence();
QCOMPARE(doCircularSequencesMatch(path1Sequence, path2Sequence), true);
}
void BandageTests::changeNodeNames()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
DeBruijnNode * node6Plus = g_assemblyGraph->m_deBruijnGraphNodes["6+"];
DeBruijnNode * node6Minus = g_assemblyGraph->m_deBruijnGraphNodes["6-"];
int nodeCountBefore = g_assemblyGraph->m_deBruijnGraphNodes.size();
g_assemblyGraph->changeNodeName("6", "12345");
DeBruijnNode * node12345Plus = g_assemblyGraph->m_deBruijnGraphNodes["12345+"];
DeBruijnNode * node12345Minus = g_assemblyGraph->m_deBruijnGraphNodes["12345-"];
int nodeCountAfter = g_assemblyGraph->m_deBruijnGraphNodes.size();
QCOMPARE(node6Plus, node12345Plus);
QCOMPARE(node6Minus, node12345Minus);
QCOMPARE(nodeCountBefore, nodeCountAfter);
}
void BandageTests::changeNodeDepths()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
DeBruijnNode * node6Plus = g_assemblyGraph->m_deBruijnGraphNodes["6+"];
DeBruijnNode * node6Minus = g_assemblyGraph->m_deBruijnGraphNodes["6-"];
DeBruijnNode * node7Plus = g_assemblyGraph->m_deBruijnGraphNodes["7+"];
DeBruijnNode * node7Minus = g_assemblyGraph->m_deBruijnGraphNodes["7-"];
std::vector<DeBruijnNode *> nodes;
nodes.push_back(node6Plus);
nodes.push_back(node7Plus);
//Complementary pairs should have the same depth.
QCOMPARE(node6Plus->getDepth(), node6Minus->getDepth());
QCOMPARE(node7Plus->getDepth(), node7Minus->getDepth());
g_assemblyGraph->changeNodeDepth(&nodes, 0.5);
//Check to make sure the change worked.
QCOMPARE(0.5, node6Plus->getDepth());
QCOMPARE(0.5, node6Minus->getDepth());
QCOMPARE(0.5, node7Plus->getDepth());
QCOMPARE(0.5, node7Minus->getDepth());
}
void BandageTests::blastQueryPaths()
{
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test_query_paths.gfa");
Settings defaultSettings;
g_settings->blastQueryFilename = getTestDirectory() + "test_query_paths.fasta";
defaultSettings.blastQueryFilename = getTestDirectory() + "test_query_paths.fasta";
createBlastTempDirectory();
//Now filter by e-value to get only strong hits and do the BLAST search.
g_settings->blastEValueFilter.on = true;
g_settings->blastEValueFilter = SciNot(1.0, -5);
QList<BlastQueryPath> query1Paths;
QList<BlastQueryPath> query2Paths;
QList<BlastQueryPath> query3Paths;
QList<BlastQueryPath> query4Paths;
QList<BlastQueryPath> query5Paths;
QList<BlastQueryPath> query6Paths;
QList<BlastQueryPath> query7Paths;
//With the default settings, queries 1 to 5 should each have one path and
//queries 6 and 7 should have 0 (because of their large inserts).
g_blastSearch->doAutoBlastSearch();
query1Paths = g_blastSearch->m_blastQueries.m_queries[0]->getPaths();
query2Paths = g_blastSearch->m_blastQueries.m_queries[1]->getPaths();
query3Paths = g_blastSearch->m_blastQueries.m_queries[2]->getPaths();
query4Paths = g_blastSearch->m_blastQueries.m_queries[3]->getPaths();
query5Paths = g_blastSearch->m_blastQueries.m_queries[4]->getPaths();
query6Paths = g_blastSearch->m_blastQueries.m_queries[5]->getPaths();
query7Paths = g_blastSearch->m_blastQueries.m_queries[6]->getPaths();
QCOMPARE(query1Paths.size(), 1);
QCOMPARE(query2Paths.size(), 1);
QCOMPARE(query3Paths.size(), 1);
QCOMPARE(query4Paths.size(), 1);
QCOMPARE(query5Paths.size(), 1);
QCOMPARE(query6Paths.size(), 0);
QCOMPARE(query7Paths.size(), 0);
//query2 has a mean hit identity of 0.98.
g_settings->minMeanHitIdentity.on = true;
g_settings->minMeanHitIdentity = 0.979;
g_blastSearch->doAutoBlastSearch();
query2Paths = g_blastSearch->m_blastQueries.m_queries[1]->getPaths();
QCOMPARE(query2Paths.size(), 1);
g_settings->minMeanHitIdentity = 0.981;
g_blastSearch->doAutoBlastSearch();
query2Paths = g_blastSearch->m_blastQueries.m_queries[1]->getPaths();
QCOMPARE(query2Paths.size(), 0);
//Turning the filter off should make the path return.
g_settings->minMeanHitIdentity.on = false;
g_blastSearch->doAutoBlastSearch();
query2Paths = g_blastSearch->m_blastQueries.m_queries[1]->getPaths();
QCOMPARE(query2Paths.size(), 1);
*g_settings = defaultSettings;
//query3 has a length discrepancy of -20.
g_settings->minLengthBaseDiscrepancy.on = true;
g_settings->minLengthBaseDiscrepancy = -20;
g_blastSearch->doAutoBlastSearch();
query3Paths = g_blastSearch->m_blastQueries.m_queries[2]->getPaths();
QCOMPARE(query3Paths.size(), 1);
g_settings->minLengthBaseDiscrepancy = -19;
g_blastSearch->doAutoBlastSearch();
query3Paths = g_blastSearch->m_blastQueries.m_queries[2]->getPaths();
QCOMPARE(query3Paths.size(), 0);
//Turning the filter off should make the path return.
g_settings->minLengthBaseDiscrepancy.on = false;
g_blastSearch->doAutoBlastSearch();
query3Paths = g_blastSearch->m_blastQueries.m_queries[2]->getPaths();
QCOMPARE(query3Paths.size(), 1);
*g_settings = defaultSettings;
//query4 has a length discrepancy of +20.
g_settings->maxLengthBaseDiscrepancy.on = true;
g_settings->maxLengthBaseDiscrepancy = 20;
g_blastSearch->doAutoBlastSearch();
query4Paths = g_blastSearch->m_blastQueries.m_queries[3]->getPaths();
QCOMPARE(query4Paths.size(), 1);
g_settings->maxLengthBaseDiscrepancy = 19;
g_blastSearch->doAutoBlastSearch();
query4Paths = g_blastSearch->m_blastQueries.m_queries[3]->getPaths();
QCOMPARE(query4Paths.size(), 0);
//Turning the filter off should make the path return.
g_settings->maxLengthBaseDiscrepancy.on = false;
g_blastSearch->doAutoBlastSearch();
query4Paths = g_blastSearch->m_blastQueries.m_queries[3]->getPaths();
QCOMPARE(query4Paths.size(), 1);
*g_settings = defaultSettings;
//query5 has a path through 4 nodes.
g_settings->maxQueryPathNodes = 4;
g_blastSearch->doAutoBlastSearch();
query5Paths = g_blastSearch->m_blastQueries.m_queries[4]->getPaths();
QCOMPARE(query5Paths.size(), 1);
g_settings->maxQueryPathNodes = 3;
g_blastSearch->doAutoBlastSearch();
query5Paths = g_blastSearch->m_blastQueries.m_queries[4]->getPaths();
QCOMPARE(query5Paths.size(), 0);
*g_settings = defaultSettings;
//By turning off length restrictions, queries 6 and 7 should get path with
//a large insert in the middle.
g_settings->minLengthPercentage.on = false;
g_settings->maxLengthPercentage.on = false;
g_settings->minLengthBaseDiscrepancy.on = false;
g_settings->maxLengthBaseDiscrepancy.on = false;
g_blastSearch->doAutoBlastSearch();
query6Paths = g_blastSearch->m_blastQueries.m_queries[5]->getPaths();
query7Paths = g_blastSearch->m_blastQueries.m_queries[6]->getPaths();
QCOMPARE(query6Paths.size(), 1);
QCOMPARE(query7Paths.size(), 1);
//Adjusting on the max length restriction can allow query 6 to get a path
//and then query 7.
g_settings->maxLengthBaseDiscrepancy.on = true;
g_settings->maxLengthBaseDiscrepancy = 1999;
g_blastSearch->doAutoBlastSearch();
query6Paths = g_blastSearch->m_blastQueries.m_queries[5]->getPaths();
query7Paths = g_blastSearch->m_blastQueries.m_queries[6]->getPaths();
QCOMPARE(query6Paths.size(), 1);
QCOMPARE(query7Paths.size(), 0);
g_settings->maxLengthBaseDiscrepancy = 2000;
g_blastSearch->doAutoBlastSearch();
query6Paths = g_blastSearch->m_blastQueries.m_queries[5]->getPaths();
query7Paths = g_blastSearch->m_blastQueries.m_queries[6]->getPaths();
QCOMPARE(query6Paths.size(), 1);
QCOMPARE(query7Paths.size(), 1);
}
void BandageTests::bandageInfo()
{
int n50 = 0;
int shortestNode = 0;
int firstQuartile = 0;
int median = 0;
int thirdQuartile = 0;
int longestNode = 0;
int componentCount = 0;
int largestComponentLength = 0;
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.LastGraph");
g_assemblyGraph->getNodeStats(&n50, &shortestNode, &firstQuartile, &median, &thirdQuartile, &longestNode);
g_assemblyGraph->getGraphComponentCountAndLargestComponentSize(&componentCount, &largestComponentLength);
QCOMPARE(17, g_assemblyGraph->m_nodeCount);
QCOMPARE(16, g_assemblyGraph->m_edgeCount);
QCOMPARE(29939, g_assemblyGraph->m_totalLength);
QCOMPARE(10, g_assemblyGraph->getDeadEndCount());
QCOMPARE(2000, n50);
QCOMPARE(59, shortestNode);
QCOMPARE(2000, longestNode);
QCOMPARE(1, componentCount);
QCOMPARE(29939, largestComponentLength);
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.fastg");
g_assemblyGraph->getNodeStats(&n50, &shortestNode, &firstQuartile, &median, &thirdQuartile, &longestNode);
g_assemblyGraph->getGraphComponentCountAndLargestComponentSize(&componentCount, &largestComponentLength);
QCOMPARE(44, g_assemblyGraph->m_nodeCount);
QCOMPARE(59, g_assemblyGraph->m_edgeCount);
QCOMPARE(214441, g_assemblyGraph->m_totalLength);
QCOMPARE(0, g_assemblyGraph->getDeadEndCount());
QCOMPARE(35628, n50);
QCOMPARE(78, shortestNode);
QCOMPARE(52213, longestNode);
QCOMPARE(1, componentCount);
QCOMPARE(214441, largestComponentLength);
createGlobals();
g_assemblyGraph->loadGraphFromFile(getTestDirectory() + "test.Trinity.fasta");
g_assemblyGraph->getNodeStats(&n50, &shortestNode, &firstQuartile, &median, &thirdQuartile, &longestNode);
g_assemblyGraph->getGraphComponentCountAndLargestComponentSize(&componentCount, &largestComponentLength);
QCOMPARE(149, g_assemblyGraph->getDeadEndCount());
QCOMPARE(66, componentCount);
QCOMPARE(9398, largestComponentLength);
}
void BandageTests::createGlobals()
{
g_settings.reset(new Settings());
g_memory.reset(new Memory());
g_blastSearch.reset(new BlastSearch());
g_assemblyGraph.reset(new AssemblyGraph());
g_graphicsView = new MyGraphicsView();
}
bool BandageTests::createBlastTempDirectory()
{
//Running from the command line, it makes more sense to put the temp
//directory in the current directory.
g_blastSearch->m_tempDirectory = "bandage_temp-" + QString::number(QCoreApplication::applicationPid()) + "/";
if (!QDir().mkdir(g_blastSearch->m_tempDirectory))
return false;
g_blastSearch->m_blastQueries.createTempQueryFiles();
return true;
}
void BandageTests::deleteBlastTempDirectory()
{
if (g_blastSearch->m_tempDirectory != "" &&
QDir(g_blastSearch->m_tempDirectory).exists() &&
QDir(g_blastSearch->m_tempDirectory).dirName().contains("bandage_temp"))
QDir(g_blastSearch->m_tempDirectory).removeRecursively();
}
QString BandageTests::getTestDirectory()
{
QDir directory = QDir::current();
//We want to find a directory "Bandage/tests/". Keep backing up in the
//directory structure until we find it.
QString path;
while (true)
{
path = directory.path() + "/Bandage/tests/";
if (QDir(path).exists())
return path;
if (!directory.cdUp())
return "";
}
return "";
}
DeBruijnEdge * BandageTests::getEdgeFromNodeNames(QString startingNodeName,
QString endingNodeName)
{
DeBruijnNode * startingNode = g_assemblyGraph->m_deBruijnGraphNodes[startingNodeName];
DeBruijnNode * endingNode = g_assemblyGraph->m_deBruijnGraphNodes[endingNodeName];
QPair<DeBruijnNode*, DeBruijnNode*> nodePair(startingNode, endingNode);
if (g_assemblyGraph->m_deBruijnGraphEdges.contains(nodePair))
return g_assemblyGraph->m_deBruijnGraphEdges[nodePair];
else
return 0;
}
//This function checks to see if two circular sequences match. It needs to
//check each possible rotation, as well as reverse complements.
bool BandageTests::doCircularSequencesMatch(QByteArray s1, QByteArray s2)
{
for (int i = 0; i < s1.length() - 1; ++i)
{
QByteArray rotatedS1 = s1.right(s1.length() - i) + s1.left(i);
if (rotatedS1 == s2)
return true;
}
//If the code got here, then all possible rotations of s1 failed to match
//s2. Now we try the reverse complement.
QByteArray s1Rc = AssemblyGraph::getReverseComplement(s1);
for (int i = 0; i < s1Rc.length() - 1; ++i)
{
QByteArray rotatedS1Rc = s1Rc.right(s1Rc.length() - i) + s1Rc.left(i);
if (rotatedS1Rc == s2)
return true;
}
return false;
}
QTEST_MAIN(BandageTests)
#include "bandagetests.moc"
|