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 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
|
//
// makecontigscommand.cpp
// Mothur
//
// Created by Sarah Westcott on 5/15/12.
// Copyright (c) 2012 Schloss Lab. All rights reserved.
//
#include "makecontigscommand.h"
#include "contigsreport.hpp"
#include "counttable.h"
//**************************************************************************************************
/**
* Convert the probability to a quality score.
*/
double convertProbToQ(double prob){
try {
return round(-10*log10(prob));
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "convertProbToQ");
exit(1);
}
}
//**************************************************************************************************
/**
* Convert the quality score to a probability.
*/
double convertQToProb(double Q){
try {
double value = pow(10,(-Q/10));
if (isnan(value) || isinf(value)) { value = 0.0; }
return value;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "convertQToProb");
exit(1);
}
}
//**************************************************************************************************
int loadQmatchValues(vector< vector<double> >& qual_match_simple_bayesian, vector< vector<double> >& qual_mismatch_simple_bayesian){
try {
vector<double> probs(47);
for(int i=0;i<probs.size();i++){
probs[i] = convertQToProb(i);
}
//qual_match_simple_bayesian - naturally symmetric
//qual_mismatch_simple_bayesian - force symmetry
for(int i=0;i<qual_match_simple_bayesian.size(); i++){
for(int j=0;j<=i;j++){
qual_match_simple_bayesian[i][j] = convertProbToQ((probs[i]*probs[j]/3)/(1-probs[i]-probs[j]+4*probs[i]*probs[j]/3));
qual_mismatch_simple_bayesian[i][j] = convertProbToQ(probs[i]*(1-probs[j]/3)/(probs[i]+probs[j]-4*probs[i]*probs[j]/3));
}
qual_mismatch_simple_bayesian[i][i] = 2.0;
}
for(int i=0;i<qual_match_simple_bayesian.size(); i++){
for(int j=0;j<i;j++){
qual_match_simple_bayesian[j][i] = qual_match_simple_bayesian[i][j];
qual_mismatch_simple_bayesian[j][i] = qual_mismatch_simple_bayesian[i][j];
}
}
return 0;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "loadQmatchValues");
exit(1);
}
}
//**************************************************************************************************
vector<string> MakeContigsCommand::setParameters(){
try {
CommandParameter pfastq("ffastq", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "fastqGroup","fasta-qfile",false,false,true); parameters.push_back(pfastq);
CommandParameter prfastq("rfastq", "InputTypes", "", "", "none", "none", "fastqGroup","fasta-qfile",false,false,true); parameters.push_back(prfastq);
CommandParameter pfasta("ffasta", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "fastaGroup","fasta",false,false,true); parameters.push_back(pfasta);
CommandParameter prfasta("rfasta", "InputTypes", "", "", "none", "none", "none","fastaGroup",false,false,true); parameters.push_back(prfasta);
CommandParameter pfqual("fqfile", "InputTypes", "", "", "none", "none", "qfileGroup","",false,false,true); parameters.push_back(pfqual);
CommandParameter prqual("rqfile", "InputTypes", "", "", "none", "none", "qfileGroup","",false,false,true); parameters.push_back(prqual);
CommandParameter pfile("file", "InputTypes", "", "", "FastaFastqFile", "FastaFastqFile", "none","fasta-qfile",false,false,true); parameters.push_back(pfile);
CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","group",false,false,true); parameters.push_back(poligos);
CommandParameter pfindex("findex", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(pfindex);
CommandParameter prindex("rindex", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(prindex);
CommandParameter pqfile("qfile", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pqfile);
CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs);
CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs);
CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs);
CommandParameter preorient("checkorient", "Boolean", "", "T", "", "", "","",false,false,true); parameters.push_back(preorient);
CommandParameter palign("align", "Multiple", "needleman-gotoh-kmer", "needleman", "", "", "","",false,false); parameters.push_back(palign);
CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pallfiles);
CommandParameter ptrimoverlap("trimoverlap", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ptrimoverlap);
CommandParameter pmatch("match", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pmatch);
CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pmismatch);
CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapopen);
CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pgapextend);
CommandParameter pthreshold("insert", "Number", "", "20", "", "", "","",false,false); parameters.push_back(pthreshold);
CommandParameter pdeltaq("deltaq", "Number", "", "6", "", "", "","",false,false); parameters.push_back(pdeltaq);
CommandParameter maxee("maxee", "Number", "", "10000", "", "", "","",false,false); parameters.push_back(maxee);
CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
CommandParameter pformat("format", "Multiple", "sanger-illumina-solexa-illumina1.8+", "illumina1.8+", "", "", "","",false,false,true); parameters.push_back(pformat);
CommandParameter pksize("ksize", "Number", "", "8", "", "", "","",false,false); parameters.push_back(pksize);
CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxambig);
CommandParameter pmaxhomop("maxhomop", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxhomop);
CommandParameter pmaxlength("maxlength", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxlength);
CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed);
CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
abort = false; calledHelp = false;
createFileGroup = false; createOligosGroup = false; gz = false;
//initialize outputTypes
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["qfile"] = tempOutNames;
outputTypes["report"] = tempOutNames;
outputTypes["count"] = tempOutNames;
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
return myArray;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "setParameters");
exit(1);
}
}
//**********************************************************************************************************************
string MakeContigsCommand::getHelpString(){
try {
string helpString = "";
helpString += "The make.contigs command reads a file, forward fastq file and a reverse fastq file or forward fasta and reverse fasta files and outputs a fasta file. \n";
helpString += "If an oligos file is provided barcodes and primers will be trimmed, and a count file will be created.\n";
helpString += "If a forward index or reverse index file is provided barcodes be trimmed, and a group file will be created. The oligos parameter is required if an index file is given.\n";
helpString += "The make.contigs command parameters are file, ffastq, rfastq, ffasta, rfasta, fqfile, rqfile, oligos, findex, rindex, qfile, format, tdiffs, bdiffs, pdiffs, align, match, mismatch, gapopen, gapextend, insert, deltaq, maxee, allfiles and processors.\n";
helpString += "The ffastq and rfastq, file, or ffasta and rfasta parameters are required.\n";
helpString += "The file parameter is 2, 3 or 4 column file containing the forward fastq files in the first column and their matching reverse fastq files in the second column, or a groupName then forward fastq file and reverse fastq file, or forward fastq file then reverse fastq then forward index and reverse index file. If you only have one index file add 'none' for the other one. Mothur will process each pair and create a combined fasta and report file with all the sequences.\n";
helpString += "The ffastq and rfastq parameters are used to provide a forward fastq and reverse fastq file to process. If you provide one, you must provide the other.\n";
helpString += "The ffasta and rfasta parameters are used to provide a forward fasta and reverse fasta file to process. If you provide one, you must provide the other.\n";
helpString += "The fqfile and rqfile parameters are used to provide a forward quality and reverse quality files to process with the ffasta and rfasta parameters. If you provide one, you must provide the other.\n";
helpString += "The format parameter is used to indicate whether your sequences are sanger, solexa, illumina1.8+ or illumina, default=illumina1.8+.\n";
helpString += "The findex and rindex parameters are used to provide a forward index and reverse index files to process. \n";
helpString += "The qfile parameter is used to indicate you want a quality file assembled. Default=f. NOTE: The assembled quality scores outputted by mothur cannot be used for downstream quality screening. The score calculations are modeled after pandseq's method. Here's a link to the explanation from their documentation, https://github.com/neufeld/pandaseq#the-scores-of-the-output-bases-seem-really-low-whats-wrong. \n";
helpString += "The align parameter allows you to specify the alignment method to use. Your options are: kmer, gotoh and needleman. The default is needleman.\n";
helpString += "The ksize parameter allows you to set the kmer size if you are doing align=kmer. Default=8.\n";
helpString += "The tdiffs parameter is used to specify the total number of differences allowed in the sequence. The default is pdiffs + bdiffs + sdiffs + ldiffs.\n";
helpString += "The bdiffs parameter is used to specify the number of differences allowed in the barcode. The default is 0.\n";
helpString += "The pdiffs parameter is used to specify the number of differences allowed in the primer. The default is 0.\n";
helpString += "The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n";
helpString += "The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n";
helpString += "The checkorient parameter will look for the reverse compliment of the barcode or primer in the sequence. If found the sequence is flipped. The default is true.\n";
helpString += "The deltaq parameter allows you to specify the delta allowed between quality scores of a mismatched base. For example in the overlap, if deltaq=5 and in the alignment seqA, pos 200 has a quality score of 30 and the same position in seqB has a quality score of 20, you take the base from seqA (30-20 >= 5). If the quality score in seqB is 28 then the base in the consensus will be an N (30-28<5). The default is 6.\n";
helpString += "The maxee parameter allows you to specify the maximum number of errors to allow in a sequence. Makes sense to use with deltaq=0. This number is a decimal number. The expected number of errors is based on Edgar's approach used in USEARCH/VSEARCH.";
helpString += "The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n";
helpString += "The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n";
helpString += "The insert parameter allows you to set a quality scores threshold. In the case where we are trying to decide whether to keep a base or remove it because the base is compared to a gap in the other fragment, if the base has a quality score equal to or below the threshold we eliminate it. Default=20.\n";
helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is all available.\n";
helpString += "The allfiles parameter will create separate group and fasta file for each grouping. The default is F.\n";
helpString += "The trimoverlap parameter allows you to trim the sequences to only the overlapping section. The default is F.\n";
helpString += "The maxambig parameter allows you to set the maximum number of ambiguous bases allowed. The default is -1, meaning ignore.\n";
helpString += "The maxhomop parameter allows you to set a maximum homopolymer length. The default is -1, meaning ignore.\n";
helpString += "The maxlength parameter allows you to set a maximum length of your sequences. The default is -1, meaning ignore.\n";
helpString += "The make.contigs command should be in the following format: \n";
helpString += "make.contigs(ffastq=yourForwardFastqFile, rfastq=yourReverseFastqFile, align=yourAlignmentMethod) \n";
return helpString;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "getHelpString");
exit(1);
}
}
//**********************************************************************************************************************
string MakeContigsCommand::getOutputPattern(string type) {
try {
string pattern = "";
if (type == "fasta") { pattern = "[filename],[tag],contigs.fasta"; }
else if (type == "qfile") { pattern = "[filename],[tag],contigs.qual"; }
else if (type == "count") { pattern = "[filename],[tag],contigs.count_table"; }
else if (type == "report") { pattern = "[filename],[tag],contigs_report"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->setControl_pressed(true); }
return pattern;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "getOutputPattern");
exit(1);
}
}
//**********************************************************************************************************************
MakeContigsCommand::MakeContigsCommand(string option) : Command() {
try {
if(option == "help") { help(); abort = true; calledHelp = true; }
else if(option == "citation") { citation(); abort = true; calledHelp = true;}
else if(option == "category") { abort = true; calledHelp = true; }
else {
OptionParser parser(option, setParameters());
map<string, string> parameters = parser.getParameters();
ValidParameters validParameter;
ffastqfile = validParameter.validFile(parameters, "ffastq");
if (ffastqfile == "not open") { abort = true; }
else if (ffastqfile == "not found") { ffastqfile = ""; }
rfastqfile = validParameter.validFile(parameters, "rfastq");
if (rfastqfile == "not open") { abort = true; }
else if (rfastqfile == "not found") { rfastqfile = ""; }
ffastafile = validParameter.validFile(parameters, "ffasta");
if (ffastafile == "not open") { abort = true; }
else if (ffastafile == "not found") { ffastafile = ""; }
rfastafile = validParameter.validFile(parameters, "rfasta");
if (rfastafile == "not open") { abort = true; }
else if (rfastafile == "not found") { rfastafile = ""; }
fqualfile = validParameter.validFile(parameters, "fqfile");
if (fqualfile == "not open") { abort = true; }
else if (fqualfile == "not found") { fqualfile = ""; }
rqualfile = validParameter.validFile(parameters, "rqfile");
if (rqualfile == "not open") { abort = true; }
else if (rqualfile == "not found") { rqualfile = ""; }
file = validParameter.validFile(parameters, "file");
if (file == "not open") { abort = true; }
else if (file == "not found") { file = ""; }
//provide at least
if ((file == "") && (ffastafile == "") && (ffastqfile == "")) { abort = true; m->mothurOut("[ERROR]: The file, ffastq and rfastq or ffasta and rfasta parameters are required.\n"); }
if ((file != "") && ((ffastafile != "") || (ffastqfile != ""))) { abort = true; m->mothurOut("[ERROR]: The file, ffastq and rfastq or ffasta and rfasta parameters are required.\n"); }
if ((ffastqfile != "") && (rfastqfile == "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the ffastq, you must provide a rfastq file.\n"); }
if ((ffastqfile == "") && (rfastqfile != "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the rfastq, you must provide a ffastq file.\n"); }
if ((ffastafile != "") && (rfastafile == "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the ffasta, you must provide a rfasta file.\n"); }
if ((ffastafile == "") && (rfastafile != "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the rfasta, you must provide a ffasta file.\n"); }
if ((fqualfile != "") && (rqualfile == "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the fqfile, you must provide a rqfile file.\n"); }
if ((fqualfile == "") && (rqualfile != "")) { abort = true; m->mothurOut("[ERROR]: If you provide use the rqfile, you must provide a fqfile file.\n"); }
if (((fqualfile != "") || (rqualfile != "")) && ((ffastafile == "") || (rfastafile == ""))) {
abort = true; m->mothurOut("[ERROR]: If you provide use the rqfile or fqfile file, you must provide the ffasta and rfasta parameters.\n");
}
oligosfile = validParameter.validFile(parameters, "oligos");
if (oligosfile == "not found") { oligosfile = ""; }
else if(oligosfile == "not open") { abort = true; }
else { current->setOligosFile(oligosfile); }
findexfile = validParameter.validFile(parameters, "findex");
if (findexfile == "not found") { findexfile = ""; }
else if(findexfile == "not open") { abort = true; }
rindexfile = validParameter.validFile(parameters, "rindex");
if (rindexfile == "not found") { rindexfile = ""; }
else if(rindexfile == "not open") { abort = true; }
if ((rindexfile != "") || (findexfile != "")) {
if (oligosfile == ""){
oligosfile = current->getOligosFile();
if (oligosfile != "") { m->mothurOut("Using " + oligosfile + " as input file for the oligos parameter.\n"); }
else {
m->mothurOut("You need to provide an oligos file if you are going to use an index file.\n"); abort = true;
}
}
//can only use an index file with the fastq parameters not fasta and qual
if ((ffastafile != "") || (rfastafile != "")) {
m->mothurOut("[ERROR]: You can only use an index file with the fastq parameters or the file option.\n"); abort = true;
}
}
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
string temp;
temp = validParameter.valid(parameters, "match"); if (temp == "not found"){ temp = "1.0"; }
util.mothurConvert(temp, match);
temp = validParameter.valid(parameters, "mismatch"); if (temp == "not found"){ temp = "-1.0"; }
util.mothurConvert(temp, misMatch);
if (misMatch > 0) { m->mothurOut("[ERROR]: mismatch must be negative.\n"); abort=true; }
temp = validParameter.valid(parameters, "gapopen"); if (temp == "not found"){ temp = "-2.0"; }
util.mothurConvert(temp, gapOpen);
if (gapOpen > 0) { m->mothurOut("[ERROR]: gapopen must be negative.\n"); abort=true; }
temp = validParameter.valid(parameters, "gapextend"); if (temp == "not found"){ temp = "-1.0"; }
util.mothurConvert(temp, gapExtend);
if (gapExtend > 0) { m->mothurOut("[ERROR]: gapextend must be negative.\n"); abort=true; }
temp = validParameter.valid(parameters, "insert"); if (temp == "not found"){ temp = "20"; }
util.mothurConvert(temp, insert);
if ((insert < 0) || (insert > 40)) { m->mothurOut("[ERROR]: insert must be between 0 and 40.\n"); abort=true; }
temp = validParameter.valid(parameters, "deltaq"); if (temp == "not found"){ temp = "6"; }
util.mothurConvert(temp, deltaq);
temp = validParameter.valid(parameters, "maxee"); if (temp == "not found"){ temp = "10000"; }
util.mothurConvert(temp, maxee);
temp = validParameter.valid(parameters, "processors"); if (temp == "not found"){ temp = current->getProcessors(); }
processors = current->setProcessors(temp);
temp = validParameter.valid(parameters, "bdiffs"); if (temp == "not found") { temp = "0"; }
util.mothurConvert(temp, bdiffs);
temp = validParameter.valid(parameters, "pdiffs"); if (temp == "not found") { temp = "0"; }
util.mothurConvert(temp, pdiffs);
temp = validParameter.valid(parameters, "tdiffs"); if (temp == "not found") { int tempTotal = pdiffs + bdiffs; temp = toString(tempTotal); }
util.mothurConvert(temp, tdiffs);
if(tdiffs == 0){ tdiffs = bdiffs + pdiffs; }
temp = validParameter.valid(parameters, "allfiles"); if (temp == "not found") { temp = "F"; }
allFiles = util.isTrue(temp);
temp = validParameter.valid(parameters, "ksize"); if (temp == "not found"){ temp = "8"; }
util.mothurConvert(temp, kmerSize);
temp = validParameter.valid(parameters, "trimoverlap"); if (temp == "not found") { temp = "F"; }
trimOverlap = util.isTrue(temp);
temp = validParameter.valid(parameters, "qfile");
if (temp == "not found") { temp = "F"; }
else { temp = util.getSimpleName(temp); }
makeQualFile = util.isTrue(temp);
align = validParameter.valid(parameters, "align"); if (align == "not found"){ align = "needleman"; }
if ((align != "needleman") && (align != "gotoh") && (align != "kmer")) { m->mothurOut(align + " is not a valid alignment method. Options are kmer, needleman or gotoh. I will use needleman.\n"); align = "needleman"; }
format = validParameter.valid(parameters, "format"); if (format == "not found"){ format = "illumina1.8+"; }
if ((format != "sanger") && (format != "illumina") && (format != "illumina1.8+") && (format != "solexa")) {
m->mothurOut(format + " is not a valid format. Your format choices are sanger, solexa, illumina1.8+ and illumina, aborting." ); m->mothurOutEndLine();
abort=true;
}
temp = validParameter.valid(parameters, "checkorient"); if (temp == "not found") { temp = "T"; }
reorient = util.isTrue(temp);
temp = validParameter.valid(parameters, "maxambig"); if (temp == "not found") { temp = "-1"; }
util.mothurConvert(temp, maxAmbig);
temp = validParameter.valid(parameters, "maxhomop"); if (temp == "not found") { temp = "-1"; }
util.mothurConvert(temp, maxHomoP);
temp = validParameter.valid(parameters, "maxlength"); if (temp == "not found") { temp = "-1"; }
util.mothurConvert(temp, maxLength);
if ((maxLength == -1) && (maxHomoP == -1) && (maxAmbig == -1)) { screenSequences = false; }
else { screenSequences = true; }
}
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "MakeContigsCommand");
exit(1);
}
}
//**********************************************************************************************************************
int MakeContigsCommand::execute(){
try {
bool debugIndex = false;
if (debugIndex) { //allows you to run the oligos and index file independantly to check for barcode issues. make.contigs(findex=yourIndexFile, bdiffs=1, oligos=yourOligosFile, checkorient=t). just used for user support
debugFunction();
}
if (abort) { if (calledHelp) { return 0; } return 2; }
unsigned long long numReads = 0;
long start = time(nullptr);
string outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, inputFile;
if (file != "") { numReads = processMultipleFileOption(outFastaFile, outMisMatchFile); inputFile = file; }
else if ((ffastqfile != "") || (ffastafile != "")) {
numReads = processSingleFileOption(outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, "");
inputFile = ffastqfile;
if (ffastafile != "") { inputFile = ffastafile; }
} else { return 0; }
if (groupMap.size() != 0) {
string thisOutputDir = outputdir;
if (outputdir == "") { thisOutputDir = util.hasPath(inputFile); }
map<string, string> vars;
vars["[filename]"] = thisOutputDir + util.getRootName(util.getSimpleName(inputFile));
vars["[tag]"] = "";
string outputCountFileName = getOutputFileName("count",vars);
outputNames.push_back(outputCountFileName); outputTypes["count"].push_back(outputCountFileName);
createCountFile(outputCountFileName, outFastaFile);
}
//add headers to mismatch file
ofstream out; util.openOutputFile(outMisMatchFile+".temp", out);
ContigsReport report; report.printHeaders(out); out.close();//print Headers
util.appendFilesFront(outMisMatchFile+".temp", outMisMatchFile); //removes temp
if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; }
string currentFasta = "";
itTypes = outputTypes.find("fasta");
if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentFasta = (itTypes->second)[0]; current->setFastaFile(currentFasta); } }
string currentCount = "";
itTypes = outputTypes.find("count");
if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentCount = (itTypes->second)[0]; current->setCountFile(currentCount); } }
string currentQual = "";
itTypes = outputTypes.find("qfile");
if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentQual = (itTypes->second)[0]; current->setQualFile(currentQual); } }
string currentReport = "";
itTypes = outputTypes.find("report");
if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentReport = (itTypes->second)[0]; current->setContigsReportFile(currentReport); } }
if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; }
//output group counts
int total = 0;
if (groupCounts.size() != 0) { m->mothurOut("\nGroup count: \n"); }
for (map<string, int>::iterator it = groupCounts.begin(); it != groupCounts.end(); it++) { total += it->second; m->mothurOut(it->first + "\t" + toString(it->second) + "\n"); }
if (total != 0) { m->mothurOut("\nTotal of all groups is " + toString(total) + "\n"); }
m->mothurOut("\nIt took " + toString(time(nullptr) - start) + " secs to process " + toString(numReads) + " sequences.\n");
//output files created by command
m->mothurOut("\nOutput File Names: \n");
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine();
return 0;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "execute");
exit(1);
}
}
/**************************************************************************************************/
int MakeContigsCommand::createCountFile(string outputGroupFile, string resultFastafile) {
try {
CountTable ct; ct.createTable(groupMap);
ct.printCompressedTable(outputGroupFile);
if(allFiles){
//run split.groups command
//use unique.seqs to create new name and fastafile
string inputString = "fasta=" + resultFastafile + ", count=" + outputGroupFile;
m->mothurOut("/******************************************/\n");
m->mothurOut("Generating allfiles... Running command: split.groups(" + inputString + ")\n");
current->setMothurCalling(true);
Command* splitCommand = new SplitGroupCommand(inputString);
splitCommand->execute();
map<string, vector<string> > filenames = splitCommand->getOutputFiles();
delete splitCommand;
current->setMothurCalling(false);
m->mothurOut("/******************************************/\n");
}
return 0;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "createCountFile");
exit(1);
}
}
//**********************************************************************************************************************
bool testGZReadable(vector<string>& fileInputs, vector<string>& indexInputs, bool& decompressionHelped, string format, MothurOut* m) {
try {
bool error = false; bool readable = true;
decompressionHelped = false;
#ifdef USE_BOOST
boost::iostreams::filtering_istream inFF, inRF;
ifstream inForward, inReverse;
string forwardFile = fileInputs[0];
string reverseFile = fileInputs[1];
Utils util;
util.openInputFileBinary(forwardFile, inForward, inFF);
util.openInputFileBinary(reverseFile, inReverse, inRF);
FastqRead fread(inFF, error, format);
FastqRead rread(inRF, error, format);
inFF.pop(); inRF.pop();
//error=true; to force test of decompression
if (error) { //error reading fastq files, try unzipping
string forwardOutput = util.getRootName(forwardFile) + "mothurTest_forward.fastq";
string reverseOutput = util.getRootName(reverseFile) + "mothurTest_reverse.fastq";
string unzipCommand = "gunzip < " + forwardFile + " > " + forwardOutput;
system(unzipCommand.c_str());
unzipCommand = "gunzip < " + reverseFile + " > " + reverseOutput;
system(unzipCommand.c_str());
ifstream inForward1, inReverse1;
util.openInputFile(forwardOutput, inForward1);
util.openInputFile(reverseOutput, inReverse1);
FastqRead fread(inForward1, error, format);
FastqRead rread(inReverse1, error, format);
if (!error) {
m->mothurOut("[WARNING]: mothur is unable to read your compressed fastq files. Decompressing files and continuing to process.\n\n");
fileInputs[0] = forwardOutput;
fileInputs[1] = reverseOutput;
if (indexInputs.size() != 0) {
if ((indexInputs[0] != "NONE") && (indexInputs[0] != "")){
string forwardIndex = util.getRootName(indexInputs[0]) + "mothurTest_forward_index.fastq";
string unzipCommand = "gunzip < " + indexInputs[0] + " > " + forwardIndex;
system(unzipCommand.c_str());
indexInputs[0] = forwardIndex;
}
if ((indexInputs[1] != "NONE") && (indexInputs[1] != "")) {
string reverseIndex = util.getRootName(indexInputs[1]) + "mothurTest_reverse_index.fastq";
unzipCommand = "gunzip < " + indexInputs[1] + " > " + reverseIndex;
system(unzipCommand.c_str());
indexInputs[1] = reverseIndex;
}
}
decompressionHelped = true;
}
else { readable = false; }
}
#endif
return readable;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "testGZReadable");
exit(1);
}
}
//**********************************************************************************************************************
unsigned long long MakeContigsCommand::processSingleFileOption(string& outFastaFile, string& outScrapFastaFile, string& outQualFile, string& outScrapQualFile, string& outMisMatchFile, string group) {
try {
unsigned long long numReads = 0;
string inputFile = "";
vector<string> fileInputs;
vector<string> qualOrIndexInputs;
delim = '>';
map<string, string> variables;
string thisOutputDir = outputdir;
if (ffastafile != "") {
inputFile = ffastafile;
if (outputdir == "") { thisOutputDir = util.hasPath(inputFile); }
fileInputs.push_back(ffastafile); fileInputs.push_back(rfastafile);
if (fqualfile != "") {
qualOrIndexInputs.push_back(fqualfile); qualOrIndexInputs.push_back(rqualfile);
variables["[filename]"] = thisOutputDir + util.getRootName(util.getSimpleName(fqualfile));
variables["[tag]"] = "trim";
outQualFile = getOutputFileName("qfile",variables);
variables["[tag]"] = "scrap";
outScrapQualFile = getOutputFileName("qfile",variables);
}else {
outQualFile = ""; outScrapQualFile = ""; makeQualFile = false;
}
variables["[filename]"] = thisOutputDir + util.getRootName(util.getSimpleName(inputFile));
delim = '>';
}else { //ffastqfile
inputFile = ffastqfile;
if (outputdir == "") { thisOutputDir = util.hasPath(inputFile); }
variables["[filename]"] = thisOutputDir + util.getRootName(util.getSimpleName(inputFile));
variables["[tag]"] = "trim";
outQualFile = getOutputFileName("qfile",variables);
variables["[tag]"] = "scrap";
outScrapQualFile = getOutputFileName("qfile",variables);
fileInputs.push_back(ffastqfile); fileInputs.push_back(rfastqfile);
if ((findexfile != "") || (rindexfile != "")){
qualOrIndexInputs.push_back("NONE"); qualOrIndexInputs.push_back("NONE");
if (findexfile != "") { qualOrIndexInputs[0] = findexfile; }
if (rindexfile != "") { qualOrIndexInputs[1] = rindexfile; }
}
delim = '@';
}
bool allGZ = true;
#ifdef USE_BOOST
bool allPlainTxt = true;
if (util.isGZ(fileInputs[0])[1]) { allPlainTxt = false; }
else { allGZ = false; }
if (util.isGZ(fileInputs[1])[1]) { allPlainTxt = false; }
else { allGZ = false; }
if (qualOrIndexInputs.size() != 0) {
if (qualOrIndexInputs[0] != "NONE") {
if (util.isGZ(qualOrIndexInputs[0])[1]) { allPlainTxt = false; }
else { allGZ = false; }
}
if (qualOrIndexInputs[1] != "NONE") {
if (util.isGZ(qualOrIndexInputs[1])[1]) { allPlainTxt = false; }
else { allGZ = false; }
}
if (!allGZ && !allPlainTxt) { //mixed bag of files, uh oh...
m->mothurOut("[ERROR]: Your files must all be in compressed .gz form or all in plain text form. Please correct. \n"); m->setControl_pressed(true);
}
}
#else
allGZ = false;
#endif
bool decompressionHelped = false;
if (allGZ) {
gz = true;
//test to make sure you can read the gz files
bool readable = testGZReadable(fileInputs, qualOrIndexInputs, decompressionHelped, format, m);
if (readable) {
if (decompressionHelped) { gz = false; }
}else {
m->mothurOut("[ERROR]: Unable to read compressed .gz files, please decompress and run make.contigs again. \n"); m->setControl_pressed(true); return 0;
}
}
else { gz = false; }
variables["[tag]"] = "trim";
outFastaFile = getOutputFileName("fasta",variables);
variables["[tag]"] = "scrap";
outScrapFastaFile = getOutputFileName("fasta",variables);
variables["[tag]"] = "";
outMisMatchFile = getOutputFileName("report",variables);
vector<vector<string> > fastaFileNames, qualFileNames;
map<string, string> uniqueFastaNames;// so we don't add the same groupfile multiple times
createOligosGroup = false;
map<int, oligosPair> pairedPrimers, rpairedPrimers, revpairedPrimers, pairedBarcodes, rpairedBarcodes, revpairedBarcodes;
vector<string> barcodeNames, primerNames;
if(oligosfile != "") { createOligosGroup = getOligos(pairedPrimers, rpairedPrimers, revpairedPrimers, pairedBarcodes, rpairedBarcodes, revpairedBarcodes, barcodeNames, primerNames); }
//give group in file file precedence
if (createFileGroup) { createOligosGroup = false; }
m->mothurOut("Making contigs...\n");
numReads = createProcesses(fileInputs, qualOrIndexInputs, outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, fastaFileNames, qualFileNames, group, pairedPrimers, rpairedPrimers, revpairedPrimers, pairedBarcodes, rpairedBarcodes, revpairedBarcodes, barcodeNames, primerNames);
if (decompressionHelped) { util.mothurRemove(fileInputs[0]); util.mothurRemove(fileInputs[1]); }
if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; }
if (file == "") {
outputNames.push_back(outFastaFile); outputTypes["fasta"].push_back(outFastaFile); outputNames.push_back(outScrapFastaFile); outputTypes["fasta"].push_back(outScrapFastaFile);
if (makeQualFile) {
outputNames.push_back(outQualFile); outputTypes["qfile"].push_back(outQualFile); outputNames.push_back(outScrapQualFile); outputTypes["qfile"].push_back(outScrapQualFile); }
else {
if (outQualFile != "") { util.mothurRemove(outQualFile); }
if (outScrapQualFile != "") { util.mothurRemove(outScrapQualFile); }
}
outputNames.push_back(outMisMatchFile); outputTypes["report"].push_back(outMisMatchFile);
}
m->mothurOut("Done.\n");
return numReads;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "processSingleFileOption");
exit(1);
}
}
/**************************************************************************************************/
struct contigsData {
MothurOut* m;
Utils util;
OutputWriter* trimFileName;
OutputWriter* scrapFileName;
OutputWriter* trimQFileName;
OutputWriter* scrapQFileName;
OutputWriter* misMatchesFile;
string align, group, format;
float match, misMatch, gapOpen, gapExtend;
bool gz, reorient, trimOverlap, createGroupFromOligos, createGroupFromFilePairs, makeQualFile, screenSequences;
char delim;
int nameType, offByOneTrimLength, pdiffs, bdiffs, tdiffs, kmerSize, insert, deltaq, maxee, maxAmbig, maxHomoP, maxLength;
vector<string> inputFiles, qualOrIndexFiles, outputNames;
set<string> badNames;
linePair linesInput;
linePair linesInputReverse;
linePair qlinesInput;
linePair qlinesInputReverse;
long long count;
vector<string> primerNameVector;
vector<string> barcodeNameVector;
map<string, int> groupCounts;
map<string, string> groupMap;
map<int, oligosPair> pairedBarcodes, reorientedPairedBarcodes, reversedPairedBarcodes;
map<int, oligosPair> pairedPrimers, reorientedPairedPrimers, reversedPairedPrimers;
contigsData(){}
~contigsData(){}
contigsData(OutputWriter* tn, OutputWriter* sn, OutputWriter* tqn, OutputWriter* sqn, OutputWriter* mmf) {
trimFileName = tn;
scrapFileName = sn;
trimQFileName = tqn;
scrapQFileName = sqn;
misMatchesFile = mmf;
m = MothurOut::getInstance();
count = 0;
makeQualFile = true;
if (trimQFileName == nullptr) { makeQualFile = false; }
}
contigsData(OutputWriter* tn, OutputWriter* sn, OutputWriter* tqn, OutputWriter* sqn, OutputWriter* mmf, vector<string> ifn, vector<string> qif, linePair li, linePair lir, linePair qli, linePair qlir) {
trimFileName = tn;
scrapFileName = sn;
trimQFileName = tqn;
scrapQFileName = sqn;
misMatchesFile = mmf;
m = MothurOut::getInstance();
inputFiles = ifn;
qualOrIndexFiles = qif;
linesInput = li;
linesInputReverse = lir;
qlinesInput = qli;
qlinesInputReverse = qlir;
count = 0;
makeQualFile = true;
if (trimQFileName == nullptr) { makeQualFile = false; }
}
void setVariables(bool isgz, char de, int nt, int offby, map<int, oligosPair> pbr, map<int, oligosPair> ppr, map<int, oligosPair> rpbr, map<int, oligosPair> rppr, map<int, oligosPair> repbr, map<int, oligosPair> reppr, vector<string> priNameVector, vector<string> barNameVector, bool ro, int pdf, int bdf, int tdf, string al, float ma, float misMa, float gapO, float gapE, int thr, int delt, double maxe, int km, string form, bool to, bool cfg, bool cgff, string gp, bool screen, int maxH, int maxL, int maxAm) {
gz = isgz;
delim = de;
nameType = nt;
offByOneTrimLength = offby;
pairedPrimers = ppr;
pairedBarcodes = pbr;
reorientedPairedPrimers = rppr;
reorientedPairedBarcodes = rpbr;
reversedPairedPrimers = reppr;
reversedPairedBarcodes = repbr;
primerNameVector = priNameVector;
barcodeNameVector = barNameVector;
group = gp;
createGroupFromOligos = cfg;
createGroupFromFilePairs = cgff;
pdiffs = pdf;
bdiffs = bdf;
tdiffs = tdf;
reorient = ro;
match = ma;
misMatch = misMa;
gapOpen = gapO;
gapExtend = gapE;
insert = thr;
kmerSize = km;
align = al;
deltaq = delt;
maxee = maxe;
format = form;
trimOverlap = to;
screenSequences = screen;
maxHomoP = maxH;
maxLength = maxL;
maxAmbig = maxAm;
}
void copyVariables(contigsData* copy) {
gz = copy->gz;
delim = copy->delim;
nameType = copy->nameType;
offByOneTrimLength = copy->offByOneTrimLength;
pairedPrimers = copy->pairedPrimers;
pairedBarcodes = copy->pairedBarcodes;
reorientedPairedPrimers = copy->reorientedPairedPrimers;
reorientedPairedBarcodes = copy->reorientedPairedBarcodes;
reversedPairedPrimers = copy->reversedPairedPrimers;
reversedPairedBarcodes = copy->reversedPairedBarcodes;
primerNameVector = copy->primerNameVector;
barcodeNameVector = copy->barcodeNameVector;
group = copy->group;
createGroupFromOligos = copy->createGroupFromOligos;
createGroupFromFilePairs = copy->createGroupFromFilePairs;
pdiffs = copy->pdiffs;
bdiffs = copy->bdiffs;
tdiffs = copy->tdiffs;
reorient = copy->reorient;
match = copy->match;
misMatch = copy->misMatch;
gapOpen = copy->gapOpen;
gapExtend = copy->gapExtend;
insert = copy->insert;
kmerSize = copy->kmerSize;
align = copy->align;
deltaq = copy->deltaq;
maxee = copy->maxee;
format = copy->format;
trimOverlap = copy->trimOverlap;
screenSequences = copy->screenSequences;
maxHomoP = copy->maxHomoP;
maxLength = copy->maxLength;
maxAmbig = copy->maxAmbig;
}
};
/**************************************************************************************************/
struct groupContigsData {
MothurOut* m;
Utils util;
int start, end;
vector< vector<string> > fileInputs;
set<string> badNames;
vector<string> file2Groups;
contigsData* bundle;
long long count;
groupContigsData() = default;
groupContigsData(vector< vector<string> > fi, int s, int e, contigsData* cd, vector<string> f2g) {
fileInputs = fi;
start = s;
end = e;
bundle = cd;
file2Groups = f2g;
count = 0;
m = MothurOut::getInstance();
}
~groupContigsData() { delete bundle; }
};
/**************************************************************************************************/
int setNameType(string forward, string reverse, int& offByOneTrimLength) {
MothurOut* m = MothurOut::getInstance();
try {
int type = 0;
Utils util;
if (forward == reverse) { type = perfectMatch; }
else {
int pos = forward.find_last_of('#');
string tempForward = forward;
if (pos != string::npos) { tempForward = forward.substr(0, pos); }
int pos2 = reverse.find_last_of('#');
string tempReverse = reverse;
if (pos2 != string::npos) { tempReverse = reverse.substr(0, pos2); }
if (tempForward == tempReverse) { type = poundMatch; }
else {
char delim = ':';
if (m->getChangedSeqNames()) { delim = '_'; }
vector<char> delims; delims.push_back(delim); delims.push_back('/');
for (int j = 0; j < delims.size(); j++) {
delim = delims[j];
int pos = forward.find_last_of(delim);
string tempForward = forward;
string tempForwardEnd = forward;
if (pos != string::npos) {
tempForwardEnd = forward.substr(pos+1);
}
int pos2 = reverse.find_last_of(delim);
string tempReverse = reverse;
string tempReverseEnd = reverse;
if (pos2 != string::npos) {
tempReverseEnd = reverse.substr(pos2+1);
}
if (tempForwardEnd != tempReverseEnd) {
if ((util.isAllAlphaNumerics(tempForwardEnd)) && (util.isAllAlphaNumerics(tempReverseEnd))) {
//check for off by one on rest of name
if (tempForward.length() == tempReverse.length()) {
int numDiffs = 0;
char forwardDiff = ' '; char reverseDiff = ' '; int spot = 0;
for (int i = 0; i < tempForward.length(); i++) {
if (tempForward[i] != tempReverse[i]) {
numDiffs++;
forwardDiff = tempForward[i];
reverseDiff = tempReverse[i];
spot = i;
}
}
if (numDiffs == 1) {
if ((forwardDiff == '1') && (reverseDiff == '2')) { type = offByOne; offByOneTrimLength = tempForward.length()-spot+1; }
}
}
}
}
}
}
}
return type;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "setNameType");
exit(1);
}
}
/**************************************************************************************************/
int setNameType(string forwardFile, string reverseFile, char delim, int& offByOneTrimLength, bool gz, string format) {
MothurOut* m = MothurOut::getInstance();
try {
int type = 0; bool error = false;
string forward = ""; string reverse = "";
Utils util;
ifstream inForward, inReverse;
#ifdef USE_BOOST
boost::iostreams::filtering_istream inFF, inRF;
#endif
if (!gz) { //plain text files
util.openInputFile(forwardFile, inForward);
util.openInputFile(reverseFile, inReverse);
if (delim == '>') {
Sequence fread(inForward);
forward = fread.getName();
Sequence rread(inReverse);
reverse = rread.getName();
}else {
FastqRead fread(inForward, error, format);
forward = fread.getName();
FastqRead rread(inReverse, error, format);
reverse = rread.getName();
}
inForward.close(); inReverse.close();
}else { //compressed files
#ifdef USE_BOOST
util.openInputFileBinary(forwardFile, inForward, inFF);
util.openInputFileBinary(reverseFile, inReverse, inRF);
if (delim == '>') {
Sequence fread(inFF);
forward = fread.getName();
Sequence rread(inRF);
reverse = rread.getName();
}else {
FastqRead fread(inFF, error, format);
forward = fread.getName();
FastqRead rread(inRF, error, format);
reverse = rread.getName();
}
inFF.pop(); inRF.pop();
#endif
}
type = setNameType(forward, reverse, offByOneTrimLength);
return type;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "setNameType");
exit(1);
}
}
//**********************************************************************************************************************
unsigned long long MakeContigsCommand::processMultipleFileOption(string& compositeFastaFile, string& compositeMisMatchFile) {
try {
//read file
vector<string> file2Group;
vector< vector<string> > fileInputs = readFileNames(file, file2Group); if (m->getControl_pressed()) { return 0; }
unsigned long long numReads = 0;
map<string, string> cvars;
string compOutputDir = outputdir;
if (outputdir == "") { compOutputDir = util.hasPath(file); }
cvars["[filename]"] = compOutputDir + util.getRootName(util.getSimpleName(file));
cvars["[tag]"] = "trim";
compositeFastaFile = getOutputFileName("fasta",cvars);
cvars["[tag]"] = "scrap";
string compositeScrapFastaFile = getOutputFileName("fasta",cvars);
cvars["[tag]"] = "trim";
string compositeQualFile = getOutputFileName("qfile",cvars);
cvars["[tag]"] = "scrap";
string compositeScrapQualFile = getOutputFileName("qfile",cvars);
cvars["[tag]"] = "";
compositeMisMatchFile = getOutputFileName("report",cvars);
ofstream outCTFasta, outCTQual, outCSFasta, outCSQual, outCMisMatch;
util.openOutputFile(compositeFastaFile, outCTFasta); outCTFasta.close(); outputNames.push_back(compositeFastaFile); outputTypes["fasta"].push_back(compositeFastaFile);
util.openOutputFile(compositeScrapQualFile, outCSQual); outCSQual.close();
util.openOutputFile(compositeQualFile, outCTQual); outCTQual.close();
if (makeQualFile) {
outputNames.push_back(compositeScrapQualFile); outputTypes["qfile"].push_back(compositeScrapQualFile);
outputNames.push_back(compositeQualFile); outputTypes["qfile"].push_back(compositeQualFile);
}
util.openOutputFile(compositeScrapFastaFile, outCSFasta); outCSFasta.close(); outputNames.push_back(compositeScrapFastaFile); outputTypes["fasta"].push_back(compositeScrapFastaFile);
util.openOutputFile(compositeMisMatchFile, outCMisMatch); outCMisMatch.close(); outputNames.push_back(compositeMisMatchFile); outputTypes["report"].push_back(compositeMisMatchFile);
if (gz) {
numReads = createProcessesGroups(fileInputs, compositeFastaFile, compositeScrapFastaFile, compositeQualFile, compositeScrapQualFile, compositeMisMatchFile, file2Group);
}else {
for (int l = 0; l < fileInputs.size(); l++) {
if (m->getControl_pressed()) { break; }
int startTime = time(nullptr);
m->mothurOut("\n>>>>>\tProcessing file pair " + fileInputs[l][0] + " - " + fileInputs[l][1] + " (files " + toString(l+1) + " of " + toString(fileInputs.size()) + ")\t<<<<<\n");
ffastqfile = fileInputs[l][0]; rfastqfile = fileInputs[l][1]; findexfile = fileInputs[l][2]; rindexfile = fileInputs[l][3];
//run file as if it was a single
string outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile;
int thisNumReads = processSingleFileOption(outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, file2Group[l]);
numReads += thisNumReads;
util.appendFiles(outMisMatchFile, compositeMisMatchFile); util.mothurRemove(outMisMatchFile);
util.appendFiles(outFastaFile, compositeFastaFile); util.mothurRemove(outFastaFile);
util.appendFiles(outScrapFastaFile, compositeScrapFastaFile); util.mothurRemove(outScrapFastaFile);
if (makeQualFile) {
util.appendFiles(outQualFile, compositeQualFile);
util.appendFiles(outScrapQualFile, compositeScrapQualFile);
}
util.mothurRemove(outQualFile); util.mothurRemove(outScrapQualFile);
m->mothurOut("\nIt took " + toString(time(nullptr) - startTime) + " secs to assemble " + toString(thisNumReads) + " reads.\n\n");
}
}
if (!makeQualFile) { util.mothurRemove(compositeQualFile); util.mothurRemove(compositeScrapQualFile); }
return numReads;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "processMultipleFileOption");
exit(1);
}
}
//***************************************************************************************************************
/**
* checks for minor diffs @MS7_15058:1:1101:11899:1633#8/1 @MS7_15058:1:1101:11899:1633#8/2 should match
*/
bool fixName(string& forward, int nameType, int offByOneTrimLength){
try {
bool match = false;
if (nameType == poundMatch) {
match = true;
int pos = forward.find_last_of('#');
if (pos != string::npos) { forward = forward.substr(0, pos); }
}else if (nameType == perfectMatch) { match = true; }
else if (nameType == offByOne) {
match = true;
forward = forward.substr(0, (forward.length()-offByOneTrimLength));
}
return match;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "fixName");
exit(1);
}
}
//***************************************************************************************************************
/**
* checks for minor diffs @MS7_15058:1:1101:11899:1633#8/1 @MS7_15058:1:1101:11899:1633#8/2 should match
*/
bool checkName(FastqRead& forward, FastqRead& reverse, int nameType, int offByOneTrimLength){
try {
bool match = false;
string forwardName = forward.getName();
string reverseName = reverse.getName();
if (nameType == poundMatch) {
match = true;
int pos = forwardName.find_last_of('#');
if (pos != string::npos) { forwardName = forwardName.substr(0, pos); }
int pos2 = reverseName.find_last_of('#');
if (pos2 != string::npos) { reverseName = reverseName.substr(0, pos2); }
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}else if (nameType == perfectMatch) {
if (forwardName == reverseName) { match = true; }
}
else if (nameType == offByOne) {
match = true;
reverseName = reverseName.substr(0, (reverseName.length()-offByOneTrimLength));
forwardName = forwardName.substr(0, (forwardName.length()-offByOneTrimLength));
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}
return match;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "ckeckName");
exit(1);
}
}
//***************************************************************************************************************
/**
* checks for minor diffs @MS7_15058:1:1101:11899:1633#8/1 @MS7_15058:1:1101:11899:1633#8/2 should match
*/
bool checkName(Sequence& forward, Sequence& reverse, int nameType, int offByOneTrimLength){
try {
bool match = false;
string forwardName = forward.getName();
string reverseName = reverse.getName();
if (nameType == poundMatch) {
match = true;
int pos = forwardName.find_last_of('#');
if (pos != string::npos) { forwardName = forwardName.substr(0, pos); }
int pos2 = reverseName.find_last_of('#');
if (pos2 != string::npos) { reverseName = reverseName.substr(0, pos2); }
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}else if (nameType == perfectMatch) { if (forwardName == reverseName) { match = true; } }
else if (nameType == offByOne) {
match = true;
reverseName = reverseName.substr(0, (reverseName.length()-offByOneTrimLength));
forwardName = forwardName.substr(0, (forwardName.length()-offByOneTrimLength));
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}
return match;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "ckeckName");
exit(1);
}
}
//***************************************************************************************************************
/**
* checks for minor diffs @MS7_15058:1:1101:11899:1633#8/1 @MS7_15058:1:1101:11899:1633#8/2 should match
*/
bool checkName(QualityScores& forward, QualityScores& reverse, int nameType, int offByOneTrimLength){
try {
bool match = false;
string forwardName = forward.getName();
string reverseName = reverse.getName();
if (nameType == poundMatch) {
match = true;
int pos = forwardName.find_last_of('#');
if (pos != string::npos) { forwardName = forwardName.substr(0, pos); }
int pos2 = reverseName.find_last_of('#');
if (pos2 != string::npos) { reverseName = reverseName.substr(0, pos2); }
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}else if (nameType == perfectMatch) { if (forwardName == reverseName) { match = true; } }
else if (nameType == offByOne) {
match = true;
reverseName = reverseName.substr(0, (reverseName.length()-offByOneTrimLength));
forwardName = forwardName.substr(0, (forwardName.length()-offByOneTrimLength));
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}
return match;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "ckeckName");
exit(1);
}
}
//***************************************************************************************************************
/**
* checks for minor diffs @MS7_15058:1:1101:11899:1633#8/1 @MS7_15058:1:1101:11899:1633#8/2 should match
*/
bool checkName(Sequence& forward, QualityScores& reverse, int nameType, int offByOneTrimLength){
try {
bool match = false;
string forwardName = forward.getName();
string reverseName = reverse.getName();
if (nameType == poundMatch) {
match = true;
string forwardName = forward.getName();
string reverseName = reverse.getName();
int pos = forwardName.find_last_of('#');
if (pos != string::npos) { forwardName = forwardName.substr(0, pos); }
int pos2 = reverseName.find_last_of('#');
if (pos2 != string::npos) { reverseName = reverseName.substr(0, pos2); }
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}else if (nameType == perfectMatch) { if (forwardName == reverseName) { match = true; } }
else if (nameType == offByOne) {
match = true;
reverseName = reverseName.substr(0, (reverseName.length()-offByOneTrimLength));
forwardName = forwardName.substr(0, (forwardName.length()-offByOneTrimLength));
if (forwardName == reverseName) {
forward.setName(forwardName);
reverse.setName(reverseName);
}else{
match = false;
}
}
return match;
}
catch(exception& e) {
MothurOut* m; m = MothurOut::getInstance();
m->errorOut(e, "MakeContigsCommand", "ckeckName");
exit(1);
}
}
/**************************************************************************************************/
//vector<int> contigScores = assembleFragments(qual_match_simple_bayesian, qual_mismatch_simple_bayesian, fSeq, rSeq, alignment, contig);
vector<int> assembleFragments(vector< vector<double> >&qual_match_simple_bayesian, vector< vector<double> >& qual_mismatch_simple_bayesian, Sequence& fSeq, Sequence& rSeq, vector<int> scores1, vector<int> scores2, bool hasQuality, Alignment*& alignment, string& contig, string& trashCode, int& oend, int& oStart, int& numMismatches, int insert, int deltaq, bool trimOverlap) {
MothurOut* m; m = MothurOut::getInstance();
try {
vector<int> contigScores;
//flip the reverse reads
rSeq.reverseComplement();
//pairwise align
alignment->align(fSeq.getUnaligned(), rSeq.getUnaligned(), true);
map<int, int> ABaseMap = alignment->getSeqAAlnBaseMap();
map<int, int> BBaseMap = alignment->getSeqBAlnBaseMap();
fSeq.setAligned(alignment->getSeqAAln());
rSeq.setAligned(alignment->getSeqBAln());
int length = fSeq.getAligned().length();
//traverse alignments merging into one contiguous seq
string seq1 = fSeq.getAligned();
string seq2 = rSeq.getAligned();
int overlapStart = fSeq.getStartPos()-1;
int seq2Start = rSeq.getStartPos()-1;
//bigger of the 2 starting positions is the location of the overlapping start
if (overlapStart < seq2Start) { //seq2 starts later so take from 0 to seq2Start from seq1
overlapStart = seq2Start;
for (int i = 0; i < overlapStart; i++) { contig += seq1[i]; if (hasQuality) { if (((seq1[i] != '-') && (seq1[i] != '.'))) { contigScores.push_back(scores1[ABaseMap[i]]); } } }
}else { //seq1 starts later so take from 0 to overlapStart from seq2
for (int i = 0; i < overlapStart; i++) { contig += seq2[i]; if (hasQuality) { if (((seq2[i] != '-') && (seq2[i] != '.'))) { contigScores.push_back(scores2[BBaseMap[i]]); } } }
}
int seq1End = fSeq.getEndPos();
int seq2End = rSeq.getEndPos();
int overlapEnd = seq1End;
if (seq2End < overlapEnd) { overlapEnd = seq2End; } //smallest end position is where overlapping ends
oStart = contig.length();
int firstForward = 0; int seq2FirstForward = 0; int lastReverse = seq1.length(); int seq2lastReverse = seq2.length(); bool firstChooseSeq1 = false; bool lastChooseSeq1 = false;
if (hasQuality) {
for (int i = 0; i < seq1.length(); i++) { if ((seq1[i] != '.') && (seq1[i] != '-')) { if (scores1[ABaseMap[i]] == 2) { firstForward++; }else { break; } } }
for (int i = 0; i < seq2.length(); i++) { if ((seq2[i] != '.') && (seq2[i] != '-')) { if (scores2[BBaseMap[i]] == 2) { seq2FirstForward++; }else { break; } } }
if (seq2FirstForward > firstForward) { firstForward = seq2FirstForward; firstChooseSeq1 = true; }
for (int i = seq1.length()-1; i >= 0; i--) { if ((seq1[i] != '.') && (seq1[i] != '-')) { if (scores1[ABaseMap[i]] == 2) { lastReverse--; }else { break; } } }
for (int i = seq2.length()-1; i >= 0; i--) { if ((seq2[i] != '.') && (seq2[i] != '-')) { if (scores2[BBaseMap[i]] == 2) { seq2lastReverse--; }else { break; } } }
if (lastReverse > seq2lastReverse) { lastReverse = seq2lastReverse; lastChooseSeq1 = true; }
}
for (int i = overlapStart; i < overlapEnd; i++) {
if (seq1[i] == seq2[i]) {
contig += seq1[i];
if (hasQuality) {
contigScores.push_back(qual_match_simple_bayesian[PHREDCLAMP(scores1[ABaseMap[i]])][PHREDCLAMP(scores2[BBaseMap[i]])]);
}
}else if (((seq1[i] == '.') || (seq1[i] == '-')) && ((seq2[i] != '-') && (seq2[i] != '.'))) { //seq1 is a gap and seq2 is a base, choose seq2, unless quality score for base is below insert. In that case eliminate base
if (hasQuality) {
if (scores2[BBaseMap[i]] <= insert) { } //
else {
contig += seq2[i];
contigScores.push_back(scores2[BBaseMap[i]]);
}
} else { contig += seq2[i]; } //with no quality info, then we keep it?
}else if (((seq2[i] == '.') || (seq2[i] == '-')) && ((seq1[i] != '-') && (seq1[i] != '.'))) { //seq2 is a gap and seq1 is a base, choose seq1, unless quality score for base is below insert. In that case eliminate base
if (hasQuality) {
if (scores1[ABaseMap[i]] <= insert) { } //eliminate base
else {
contig += seq1[i];
contigScores.push_back(scores1[ABaseMap[i]]);
}
}else { contig += seq1[i]; } //with no quality info, then we keep it?
}else if (((seq1[i] != '-') && (seq1[i] != '.')) && ((seq2[i] != '-') && (seq2[i] != '.'))) { //both bases choose one with better quality
if (hasQuality) {
if (abs(scores1[ABaseMap[i]] - scores2[BBaseMap[i]]) >= deltaq) { //is the difference in qual scores >= deltaq, if yes choose base with higher score
char c = seq1[i];
if (scores1[ABaseMap[i]] < scores2[BBaseMap[i]]) { c = seq2[i]; }
contig += c;
if ((i >= firstForward) && (i <= lastReverse)) { //in unmasked section
contigScores.push_back(qual_mismatch_simple_bayesian[PHREDCLAMP(scores1[ABaseMap[i]])][PHREDCLAMP(scores2[BBaseMap[i]])]);
}else if (i < firstForward) {
if (firstChooseSeq1) { contigScores.push_back(scores1[ABaseMap[i]]); }
else { contigScores.push_back(scores2[BBaseMap[i]]); }
}else if ((i > lastReverse)) {
if (lastChooseSeq1) { contigScores.push_back(scores1[ABaseMap[i]]); }
else { contigScores.push_back(scores2[BBaseMap[i]]); }
}else { contigScores.push_back(2); } //N
}else { //if no, base becomes n
contig += 'N'; contigScores.push_back(2);
}
numMismatches++;
}else { numMismatches++; } //cant decide, so eliminate and mark as mismatch
}else { //should never get here
m->mothurOut("[ERROR]: case I didn't think of seq1 = " + toString(seq1[i]) + " and seq2 = " + toString(seq2[i]) + "\n");
}
//printf("Overlap seq: %i, %i, %i, %c, %i\n", i, scores1[ABaseMap[i]], scores2[BBaseMap[i]], contig[contig.length()-1], contigScores[contigScores.size()-1]);
}
oend = contig.length();
if (seq1End < seq2End) { //seq1 ends before seq2 so take from overlap to length from seq2
for (int i = overlapEnd; i < length; i++) { contig += seq2[i]; if (hasQuality) { if (((seq2[i] != '-') && (seq2[i] != '.'))) { contigScores.push_back(scores2[BBaseMap[i]]); } }
}
}else { //seq2 ends before seq1 so take from overlap to length from seq1
for (int i = overlapEnd; i < length; i++) { contig += seq1[i]; if (hasQuality) { if (((seq1[i] != '-') && (seq1[i] != '.'))) { contigScores.push_back(scores1[ABaseMap[i]]); } }
}
}
if (trimOverlap) {
contig = contig.substr(overlapStart, oend-oStart);
if (hasQuality) {
vector<int> newContigScores;
for (int i = overlapStart; i < oend; i++) { newContigScores.push_back(contigScores[i]); }
contigScores = newContigScores;
}
}
if (contig == "") { trashCode += "l"; contig = "NNNN"; contigScores.push_back(2); contigScores.push_back(2); contigScores.push_back(2); contigScores.push_back(2); }
return contigScores;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "assembleFragments");
exit(1);
}
}
/**************************************************************************************************/
void screenSequence(string& contig, string& trashCode, contigsData* params) {
try {
//if you failed before screening, don't bother screening
if (trashCode.length() != 0) { return; }
else {
bool goodSeq = true; // innocent until proven guilty
Sequence currSeq("dummy", contig);
if(params->maxAmbig != -1 && params->maxAmbig < currSeq.getAmbigBases()) { goodSeq = false; trashCode += "ambig|"; }
if(params->maxHomoP != -1 && params->maxHomoP < currSeq.getLongHomoPolymer()) { goodSeq = false; trashCode += "homop|"; }
if(params->maxLength != -1 && params->maxLength < currSeq.getNumBases()) { goodSeq = false; trashCode += ">length|";}
}
}
catch(exception& e) {
params->m->errorOut(e, "MakeContigsCommand", "screenSequence");
exit(1);
}
}
/**************************************************************************************************/
#ifdef USE_BOOST
//ignore = read(fSeq, rSeq, fQual, rQual, savedFQual, savedRQual, findexBarcode, rindexBarcode, delim, inFF, inRF, inFQ, inRQ);
bool read(Sequence& fSeq, Sequence& rSeq, QualityScores*& fQual, QualityScores*& rQual, Sequence& findexBarcode, Sequence& rindexBarcode, char delim, boost::iostreams::filtering_istream& inFF, boost::iostreams::filtering_istream& inRF, boost::iostreams::filtering_istream& inFQ, boost::iostreams::filtering_istream& inRQ, string thisfqualindexfile, string thisrqualindexfile, string format, int nameType, int offByOneTrimLength, MothurOut* m) {
try {
bool ignore = false;
Utils util;
if (delim == '@') { //fastq files
bool tignore = false;
FastqRead fread(inFF, tignore, format); gobble(inFF);
FastqRead rread(inRF, ignore, format); gobble(inRF);
if (!checkName(fread, rread, nameType, offByOneTrimLength)) {
FastqRead f2read(inFF, tignore, format);
if (!checkName(f2read, rread, nameType, offByOneTrimLength)) {
FastqRead r2read(inRF, ignore, format);
if (!checkName(fread, r2read, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse fastq file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { rread = r2read; }
}else { fread = f2read; }
}
if (tignore) { ignore=true; }
fSeq.setName(fread.getName()); fSeq.setAligned(fread.getSeq());
rSeq.setName(rread.getName()); rSeq.setAligned(rread.getSeq());
fQual = new QualityScores(fread.getName(), fread.getScores());
rQual = new QualityScores(rread.getName(), rread.getScores());
if (thisfqualindexfile != "") { //forward index file
FastqRead firead(inFQ, tignore, format);
if (tignore) { ignore=true; }
findexBarcode.setAligned(firead.getSeq());
if (!checkName(fread, firead, nameType, offByOneTrimLength)) {
FastqRead f2iread(inFQ, tignore, format);
if (tignore) { ignore=true; }
if (!checkName(fread, f2iread, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward index file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { firead = f2iread; findexBarcode.setAligned(firead.getSeq()); }
}
}
if (thisrqualindexfile != "") { //reverse index file
FastqRead riread(inRQ, tignore, format);
if (tignore) { ignore=true; }
rindexBarcode.setAligned(riread.getSeq());
if (!checkName(fread, riread, nameType, offByOneTrimLength)) {
FastqRead r2iread(inRQ, tignore, format); gobble(inRQ);
if (tignore) { ignore=true; }
if (!checkName(fread, r2iread, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in reverse index file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { riread = r2iread; rindexBarcode.setAligned(riread.getSeq()); }
}
}
}else { //reading fasta and maybe qual
Sequence tfSeq(inFF);
Sequence trSeq(inRF);
if (!checkName(tfSeq, trSeq, nameType, offByOneTrimLength)) {
Sequence t2fSeq(inFF);
if (!checkName(t2fSeq, trSeq, nameType, offByOneTrimLength)) {
Sequence t2rSeq(inRF);
if (!checkName(tfSeq, t2rSeq, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse fasta file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true;
}else { trSeq = t2fSeq; }
}else { tfSeq = t2fSeq; }
}
fSeq.setName(tfSeq.getName()); fSeq.setAligned(tfSeq.getAligned());
rSeq.setName(trSeq.getName()); rSeq.setAligned(trSeq.getAligned());
if (thisfqualindexfile != "") {
fQual = new QualityScores(inFQ); gobble(inFQ);
rQual = new QualityScores(inRQ); gobble(inRQ);
if (!checkName(*fQual, *rQual, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse qual file. Ignoring, " + fQual->getName() + ".\n"); ignore = true;
}
if (fQual->getName() != tfSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in forward quality file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true; }
if (rQual->getName() != trSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in reverse quality file. Ignoring, " + trSeq.getName() + ".\n"); ignore = true; }
}
if (tfSeq.getName() != trSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in forward and reverse fasta file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true; }
}
return ignore;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "read");
exit(1);
}
}
#endif
/**************************************************************************************************/
bool read(Sequence& fSeq, Sequence& rSeq, QualityScores*& fQual, QualityScores*& rQual,Sequence& findexBarcode, Sequence& rindexBarcode, char delim, ifstream& inFFasta, ifstream& inRFasta, ifstream& inFQualIndex, ifstream& inRQualIndex, string thisfqualindexfile, string thisrqualindexfile, string format, int nameType, int offByOneTrimLength, MothurOut* m) {
try {
bool ignore = false;
Utils util;
if (delim == '@') { //fastq files
bool tignore;
FastqRead fread(inFFasta, tignore, format); gobble(inFFasta);
FastqRead rread(inRFasta, ignore, format); gobble(inRFasta);
if (!checkName(fread, rread, nameType, offByOneTrimLength)) {
FastqRead f2read(inFFasta, tignore, format); gobble(inFFasta);
if (!checkName(f2read, rread, nameType, offByOneTrimLength)) {
FastqRead r2read(inRFasta, ignore, format); gobble(inRFasta);
if (!checkName(fread, r2read, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse fastq file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { rread = r2read; }
}else { fread = f2read; }
}
if (tignore) { ignore=true; }
fSeq.setName(fread.getName()); fSeq.setAligned(fread.getSeq());
rSeq.setName(rread.getName()); rSeq.setAligned(rread.getSeq());
fQual = new QualityScores(fread.getName(), fread.getScores());
rQual = new QualityScores(rread.getName(), rread.getScores());
if (thisfqualindexfile != "") { //forward index file
FastqRead firead(inFQualIndex, tignore, format); gobble(inFQualIndex);
if (tignore) { ignore=true; }
findexBarcode.setAligned(firead.getSeq());
if (!checkName(fread, firead, nameType, offByOneTrimLength)) {
FastqRead f2iread(inFQualIndex, tignore, format); gobble(inFQualIndex);
if (tignore) { ignore=true; }
if (!checkName(fread, f2iread, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward index file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { firead = f2iread; findexBarcode.setAligned(firead.getSeq()); }
}
}
if (thisrqualindexfile != "") { //reverse index file
FastqRead riread(inRQualIndex, tignore, format); gobble(inRQualIndex);
if (tignore) { ignore=true; }
rindexBarcode.setAligned(riread.getSeq());
if (!checkName(fread, riread, nameType, offByOneTrimLength)) {
FastqRead r2iread(inRQualIndex, tignore, format); gobble(inRQualIndex);
if (tignore) { ignore=true; }
if (!checkName(fread, r2iread, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in reverse index file. Ignoring, " + fread.getName() + ".\n"); ignore = true;
}else { riread = r2iread; rindexBarcode.setAligned(riread.getSeq()); }
}
}
}else { //reading fasta and maybe qual
Sequence tfSeq(inFFasta); gobble(inFFasta);
Sequence trSeq(inRFasta); gobble(inRFasta);
if (!checkName(tfSeq, trSeq, nameType, offByOneTrimLength)) {
Sequence t2fSeq(inFFasta); gobble(inFFasta);
if (!checkName(t2fSeq, trSeq, nameType, offByOneTrimLength)) {
Sequence t2rSeq(inRFasta); gobble(inRFasta);
if (!checkName(tfSeq, t2rSeq, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse fasta file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true;
}else { trSeq = t2fSeq; }
}else { tfSeq = t2fSeq; }
}
fSeq.setName(tfSeq.getName()); fSeq.setAligned(tfSeq.getAligned());
rSeq.setName(trSeq.getName()); rSeq.setAligned(trSeq.getAligned());
if (thisfqualindexfile != "") {
fQual = new QualityScores(inFQualIndex); gobble(inFQualIndex);
rQual = new QualityScores(inRQualIndex); gobble(inRQualIndex);
if (!checkName(*fQual, *rQual, nameType, offByOneTrimLength)) {
m->mothurOut("[WARNING]: name mismatch in forward and reverse qual file. Ignoring, " + fQual->getName() + ".\n"); ignore = true;
}
if (fQual->getName() != tfSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in forward quality file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true; }
if (rQual->getName() != trSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in reverse quality file. Ignoring, " + trSeq.getName() + ".\n"); ignore = true; }
}
if (tfSeq.getName() != trSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in forward and reverse fasta file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true; }
}
return ignore;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "read");
exit(1);
}
}
/**************************************************************************************************/
vector<int> trimBarCodesAndPrimers(Sequence& fSeq, Sequence& rSeq, QualityScores*& fQual, QualityScores*& rQual, Sequence& findexBarcode, Sequence& rindexBarcode, vector<TrimOligos*> trims, vector<string>& codes, int numBarcodes, int numPrimers, bool hasQuality, bool hasIndex, int pdiffs, int bdiffs, int tdiffs, MothurOut* m) {
try {
vector<int> oligosResults; oligosResults.resize(2, 0); //barcodeIndex, primerIndex
codes.resize(2, "");
for (int i = 0; i < trims.size(); i++) {
Sequence savedFSeq(fSeq.getName(), fSeq.getAligned());
Sequence savedRSeq(rSeq.getName(), rSeq.getAligned());
Sequence savedFindex(findexBarcode.getName(), findexBarcode.getAligned());
Sequence savedRIndex(rindexBarcode.getName(), rindexBarcode.getAligned());
QualityScores* savedFQual = nullptr;
QualityScores* savedRQual = nullptr;
if (hasQuality) {
savedFQual = new QualityScores(fQual->getName(), fQual->getScores());
savedRQual = new QualityScores(rQual->getName(), rQual->getScores());
}
string trashCode = "";
string commentString = "";
int currentSeqsDiffs = 0;
int barcodeIndex = 0;
int primerIndex = 0;
if(numBarcodes != 0){
vector<int> results;
if (hasQuality) {
if (hasIndex) { results = trims[i]->stripBarcode(savedFindex, savedRIndex, *savedFQual, *savedRQual, barcodeIndex); }
else { results = trims[i]->stripBarcode(savedFSeq, savedRSeq, *savedFQual, *savedRQual, barcodeIndex); }
}else {
results = trims[i]->stripBarcode(savedFSeq, savedRSeq, barcodeIndex);
}
int success = results[0] + results[2];
commentString += "fbdiffs=" + toString(results[0]) + "(" + trims[i]->getCodeValue(results[1], bdiffs) + "), rbdiffs=" + toString(results[2]) + "(" + trims[i]->getCodeValue(results[3], bdiffs) + ") ";
if(success > bdiffs) { trashCode += 'b'; }
else{ currentSeqsDiffs += success; }
}
if(numPrimers != 0){
vector<int> results;
if (hasQuality) { results = trims[i]->stripForward(savedFSeq, savedRSeq, *savedFQual, *savedRQual, primerIndex); }
else { results = trims[i]->stripForward(savedFSeq, savedRSeq, primerIndex); }
int success = results[0] + results[2];
commentString += "fpdiffs=" + toString(results[0]) + "(" + trims[i]->getCodeValue(results[1], pdiffs) + "), rpdiffs=" + toString(results[2]) + "(" + trims[i]->getCodeValue(results[3], pdiffs) + ") ";
if(success > pdiffs) { trashCode += 'f'; }
else{ currentSeqsDiffs += success; }
}
if (currentSeqsDiffs > tdiffs) { trashCode += 't'; }
if (trashCode == "") {
oligosResults[0] = barcodeIndex;
oligosResults[1] = primerIndex;
codes[0] = "";
codes[1] = commentString;
if (i > 0) { //checkOrient trimOligos - reoriented and reversed
savedFSeq.reverseComplement();
savedRSeq.reverseComplement();
}
fSeq.setAligned(savedFSeq.getUnaligned());
rSeq.setAligned(savedRSeq.getUnaligned());
if(hasQuality){
if (i > 0) { //checkOrient trimOligos - reoriented and reversed
savedFQual->flipQScores();
savedRQual->flipQScores();
}
fQual->setScores(savedFQual->getScores());
rQual->setScores(savedRQual->getScores());
delete savedRQual; delete savedFQual;
}
break;
}else {
if (codes[0] == "") { codes[0] = trashCode; }
else { codes[0] += "(" + trashCode + ")"; }
codes[1] = commentString;
if(hasQuality){ delete savedRQual; delete savedFQual; }
}
}
if (hasQuality) { rQual->flipQScores(); }
return oligosResults;
}catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "read");
exit(1);
}
}
//**********************************************************************************************************************
//vector<vector<string> > fastaFileNames, vector<vector<string> > qualFileNames, , string group
void driverContigs(contigsData* params){
try {
vector< vector<double> > qual_match_simple_bayesian;
qual_match_simple_bayesian.resize(47);
for (int i = 0; i < qual_match_simple_bayesian.size(); i++) { qual_match_simple_bayesian[i].resize(47); }
vector< vector<double> > qual_mismatch_simple_bayesian;
qual_mismatch_simple_bayesian.resize(47);
for (int i = 0; i < qual_mismatch_simple_bayesian.size(); i++) { qual_mismatch_simple_bayesian[i].resize(47); }
loadQmatchValues(qual_match_simple_bayesian, qual_mismatch_simple_bayesian);
params->count = 0;
string thisfqualindexfile, thisrqualindexfile, thisffastafile, thisrfastafile;
thisfqualindexfile = ""; thisrqualindexfile = "";
thisffastafile = params->inputFiles[0]; thisrfastafile = params->inputFiles[1];
if (params->qualOrIndexFiles.size() != 0) {
thisfqualindexfile = params->qualOrIndexFiles[0];
thisrqualindexfile = params->qualOrIndexFiles[1];
}
if (params->m->getDebug()) { params->m->mothurOut("[DEBUG]: ffasta = " + thisffastafile + ".\n[DEBUG]: rfasta = " + thisrfastafile + ".\n[DEBUG]: fqualindex = " + thisfqualindexfile + ".\n[DEBUG]: rqualindex = " + thisfqualindexfile + ".\n"); }
ifstream inFFasta, inRFasta, inFQualIndex, inRQualIndex;
#ifdef USE_BOOST
boost::iostreams::filtering_istream inFF, inRF, inFQ, inRQ;
#endif
if (!params->gz) { //plain text files
params->util.openInputFile(thisffastafile, inFFasta);
params->util.openInputFile(thisrfastafile, inRFasta);
inFFasta.seekg(params->linesInput.start);
inRFasta.seekg(params->linesInputReverse.start);
}else { //compressed files - no need to seekg because compressed files divide workload differently
#ifdef USE_BOOST
params->util.openInputFileBinary(thisffastafile, inFFasta, inFF);
params->util.openInputFileBinary(thisrfastafile, inRFasta, inRF);
#endif
}
ofstream outFasta, outMisMatch, outScrapFasta, outQual, outScrapQual;
if (thisfqualindexfile != "") {
if (thisfqualindexfile != "NONE") {
if (!params->gz) { //plain text files
params->util.openInputFile(thisfqualindexfile, inFQualIndex);
inFQualIndex.seekg(params->qlinesInput.start);
}else {
#ifdef USE_BOOST
params->util.openInputFileBinary(thisfqualindexfile, inFQualIndex, inFQ);
#endif
} //compressed files - no need to seekg because compressed files divide workload differently
}
else { thisfqualindexfile = ""; }
if (thisrqualindexfile != "NONE") {
if (!params->gz) { //plain text files
params->util.openInputFile(thisrqualindexfile, inRQualIndex);
inRQualIndex.seekg(params->qlinesInputReverse.start);
}else {
#ifdef USE_BOOST
params->util.openInputFileBinary(thisrqualindexfile, inRQualIndex, inRQ);
#endif
} //compressed files - no need to seekg because compressed files divide workload differently
}
else { thisrqualindexfile = ""; }
}
bool hasQuality = false;
bool hasIndex = false;
if (params->delim == '@') { //fastq files so make an output quality
hasQuality = true;
if (thisfqualindexfile != "") { if (thisfqualindexfile != "NONE") { hasIndex = true; } }
if (thisrqualindexfile != "") { if (thisrqualindexfile != "NONE") { hasIndex = true; } }
}else if ((params->delim == '>') && (params->qualOrIndexFiles.size() != 0)) { hasQuality = true; }
if (params->m->getDebug()) { if (hasQuality) { params->m->mothurOut("[DEBUG]: hasQuality = true\n"); } else { params->m->mothurOut("[DEBUG]: hasQuality = false\n"); } }
int numPrimers = params->pairedPrimers.size();
int numBarcodes = params->pairedBarcodes.size();
vector<TrimOligos*> trims;
if ((numPrimers != 0) || (numBarcodes != 0)) {
//standard
trims.push_back(new TrimOligos(params->pdiffs, params->bdiffs, 0, 0, params->pairedPrimers, params->pairedBarcodes, hasIndex));
if (params->reorient) {
//reoriented
trims.push_back(new TrimOligos(params->pdiffs, params->bdiffs, 0, 0, params->reorientedPairedPrimers, params->reorientedPairedBarcodes, hasIndex));
//reversed
trims.push_back(new TrimOligos(params->pdiffs, params->bdiffs, 0, 0, params->reversedPairedPrimers, params->reversedPairedBarcodes, hasIndex));
}
}
Alignment* alignment; int longestBase = 1000;
if(params->align == "gotoh") { alignment = new GotohOverlap(params->gapOpen, params->gapExtend, params->match, params->misMatch, longestBase); }
else if(params->align == "needleman") { alignment = new NeedlemanOverlap(params->gapOpen, params->match, params->misMatch, longestBase); }
else if(params->align == "kmer") { alignment = new KmerAlign(params->kmerSize); }
bool good = true;
while (good) {
if (params->m->getControl_pressed()) { break; }
bool ignore = false;
Sequence fSeq, rSeq;
QualityScores* fQual = nullptr; QualityScores* rQual = nullptr;
Sequence findexBarcode("findex", "NONE"); Sequence rindexBarcode("rindex", "NONE");
//read from input files
if (params->gz) {
#ifdef USE_BOOST
ignore = read(fSeq, rSeq, fQual, rQual, findexBarcode, rindexBarcode, params->delim, inFF, inRF, inFQ, inRQ, thisfqualindexfile, thisrqualindexfile, params->format, params->nameType, params->offByOneTrimLength, params->m);
#endif
}else {
ignore = read(fSeq, rSeq, fQual, rQual, findexBarcode, rindexBarcode, params->delim, inFFasta, inRFasta, inFQualIndex, inRQualIndex, thisfqualindexfile, thisrqualindexfile, params->format, params->nameType, params->offByOneTrimLength, params->m);
}
if (!ignore) {
//remove primers and barcodes if neccessary
vector<string> codes;
vector<int> oligosResults = trimBarCodesAndPrimers(fSeq, rSeq, fQual, rQual, findexBarcode, rindexBarcode, trims, codes, numBarcodes, numPrimers, hasQuality, hasIndex, params->pdiffs, params->bdiffs, params->tdiffs, params->m);
string trashCode = codes[0];
string commentString = codes[1];
int barcodeIndex = oligosResults[0];
int primerIndex = oligosResults[1];
//assemble reads
string contig = "";
int oend, oStart;
int numMismatches = 0;
vector<int> scores1, scores2;
if(hasQuality){
scores1 = fQual->getScores(); scores2 = rQual->getScores();
delete fQual; delete rQual;
}
vector<int> contigScores = assembleFragments(qual_match_simple_bayesian, qual_mismatch_simple_bayesian, fSeq, rSeq, scores1, scores2, hasQuality, alignment, contig, trashCode, oend, oStart, numMismatches, params->insert, params->deltaq, params->trimOverlap);
//Note that usearch/vsearch cap the maximum Q value at 41 - perhaps due to ascii
//limits? we leave this value unbounded. if two sequences have a 40 then the
//assembled quality score will be 85. If two 250 nt reads are all 40 and they
//perfectly match each other, then the difference in the number of expected errors
//between using 85 and 41 all the way across will be 0.01986 - this is a "worst"
//case scenario
double expected_errors = 0;
for(int i=0;i<contigScores.size();i++){
expected_errors += convertQToProb(contigScores[i]);
}
if(expected_errors > params->maxee) { trashCode += 'e' ;}
if (params->screenSequences) { screenSequence(contig, trashCode, params); }
if(trashCode.length() == 0){
string thisGroup = params->group; //group from file file
if (params->createGroupFromOligos) { //overwrite file file group for oligos group
if(numBarcodes != 0){
thisGroup = params->barcodeNameVector[barcodeIndex];
if (numPrimers != 0) {
if (params->primerNameVector[primerIndex] != "") {
if(thisGroup != "") { thisGroup += "." + params->primerNameVector[primerIndex]; }
else { thisGroup = params->primerNameVector[primerIndex]; }
}
}
}
}
int pos = thisGroup.find("ignore");
if (pos == string::npos) {
if (thisGroup != "") {
params->groupMap[fSeq.getName()] = thisGroup;
map<string, int>::iterator it = params->groupCounts.find(thisGroup);
if (it == params->groupCounts.end()) { params->groupCounts[thisGroup] = 1; }
else { params->groupCounts[it->first] ++; }
}
}else { ignore = true; }
//print good stuff
if(!ignore){
//output
string output = ">" + fSeq.getName() + '\t' + "ee=" + toString(expected_errors) + '\t' + commentString + "\n" + contig + "\n";
params->trimFileName->write(output);
if (hasQuality && params->makeQualFile) {
output = ">" + fSeq.getName() + '\t' + "ee=" + toString(expected_errors) + '\t' + commentString +"\n";
for (int i = 0; i < contigScores.size(); i++) { output += toString(contigScores[i]) + " "; } output += "\n";
params->trimQFileName->write(output);
}
int numNs = 0;
for (int i = 0; i < contig.length(); i++) { if (contig[i] == 'N') { numNs++; } }
output = fSeq.getName() + '\t' + toString(contig.length()) + '\t' + toString(oend-oStart) + '\t' + toString(oStart) + '\t' + toString(oend) + '\t' + toString(numMismatches) + '\t' + toString(numNs) + '\t' + toString(expected_errors) + "\n";
params->misMatchesFile->write(output);
}
}else{
params->badNames.insert(fSeq.getName());
string output = ">" + fSeq.getName() + " | " + trashCode + '\t' + "ee=" + toString(expected_errors) + '\t' + commentString + "\n" + contig + "\n";
params->scrapFileName->write(output);
if (hasQuality && params->makeQualFile) {
output = ">" + fSeq.getName() + " | " + trashCode + '\t' + "ee=" + toString(expected_errors) + '\t' + commentString + "\n";
for (int i = 0; i < contigScores.size(); i++) { output += toString(contigScores[i]) + " "; } output += "\n";
params->scrapQFileName->write(output);
}
}
if (params->m->getDebug()) { params->m->mothurOut("\n"); }
}
params->count++;
#if defined NON_WINDOWS
if (!params->gz) {
double pos = inFFasta.tellg();
if (params->util.isEqual(pos,-1) || (pos >= params->linesInput.end)) { good = false; break; }
}else {
#ifdef USE_BOOST
if (inFF.eof() || inRF.eof()) { good = false; break; }
#endif
}
#else
if (!params->gz) {
if (params->count >= params->linesInput.end) { good = false; break; }
}else {
#ifdef USE_BOOST
if (inFF.eof() || inRF.eof()) { good = false; break; }
#endif
}
#endif
//report progress
if((params->count) % 1000 == 0){ params->m->mothurOutJustToScreen(toString(params->count)+"\n"); }
}
//report progress
if((params->count) % 1000 != 0){ params->m->mothurOutJustToScreen(toString(params->count)+"\n"); }
//close files
inFFasta.close();
inRFasta.close();
if (params->gz) {
#ifdef USE_BOOST
inFF.pop(); inRF.pop();
#endif
}
if (params->delim == '@') {
if (thisfqualindexfile != "") { inFQualIndex.close();
if (params->gz) {
#ifdef USE_BOOST
inFQ.pop();
#endif
}
}
if (thisrqualindexfile != "") { inRQualIndex.close();
if (params->gz) {
#ifdef USE_BOOST
inRQ.pop();
#endif
}
}
}else{
if (hasQuality) {
inFQualIndex.close();
inRQualIndex.close();
if (params->gz) {
#ifdef USE_BOOST
inFQ.pop(); inRQ.pop();
#endif
}
}
}
//cleanup memory
for (int i = 0; i < trims.size(); i++) { delete trims[i]; }
delete alignment;
}
catch(exception& e) {
params->m->errorOut(e, "MakeContigsCommand", "driverContigs");
exit(1);
}
}
//**********************************************************************************************************************
//fileInputs[0] = forward Fasta or Forward Fastq, fileInputs[1] = reverse Fasta or reverse Fastq. if qualOrIndexFiles.size() != 0, then qualOrIndexFiles[0] = forward qual or Forward index, qualOrIndexFiles[1] = reverse qual or reverse index.
//lines[0] - ffasta, lines[1] - rfasta) - processor1
//lines[2] - ffasta, lines[3] - rfasta) - processor2
//lines[4] - ffasta, lines[5] - rfasta) - processor3
//...
//qlines[0] - fqual or findex, qlines[1] - rqual or rindex) - processor1
//qlines[2] - fqual or findex, qlines[3] - rqual or rindex) - processor2
//qlines[4] - fqual or findex, qlines[5] - rqual or rindex) - processor3
//...
//if using index files and only have 1 then the file name = NONE, and entries are duds. Copies of other index file.
//if no index files are given, then qualOrIndexFiles.size() == 0.
unsigned long long MakeContigsCommand::createProcesses(vector<string> fileInputs, vector<string> qualOrIndexFiles, string outputFasta, string outputScrapFasta, string outputQual, string outputScrapQual, string outputMisMatches, vector<vector<string> > fastaFileNames, vector<vector<string> > qualFileNames, string group, map<int, oligosPair>& pairedPrimers, map<int, oligosPair>& rpairedPrimers, map<int, oligosPair>& revpairedPrimers, map<int, oligosPair>& pairedBarcodes, map<int, oligosPair>& rpairedBarcodes, map<int, oligosPair>& revpairedBarcodes, vector<string>& barcodeNames, vector<string>& primerNames) {
try {
vector<linePair> lines;
vector<linePair> qLines;
if (gz) {
nameType = setNameType(fileInputs[0], fileInputs[1], delim, offByOneTrimLength, gz, format);
for (int i = 0; i < fileInputs.size(); i++) {
//fake out lines - we are just going to check for end of file. Work is divided by number of files per processor.
lines.push_back(linePair(0, 1000));
qLines.push_back(linePair(0, 1000));
}
processors = fileInputs.size() / 2;
}else {
//divides the files so that the processors can share the workload.
setLines(fileInputs, qualOrIndexFiles, lines, qLines, delim);
}
bool hasQuality = false;
if (delim == '@') { hasQuality = true; }
else if ((delim == '>') && (qualOrIndexFiles.size() != 0)) { hasQuality = true; }
//create array of worker threads
vector<std::thread*> workerThreads;
vector<contigsData*> data;
auto synchronizedOutputFastaTrimFile = std::make_shared<SynchronizedOutputFile>(outputFasta);
auto synchronizedOutputFastaScrapFile = std::make_shared<SynchronizedOutputFile>(outputScrapFasta);
auto synchronizedMisMatchFile = std::make_shared<SynchronizedOutputFile>(outputMisMatches);
auto synchronizedOutputQTrimFile = std::make_shared<SynchronizedOutputFile>(outputQual);
auto synchronizedOutputQScrapFile = std::make_shared<SynchronizedOutputFile>(outputScrapQual);
//Lauch worker threads
for (int i = 0; i < processors-1; i++) {
OutputWriter* threadFastaTrimWriter = new OutputWriter(synchronizedOutputFastaTrimFile);
OutputWriter* threadFastaScrapWriter = new OutputWriter(synchronizedOutputFastaScrapFile);
OutputWriter* threadMismatchWriter = new OutputWriter(synchronizedMisMatchFile);
OutputWriter* threadQTrimWriter = nullptr;
OutputWriter* threadQScrapWriter = nullptr;
if (makeQualFile) {
threadQTrimWriter = new OutputWriter(synchronizedOutputQTrimFile);
threadQScrapWriter = new OutputWriter(synchronizedOutputQScrapFile);
}
int spot = (i+1)*2;
contigsData* dataBundle = new contigsData(threadFastaTrimWriter, threadFastaScrapWriter, threadQTrimWriter, threadQScrapWriter, threadMismatchWriter, fileInputs, qualOrIndexFiles, lines[spot], lines[spot+1], qLines[spot], qLines[spot+1]);
dataBundle->setVariables(gz, delim, nameType, offByOneTrimLength, pairedBarcodes, pairedPrimers, rpairedBarcodes, rpairedPrimers, revpairedBarcodes, revpairedPrimers, primerNames, barcodeNames, reorient, pdiffs, bdiffs, tdiffs, align, match, misMatch, gapOpen, gapExtend, insert, deltaq, maxee, kmerSize, format, trimOverlap, createOligosGroup, createFileGroup, group, screenSequences, maxHomoP, maxLength, maxAmbig);
data.push_back(dataBundle);
workerThreads.push_back(new std::thread(driverContigs, dataBundle));
}
OutputWriter* threadMisMatchWriter = new OutputWriter(synchronizedMisMatchFile);
OutputWriter* threadFastaTrimWriter = new OutputWriter(synchronizedOutputFastaTrimFile);
OutputWriter* threadFastaScrapWriter = new OutputWriter(synchronizedOutputFastaScrapFile);
OutputWriter* threadQTrimWriter = nullptr;
OutputWriter* threadQScrapWriter = nullptr;
if (makeQualFile) {
threadQTrimWriter = new OutputWriter(synchronizedOutputQTrimFile);
threadQScrapWriter = new OutputWriter(synchronizedOutputQScrapFile);
}
contigsData* dataBundle = new contigsData(threadFastaTrimWriter, threadFastaScrapWriter, threadQTrimWriter, threadQScrapWriter, threadMisMatchWriter, fileInputs, qualOrIndexFiles, lines[0], lines[1], qLines[0], qLines[1]);
dataBundle->setVariables(gz, delim, nameType, offByOneTrimLength, pairedBarcodes, pairedPrimers, rpairedBarcodes, rpairedPrimers, revpairedBarcodes, revpairedPrimers, primerNames, barcodeNames, reorient, pdiffs, bdiffs, tdiffs, align, match, misMatch, gapOpen, gapExtend, insert, deltaq, maxee, kmerSize, format, trimOverlap, createOligosGroup, createFileGroup, group, screenSequences, maxHomoP, maxLength, maxAmbig);
driverContigs(dataBundle);
long long num = dataBundle->count;
badNames.insert(dataBundle->badNames.begin(), dataBundle->badNames.end());
groupMap.insert(dataBundle->groupMap.begin(), dataBundle->groupMap.end());
for (map<string, int>::iterator it = dataBundle->groupCounts.begin(); it != dataBundle->groupCounts.end(); it++) {
map<string, int>::iterator itMine = groupCounts.find(it->first);
if (itMine != groupCounts.end()) { itMine->second += it->second; }
else { groupCounts[it->first] = it->second; }
}
for (int i = 0; i < processors-1; i++) {
workerThreads[i]->join();
num += data[i]->count;
delete data[i]->trimFileName;
delete data[i]->scrapFileName;
delete data[i]->misMatchesFile;
if (makeQualFile) {
delete data[i]->trimQFileName;
delete data[i]->scrapQFileName;
}
badNames.insert(data[i]->badNames.begin(), data[i]->badNames.end());
groupMap.insert(data[i]->groupMap.begin(), data[i]->groupMap.end());
//merge counts
for (map<string, int>::iterator it = data[i]->groupCounts.begin(); it != data[i]->groupCounts.end(); it++) {
map<string, int>::iterator itMine = groupCounts.find(it->first);
if (itMine != groupCounts.end()) { itMine->second += it->second; }
else { groupCounts[it->first] = it->second; }
}
delete data[i];
delete workerThreads[i];
}
delete threadFastaTrimWriter;
delete threadFastaScrapWriter;
delete threadMisMatchWriter;
if (makeQualFile) {
delete threadQTrimWriter;
delete threadQScrapWriter;
}
delete dataBundle;
return num;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "createProcesses");
exit(1);
}
}
//**********************************************************************************************************************
//process one file at a time, only get here with gz=true
void driverContigsGroups(groupContigsData* gparams) {
try {
gparams->count = 0;
gparams->bundle->delim = '@';
for (int l = gparams->start; l < gparams->end; l++) {
int startTime = time(nullptr);
if (gparams->bundle->m->getControl_pressed()) { break; }
gparams->bundle->m->mothurOut("\n>>>>>\tProcessing file pair " + gparams->fileInputs[l][0] + " - " + gparams->fileInputs[l][1] + " (files " + toString(l+1) + " of " + toString(gparams->fileInputs.size()) + ")\t<<<<<\n");
vector<string> theseFileInputs;
vector<string> theseQIInputs;
string ffastqfile = gparams->fileInputs[l][0]; theseFileInputs.push_back(ffastqfile);
string rfastqfile = gparams->fileInputs[l][1]; theseFileInputs.push_back(rfastqfile);
string findexfile = gparams->fileInputs[l][2]; theseQIInputs.push_back(findexfile); //could be blank, "NONE" or filename
string rindexfile = gparams->fileInputs[l][3]; theseQIInputs.push_back(rindexfile); //could be blank, "NONE" or filename
gparams->bundle->group = gparams->file2Groups[l]; //blank if no group assigned to file pair
bool decompressionHelped = false;
//test to make sure you can read the gz files
bool readable = testGZReadable(theseFileInputs, theseQIInputs, decompressionHelped, gparams->bundle->format, gparams->bundle->m);
if (readable) {
if (decompressionHelped) { gparams->bundle->gz = false; }
}else {
gparams->bundle->m->mothurOut("[ERROR]: Unable to read compressed .gz files, please decompress and run make.contigs again. \n"); gparams->bundle->m->setControl_pressed(true); break;
}
//find read name type to speed read matching later
gparams->bundle->nameType = setNameType(theseFileInputs[0], theseFileInputs[1], gparams->bundle->delim, gparams->bundle->offByOneTrimLength, gparams->bundle->gz, gparams->bundle->format);
//fake out lines - we are just going to check for end of file. Work is divided by number of files per processor.
vector<linePair> thisLines; vector<linePair> thisQLines;
if (decompressionHelped) {
//set file positions for file
int processors = 1;
vector<double> fastaFilePos = gparams->bundle->util.divideFile(theseFileInputs[0], processors, gparams->bundle->delim);
thisLines.push_back(linePair(fastaFilePos[0], fastaFilePos[1])); //forward fastq
fastaFilePos = gparams->bundle->util.divideFile(theseFileInputs[1], processors, gparams->bundle->delim);
thisLines.push_back(linePair(fastaFilePos[0], fastaFilePos[1])); //reverse fastq
if ((theseQIInputs[0] != "") && (theseQIInputs[0] != "NONE")){
fastaFilePos = gparams->bundle->util.divideFile(theseQIInputs[0], processors, gparams->bundle->delim);
thisQLines.push_back(linePair(fastaFilePos[0], fastaFilePos[1])); //forward index
}
if ((theseQIInputs[1] != "") && (theseQIInputs[1] != "NONE")){
fastaFilePos = gparams->bundle->util.divideFile(theseQIInputs[1], processors, gparams->bundle->delim);
thisQLines.push_back(linePair(fastaFilePos[0], fastaFilePos[1])); //forward index
}
if (thisQLines.size() == 0) { thisQLines = thisLines; }
}
else {
thisLines.push_back(linePair(0, 1000)); thisLines.push_back(linePair(0, 1000)); //fasta[0], fasta[1] - forward and reverse
thisQLines.push_back(linePair(0, 1000)); thisQLines.push_back(linePair(0, 1000)); //qual[0], qual[1] - forward and reverse
}
gparams->bundle->m->mothurOut("Making contigs...\n");
contigsData* dataBundle = new contigsData(gparams->bundle->trimFileName, gparams->bundle->scrapFileName, gparams->bundle->trimQFileName, gparams->bundle->scrapQFileName, gparams->bundle->misMatchesFile, theseFileInputs, theseQIInputs, thisLines[0], thisLines[1], thisQLines[0], thisQLines[1]);
dataBundle->copyVariables(gparams->bundle);
driverContigs(dataBundle);
if (decompressionHelped) {
gparams->bundle->util.mothurRemove(theseFileInputs[0]); gparams->bundle->util.mothurRemove(theseFileInputs[1]);
if (theseQIInputs[0] != "NONE") { gparams->bundle->util.mothurRemove(theseQIInputs[0]); }
if (theseQIInputs[1] != "NONE") { gparams->bundle->util.mothurRemove(theseQIInputs[1]); }
}
gparams->count += dataBundle->count;
gparams->badNames.insert(dataBundle->badNames.begin(), dataBundle->badNames.end());
gparams->bundle->groupMap.insert(dataBundle->groupMap.begin(), dataBundle->groupMap.end());
for (map<string, int>::iterator it = dataBundle->groupCounts.begin(); it != dataBundle->groupCounts.end(); it++) {
map<string, int>::iterator itMine = gparams->bundle->groupCounts.find(it->first);
if (itMine != gparams->bundle->groupCounts.end()) { itMine->second += it->second; }
else { gparams->bundle->groupCounts[it->first] = it->second; }
}
gparams->bundle->m->mothurOut("Done.\n\nIt took " + toString(time(nullptr) - startTime) + " secs to assemble " + toString(dataBundle->count) + " reads.\n\n");
delete dataBundle;
}
}
catch(exception& e) {
gparams->bundle->m->errorOut(e, "MakeContigsCommand", "driverContigsGroups");
exit(1);
}
}
//**********************************************************************************************************************
//only getting here is gz=true
unsigned long long MakeContigsCommand::createProcessesGroups(vector< vector<string> > fileInputs, string compositeFastaFile, string compositeScrapFastaFile, string compositeQualFile, string compositeScrapQualFile, string compositeMisMatchFile, vector<string>& file2Groups) {
try {
map<int, oligosPair> pairedPrimers, rpairedPrimers, revpairedPrimers, pairedBarcodes, rpairedBarcodes, revpairedBarcodes;
vector<string> barcodeNames, primerNames;
if(oligosfile != "") { createOligosGroup = getOligos(pairedPrimers, rpairedPrimers, revpairedPrimers, pairedBarcodes, rpairedBarcodes, revpairedBarcodes, barcodeNames, primerNames); }
//give group in file file precedence
if (createFileGroup) { createOligosGroup = false; }
vector<std::thread*> workerThreads;
vector<groupContigsData*> data;
//divide files between processors
vector<linePair> startEndIndexes;
int remainingPairs = fileInputs.size();
if (remainingPairs < processors) { processors = remainingPairs; }
int startIndex = 0;
for (int remainingProcessors = processors; remainingProcessors > 0; remainingProcessors--) {
int numPairs = remainingPairs; //case for last processor
if (remainingProcessors != 1) { numPairs = ceil(remainingPairs / remainingProcessors); }
startEndIndexes.push_back(linePair(startIndex, (startIndex+numPairs))); //startIndex, endIndex
startIndex = startIndex + numPairs;
remainingPairs = remainingPairs - numPairs;
}
auto synchronizedOutputFastaTrimFile = std::make_shared<SynchronizedOutputFile>(compositeFastaFile);
auto synchronizedOutputFastaScrapFile = std::make_shared<SynchronizedOutputFile>(compositeScrapFastaFile);
auto synchronizedOutputQTrimFile = std::make_shared<SynchronizedOutputFile>(compositeQualFile);
auto synchronizedOutputQScrapFile = std::make_shared<SynchronizedOutputFile>(compositeScrapQualFile);
auto synchronizedMisMatchFile = std::make_shared<SynchronizedOutputFile>(compositeMisMatchFile);
//Lauch worker threads
for (int i = 0; i < processors-1; i++) {
OutputWriter* threadFastaTrimWriter = new OutputWriter(synchronizedOutputFastaTrimFile);
OutputWriter* threadFastaScrapWriter = new OutputWriter(synchronizedOutputFastaScrapFile);
OutputWriter* threadMismatchWriter = new OutputWriter(synchronizedMisMatchFile);
OutputWriter* threadQTrimWriter = nullptr;
OutputWriter* threadQScrapWriter = nullptr;
if (makeQualFile) {
threadQTrimWriter = new OutputWriter(synchronizedOutputQTrimFile);
threadQScrapWriter = new OutputWriter(synchronizedOutputQScrapFile);
}
contigsData* dataBundle = new contigsData(threadFastaTrimWriter, threadFastaScrapWriter, threadQTrimWriter, threadQScrapWriter, threadMismatchWriter);
dataBundle->setVariables(gz, delim, nameType, offByOneTrimLength, pairedBarcodes, pairedPrimers, rpairedBarcodes, rpairedPrimers, revpairedBarcodes, revpairedPrimers, primerNames, barcodeNames, reorient, pdiffs, bdiffs, tdiffs, align, match, misMatch, gapOpen, gapExtend, insert, deltaq, maxee, kmerSize, format, trimOverlap, createOligosGroup, createFileGroup, "", screenSequences, maxHomoP, maxLength, maxAmbig);
groupContigsData* groupDataBundle = new groupContigsData(fileInputs, startEndIndexes[i+1].start, startEndIndexes[i+1].end, dataBundle, file2Groups);
data.push_back(groupDataBundle);
workerThreads.push_back(new std::thread(driverContigsGroups, groupDataBundle));
}
OutputWriter* threadMisMatchWriter = new OutputWriter(synchronizedMisMatchFile);
OutputWriter* threadFastaTrimWriter = new OutputWriter(synchronizedOutputFastaTrimFile);
OutputWriter* threadFastaScrapWriter = new OutputWriter(synchronizedOutputFastaScrapFile);
OutputWriter* threadQTrimWriter = nullptr;
OutputWriter* threadQScrapWriter = nullptr;
if (makeQualFile) {
threadQTrimWriter = new OutputWriter(synchronizedOutputQTrimFile);
threadQScrapWriter = new OutputWriter(synchronizedOutputQScrapFile);
}
contigsData* dataBundle = new contigsData(threadFastaTrimWriter, threadFastaScrapWriter, threadQTrimWriter, threadQScrapWriter, threadMisMatchWriter);
dataBundle->setVariables(gz, delim, nameType, offByOneTrimLength, pairedBarcodes, pairedPrimers, rpairedBarcodes, rpairedPrimers, revpairedBarcodes, revpairedPrimers, primerNames, barcodeNames, reorient, pdiffs, bdiffs, tdiffs, align, match, misMatch, gapOpen, gapExtend, insert, deltaq, maxee, kmerSize, format, trimOverlap, createOligosGroup, createFileGroup, "", screenSequences, maxHomoP, maxLength, maxAmbig);
groupContigsData* groupDataBundle = new groupContigsData(fileInputs, startEndIndexes[0].start, startEndIndexes[0].end, dataBundle, file2Groups);
driverContigsGroups(groupDataBundle);
delete threadFastaTrimWriter;
delete threadFastaScrapWriter;
delete threadMisMatchWriter;
if (makeQualFile) {
delete threadQTrimWriter;
delete threadQScrapWriter;
}
long long num = groupDataBundle->count;
badNames.insert(dataBundle->badNames.begin(), dataBundle->badNames.end());
groupMap.insert(groupDataBundle->bundle->groupMap.begin(), groupDataBundle->bundle->groupMap.end());
for (map<string, int>::iterator it = dataBundle->groupCounts.begin(); it != dataBundle->groupCounts.end(); it++) {
map<string, int>::iterator itMine = groupCounts.find(it->first);
if (itMine != groupCounts.end()) { itMine->second += it->second; }
else { groupCounts[it->first] = it->second; }
}
delete groupDataBundle;
for (int i = 0; i < processors-1; i++) {
workerThreads[i]->join();
num += data[i]->count;
delete data[i]->bundle->trimFileName;
delete data[i]->bundle->scrapFileName;
delete data[i]->bundle->misMatchesFile;
if (makeQualFile) {
delete data[i]->bundle->trimQFileName;
delete data[i]->bundle->scrapQFileName;
}
badNames.insert(data[i]->badNames.begin(), data[i]->badNames.end());
groupMap.insert(data[i]->bundle->groupMap.begin(), data[i]->bundle->groupMap.end());
//merge counts
for (map<string, int>::iterator it = data[i]->bundle->groupCounts.begin(); it != data[i]->bundle->groupCounts.end(); it++) {
map<string, int>::iterator itMine = groupCounts.find(it->first);
if (itMine != groupCounts.end()) { itMine->second += it->second; }
else { groupCounts[it->first] = it->second; }
}
delete data[i];
delete workerThreads[i];
}
return num;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "createProcessesGroups");
exit(1);
}
}
/**************************************************************************************************/
int MakeContigsCommand::setLines(vector<string> fasta, vector<string> qual, vector<linePair>& lines, vector<linePair>& qLines, char delim) {
try {
lines.clear();
qLines.clear();
vector<double> fastaFilePos;
vector<double> qfileFilePos;
vector<double> temp;
nameType = setNameType(fasta[0], fasta[1], delim, offByOneTrimLength, gz, format);
#if defined NON_WINDOWS
//set file positions for fasta file
fastaFilePos = util.divideFile(fasta[0], processors, delim);
//get name of first sequence in each chunk
map<string, int> firstSeqNames; map<string, int> trimmedNames;
for (int i = 0; i < (fastaFilePos.size()-1); i++) {
ifstream in; util.openInputFile(fasta[0], in);
in.seekg(fastaFilePos[i]);
string name = "";
if (delim == '>') {
Sequence temp(in);
name = temp.getName();
}else {
string line = util.getline(in); gobble(in);
vector<string> pieces = util.splitWhiteSpace(line);
name = pieces[0];
name = name.substr(1);
util.checkName(name);
}
fixName(name, nameType, offByOneTrimLength);
firstSeqNames[name] = i;
in.close();
}
map<string, int> copy;
if (qual.size() != 0) { copy = firstSeqNames; }
//look for match in reverse file
ifstream in2;
util.openInputFile(fasta[1], in2);
string input;
while(!in2.eof()){
input = util.getline(in2); gobble(in2);
if (input.length() != 0) {
if(input[0] == delim){ //this is a name line
vector<string> pieces = util.splitWhiteSpace(input);
string name = pieces[0];
name = name.substr(1);
util.checkName(name);
fixName(name, nameType, offByOneTrimLength);
map<string, int>::iterator it = firstSeqNames.find(name);
if (it != firstSeqNames.end()) { //this is the start of a new chunk
double pos = in2.tellg();
qfileFilePos.push_back(pos - input.length() - 1);
firstSeqNames.erase(it);
}
}
}
if ((firstSeqNames.size() == 0)) { break; }
}
in2.close();
//get last file position of reverse fasta[1]
FILE * pFile;
double size;
//get num bytes in file
fasta[1] = util.getFullPathName(fasta[1]);
pFile = fopen (fasta[1].c_str(),"rb");
if (pFile==nullptr) perror ("Error opening file");
else{
fseek (pFile, 0, SEEK_END);
size=ftell (pFile);
fclose (pFile);
}
qfileFilePos.push_back(size);
if ((firstSeqNames.size() != 0)){
for (map<string, int>::iterator it = firstSeqNames.begin(); it != firstSeqNames.end(); it++) {
if (delim == '>') {
m->mothurOut(it->first + " is in your forward fasta file and not in your reverse file, please remove it using the remove.seqs command before proceeding.\n");
}else {
m->mothurOut(it->first + " is in your forward fastq file and not in your reverse file, please remove it using the remove.seqs command before proceeding.\n");
}
}
m->setControl_pressed(true);
return processors;
}
//fill lines with paired forward and reverse fasta lines
for (int i = 0; i < (fastaFilePos.size()-1); i++) {
if (m->getDebug()) { m->mothurOut("[DEBUG]: forward " + toString(i) +'\t' + toString(fastaFilePos[i]) + '\t' + toString(fastaFilePos[i+1]) + '\n'); }
lines.push_back(linePair(fastaFilePos[i], fastaFilePos[(i+1)]));
if (m->getDebug()) { m->mothurOut("[DEBUG]: reverse " + toString(i) +'\t' + toString(qfileFilePos[i]) + '\t' + toString(qfileFilePos[i+1]) + '\n'); }
lines.push_back(linePair(qfileFilePos[i], qfileFilePos[(i+1)]));
}
qfileFilePos.clear();
if (qual.size() != 0) {
firstSeqNames = copy;
if (qual[0] != "NONE") {
//seach for filePos of each first name in the qfile and save in qfileFilePos
ifstream inQual;
util.openInputFile(qual[0], inQual);
string input;
while(!inQual.eof()){
input = util.getline(inQual); gobble(inQual);
if (input.length() != 0) {
if(input[0] == delim){ //this is a sequence name line
vector<string> pieces = util.splitWhiteSpace(input);
string name = pieces[0];
name = name.substr(1);
util.checkName(name);
fixName(name, nameType, offByOneTrimLength);
map<string, int>::iterator it = firstSeqNames.find(name);
if(it != firstSeqNames.end()) { //this is the start of a new chunk
double pos = inQual.tellg();
qfileFilePos.push_back(pos - input.length() - 1);
firstSeqNames.erase(it);
} }
}
if ((firstSeqNames.size() == 0)) { break; }
}
inQual.close();
//get last file position of reverse qual[0]
FILE * pFile;
double size;
//get num bytes in file
qual[0] = util.getFullPathName(qual[0]);
pFile = fopen (qual[0].c_str(),"rb");
if (pFile==nullptr) perror ("Error opening file");
else{
fseek (pFile, 0, SEEK_END);
size=ftell (pFile);
fclose (pFile);
}
qfileFilePos.push_back(size);
if ((firstSeqNames.size() != 0)){
for (map<string, int>::iterator it = firstSeqNames.begin(); it != firstSeqNames.end(); it++) {
if (delim == '>') {
m->mothurOut(it->first + " is in your forward fasta file and reverse fasta file, but not your forward qfile, please remove it using the remove.seqs command before proceeding.\n");
}else {
m->mothurOut(it->first + " is in your forward fastq file and reverse fastq file, but not your forward index, please remove it using the remove.seqs command before proceeding.\n");
}
}
m->setControl_pressed(true);
return processors;
}
}
firstSeqNames = copy;
if (qual[1] != "NONE") {
ifstream inQual2;
util.openInputFile(qual[1], inQual2);
while(!inQual2.eof()){
input = util.getline(inQual2); gobble(inQual2);
if (input.length() != 0) {
if(input[0] == delim){ //this is a sequence name line
vector<string> pieces = util.splitWhiteSpace(input);
string name = pieces[0];
name = name.substr(1);
util.checkName(name);
fixName(name, nameType, offByOneTrimLength);
map<string, int>::iterator it = firstSeqNames.find(name);
if(it != firstSeqNames.end()) { //this is the start of a new chunk
double pos = inQual2.tellg();
temp.push_back(pos - input.length() - 1);
firstSeqNames.erase(it);
}
}
}
if ((firstSeqNames.size() == 0)) { break; }
}
inQual2.close();
//get last file position of reverse qual[1]
FILE * pFile2;
//get num bytes in file
qual[1] = util.getFullPathName(qual[1]);
pFile2 = fopen (qual[1].c_str(),"rb");
if (pFile2==nullptr) perror ("Error opening file");
else{
fseek (pFile2, 0, SEEK_END);
size=ftell (pFile2);
fclose (pFile2);
}
temp.push_back(size);
if ((firstSeqNames.size() != 0)){
for (map<string, int>::iterator it = firstSeqNames.begin(); it != firstSeqNames.end(); it++) {
if (delim == '>') {
m->mothurOut(it->first + " is in your forward fasta file, reverse fasta file, and forward qfile but not your reverse qfile, please remove it using the remove.seqs command before proceeding.\n");
}else {
if (qual[0] != "NONE") {
m->mothurOut(it->first + " is in your forward fastq file, reverse fastq file, and forward index but not your reverse index, please remove it using the remove.seqs command before proceeding.\n");
}else {
m->mothurOut(it->first + " is in your forward fastq file, reverse fastq file, but not your reverse index, please remove it using the remove.seqs command before proceeding.\n");
}
}
}
m->setControl_pressed(true);
return processors;
}
}
if (qual[0] == "NONE") { qfileFilePos = temp; } //fill with duds, if both were NONE then qual.size() == 0
if (qual[1] == "NONE") { temp = qfileFilePos; } //fill with duds, if both were NONE then qual.size() == 0
//fill lines with paired forward and reverse fasta lines
for (int i = 0; i < (fastaFilePos.size()-1); i++) {
if (m->getDebug()) { m->mothurOut("[DEBUG]: forward " + toString(i) +'\t' + toString(qfileFilePos[i]) + '\t' + toString(qfileFilePos[i+1]) + '\n'); }
qLines.push_back(linePair(qfileFilePos[i], qfileFilePos[(i+1)]));
if (m->getDebug()) { m->mothurOut("[DEBUG]: reverse " + toString(i) +'\t' + toString(temp[i]) + '\t' + toString(temp[i+1]) + '\n'); }
qLines.push_back(linePair(temp[i], temp[(i+1)]));
}
}else { qLines = lines; } //files with duds
return processors;
#else
long long numFastaSeqs = 0;
fastaFilePos = util.setFilePosFasta(fasta[0], numFastaSeqs, delim); //forward
if (numFastaSeqs < processors) { processors = numFastaSeqs; }
long long numRFastaSeqs = 0;
qfileFilePos = util.setFilePosFasta(fasta[1], numRFastaSeqs, delim); //reverse
if (numFastaSeqs != numRFastaSeqs) {
if (delim == '>') {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fasta file, but " + toString(numRFastaSeqs) + " sequences in your reverse fasta file. Please use the list.seqs and get.seqs commands to make the files match before proceeding. list.seqs(fasta=yourForward.fasta-yourReverse.fasta);get.seqs(fasta=yourForward.fasta, accnos=current);get.seqs(fasta=yourReverse.fasta, accnos=current);\n"); m->setControl_pressed(true); return processors;
}else {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fastq file, but " + toString(numRFastaSeqs) + " sequences in your reverse fastq file. Please use the list.seqs and get.seqs commands to make the files match before proceeding. list.seqs(fastq=yourForward.fastq-yourReverse.fastq);get.seqs(fastq=yourForward.fastq, accnos=current);get.seqs(fastq=yourReverse.fastq, accnos=current);\n"); m->setControl_pressed(true); return processors;
}
}
//figure out how many sequences you have to process
unsigned long long numSeqsPerProcessor = numFastaSeqs / processors;
for (int i = 0; i < processors; i++) {
unsigned long long startIndex = i * numSeqsPerProcessor;
if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; }
lines.push_back(linePair(fastaFilePos[startIndex], numSeqsPerProcessor)); //forward
lines.push_back(linePair(qfileFilePos[startIndex], numSeqsPerProcessor)); //reverse
}
if (qual.size() != 0) {
long long numFQualSeqs = 0;
long long numRQualSeqs = 0;
fastaFilePos.clear();
qfileFilePos.clear();
if (qual[0] != "NONE") { fastaFilePos = util.setFilePosFasta(qual[0], numFQualSeqs, delim); } //forward index or qual file
if (qual[1] != "NONE") { qfileFilePos = util.setFilePosFasta(qual[1], numRQualSeqs, delim); }//reverse index or qual file
if (qual[0] == "NONE") { fastaFilePos = qfileFilePos; numFQualSeqs = numRQualSeqs; } //fill with duds, if both were NONE then qual.size() == 0
if (qual[1] == "NONE") { qfileFilePos = fastaFilePos; numRQualSeqs = numFQualSeqs; } //fill with duds, if both were NONE then qual.size() == 0
if ((numFQualSeqs != numRQualSeqs) || (numFQualSeqs != numFastaSeqs)){
if (delim == '>') {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fasta file, " + toString(numRFastaSeqs) + " sequences in your reverse fasta file, " + toString(numFQualSeqs) + " sequences in your forward qual file, " + toString(numRQualSeqs) + " sequences in your reverse qual file. Please use the list.seqs and get.seqs commands to make the files match before proceeding.\n"); m->setControl_pressed(true); return processors;
}else {
if (qual[0] != "NONE") {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fastq file, " + toString(numRFastaSeqs) + " sequences in your reverse fastq file and " + toString(numRQualSeqs) + " sequences in your reverse index file. Please use the list.seqs and get.seqs commands to make the files match before proceeding.\n"); m->setControl_pressed(true); return processors;
}else if (qual[1] != "NONE") {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fastq file, " + toString(numRFastaSeqs) + " sequences in your reverse fastq file and " + toString(numFQualSeqs) + " sequences in your forward index file. Please use the list.seqs and get.seqs commands to make the files match before proceeding.\n"); m->setControl_pressed(true); return processors;
}else {
m->mothurOut("[ERROR]: You have " + toString(numFastaSeqs) + " sequences in your forward fastq file, " + toString(numRFastaSeqs) + " sequences in your reverse fastq file, " + toString(numFQualSeqs) + " sequences in your forward index file, " + toString(numRQualSeqs) + " sequences in your reverse index file. Please use the list.seqs and get.seqs commands to make the files match before proceeding.\n"); m->setControl_pressed(true); return processors;
}
}
}
//figure out how many sequences you have to process
unsigned long long numSeqsPerProcessor = numFQualSeqs / processors;
for (int i = 0; i < processors; i++) {
unsigned long long startIndex = i * numSeqsPerProcessor;
if(i == (processors - 1)){ numSeqsPerProcessor = numFQualSeqs - i * numSeqsPerProcessor; }
qLines.push_back(linePair(fastaFilePos[startIndex], numSeqsPerProcessor)); //forward
qLines.push_back(linePair(qfileFilePos[startIndex], numSeqsPerProcessor)); //reverse
}
}else { qLines = lines; } //files with duds
if(qual.size() == 0) { qLines = lines; } //files with duds
return 1;
#endif
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "setLines");
exit(1);
}
}
//***************************************************************************************************************
//lines can be 2, 3, or 4 columns
// forward.fastq reverse.fastq -> 2 column
// groupName forward.fastq reverse.fastq -> 3 column
// forward.fastq reverse.fastq forward.index.fastq reverse.index.fastq -> 4 column
// forward.fastq reverse.fastq none reverse.index.fastq -> 4 column
// forward.fastq reverse.fastq forward.index.fastq none -> 4 column
vector< vector<string> > MakeContigsCommand::readFileNames(string filename, vector<string>& file2Group){
try {
FileFile dataFile(filename, "contigs");
vector< vector<string> > files = dataFile.getFiles();
gz = dataFile.isGZ();
file2Group = dataFile.getGroupNames();
createFileGroup = dataFile.isColumnWithGroupNames();
if (dataFile.containsIndexFiles() && (oligosfile == "")) { m->mothurOut("[ERROR]: You need to provide an oligos file if you are going to use an index file.\n"); m->setControl_pressed(true); }
if (files.size() == 0) { m->setControl_pressed(true); }
return files;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "readFileNames");
exit(1);
}
}
//***************************************************************************************************************
//illumina data requires paired forward and reverse data
//BARCODE atgcatgc atgcatgc groupName
//PRIMER atgcatgc atgcatgc groupName
//PRIMER atgcatgc atgcatgc
bool MakeContigsCommand::getOligos(map<int, oligosPair>& pairedPrimers, map<int, oligosPair>& rpairedPrimers, map<int, oligosPair>& revpairedPrimers, map<int, oligosPair>& pairedBarcodes, map<int, oligosPair>& rpairedBarcodes, map<int, oligosPair>& revpairedBarcodes, vector<string>& barcodeNames, vector<string>& primerNames){
try {
if (m->getDebug()) { m->mothurOut("[DEBUG]: oligosfile = " + oligosfile + "\n"); }
bool allBlank = false;
Oligos oligos; oligos.read(oligosfile, false);
if (m->getControl_pressed()) { return false; } //error in reading oligos
if (oligos.hasPairedBarcodes() || oligos.hasPairedPrimers()) {
pairedPrimers = oligos.getPairedPrimers();
rpairedPrimers = oligos.getReorientedPairedPrimers();
revpairedPrimers = oligos.getReversedPairedPrimers();
primerNames = oligos.getPrimerNames();
pairedBarcodes = oligos.getPairedBarcodes();
rpairedBarcodes = oligos.getReorientedPairedBarcodes();
revpairedBarcodes = oligos.getReversedPairedBarcodes();
barcodeNames = oligos.getBarcodeNames();
if (m->getDebug()) {
map<int, oligosPair>::iterator it;
m->mothurOut("\n[DEBUG]: paired primers - \n");
for (it = pairedPrimers.begin(); it != pairedPrimers.end(); it++) {
m->mothurOut("[DEBUG]: " + primerNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
m->mothurOut("\n[DEBUG]: paired reoriented primers - \n");
for (it = rpairedPrimers.begin(); it != rpairedPrimers.end(); it++) {
m->mothurOut("[DEBUG]: " + primerNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
m->mothurOut("\n[DEBUG]: paired reversed primers - \n");
for (it = revpairedPrimers.begin(); it != revpairedPrimers.end(); it++) {
m->mothurOut("[DEBUG]: " + primerNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
m->mothurOut("\n[DEBUG]: paired barcodes - \n");
for (it = pairedBarcodes.begin(); it != pairedBarcodes.end(); it++) {
m->mothurOut("[DEBUG]: " + barcodeNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
m->mothurOut("\n[DEBUG]: paired reoriented barcodes - \n");
for (it = rpairedBarcodes.begin(); it != rpairedBarcodes.end(); it++) {
m->mothurOut("[DEBUG]: " + barcodeNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
m->mothurOut("\n[DEBUG]: paired reversed barcodes - \n");
for (it = revpairedBarcodes.begin(); it != revpairedBarcodes.end(); it++) {
m->mothurOut("[DEBUG]: " + barcodeNames[it->first] + "\t" + it->second.forward + "\t" + it->second.reverse + "\n");
}
}
}else {
m->mothurOut("[ERROR]: make.contigs requires paired barcodes and primers. You can set one end to NONE if you are using an index file.\n"); m->setControl_pressed(true);
}
if (m->getControl_pressed()) { return false; }
int numLinkers = oligos.getLinkers().size();
int numSpacers = oligos.getSpacers().size();
if (numLinkers != 0) { m->mothurOut("[WARNING]: make.contigs is not setup to remove linkers, ignoring.\n"); }
if (numSpacers != 0) { m->mothurOut("[WARNING]: make.contigs is not setup to remove spacers, ignoring.\n"); }
vector<string> groupNames = oligos.getGroupNames();
if (groupNames.size() == 0) { allFiles = false; allBlank = true; }
if (allBlank) {
m->mothurOut("[WARNING]: your oligos file does not contain any group names. mothur will not create a groupfile.\n");
allFiles = false;
return false;
}
return true;
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "getOligos");
exit(1);
}
}
//**********************************************************************************************************************
void MakeContigsCommand::debugFunction() {
try{
//allows you to run the oligos and index file independantly to check for barcode issues. make.contigs(findex=yourIndexFile, bdiffs=1, oligos=yourOligosFile, checkorient=t). just used for user support
map<int, oligosPair> pairedPrimers, pairedBarcodes, reorientedPairedBarcodes, reorientedPairedPrimers, reversedPairedBarcodes, reverseedPairedPrimers;
vector<string> barcodeNames, primerNames;
if(oligosfile != "") { createOligosGroup = getOligos(pairedPrimers, reorientedPairedPrimers, reverseedPairedPrimers, pairedBarcodes, reorientedPairedBarcodes, reversedPairedBarcodes, barcodeNames, primerNames); }
int numPrimers = pairedPrimers.size();
TrimOligos trimOligos(pdiffs, bdiffs, 0, 0, pairedPrimers, pairedBarcodes, true);
int numBarcodes = pairedBarcodes.size();
TrimOligos* rtrimOligos = nullptr;
if (reorient) { rtrimOligos = new TrimOligos(pdiffs, bdiffs, 0, 0, reorientedPairedPrimers, reorientedPairedBarcodes, true); numBarcodes = reorientedPairedBarcodes.size(); numPrimers = reorientedPairedPrimers.size(); }
ifstream in; util.openInputFile(findexfile, in);
while (!in.eof()) {
if (m->getControl_pressed()) { break; }
bool ignore = false;
FastqRead index(in, ignore, format); gobble(in);
int success = 1;
string trashCode = "";
string commentString = "";
int currentSeqsDiffs = 0;
int barcodeIndex = 0;
Sequence fSeq, rSeq;
QualityScores* fQual = nullptr; QualityScores* rQual = nullptr;
QualityScores* savedFQual = nullptr; QualityScores* savedRQual = nullptr;
Sequence findexBarcode("findex", index.getSeq()); Sequence rindexBarcode("rindex", "NONE");
Sequence savedFindex("findex", index.getSeq()); Sequence savedRIndex("rindex", "NONE");
if(numBarcodes != 0){
vector<int> results;
results = trimOligos.stripBarcode(findexBarcode, rindexBarcode, *fQual, *rQual, barcodeIndex);
success = results[0] + results[2];
commentString += "fbdiffs=" + toString(results[0]) + "(" + trimOligos.getCodeValue(results[1], bdiffs) + "), rbdiffs=" + toString(results[2]) + "(" + trimOligos.getCodeValue(results[3], bdiffs) + ") ";
if(success > bdiffs) { trashCode += 'b'; }
else{ currentSeqsDiffs += success; }
}
if (reorient && (trashCode != "")) { //if you failed and want to check the reverse
int thisSuccess = 0;
string thisTrashCode = "";
string thiscommentString = "";
int thisCurrentSeqsDiffs = 0;
int thisBarcodeIndex = 0;
if(numBarcodes != 0){
vector<int> results;
results = rtrimOligos->stripBarcode(savedFindex, savedRIndex, *savedFQual, *savedRQual, thisBarcodeIndex);
thisSuccess = results[0] + results[2];
thiscommentString += "fbdiffs=" + toString(results[0]) + "(" + rtrimOligos->getCodeValue(results[1], bdiffs) + "), rbdiffs=" + toString(results[2]) + "(" + rtrimOligos->getCodeValue(results[3], bdiffs) + ") ";
if(thisSuccess > bdiffs) { thisTrashCode += 'b'; }
else{ thisCurrentSeqsDiffs += thisSuccess; }
}
if (thisTrashCode == "") {
trashCode = thisTrashCode;
success = thisSuccess;
currentSeqsDiffs = thisCurrentSeqsDiffs;
commentString = thiscommentString;
barcodeIndex = thisBarcodeIndex;
}else { trashCode += "(" + thisTrashCode + ")"; }
}
if (trashCode == "") {
string thisGroup = "";
if(numBarcodes != 0){ thisGroup = barcodeNames[barcodeIndex]; }
int pos = thisGroup.find("ignore");
if (pos == string::npos) {
if (thisGroup != "") {
groupMap[index.getName()] = thisGroup;
map<string, int>::iterator it = groupCounts.find(thisGroup);
if (it == groupCounts.end()) { groupCounts[thisGroup] = 1; }
else { groupCounts[it->first] ++; }
}
}
}
cout << index.getName() << '\t' << commentString << endl;
}
in.close();
int total = 0;
if (groupCounts.size() != 0) { m->mothurOut("\nGroup count: \n"); }
for (map<string, int>::iterator it = groupCounts.begin(); it != groupCounts.end(); it++) { total += it->second; m->mothurOut(it->first + "\t" + toString(it->second) + "\n"); }
if (total != 0) { m->mothurOut("\nTotal of all groups is " + toString(total) + "\n"); }
exit(1);
}
catch(exception& e) {
m->errorOut(e, "MakeContigsCommand", "debugFunction");
exit(1);
}
}
//**********************************************************************************************************************
|