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
|
package assemble;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import dna.AminoAcid;
import fileIO.ByteFile;
import fileIO.ByteStreamWriter;
import fileIO.FileFormat;
import fileIO.ReadWrite;
import fileIO.TextStreamWriter;
import jgi.BBMerge;
import kmer.AbstractKmerTableSet;
import kmer.HashBuffer;
import shared.KillSwitch;
import shared.Parse;
import shared.Parser;
import shared.PreParser;
import shared.Shared;
import shared.Timer;
import shared.Tools;
import shared.TrimRead;
import sort.ContigLengthComparator;
import stream.ConcurrentReadInputStream;
import stream.ConcurrentReadOutputStream;
import stream.FastaReadInputStream;
import stream.Read;
import structures.ByteBuilder;
import structures.IntList;
import structures.ListNum;
import structures.LongList;
import tracker.ReadStats;
import ukmer.Kmer;
import ukmer.KmerTableSetU;
/**
* Short-kmer assembler based on KmerCountExact.
* @author Brian Bushnell
* @date May 15, 2015
*
*/
public abstract class Tadpole extends ShaveObject{
/**
* Code entrance from the command line.
* @param args Command line arguments
*/
public static void main(String[] args){
Timer t=new Timer(), t2=new Timer();
t.start();
t2.start();
final Tadpole x=makeTadpole(args, true);
t2.stop();
outstream.println("Initialization Time: \t"+t2);
///And run it
x.process(t);
//Close the print stream if it was redirected
Shared.closeStream(outstream);
}
public static Tadpole makeTadpole(String[] args, boolean setDefaults){
final int k=preparseK(args);
if(k>31 || FORCE_TADPOLE2){
synchronized(Tadpole.class){
AbstractKmerTableSet.MASK_CORE=false;
}
return new Tadpole2(args, true);
}else{
synchronized(Tadpole.class){
AbstractKmerTableSet.MASK_CORE=true;
}
Tadpole tad=new Tadpole1(args, true);
// if(!tad.setShave){tad.removeDeadEnds=true;}
// if(!tad.setRinse){tad.removeBubbles=true;}
return tad;
}
}
public static final int preparseK(String[] args){
int k=31;
for(int i=0; i<args.length; i++){
final String arg=args[i];
String[] split=arg.split("=");
String a=split[0].toLowerCase();
String b=split.length>1 ? split[1] : null;
while(a.charAt(0)=='-'){a=a.substring(1);}
if(a.equals("k")){
k=Integer.parseInt(b);
}else if(a.equals("tad2") || a.equals("tadpole2")){
FORCE_TADPOLE2=Parse.parseBoolean(b);
}
}
return Kmer.getMult(k)*Kmer.getK(k);
}
/**
* Constructor.
* @param args Command line arguments
*/
public Tadpole(String[] args, boolean setDefaults){
{//Preparse block for help, config files, and outstream
PreParser pp=new PreParser(args, getClass(), true);
args=pp.args;
outstream=pp.outstream;
}
kbig=preparseK(args);
if(setDefaults){
/* Set global defaults */
ReadWrite.ZIPLEVEL=2;
ReadWrite.USE_UNPIGZ=true;
ReadWrite.USE_PIGZ=true;
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){
ByteFile.FORCE_MODE_BF2=true;
}
AbstractKmerTableSet.defaultMinprob=0.5;
}
/* Initialize local variables with defaults */
Parser parser=new Parser();
boolean ecc_=false, ecco_=false, merge_=false, testMerge_=true, vstrict_=false, setEcc_=false;
boolean useOwnership_=false, setUseOwnership_=false;
int prefilter=0;
/* Parse arguments */
for(int i=0; i<args.length; i++){
final String arg=args[i];
String[] split=arg.split("=");
String a=split[0].toLowerCase();
String b=split.length>1 ? split[1] : null;
if(a.equals("in") || a.equals("in1") || a.equals("ine") || a.equals("ine1")){
in1.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
in1.add(ss);
}
}
}else if(a.equals("in2") || a.equals("ine2")){
in2.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
in2.add(ss);
}
}
}else if(a.equals("extra")){
//Do nothing
}else if(a.equals("out") || a.equals("out1") || a.equals("oute") || a.equals("oute1")){
out1.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
out1.add(ss);
}
}
}else if(a.equals("out2") || a.equals("oute2")){
out2.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
out2.add(ss);
}
}
}else if(a.equals("outd") || a.equals("outdiscard") || a.equals("outd1") || a.equals("outdiscard1")){
outd1.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
outd1.add(ss);
}
}
}else if(a.equals("outd2") || a.equals("outdiscard2")){
outd2.clear();
if(b!=null){
String[] s=b.split(",");
for(String ss : s){
outd2.add(ss);
}
}
}else if(a.equals("dot") || a.equals("outdot")){
outDot=b;
}else if(a.equals("buildthreads") || a.equals("bt")){
BUILD_THREADS=Integer.parseInt(b);
}else if(a.equals("processcontigs")){
processContigs=Parse.parseBoolean(b);
}else if(a.equals("pop") || a.equalsIgnoreCase("popBubbles")){
popBubbles=Parse.parseBoolean(b);
}else if(a.equalsIgnoreCase("bubblePasses")){
bubblePasses=Tools.max(1, Integer.parseInt(b));
}else if(a.equalsIgnoreCase("popDirect")){
BubblePopper.popDirect=Parse.parseBoolean(b);
}else if(a.equalsIgnoreCase("popIndirect")){
BubblePopper.popIndirect=Parse.parseBoolean(b);
}else if(a.equalsIgnoreCase("debranch")){
BubblePopper.debranch=Parse.parseBoolean(b);
}else if(a.equals("etr") || a.equalsIgnoreCase("expandTandemRepeats")){
expandTandemRepeats=Parse.parseBoolean(b);
assert(false) : "TODO";
}else if(a.equals("outkmers") || a.equals("outk") || a.equals("dump")){
outKmers=b;
}else if(a.equals("mincounttodump")){
minToDump=Parse.parseIntKMG(b);
}else if(a.equals("maxcounttodump")){
maxToDump=Parse.parseIntKMG(b);
}else if(a.equals("hist") || a.equals("khist")){
outHist=b;
}else if(a.equals("gchist")){
gcHist=Parse.parseBoolean(b);
}else if(a.equals("ihist") || a.equals("inserthistogram")){
outInsert=b;
}else if(a.equals("append") || a.equals("app")){
append=ReadStats.append=Parse.parseBoolean(b);
}else if(a.equals("overwrite") || a.equals("ow")){
overwrite=Parse.parseBoolean(b);
}else if(a.equals("mode")){
assert(b!=null) : "Bad parameter: "+arg;
if(Tools.isDigit(b.charAt(0))){
processingMode=Parse.parseIntKMG(b);
}else if(b.equalsIgnoreCase("contig")){
processingMode=contigMode;
}else if(b.equalsIgnoreCase("extend")){
processingMode=extendMode;
}else if(b.equalsIgnoreCase("correct") || b.equalsIgnoreCase("ecc") || b.equalsIgnoreCase("ecct")){
processingMode=correctMode;
}else if(b.equalsIgnoreCase("insert")){
processingMode=insertMode;
}else if(b.equalsIgnoreCase("discard") || b.equalsIgnoreCase("toss") || b.equalsIgnoreCase("filter")){
processingMode=discardMode;
}else{
assert(false) : "Unknown mode "+b;
}
}else if(a.equals("ownership")){
if("auto".equalsIgnoreCase(b)){
setUseOwnership_=false;
}else{
useOwnership_=Parse.parseBoolean(b);
setUseOwnership_=true;
}
}else if(a.equals("showstats") || a.equals("stats")){
showStats=Parse.parseBoolean(b);
}else if(a.equals("maxextension") || a.equals("maxe")){
extendLeft=extendRight=Parse.parseIntKMG(b);
}else if(a.equals("extendright") || a.equals("er")){
extendRight=Parse.parseIntKMG(b);
}else if(a.equals("extendleft") || a.equals("el")){
extendLeft=Parse.parseIntKMG(b);
}else if(a.equals("extensionrollback") || a.equals("extendrollback")){
extensionRollback=Parse.parseIntKMG(b);
}else if(a.equals("minextension") || a.equals("mine")){
minExtension=Parse.parseIntKMG(b);
}else if(a.equals("maxcontiglength") || a.equals("maxcontig") || a.equals("maxlength") || a.equals("maxlen") || a.equals("maxc")){
maxContigLen=Parse.parseIntKMG(b);
if(maxContigLen<0){maxContigLen=1000000000;}
}else if(a.equals("mincontiglength") || a.equals("mincontiglen") || a.equals("mincontig") || a.equals("minc")){
if("auto".equalsIgnoreCase(b)){
minContigLen=-1;
}else{
minContigLen=Parse.parseIntKMG(b);
}
}else if(a.equals("mincoverage") || a.equals("mincov")){
minCoverage=Float.parseFloat(b);
}else if(a.equals("maxcoverage") || a.equals("maxcov")){
if(b.equalsIgnoreCase("inf")){maxCoverage=Float.MAX_VALUE;}
else{maxCoverage=Float.parseFloat(b);}
}else if(a.equals("branchlower") || a.equals("branchlowerconst") || a.equals("blc")){
branchLowerConst=Parse.parseIntKMG(b);
}else if(a.equals("branchmult2") || a.equals("bm2")){
branchMult2=Parse.parseIntKMG(b);
}else if(a.equals("branchmult") || a.equals("branchmult1") || a.equals("bm1")){
branchMult1=Parse.parseIntKMG(b);
}else if(a.equals("mincount") || a.equals("mindepth") || a.equals("min")){
minCountSeed=minCountExtend=Parse.parseIntKMG(b);
}else if(a.equals("mindepthseed") || a.equals("mds") || a.equals("mincountseed") || a.equals("mcs")){
minCountSeed=Parse.parseIntKMG(b);
}else if(a.equals("mindepthextend") || a.equals("mde") || a.equals("mincountextend") || a.equals("mce")){
minCountExtend=Parse.parseIntKMG(b);
}else if(a.equals("mincountretain") || a.equals("mincr") || a.equals("mindepthretain") || a.equals("mindr")){
kmerRangeMin=Parse.parseIntKMG(b);
}else if(a.equals("maxcountretain") || a.equals("maxcr") || a.equals("maxdepthretain") || a.equals("maxdr")){
kmerRangeMax=Parse.parseIntKMG(b);
}else if(a.equals("contigpasses")){
contigPasses=Parse.parseIntKMG(b);
}else if(a.equals("contigpassmult")){
contigPassMult=Double.parseDouble(b);
assert(contigPassMult>=1) : "contigPassMult must be at least 1.";
}else if(a.equals("threads") || a.equals("t")){
Shared.setThreads(b);
}else if(a.equals("showspeed") || a.equals("ss")){
showSpeed=Parse.parseBoolean(b);
}else if(a.equals("verbose")){
// assert(false) : "Verbose flag is currently static final; must be recompiled to change.";
verbose=Parse.parseBoolean(b);
}else if(a.equals("verbose2")){
// assert(false) : "Verbose flag is currently static final; must be recompiled to change.";
verbose2=Parse.parseBoolean(b);
}else if(a.equals("ordered")){
ordered=Parse.parseBoolean(b);
}else if(a.equals("reads") || a.startsWith("maxreads")){
maxReads=Parse.parseKMG(b);
}else if(a.equals("histcolumns")){
histColumns=Parse.parseIntKMG(b);
}else if(a.equals("histmax")){
histMax=Parse.parseIntKMG(b);
}else if(a.equals("histheader")){
histHeader=Parse.parseBoolean(b);
}else if(a.equals("nzo") || a.equals("nonzeroonly")){
histZeros=!Parse.parseBoolean(b);
}else if(a.equals("ilb") || a.equals("ignoreleftbranches") || a.equals("ignoreleftjunctions") || a.equals("ibb") || a.equals("ignorebackbranches")){
extendThroughLeftJunctions=Parse.parseBoolean(b);
}else if(a.equals("ibo") || a.equals("ignorebadowner")){
IGNORE_BAD_OWNER=Parse.parseBoolean(b);
}else if(a.equals("tad2") || a.equals("tadpole2")){
FORCE_TADPOLE2=Parse.parseBoolean(b);
}
else if(a.equals("maskcore") || a.equals("coremask")){
AbstractKmerTableSet.MASK_CORE=Kmer.MASK_CORE=Parse.parseBoolean(b);
}else if(a.equals("fillfast") || a.equals("fastfill")){
AbstractKmerTableSet.FAST_FILL=Parse.parseBoolean(b);
}
//Shaver
else if(a.equals("shaverinse") || a.equals("shaveandrinse") || a.equals("wash") || a.equals("sr")){
if(b==null || Character.isLetter(b.charAt(0))){
removeDeadEnds=removeBubbles=Parse.parseBoolean(b);
}else{
maxShaveDepth=Integer.parseInt(b);
removeDeadEnds=removeBubbles=(maxShaveDepth>0);
}
setShave=setRinse=true;
}else if(a.equals("shave") || a.equals("removedeadends")){
if(b==null || Character.isLetter(b.charAt(0))){
removeDeadEnds=Parse.parseBoolean(b);
}else{
maxShaveDepth=Integer.parseInt(b);
removeDeadEnds=(maxShaveDepth>0);
}
setShave=true;
}else if(a.equals("rinse") || a.equals("shampoo") || a.equals("removebubbles")){
removeBubbles=Parse.parseBoolean(b);
setRinse=true;
}else if(a.equals("maxshavedepth") || a.equals("shavedepth") || a.equals("msd")){
maxShaveDepth=Integer.parseInt(b);
}else if(a.equals("shavediscardlength") || a.equals("shavelength") || a.equals("discardlength") || a.equals("sdl")){
shaveDiscardLen=Integer.parseInt(b);
}else if(a.equals("shaveexploredistance") || a.equals("shaveexploredist") || a.equals("exploredist") || a.equals("sed")){
shaveExploreDist=Integer.parseInt(b);
}else if(a.equals("printeventcounts")){
Shaver.printEventCounts=Parse.parseBoolean(b);
}else if(a.equalsIgnoreCase("startFromHighCounts")){
Shaver.startFromHighCounts=Parse.parseBoolean(b);
}else if(a.equalsIgnoreCase("shaveFast") || a.equalsIgnoreCase("fastShave")){
Shaver.shaveFast=Parse.parseBoolean(b);
}
//Junk removal
else if(a.equals("tossjunk") || a.equals("tj")){
tossJunk=Parse.parseBoolean(b);
}else if(a.equals("tossdepth") || a.equals("discarddepth")){
discardLowDepthReads=Integer.parseInt(b);
}else if(a.equals("lowdepthfraction") || a.equals("ldf") || a.equals("lcf") || a.equals("lddf")){
lowDepthDiscardFraction=Float.parseFloat(b);
}else if(a.equals("requirebothbad") || a.equals("rbb")){
requireBothBad=Parse.parseBoolean(b);
}else if(a.equals("tossuncorrectable") || a.equals("tu")){
discardUncorrectable=Parse.parseBoolean(b);
}
//Error Correction
else if(a.equals("ecctail") || a.equals("eccright") || a.equals("tail")){
ECC_TAIL=Parse.parseBoolean(b);
}else if(a.equals("pincer") || a.equals("eccpincer")){
ECC_PINCER=Parse.parseBoolean(b);
}else if(a.equals("reassemble") || a.equals("eccreassemble")){
ECC_REASSEMBLE=Parse.parseBoolean(b);
}else if(a.equals("rollback") || a.equals("eccrollback")){
ECC_ROLLBACK=Parse.parseBoolean(b);
}else if(a.equals("bidirectional") || a.equals("requirebidirectional") || a.equals("eccbidirectional") || a.equals("rbi") || a.equals("rb")){
ECC_REQUIRE_BIDIRECTIONAL=Parse.parseBoolean(b);
}else if(a.equals("eccall") || a.equals("eccfull")){
ECC_ALL=Parse.parseBoolean(b);
}else if(a.equals("aecc") || a.equals("aec") || a.equals("aggressive")){
ECC_AGGRESSIVE=Parse.parseBoolean(b);
if(ECC_AGGRESSIVE){
ECC_CONSERVATIVE=false;
ecc_=setEcc_=true;
}
}else if(a.equals("cecc") || a.equals("cec") || a.equals("conservative")){
ECC_CONSERVATIVE=Parse.parseBoolean(b);
if(ECC_CONSERVATIVE){
ECC_AGGRESSIVE=false;
ecc_=setEcc_=true;
}
}else if(a.equals("ecc") || a.equals("ecct")){
ecc_=Parse.parseBoolean(b);
setEcc_=true;
}else if(a.equals("ecco")){
ecco_=Parse.parseBoolean(b);
}else if(a.equals("merge")){
merge_=Parse.parseBoolean(b);
}else if(a.equals("testmerge")){
testMerge_=Parse.parseBoolean(b);
}else if(a.equals("testmergewidth")){
testMergeWidth=Integer.parseInt(b);
}else if(a.equals("testmergethresh")){
testMergeThresh=Integer.parseInt(b);
}else if(a.equals("testmergemult")){
testMergeMult=Parse.parseKMG(b);
}else if(a.equals("vstrict")){
vstrict_=Parse.parseBoolean(b);
}else if(a.equals("ep") || a.equals("errorpath")){
errorPath=Integer.parseInt(b);
}else if(a.equals("em1") || a.equals("errormult1")){
errorMult1=Float.parseFloat(b);
}else if(a.equals("em2") || a.equals("errormult2")){
errorMult2=Float.parseFloat(b);
}else if(a.equals("emq") || a.equals("errormultqfactor")){
errorMultQFactor=Float.parseFloat(b);
}else if(a.equals("elc") || a.equals("errorlowerconst")){
errorLowerConst=Integer.parseInt(b);
}else if(a.equals("mcc") || a.equals("mincountcorrect")){
minCountCorrect=Integer.parseInt(b);
}else if(a.equals("psc") || a.equals("pathsimilarityconstant")){
pathSimilarityConstant=Integer.parseInt(b);
}else if(a.equals("psf") || a.equals("pathsimilarityfraction")){
pathSimilarityFraction=Float.parseFloat(b);
}else if(a.equals("eer") || a.equals("errorextensionreassemble")){
errorExtensionReassemble=Integer.parseInt(b);
}else if(a.equals("eep") || a.equals("errorextensionpincer")){
errorExtensionPincer=Integer.parseInt(b);
}else if(a.equals("eet") || a.equals("errorextensiontail")){
errorExtensionTail=Integer.parseInt(b);
}else if(a.equals("dz") || a.equals("deadzone")){
deadZone=Integer.parseInt(b);
}else if(a.equals("window") || a.equals("windowlen") || a.equals("w")){
windowLen=Integer.parseInt(b);
}else if(a.equals("windowcount") || a.equals("windowlimit") || a.equals("wc")){
windowCount=Integer.parseInt(b);
}else if(a.equals("windowcounthq") || a.equals("windowlimithq") || a.equals("wchq")){
windowCountHQ=Integer.parseInt(b);
}else if(a.equals("hqthresh") || a.equals("windowhqthresh") || a.equals("hqt")){
windowHQThresh=(byte)Integer.parseInt(b);
}else if(a.equals("qualsum") || a.equals("windowqualsum") || a.equals("qs")){
windowQualSum=Integer.parseInt(b);
}
else if(a.equals("mbb") || a.equals("markbad") || a.equals("markbadbases")){
if(b==null){b="1";}
MARK_BAD_BASES=Integer.parseInt(b);
}else if(a.equals("mdo") || a.equals("markdeltaonly")){
MARK_DELTA_ONLY=Parse.parseBoolean(b);
}else if(a.equals("meo") || a.equals("markerrorreadsonly")){
MARK_ERROR_READS_ONLY=Parse.parseBoolean(b);
}else if(a.equals("mq") || a.equals("markquality")){
MARK_QUALITY=(byte)Integer.parseInt(b);
}
//Trimming
else if(a.equals("trim") || a.equals("trimends")){
if(b==null || Character.isLetter(b.charAt(0))){
if("auto".equalsIgnoreCase(b)){trimEnds=-1;}
else{trimEnds=Parse.parseBoolean(b) ? -1 : 0;}
}else{
trimEnds=Integer.parseInt(b);
}
}else if(a.equals("trimcircular") || a.equals("trimloop") || a.equals("trimlooploop")){
trimCircular=Parse.parseBoolean(b);
}
else if(a.equalsIgnoreCase("sortbuffers") || a.equalsIgnoreCase("sortbuffer")){
HashBuffer.SORT_BUFFERS=Parse.parseBoolean(b);
}
else if(Parser.parseCommonStatic(arg, a, b)){
//do nothing
}else if(Parser.parseZip(arg, a, b)){
//do nothing
}else if(Parser.parseQuality(arg, a, b)){
//do nothing
}else if(Parser.parseFasta(arg, a, b)){
//do nothing
}else if(parser.parseInterleaved(arg, a, b)){
//do nothing
}else if(parser.parseTrim(arg, a, b)){
//do nothing
}
else if(a.equals("prefilter")){
if(b==null){prefilter=2;}
else if(Character.isLetter(b.charAt(0))){prefilter=Parse.parseBoolean(b) ? 2 : 0;}
else{prefilter=Integer.parseInt(b);}
}else if(KmerTableSetU.isValidArgument(a)){
//Do nothing
}else{
throw new RuntimeException("Unknown parameter "+args[i]);
}
}
kmerRangeMin=Tools.max(prefilter+1, kmerRangeMin);
if(outDot!=null || popBubbles){processContigs=true;}
if(ECC_AGGRESSIVE){
ECC_REQUIRE_BIDIRECTIONAL=false;
errorExtensionReassemble=0;
errorExtensionPincer=3;
errorExtensionTail=4;
errorMult1=Tools.max(4, errorMult1*0.6f);
minCountCorrect=Tools.min(minCountCorrect, 3);
deadZone=0;
pathSimilarityFraction*=1.4f;
windowCount=Tools.max(windowCount, 6);
windowQualSum=Tools.min(windowQualSum, 65);
windowLen=Tools.min(windowLen, 12);
ECC_REQUIRE_BIDIRECTIONAL=false;
}else if(ECC_CONSERVATIVE){
errorExtensionReassemble+=2;
errorExtensionPincer+=2;
errorExtensionTail+=2;
errorMult1=(errorMult1*1.2f);
minCountCorrect=Tools.max(minCountCorrect, 4);
deadZone=Tools.max(deadZone+1, 5);
pathSimilarityFraction*=0.8f;
windowLen=Tools.max(windowLen, 12);
windowCount=Tools.min(windowCount, 4);
windowQualSum=Tools.min(windowQualSum, 65);
ECC_REQUIRE_BIDIRECTIONAL=true;
ECC_ROLLBACK=true;
}
// assert(false) : ECC_REASSEMBLE;
if(trimEnds<0){
trimEnds=kbig/2;
}
if(minContigLen<0){
minContigLen=Tools.max(124, 2*kbig);
}
if(verbose){
BubblePopper.verbose=true;
// assert(false) : "Verbose is disabled.";
// AbstractKmerTableU.verbose=true;
}
THREADS=Shared.threads();
assert(kmerRangeMax>=kmerRangeMin) : "kmerRangeMax must be at least kmerRangeMin: "+kmerRangeMax+", "+kmerRangeMin;
if(processingMode<0){//unset
if(ecc_ || discardUncorrectable){
processingMode=correctMode;
outstream.println("Switching to correct mode because ecc=t.");
}else if(extendLeft>0 || extendRight>0){
processingMode=extendMode;
outstream.println("Switching to extend mode because an extend flag was set.");
}else if(tossJunk || discardLowDepthReads>0){
processingMode=discardMode;
outstream.println("Switching to discard mode because a discard flag was set.");
}else{
processingMode=contigMode;
//outstream.println("Operating in contig mode.");
}
}
if(processingMode==extendMode || processingMode==correctMode || processingMode==discardMode){
// {//Use in and out if ine and oute are not specified, in this mode.
// if(ine1.isEmpty() && ine2.isEmpty()){
// ine1.addAll(in1);
// ine2.addAll(in2);
// }
// if(oute1.isEmpty() && oute2.isEmpty() && outContigs!=null){
// oute1.add(outContigs);
// }
// }
if(processingMode==extendMode){
if(extendLeft==-1){extendLeft=100;}
if(extendRight==-1){extendRight=100;}
}else if(processingMode==correctMode){
// extendLeft=extendRight=0;
if(!setEcc_){ecc_=true;}
}else if(processingMode==discardMode){
extendLeft=extendRight=0;
if(!setEcc_){ecc_=false;}
}
}
{//Process parser fields
Parser.parseQuality("","","");
Parser.processQuality();
}
if(setUseOwnership_){
useOwnership=useOwnership_;
}else{
useOwnership=(processingMode==contigMode || removeBubbles || removeDeadEnds);
}
final int extraBytesPerKmer;
{
int x=0;
if(useOwnership){x+=4;}
if(processingMode==correctMode || processingMode==discardMode){}
else if(processingMode==contigMode || processingMode==extendMode){x+=1;}
extraBytesPerKmer=x;
}
/* Set final variables; post-process and validate argument combinations */
ecc=ecc_;
ecco=ecco_;
merge=merge_;
testMerge=testMerge_;
vstrict=vstrict_;
/* Adjust I/O settings and filenames */
assert(FastaReadInputStream.settingsOK());
for(int i=0; i<in1.size(); i++){
String s=in1.get(i);
if(s!=null && s.contains("#") && !new File(s).exists()){
int pound=s.lastIndexOf('#');
String a=s.substring(0, pound);
String b=s.substring(pound+1);
in1.set(i, a+1+b);
in2.add(a+2+b);
}
}
for(int i=0; i<out1.size(); i++){
String s=out1.get(i);
if(s!=null && s.contains("#")){
int pound=s.lastIndexOf('#');
String a=s.substring(0, pound);
String b=s.substring(pound+1);
out1.set(i, a+1+b);
out2.add(a+2+b);
}
}
for(int i=0; i<outd1.size(); i++){
String s=outd1.get(i);
if(s!=null && s.contains("#")){
int pound=s.lastIndexOf('#');
String a=s.substring(0, pound);
String b=s.substring(pound+1);
outd1.set(i, a+1+b);
outd2.add(a+2+b);
}
}
nextTable=new AtomicInteger[contigPasses];
nextVictims=new AtomicInteger[contigPasses];
for(int i=0; i<contigPasses; i++){
nextTable[i]=new AtomicInteger(0);
nextVictims[i]=new AtomicInteger(0);
}
if(!Tools.testOutputFiles(overwrite, append, false, outKmers, outHist)){
throw new RuntimeException("\nCan't write to some output files; overwrite="+overwrite+"\n");
}
if(!Tools.testOutputFiles(overwrite, append, false, out1, out2)){
throw new RuntimeException("\nCan't write to some output files; overwrite="+overwrite+"\n");
}
in1=Tools.fixExtension(in1);
in2=Tools.fixExtension(in2);
assert(!in1.isEmpty()) : "Requires at least one input file.";
if(!Tools.testInputFiles(true, true, in1, in2)){
throw new RuntimeException("\nCan't read some input files.\n");
}
assert(THREADS>0);
outstream.println("Using "+THREADS+" threads.");
}
/*--------------------------------------------------------------*/
/*---------------- Outer Methods ----------------*/
/*--------------------------------------------------------------*/
public final void process(Timer t){
/* Check for output file collisions */
Tools.testOutputFiles(overwrite, append, false, outKmers, outHist);
/* Count kmers */
process2(processingMode);
if(THREADS>1 && outHist!=null && outKmers!=null){
Timer tout=new Timer();
tout.start();
Thread a=new DumpKmersThread();
Thread b=new MakeKhistThread();
a.start();
b.start();
while(a.getState()!=Thread.State.TERMINATED){
try {
a.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while(b.getState()!=Thread.State.TERMINATED){
try {
b.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
tout.stop();
outstream.println("Write Time: \t"+tout);
}else{
if(outHist!=null){
makeKhist();
}
if(outKmers!=null){
dumpKmersAsText();
}
}
clearData();
/* Stop timer and calculate speed statistics */
t.stop();
if(showSpeed){
outstream.println("\nTotal Time: \t"+t);
if(processingMode==extendMode || processingMode==correctMode || processingMode==discardMode){
outstream.println(Tools.readsBasesProcessed(t.elapsed, readsIn, basesIn, 8));
}
}
{
String outContigs=out1.isEmpty() ? null : out1.get(0);
if(showStats && outContigs!=null && processingMode==contigMode && FileFormat.isFastaExt(ReadWrite.rawExtension(outContigs)) && !FileFormat.isStdio(outContigs)){
outstream.println();
jgi.AssemblyStats2.main(new String[] {"in="+outContigs, "printextended"});
}
}
/* Throw an exception if errors were detected */
if(errorState){
throw new RuntimeException(getClass().getSimpleName()+" terminated in an error state; the output may be corrupt.");
}
}
abstract void makeKhist();
abstract void dumpKmersAsText();
public abstract long loadKmers(Timer t);
public final void clearData(){
allContigs=null;
tables().clear();
}
public final void process2(int mode){
/* Start phase timer */
Timer t=new Timer();
/* Fill tables with kmers */
outstream.println("\nLoading kmers.\n");
loadKmers(t);
t.stop();
// outstream.println("Input: \t"+tables.readsIn+" reads \t\t"+tables.basesIn+" bases.");
// outstream.println("Unique Kmers: \t"+tables.kmersLoaded);
// outstream.println("Load Time: \t"+t);
t.start();
if(kmerRangeMin>1 || kmerRangeMax<Integer.MAX_VALUE){
AbstractRemoveThread.process(THREADS, kmerRangeMin, kmerRangeMax, tables(), true);
}
shaveAndRinse(t, removeDeadEnds, removeBubbles, true);
if(mode==extendMode || mode==correctMode || mode==discardMode){
outstream.println("\nExtending/error-correcting/discarding.\n");
final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR;
Read.VALIDATE_IN_CONSTRUCTOR=false;
extendReads();
Read.VALIDATE_IN_CONSTRUCTOR=vic;
if(DISPLAY_PROGRESS){
outstream.println("\nAfter extending reads:");
Shared.printMemory();
outstream.println();
}
t.stop();
outstream.println("Input: \t"+readsIn+" reads \t\t"+basesIn+" bases.");
outstream.println("Output: \t"+readsIn+" reads \t\t"+(basesIn+basesExtended)+" bases.");
if(extendLeft>0 || extendRight>0){
outstream.println("Bases extended: \t"+basesExtended);
outstream.println("Reads extended: \t"+readsExtended+Tools.format(" \t(%.2f%%)", readsExtended*100.0/readsIn));
}
if(ecc){
long partial=(readsCorrected-readsFullyCorrected);
outstream.println("Errors detected: \t"+(basesDetected+basesCorrectedEcco));
{
final long corrected=(basesCorrectedTail+basesCorrectedPincer+basesCorrectedReassemble+basesCorrectedEcco);
StringBuilder sb=new StringBuilder();
sb.append("Errors corrected: \t"+Tools.padRight(corrected, 7)+" \t(");
String comma="";
if(ECC_PINCER){
sb.append(comma).append(basesCorrectedPincer+" pincer");
comma=", ";
}
if(ECC_TAIL || ECC_ALL){
sb.append(comma).append(basesCorrectedTail+" tail");
comma=", ";
}
if(ECC_REASSEMBLE){
sb.append(comma).append(basesCorrectedReassemble+" reassemble");
comma=", ";
}
if(ecco || merge){
sb.append(comma).append(basesCorrectedEcco+" overlap");
comma=", ";
}
sb.append(")");
outstream.println(sb);
}
if(ecco || merge){outstream.println("Reads merged: \t"+Tools.padRight(readsMerged, 7)+
Tools.format(" \t(%.2f%%)", readsMerged*200.0/readsIn));}
outstream.println("Reads with errors detected: \t"+Tools.padRight(readsDetected, 7)+
Tools.format(" \t(%.2f%%)", readsDetected*100.0/readsIn));
outstream.println("Reads fully corrected: \t"+Tools.padRight(readsFullyCorrected, 7)+
Tools.format(" \t(%.2f%% of detected)", readsFullyCorrected*100.0/readsDetected));
outstream.println("Reads partly corrected: \t"+Tools.padRight(partial, 7)+
Tools.format(" \t(%.2f%% of detected)", partial*100.0/readsDetected));
if(ECC_ROLLBACK || rollbacks>0){
outstream.println("Rollbacks: \t"+Tools.padRight(rollbacks, 7)+
Tools.format(" \t(%.2f%% of detected)", rollbacks*100.0/readsDetected));
}
}
if(tossJunk || discardLowDepthReads>=0 || discardUncorrectable){
outstream.println("Reads discarded: \t"+readsDiscarded+Tools.format(" \t(%.2f%%)", readsDiscarded*100.0/readsIn));
outstream.println("Bases discarded: \t"+basesDiscarded+Tools.format(" \t(%.2f%%)", basesDiscarded*100.0/basesIn));
}
if(MARK_BAD_BASES>0){
outstream.println("Reads marked: \t"+readsMarked+Tools.format(" \t(%.2f%%)", readsMarked*100.0/readsIn));
outstream.println("Bases marked: \t"+basesMarked+Tools.format(" \t(%.2f%%)", basesMarked*100.0/basesIn));
}
outstream.println("Extend/error-correct time: \t"+t);
}else{
/* Build contigs */
outstream.println("\nBuilding contigs.\n");
buildContigs(mode);
if(DISPLAY_PROGRESS){
outstream.println("\nAfter building contigs:");
Shared.printMemory();
outstream.println();
}
t.stop();
if(readsIn>0){outstream.println("Input: \t"+readsIn+" reads \t\t"+basesIn+" bases.");}
outstream.println("Bases generated: \t"+basesBuilt);
outstream.println("Contigs generated: \t"+contigsBuilt);
outstream.println("Longest contig: \t"+longestContig);
if(popBubbles){outstream.println("Bubbles popped: \t"+bubblesPopped);}
outstream.println("Contig-building time: \t"+t);
}
}
/*--------------------------------------------------------------*/
/*---------------- Inner Methods ----------------*/
/*--------------------------------------------------------------*/
public final long shaveAndRinse(Timer t, boolean shave, boolean rinse, boolean print){
long removed=0;
if(shave || rinse){
if(print){
if(rinse && shave){
outstream.println("\nRemoving dead ends and error bubbles.");
}else if(shave){
outstream.println("\nRemoving dead ends.");
}else if(rinse){
outstream.println("\nRemoving error bubbles.");
}
}
removed=shave(shave, rinse);
t.stop();
if(print){
outstream.println("Kmers removed: \t"+removed);
outstream.println("Removal time: \t"+t);
}
t.start();
}
return removed;
}
abstract long shave(boolean shave, boolean rinse);
abstract void initializeOwnership();
/**
* Build contigs.
*/
private final void buildContigs(final int mode){
if(mode==contigMode){
allContigs=new ArrayList<Contig>();
allInserts=null;
if(useOwnership){
Timer t=new Timer(outstream, true);
t.start("Initializing ownership.");
initializeOwnership();
t.stop("Time: ");
}
}else if(mode==insertMode){
allContigs=null;
allInserts=new LongList();
}else if(mode==extendMode){
throw new RuntimeException("extendMode: TODO");
}else{
throw new RuntimeException("Unknown mode "+mode);
}
/* Create read input stream */
final ConcurrentReadInputStream[] crisa=(mode==contigMode ? null : makeCrisArray(in1, in2));
runBuildThreads(mode, crisa);
/* Shut down I/O streams; capture error status */
if(crisa!=null){
for(ConcurrentReadInputStream cris : crisa){
errorState|=ReadWrite.closeStreams(cris);
}
}
if(allContigs!=null){
ContigLengthComparator.comparator.setAscending(false);
Shared.sort(allContigs, ContigLengthComparator.comparator);
if(processContigs){
processContigs();
}
}
if(outInsert!=null){
FileFormat ff=FileFormat.testOutput(outInsert, FileFormat.TEXT, 0, 0, true, overwrite, append, false);
TextStreamWriter tsw=new TextStreamWriter(ff);
tsw.start();
for(int i=0; i<allInserts.size; i++){
long count=allInserts.get(i);
if(count>0 || histZeros){
tsw.print(i+"\t"+count+"\n");
}
}
errorState|=tsw.poisonAndWait();
}
String outContigs=out1.isEmpty() ? null : out1.get(0);
if(outContigs!=null){
FileFormat ff=FileFormat.testOutput(outContigs, FileFormat.FA, 0, 0, true, overwrite, append, false);
// ConcurrentReadOutputStream ros=ConcurrentReadOutputStream.getStream(ff, null, null, null, 4, null, false);
// ros.start();
ByteStreamWriter bsw=new ByteStreamWriter(ff);
bsw.start();
if(allContigs!=null){
for(int i=0; i<allContigs.size(); i++){
Contig r=allContigs.get(i);
if(r.length()>=minContigLen){
bsw.println(r);
}
}
}
errorState|=bsw.poisonAndWait();
}
}
void runBuildThreads(int mode, ConcurrentReadInputStream[] crisa){
Timer t=new Timer(outstream, true);
if(BUILD_THREADS<1){BUILD_THREADS=THREADS;}
/* Create ProcessThreads */
ArrayList<AbstractBuildThread> alpt=new ArrayList<AbstractBuildThread>(BUILD_THREADS);
for(int i=0; i<BUILD_THREADS; i++){alpt.add(makeBuildThread(i, mode, crisa));}
for(AbstractBuildThread pt : alpt){pt.start();}
/* Wait for threads to die, and gather statistics */
for(AbstractBuildThread pt : alpt){
while(pt.getState()!=Thread.State.TERMINATED){
try {
pt.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(Contig contig : pt.contigs){
allContigs.add(contig);
contigsBuilt++;
basesBuilt+=contig.length();
longestContig=Tools.max(longestContig, contig.length());
}
if(allInserts!=null){
allInserts.incrementBy(pt.insertSizes);
}
readsIn+=pt.readsInT;
basesIn+=pt.basesInT;
lowqReads+=pt.lowqReadsT;
lowqBases+=pt.lowqBasesT;
}
t.stop("Time: ");
}
void processContigs(){
// outstream.println("Initializing contigs.\n");
Timer t=new Timer(outstream, true);
outstream.println("Making contig graph.");
initializeContigs(allContigs);
runProcessContigThreads();
outstream.println("Finished contig graph.");
t.stop("Time: ");
if(popBubbles){
t.start();
for(int popped=1, i=0; popped>0 && i<bubblePasses; i++){
popped=popBubbles(BubblePopper.debranch && (i==bubblePasses-1));
}
t.stop("Time: ");
}
if(outDot!=null){
outstream.println("Writing contig graph.");
FileFormat ff=FileFormat.testOutput(outDot, FileFormat.TEXT, null, true, overwrite, append, false);
ByteStreamWriter bsw=new ByteStreamWriter(ff);
bsw.start();
ByteBuilder bb=new ByteBuilder(1000);
bb.append("digraph G {\n");
for(Contig c : allContigs){
bb.tab().append(c.id);
bb.append(" [label=\"id=").append(c.id);
bb.append("\\nlen=").append(c.bases.length);
bb.append("\\ncov=").append(c.coverage, 1);
bb.append("\\nleft=").append(codeStrings[c.leftCode]);
bb.append("\\nright=").append(codeStrings[c.rightCode]).append("\"]").append('\n');
if(c.leftEdges!=null){
for(Edge e : c.leftEdges){
bb.tab();
e.toDot(bb);
}
}
if(c.rightEdges!=null){
for(Edge e : c.rightEdges){
bb.tab();
e.toDot(bb);
}
}
bsw.print(bb);
bb.clear();
}
bb.append("}\n");
bsw.print(bb);
bsw.poisonAndWait();
}
}
HashMap<Integer, ArrayList<Edge>> destToEdgeMap(){
HashMap<Integer, ArrayList<Edge>> destToEdgeMap=new HashMap<Integer, ArrayList<Edge>>();
for(Contig c : allContigs){
if(!c.used() && !c.associate()){
if(c.leftEdges!=null){
for(Edge e : c.leftEdges){
Integer d=e.destination;
ArrayList<Edge> list=destToEdgeMap.get(d);
if(list==null){
list=new ArrayList<Edge>(2);
destToEdgeMap.put(d, list);
}
list.add(e);
}
}
if(c.rightEdges!=null){
for(Edge e : c.rightEdges){
Integer d=e.destination;
ArrayList<Edge> list=destToEdgeMap.get(d);
if(list==null){
list=new ArrayList<Edge>(2);
destToEdgeMap.put(d, list);
}
list.add(e);
}
}
}
}
return destToEdgeMap;
}
int popBubbles(boolean debranch){
outstream.println("Popping bubbles; contigs="+allContigs.size());
HashMap<Integer, ArrayList<Edge>> destToEdgeMap=destToEdgeMap();
int bubblesPoppedThisPass=0;
BubblePopper bp=new BubblePopper(allContigs, destToEdgeMap, kbig);
if(debranch) {
for(Contig c : allContigs){
bp.debranch(c);
}
}
for(Contig c : allContigs){
if(!c.used() && (c.leftForwardBranch() || c.rightForwardBranch())) {
bubblesPoppedThisPass+=bp.expand(c);
}
}
ArrayList<Contig> temp=new ArrayList<Contig>(allContigs.size());
basesBuilt=0;
contigsBuilt=0;
longestContig=0;
for(Contig c : allContigs){
if(c.used()){
// assert(bp.validate(c));
//Potentially do something about inbound edges... there shouldn't be any, though.
}else{
bp.removeDeadEdges(c);//Should not be necessary but found cases where it is.
// assert(bp.validate(c));
temp.add(c);
final int len=c.length();
if(len>=minContigLen){
basesBuilt+=len;
contigsBuilt++;
longestContig=Tools.max(len, longestContig);
}
}
}
Shared.sort(temp, ContigLengthComparator.comparator);
int newID=0;
destToEdgeMap=destToEdgeMap();
for(Contig c : temp){
c.renumber(newID, destToEdgeMap.get(c.id));
newID++;
}
allContigs.clear();
allContigs.addAll(temp);
// destToEdgeMap=destToEdgeMap();
// bp=new BubblePopper(allContigs, destToEdgeMap, kbig);
//
// for(int i=0; i<allContigs.size(); i++){
//// assert(i<allContigs.size()) : i+", "+allContigs.size();
// Contig c=allContigs.get(i);
// assert(c.id==i);
// assert(bp.validate(c));
// }
// for(Contig c : temp){
// if(!c.used && c.length()>minContigLen){
//
// allContigs.add(c);
//
// int len=c.length();
// basesBuilt+=len;
// contigsBuilt++;
// longestContig=Tools.max(len, longestContig);
// }
// }
bubblesPopped+=bubblesPoppedThisPass;
outstream.println("Popped "+bubblesPoppedThisPass+" bubbles"+(bp.debranch ? "; removed "+bp.branchesRemoved+" branches." : "."));
return bubblesPoppedThisPass;
}
void runProcessContigThreads(){
/* Create ProcessThreads */
AtomicInteger next=new AtomicInteger(0);
ArrayList<AbstractProcessContigThread> alpt=new ArrayList<AbstractProcessContigThread>(THREADS);
for(int i=0; i<THREADS; i++){alpt.add(makeProcessContigThread(allContigs, next));}
for(AbstractProcessContigThread pt : alpt){pt.start();}
/* Wait for threads to die, and gather statistics */
for(AbstractProcessContigThread pt : alpt){
while(pt.getState()!=Thread.State.TERMINATED){
try {
pt.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
edgesMade+=pt.edgesMadeT;
}
}
abstract void initializeContigs(ArrayList<Contig> contigs);
abstract AbstractBuildThread makeBuildThread(int i, int mode, ConcurrentReadInputStream[] crisa);
abstract AbstractProcessContigThread makeProcessContigThread(ArrayList<Contig> contigs, AtomicInteger next);
/**
* Extend reads.
*/
private final void extendReads(){
/* Create read input stream */
final ConcurrentReadInputStream[] crisa=makeCrisArray(in1, in2);
/* Create read input stream */
final ConcurrentReadOutputStream[] rosa=makeCrosArray(out1, out2);
/* Create read input stream */
final ConcurrentReadOutputStream[] rosda=makeCrosArray(outd1, outd2);
/* Create ProcessThreads */
ArrayList<ExtendThread> alpt=new ArrayList<ExtendThread>(THREADS);
for(int i=0; i<THREADS; i++){alpt.add(new ExtendThread(i, crisa, rosa, rosda));}
for(ExtendThread pt : alpt){pt.start();}
/* Wait for threads to die, and gather statistics */
for(ExtendThread pt : alpt){
while(pt.getState()!=Thread.State.TERMINATED){
try {
pt.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
readsIn+=pt.readsInT;
basesIn+=pt.basesInT;
lowqReads+=pt.lowqReadsT;
lowqBases+=pt.lowqBasesT;
readsExtended+=pt.readsExtendedT;
basesExtended+=pt.basesExtendedT;
readsCorrected+=pt.readsCorrectedT;
basesCorrectedPincer+=pt.basesCorrectedPincerT;
basesCorrectedTail+=pt.basesCorrectedTailT;
basesCorrectedReassemble+=pt.basesCorrectedReassembleT;
readsFullyCorrected+=pt.readsFullyCorrectedT;
rollbacks+=pt.rollbacksT;
readsDetected+=pt.readsDetectedT;
basesDetected+=pt.basesDetectedT;
readsMarked+=pt.readsMarkedT;
basesMarked+=pt.basesMarkedT;
readsDiscarded+=pt.readsDiscardedT;
basesDiscarded+=pt.basesDiscardedT;
readsMerged+=pt.readsMergedT;
readsCorrectedEcco+=pt.readsCorrectedEccoT;
basesCorrectedEcco+=pt.basesCorrectedEccoT;
}
/* Shut down I/O streams; capture error status */
for(ConcurrentReadInputStream cris : crisa){
errorState|=ReadWrite.closeStreams(cris);
}
/* Shut down I/O streams; capture error status */
if(rosa!=null){
for(ConcurrentReadOutputStream ros : rosa){
errorState|=ReadWrite.closeStream(ros);
}
}
if(rosda!=null){
for(ConcurrentReadOutputStream ros : rosda){
errorState|=ReadWrite.closeStream(ros);
}
}
}
private final ConcurrentReadInputStream[] makeCrisArray(ArrayList<String> list1, ArrayList<String> list2){
final ConcurrentReadInputStream[] array;
array=new ConcurrentReadInputStream[list1.size()];
for(int i=0; i<list1.size(); i++){
String a=list1.get(i);
String b=(list2.size()>i ? list2.get(i): null);
if(verbose){outstream.println("Creating cris for "+a);}
final ConcurrentReadInputStream cris;
{
FileFormat ff1=FileFormat.testInput(a, FileFormat.FASTA, null, true, true);
FileFormat ff2=(b==null ? null : FileFormat.testInput(b, FileFormat.FASTA, null, true, true));
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ff1, ff2);
}
array[i]=cris;
}
return array;
}
private final static ConcurrentReadOutputStream[] makeCrosArray(ArrayList<String> list1, ArrayList<String> list2){
final ConcurrentReadOutputStream[] array;
array=new ConcurrentReadOutputStream[list1.size()];
for(int i=0; i<list1.size(); i++){
String a=list1.get(i);
String b=(list2.size()>i ? list2.get(i): null);
if(verbose){outstream.println("Creating cris for "+a);}
final ConcurrentReadOutputStream cris;
{
final int buff=(!ordered ? 12 : Tools.max(32, 2*Shared.threads()));
FileFormat ff1=FileFormat.testOutput(a, FileFormat.FASTQ, null, true, overwrite, append, ordered);
FileFormat ff2=(b==null ? null : FileFormat.testOutput(b, FileFormat.FASTQ, null, true, overwrite, append, ordered));
// assert(false) : list1+", "+list2;
cris=ConcurrentReadOutputStream.getStream(ff1, ff2, null, null, buff, null, false);
}
array[i]=cris;
}
return array;
}
/** Examines kmer counts around the merge borders to ensure the merge was not chimeric */
public boolean mergeOK(Read merged, final int len1, final int len2, final BitSet bs, final IntList countList, final Kmer kmer,
final int width, final int thresh, final long mult){
final int len=merged.length();
final int overlap=Tools.min(len, len1+len2-len);
final byte[] bases=merged.bases;
if(len<len1+width+1 || len<len2+width+1 || len<kbig+width){return true;}
// int valid=corrector.fillKmers(bases, kmers);
final int a=len-len2-1; //Base to left of first boundary
final int b=a+1; //Base to right of first boundary
final int c=len1-1;
final int d=c+1;
final int ak=a-kbig+1; //kmer to left of first boundary
final int bk=b; //kmer to right of first boundary
final int ck=c-kbig+1; //kmer to left of second boundary
final int dk=d; //kmer to right of second boundary
bs.clear();
if(ak-width>=0 && ak+width<len){bs.set(ak-width, ak+width+1);} //probably from ak-width+1
if(bk-width>=0 && ck+width<len){bs.set(bk-width, bk+width+1);} //Technically to bk+width
if(ck-width>=0 && bk+width<len){bs.set(ck-width, ck+width+1);}
if(dk-width>=0 && dk+width<len){bs.set(dk-width, dk+width+1);}
tables().fillSpecificCounts(bases, countList, bs, kmer);
if(ak-width>=0 && ak+width<len){
int min=countList.get(ak);
for(int i=ak-width+1; i<ak; i++){min=Tools.min(min, countList.get(i));}
int min2=countList.get(ak+1);
for(int i=ak+2; i<=ak+width; i++){min2=Tools.min(min2, countList.get(i));}
assert(min>=0 && min2>=0);
if(min>=thresh && min2<=1){return false;}
if(min2>0 && min>min2*mult){return false;}
}
if(ck-width>=0 && ck+width<len){
// if(dk>=len || countList.get(dk)>1){//Skip this operation if there is an error to the left
int min=countList.get(ck);
for(int i=ck-width+1; i<ck; i++){min=Tools.min(min, countList.get(i));}
int min2=countList.get(ck+1);
for(int i=ck+2; i<=ck+width; i++){min2=Tools.min(min2, countList.get(i));}
assert(min>=0 && min2>=0);
if(min>=thresh && min2<=1){return false;}
if(min2>0 && min>min2*mult){return false;}
// }
}
if(bk-width>=0 && bk+width<len){
// if(ak<0 || countList.get(ak)>1){//Skip this operation if there is an error to the right
int min=countList.get(bk);
for(int i=bk+1; i<=bk+width; i++){min=Tools.min(min, countList.get(i));}
int min2=countList.get(bk-1);
for(int i=bk-width; i<bk-1; i++){min2=Tools.min(min2, countList.get(i));}
assert(min>=0 && min2>=0);
if(min>=thresh && min2<=1){return false;}
if(min2>0 && min>min2*mult){return false;}
// }
}
if(dk-width>=0 && dk+width<len){
int min=countList.get(dk);
for(int i=dk+1; i<=dk+width; i++){min=Tools.min(min, countList.get(i));}
int min2=countList.get(dk-1);
for(int i=dk-width; i<dk-1; i++){min2=Tools.min(min2, countList.get(i));}
assert(min>=0 && min2>=0);
if(min>=thresh && min2<=1){return false;}
if(min2>0 && min>min2*mult){return false;}
}
return true;
}
/*--------------------------------------------------------------*/
/*---------------- Inner Classes ----------------*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
/*---------------- ExtendThread ----------------*/
/*--------------------------------------------------------------*/
/**
* Extends reads.
*/
private final class ExtendThread extends Thread{
/**
* Constructor
* @param id_
* @param crisa_ Read input stream array
* @param rosa_
* @param rosda_
*/
public ExtendThread(int id_, ConcurrentReadInputStream[] crisa_, ConcurrentReadOutputStream[] rosa_, ConcurrentReadOutputStream[] rosda_){
tid=id_;
crisa=crisa_;
rosa=rosa_;
rosda=rosda_;
leftCounts=extendThroughLeftJunctions ? null : KillSwitch.allocInt1D(4);
}
@Override
public void run(){
initializeThreadLocals();
for(int i=0; i<crisa.length; i++){
ConcurrentReadInputStream cris=crisa[i];
ConcurrentReadOutputStream ros=(rosa!=null && rosa.length>i ? rosa[i] : null);
ConcurrentReadOutputStream rosd=(rosda!=null && rosda.length>i ? rosda[i] : null);
synchronized(crisa){
if(!cris.started()){
cris.start();
}
}
if(ros!=null){
synchronized(rosa){
if(!ros.started()){
ros.start();
}
}
}
if(rosd!=null){
synchronized(rosda){
if(!rosd.started()){
rosd.start();
}
}
}
run(cris, ros, rosd);
}
}
private void run(ConcurrentReadInputStream cris, ConcurrentReadOutputStream ros, ConcurrentReadOutputStream rosd){
ListNum<Read> ln=cris.nextList();
ArrayList<Read> reads=(ln!=null ? ln.list : null);
//While there are more reads lists...
while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
final ArrayList<Read> listOut=new ArrayList<Read>(reads.size());
final ArrayList<Read> listOutD=(rosd==null ? null : new ArrayList<Read>(reads.size()));
//For each read (or pair) in the list...
for(int i=0; i<reads.size(); i++){
final Read r1=reads.get(i);
final Read r2=r1.mate;
processReadPair(r1, r2);
if(r1.discarded() && (r2==null || r2.discarded())){
readsDiscardedT+=r1.pairCount();
basesDiscardedT+=r1.pairLength();
if(listOutD!=null){listOutD.add(r1);}
}else{
listOut.add(r1);
}
}
if(ros!=null){ros.add(listOut, ln.id);}
if(rosd!=null){rosd.add(listOutD, ln.id);}
//Fetch a new read list
cris.returnList(ln);
ln=cris.nextList();
reads=(ln!=null ? ln.list : null);
}
cris.returnList(ln);
}
final int findOverlap(Read r1, Read r2, boolean ecc){
if(vstrict){
return BBMerge.findOverlapVStrict(r1, r2, ecc);
}else{
return BBMerge.findOverlapStrict(r1, r2, ecc);
}
}
private void processReadPair(final Read r10, final Read r20){
Read r1=r10, r2=r20;
if(verbose){outstream.println("Considering read "+r1.id+" "+new String(r1.bases));}
final String r2id=r1.mateId();
final int initialLength1=r1.length();
final int initialLength2=r1.mateLength();
readsInT++;
basesInT+=r1.length();
if(r2!=null){
readsInT++;
basesInT+=r2.length();
}
final Read r1_0=r1, r2_0=r2;
if((ecco || merge) && r1!=null && r2!=null && !r1.discarded() && !r2.discarded()){
final int insert=findOverlap(r1, r2, false);
if(merge){
if(insert>0){
r2.reverseComplement();
r1=r1.joinRead(insert);
r2.reverseComplement();
r2=null;
if(testMerge && !mergeOK(r1, initialLength1, initialLength2, mergeOKBitsetT, countList, kmerT, testMergeWidth, testMergeThresh, testMergeMult)){
r1=r1_0;
r2=r2_0;
}else{
r2_0.reverseComplement();
int errors=BBMerge.countErrors(r1_0, r2_0, r1);
r2_0.reverseComplement();
basesCorrectedEccoT+=errors;
readsCorrectedEccoT+=(errors>0 ? 1 : 0);
readsMergedT++;
}
}
}else if(ecco){
// findOverlap(r1, r2, true);
if(insert>0){
r2.reverseComplement();
Read merged=r1.joinRead(insert);
if(!testMerge || mergeOK(merged, initialLength1, initialLength2, mergeOKBitsetT, countList, kmerT, testMergeWidth, testMergeThresh, testMergeMult)){
int errors=BBMerge.errorCorrectWithInsert(r1, r2, insert);
basesCorrectedEccoT+=errors;
readsCorrectedEccoT+=(errors>0 ?1 : 0);
readsMergedT++;
}
r2.reverseComplement();
}
}
}
processRead(r1);
processRead(r2);
//Unmerge
if(merge && r2==null && r2id!=null && !trackerT.rollback){
final int to=r1.length()-1;
final int len=Tools.min(r1.length(), initialLength2);
r2=r1.subRead(to-len+1, to);
r2.setPairnum(1);
r2.reverseComplement();
r2.mate=r1;
r1.mate=r2;
r2.id=r2id;
if(r1.length()>initialLength1){
r1.bases=Arrays.copyOf(r1.bases, initialLength1);
if(r1.quality!=null){r1.quality=Arrays.copyOf(r1.quality, initialLength1);}
}
r10.bases=r1.bases;
r10.quality=r1.quality;
r10.flags=r1.flags;
r20.bases=r2.bases;
r20.quality=r2.quality;
r20.flags=r2.flags;
}
}
private void processRead(Read r){
if(r==null){return;}
if(!r.validated()){r.validate(true);}
if(r.discarded()){
lowqBasesT+=r.length();
lowqReadsT++;
return;
}
if(ecc || MARK_BAD_BASES>0){
final int corrected=errorCorrect(r, leftCounts, rightCounts, kmerList, countList, countList2, builderT, builderT2, trackerT, bitsetT, kmerT, kmerT2);
final int detected=trackerT.detected();
final int correctedPincer=trackerT.correctedPincer;
final int correctedTail=trackerT.correctedTail;
final int correctedReassemble=trackerT.correctedReassemble();
final int marked=trackerT.marked;
assert(corrected==correctedPincer+correctedTail+correctedReassemble) : corrected+", "+trackerT;
if(marked>0){
readsMarkedT++;
basesMarkedT+=marked;
}
if(trackerT.rollback){rollbacksT++;}
if(detected>0){
readsDetectedT++;
basesDetectedT+=detected;
if(corrected>0){
readsCorrectedT++;
basesCorrectedPincerT+=correctedPincer;
basesCorrectedTailT+=correctedTail;
basesCorrectedReassembleT+=correctedReassemble;
}
if(corrected==detected || (corrected>0 && countErrors(countList, r.quality)==0)){
readsFullyCorrectedT++;
}else if(discardUncorrectable){
r.setDiscarded(true);
if(r.mate!=null && !requireBothBad){
r.mate.setDiscarded(true);
return;
}else if(r.mate==null){return;}
}
}
}
if(tossJunk && isJunk(r, rightCounts, kmerT)){
r.setDiscarded(true);
return;
}
if(discardLowDepthReads>=0 && hasKmersAtOrBelow(r, discardLowDepthReads, lowDepthDiscardFraction, kmerT)){
r.setDiscarded(true);
if(r.mate!=null && !requireBothBad){
r.mate.setDiscarded(true);
return;
}else if(r.mate==null){return;}
}
int extensionRight=0, extensionLeft=0;
if(extendRight>0){
extensionRight=extendRead(r, builderT, leftCounts, rightCounts, extendRight, kmerT);
}
if(extendLeft>0){
r.reverseComplement();
extensionLeft=extendRead(r, builderT, leftCounts, rightCounts, extendLeft, kmerT);
r.reverseComplement();
}
if(extensionRollback>0){
int leftMod=0, rightMod=0;
if(extensionLeft>0 && extensionLeft<extendLeft){
leftMod=Tools.min(extensionLeft, (int)(r.numericID%(extensionRollback+1)));
extensionLeft-=leftMod;
}
if(extensionRight>0 && extensionRight<extendRight){
rightMod=Tools.min(extensionRight, (int)(r.numericID%(extensionRollback+1)));
extensionRight-=rightMod;
}
if(leftMod>0 || rightMod>0){TrimRead.trimByAmount(r, leftMod, rightMod, 0);}
}
final int extension=extensionRight+extensionLeft;
basesExtendedT+=extension;
readsExtendedT+=(extension>0 ? 1 : 0);
}
/*--------------------------------------------------------------*/
/** Input read stream */
private final ConcurrentReadInputStream[] crisa;
private final ConcurrentReadOutputStream[] rosa;
private final ConcurrentReadOutputStream[] rosda;
private final int[] leftCounts;
private final int[] rightCounts=KillSwitch.allocInt1D(4);
private final ErrorTracker trackerT=new ErrorTracker();
private final ByteBuilder builderT=new ByteBuilder();
private final ByteBuilder builderT2=new ByteBuilder();
private final Kmer kmerT=new Kmer(kbig);
private final Kmer kmerT2=new Kmer(kbig);
private final BitSet bitsetT=new BitSet(300);
private final BitSet mergeOKBitsetT=new BitSet(300);
private final LongList kmerList=new LongList();
private final IntList countList=new IntList();
private final IntList countList2=new IntList();
long readsInT=0;
long basesInT=0;
long lowqReadsT=0;
long lowqBasesT=0;
long readsExtendedT=0;
long basesExtendedT=0;
long readsCorrectedT=0;
long basesCorrectedPincerT=0;
long basesCorrectedTailT=0;
long basesCorrectedReassembleT=0;
long readsFullyCorrectedT=0;
long rollbacksT=0;
long readsDetectedT=0;
long basesDetectedT=0;
long readsMarkedT=0;
long basesMarkedT=0;
long readsDiscardedT=0;
long basesDiscardedT=0;
long readsMergedT=0;
long readsCorrectedEccoT=0;
long basesCorrectedEccoT=0;
private final int tid;
}
/*--------------------------------------------------------------*/
/*---------------- Extension Methods ----------------*/
/*--------------------------------------------------------------*/
public abstract int extendRead(Read r, ByteBuilder bb, int[] leftCounts, int[] rightCounts, int distance);
public abstract int extendRead(Read r, ByteBuilder bb, int[] leftCounts, int[] rightCounts, int distance, final Kmer kmer);
// {
// throw new RuntimeException("Must be overridden.");
// }
/**
* Extend these bases to the right by at most 'distance'.
* Stops at right junctions only.
* Does not claim ownership.
*/
public abstract int extendToRight2(final ByteBuilder bb, final int[] leftCounts, final int[] rightCounts, final int distance, boolean includeJunctionBase);
/**
* Extend these bases to the right by at most 'distance'.
* Stops at right junctions only.
* Does not claim ownership.
*/
public int extendToRight2(final ByteBuilder bb, final int[] leftCounts, final int[] rightCounts, final int distance, boolean includeJunctionBase, Kmer kmer){
throw new RuntimeException("Must be overridden.");
}
/*--------------------------------------------------------------*/
/*---------------- Junk Detection ----------------*/
/*--------------------------------------------------------------*/
/** Test a read to see if it could possibly assemble. */
public abstract boolean isJunk(Read r);
public abstract boolean isJunk(Read r, final int[] localLeftCounts, Kmer kmer);
/** True if at least fraction of the reads kmers are at or below count. */
public abstract boolean hasKmersAtOrBelow(Read r, int count, float fraction);
/** True if at least fraction of the reads kmers are at or below count. */
public abstract boolean hasKmersAtOrBelow(Read r, int count, float fraction, Kmer kmer);
/*--------------------------------------------------------------*/
/*---------------- Error Correction ----------------*/
/*--------------------------------------------------------------*/
public final int countErrors(IntList counts, byte[] quals){
int possibleErrors=0;
for(int i=1; i<counts.size; i++){
final int a=counts.get(i-1), b=counts.get(i);
boolean error;
if(quals!=null){
error=isErrorBidirectional(a, b, quals[i-1], quals[i+kbig-1]);
}else{
error=isErrorBidirectional(a, b, (byte)20, (byte)20);
}
if(error){
possibleErrors++;
i+=kbig;
}
}
return possibleErrors;
}
public abstract int errorCorrect(Read r);
public abstract int errorCorrect(Read r, final int[] leftCounts, final int[] rightCounts, LongList kmers, IntList counts, IntList counts2,
final ByteBuilder bb, final ByteBuilder bb2, final ErrorTracker tracker, final BitSet bs, Kmer kmer, Kmer kmer2);
public abstract int reassemble_inner(ByteBuilder bb, byte[] quals, final int[] rightCounts, IntList counts,
final int extension, final Kmer kmer, final Kmer kmer2);
public final int reassemble(final byte[] bases, final byte[] quals, final int[] rightCounts, final IntList counts, final IntList counts2,
final ErrorTracker tracker, final int errorExtension, final ByteBuilder bb, final ByteBuilder bb2, final Kmer kmer, final Kmer regenKmer, BitSet bs){
if(bases.length<kbig+1+deadZone){return 0;}
final ByteBuilder fromLeft=new ByteBuilder(bases.length);
final ByteBuilder fromRight=new ByteBuilder(bases.length);
int detected0=tracker.detectedReassemble;
int corrected=reassemble_pass(bases, quals, fromLeft, fromRight, rightCounts, counts, counts2, tracker, errorExtension, kmer, regenKmer, bs);
int correctedIncr=corrected;
int detectedIncr=tracker.detectedReassemble-detected0;
int uncorrected=detectedIncr-correctedIncr;
for(int passes=1; passes<6 && correctedIncr>0 && uncorrected>0; passes++){//Without a pass limit this could, in rare cases, make an infinite loop
tracker.detectedReassemble-=uncorrected;
detected0=tracker.detectedReassemble;
correctedIncr=reassemble_pass(bases, quals, fromLeft, fromRight, rightCounts, counts, counts2, tracker, errorExtension, kmer, regenKmer, bs);
corrected+=correctedIncr;
detectedIncr=tracker.detectedReassemble-detected0;
uncorrected=detectedIncr-correctedIncr;
}
return corrected;
}
public final int reassemble_pass(final byte[] bases, final byte[] quals, final ByteBuilder fromLeft, final ByteBuilder fromRight,
final int[] rightCounts, final IntList counts, final IntList counts2, final ErrorTracker tracker, final int errorExtension,
final Kmer kmer, final Kmer kmer2, final BitSet bs){
if(bases.length<kbig+1+deadZone){return 0;}
fromLeft.clear();
fromRight.clear();
for(byte b : bases){
fromLeft.append(b);
fromRight.append(b);
}
assert(counts.size>0) : counts+", "+bases.length;
counts2.clear();
counts2.addAll(counts);
reassemble_inner(fromLeft, quals, rightCounts, counts2, errorExtension, kmer, kmer2);
fromRight.reverseComplementInPlace();
counts2.clear();
counts2.addAll(counts);
counts2.reverse();
reassemble_inner(fromRight, quals, rightCounts, counts2, errorExtension, kmer, kmer2);
fromRight.reverseComplementInPlace();
// outstream.println(new String(fromRight));
// outstream.println(copy);
// outstream.println();
int correctedInner=0;
int correctedOuter=0;
int detectedInner=0;
int detectedOuter=0;
boolean rollback=false;
for(int i=0; i<bases.length; i++){
byte a=bases[i];
byte b=fromLeft.get(i);
byte c=fromRight.get(i);
if(a!=b || a!=c){
if(b==c){detectedInner++;}
else{
detectedOuter++;
if(a!=b && a!=c){
assert(b!=c);
rollback=true;
}
}
}
if(b==a){fromLeft.set(i, (byte)0);}
if(c==a){fromRight.set(i, (byte)0);}
}
final int detected=detectedInner+detectedOuter;
tracker.detectedReassemble+=detected;
if(rollback || detected==0){return 0;}
bs.clear();
int clearedLeft=clearWindow2(fromLeft, quals, windowLen, windowCount, windowQualSum/*, windowCountHQ, windowHQThresh*/);
fromRight.reverseInPlace();
Tools.reverseInPlace(quals);
int clearedRight=clearWindow2(fromRight, quals, windowLen, windowCount, windowQualSum/*, windowCountHQ, windowHQThresh*/);
fromRight.reverseInPlace();
Tools.reverseInPlace(quals);
for(int i=0; i<bases.length; i++){
byte a=bases[i];
byte b=fromLeft.get(i);
byte c=fromRight.get(i);
byte d=a;
if(b==0 && c==0){
//do nothing
}else if(b==c){
d=b;
}else if(b==0){
d=c;
}else if(c==0){
d=b;
}else if(b!=c){
// if(AminoAcid.isFullyDefined(a)){
// quals[i]=(byte)Tools.max(2, q-3);
// }
}
if(ECC_REQUIRE_BIDIRECTIONAL && b!=c && i>=kbig && i<bases.length-kbig){d=a;}//Clause to force pincer mode in the middle
if(d!=a){
byte q=(quals==null ? 30 : quals[i]);
if(b==c){
correctedInner++;
q=(byte)Tools.mid(q+qIncreasePincer, qMinPincer, qMaxPincer);
}else{
correctedOuter++;
q=(byte)Tools.mid(q+qIncreaseTail, qMinTail, qMaxTail);
}
if(!rollback){
bs.set(i);
bases[i]=d;
if(quals!=null){quals[i]=q;}
}
}
}
if(rollback && correctedInner+correctedOuter>0){
tracker.rollback=true;
return 0;
}
{
tracker.correctedReassembleInner+=correctedInner;
tracker.correctedReassembleOuter+=correctedOuter;
}
int corrected=correctedOuter+correctedInner;
if(corrected>0){
AbstractKmerTableSet tables=tables();
// counts.clear();
// tables.fillCounts(bases, counts, kmer);
tables.regenerateCounts(bases, counts, kmer, bs);
assert(counts.size>0);
}
return corrected;
}
private static int clearWindow2(final ByteBuilder bb, final byte[] quals, final int window,
final int limit, final int qsumLimit/*, final int limitHQ, final byte hqThresh*/){
final int len=bb.length;
final byte[] array=bb.array;
int cleared=0;
int count=0, countHQ=0, qsum=0;
for(int i=0, prev=-window; i<len; i++, prev++){
byte b=array[i];
if(b!=0 && (quals==null || quals[prev]>0)){
count++;
if(quals!=null){
qsum+=quals[i];
// if(quals!=null && quals[i]>=hqThresh){countHQ++;}
}
if(count>limit || qsum>qsumLimit /*|| countHQ>limitHQ*/){
for(int j=Tools.max(0, i-window), lim=bb.length(); j<lim; j++){
if(array[j]!=0){
array[j]=0;
cleared++;
}
}
return cleared;
}
}
if(prev>=0 && array[prev]>0 && (quals==null || quals[prev]>0)){
count--;
if(quals!=null){
countHQ--;
// if(quals[prev]>=hqThresh){qsum-=quals[i];}
}
}
}
return cleared;
}
/** Changes to N any base covered strictly by kmers with count below minCount */
public final int markBadBases(final byte[] bases, final byte[] quals, final IntList counts, final BitSet bs,
final int minCount, boolean deltaOnly, final byte markQuality){
if(counts.size<1){return 0;}
bs.clear();
assert(counts.size==bases.length-kbig+1) : counts.size+", "+bases.length;
// boolean flag=true;
for(int i=0; i<counts.size;){
final int count=counts.get(i);
if(count>=minCount){
bs.set(i, i+kbig);
i+=kbig;
}else{
// flag=false;
i++;
}
}
{//Last cycle
final int i=counts.size-1;
final int count=counts.get(i);
if(count>=minCount){
bs.set(i, i+kbig);
}
}
final int card=bs.cardinality();
final int toMark=bases.length-card;
int marked=0;
assert(card<=bases.length);
int consecutiveBad=0;
for(int i=0; i<bases.length; i++){
if(bs.get(i)){
consecutiveBad=0;
}else{
consecutiveBad++;
boolean mark=((quals!=null && quals[i]>markQuality) || bases[i]!='N');
if(mark && deltaOnly){
mark=(consecutiveBad>=kbig) || bs.get(i+1) || (i>0 && bs.get(i-1));
}
if(mark){
marked++;
if(markQuality<1){
bases[i]='N';
}
if(quals!=null){
quals[i]=Tools.min(quals[i], (bases[i]=='N' ? 0 : markQuality));
}
}
if(bases[i]=='N' || (quals!=null && quals[i]<=markQuality)){consecutiveBad=0;}
}
}
// assert(toMark==0 && flag) : "toMark="+toMark+"card="+card+"len="+bases.length+"\n"+bs+"\n"+new String(bases)+"\n"+counts+"\nminCount="+minCount+"\n";
return marked;
}
protected final boolean isSimilar(final int a, int loc1, int loc2, final IntList counts){
loc1=Tools.max(loc1, 0);
loc2=Tools.min(loc2, counts.size-1);
for(int i=loc1; i<=loc2; i++){
if(!isSimilar(a, counts.get(i))){return false;}
}
return true;
}
protected final boolean isSimilar(final int a, final int b){
int min=Tools.min(a, b);
int max=Tools.max(a, b);
int dif=max-min;
assert(dif>=0);
return (dif<pathSimilarityConstant || dif<max*pathSimilarityFraction);
}
protected final boolean isError(final int a, int loc1, int loc2, final IntList counts){
loc1=Tools.max(loc1, 0);
loc2=Tools.min(loc2, counts.size-1);
for(int i=loc1; i<=loc2; i++){
if(!isError(a, counts.get(i))){return false;}
}
return true;
}
protected final boolean isErrorBidirectional(final int a, final int b, final byte qa, final byte qb){
return (a>=b ? isError(a, b, qb) : isError(b, a, qa));
}
protected final boolean isError(final int high, final int low){
float em1;
if(errorPath==1){
em1=errorMult1;
}else if(errorPath==2){
// if(low<minCountCorrect && high>=minCountCorrect && high>2*low){return true;}
// final float em1=4;//Tools.mid(errorMult1, 4, low-1); //4;//(low<3 ? 4 : Tools.min(errorMult1, 2*low));
em1=Tools.mid(errorMult1, 4, low*1.6f-3);
// final float em1=4;
}else{throw new RuntimeException(""+errorPath);}
return (low*em1<high || (low<=errorLowerConst && high>=Tools.max(minCountCorrect, low*errorMult2)));
}
protected final boolean isError(final int high, final int low, final byte q){
float em1;
if(errorPath==1){
em1=errorMult1*(1+q*errorMultQFactor);
}else if(errorPath==2){
if(low<minCountCorrect && high>=minCountCorrect && q<20 && high>2*low){return true;}
// final float em1=errorMult1*(1+q*errorMultQFactor);
em1=Tools.mid(errorMult1, 4, low*(q<=10 ? 1.6f : 2f)-3); //final float em1=4;//(low<3 ? 4 : Tools.min(errorMult1, 2*low));
em1=em1*(1+q*errorMultQFactor);
}else{throw new RuntimeException(""+errorPath);}
return (low*em1<high || (low<=errorLowerConst && high>=Tools.max(minCountCorrect, low*errorMult2)));
}
protected final boolean isSubstitution(int ca, int errorExtension, byte qb, IntList counts){
final int cb=ca+1;
final int aCount=counts.get(ca);
final int bCount=counts.get(cb);
if(isError(aCount, bCount, qb) && isSimilar(aCount, ca-errorExtension, ca-1, counts) &&
isError(aCount, ca+2, ca+kbig, counts)){
final int cc=ca+kbig;
final int cd=cc+1;
if(cd<counts.size){
final int cCount=counts.get(cc);
final int dCount=counts.get(cd);
if(isError(aCount, dCount) || isError(dCount, cCount, qb)){
return true;
}
}else{return true;}
}
return false;
}
/*--------------------------------------------------------------*/
/*---------------- Helper Methods ----------------*/
/*--------------------------------------------------------------*/
protected static final Kmer getKmer(byte[] bases, int loc, Kmer kmer){
kmer.clear();
for(int i=loc, lim=loc+kmer.kbig; i<lim; i++){
byte b=bases[i];
int x=AminoAcid.baseToNumber[b];
if(x<0){return null;}
kmer.addRightNumeric(x);
}
assert(kmer.len==kmer.kbig);
return kmer;
}
protected final boolean isJunction(int rightMax, int rightSecond, int leftMax, int leftSecond){
if(isJunction(rightMax, rightSecond)){return true;}
return isJunction(leftMax, leftSecond);
}
/** Technically, returns true if it is junction or max */
protected final boolean isJunction(int max, int second){
if(second<1 || second*branchMult1<max || (second<=branchLowerConst && max>=Tools.max(minCountExtend, second*branchMult2))){
return false;
}
if(verbose){outstream.println("Breaking because second-highest was too high:\n" +
"max="+max+", second="+second+", branchMult1="+branchMult1+"\n" +
"branchLowerConst="+branchLowerConst+", minCountExtend="+minCountExtend+", branchMult2="+branchMult2+"\n" +
(second*branchMult1<max)+", "+(second<=branchLowerConst)+", "+(max>=Tools.max(minCountExtend, second*branchMult2)));}
return true;
}
float calcRatio(int[] counts){
int a=0, b=0;
for(int i=0; i<counts.length; i++){
int x=counts[i];
if(x>a){
b=a;
a=x;
}else if(x>b){
b=x;
}
}
return (b<1 ? 99f : ((float)a)/b);
}
/*--------------------------------------------------------------*/
/*---------------- Helper Classes ----------------*/
/*--------------------------------------------------------------*/
private final class DumpKmersThread extends Thread {
DumpKmersThread(){}
@Override
public void run(){
dumpKmersAsText();
}
}
private final class MakeKhistThread extends Thread {
MakeKhistThread(){}
@Override
public void run(){
makeKhist();
}
}
/*--------------------------------------------------------------*/
/*---------------- Fields ----------------*/
/*--------------------------------------------------------------*/
public abstract AbstractKmerTableSet tables();
// int ways; //MUST be set by subclass
/** Big kmer length */
final int kbig;
public final int k(){return kbig;}
private ArrayList<Contig> allContigs;
private LongList allInserts;
private long contigsBuilt=0;
private long basesBuilt=0;
private long longestContig=0;
protected boolean extendThroughLeftJunctions=true;
private boolean removeBubbles=false;
private boolean removeDeadEnds=false;
private boolean setShave=false;
private boolean setRinse=false;
protected int maxShaveDepth=1;
protected int shaveDiscardLen=150;
protected int shaveExploreDist=300;
protected int kmerRangeMin=0;
protected int kmerRangeMax=Integer.MAX_VALUE;
protected int processingMode=-1;
protected int extendLeft=-1;
protected int extendRight=-1;
protected int extensionRollback=3;
/** Track kmer ownership */
public final boolean useOwnership;
public int maxContigLen=1000000000;
public int minExtension=2;
public int minContigLen=-1;
public float minCoverage=1;
public float maxCoverage=Float.MAX_VALUE;
public boolean joinContigs;
int trimEnds=0;
boolean trimCircular=true;
int minCountSeed=3;
protected int minCountExtend=2;
protected float branchMult1=20;
protected float branchMult2=3;
private int branchLowerConst=3;
private int errorPath=1;
private float errorMult1=16;
private float errorMult2=2.6f;
private float errorMultQFactor=0.002f;
private int errorLowerConst=4;//3 seems fine
private int minCountCorrect=3;//5 is more conservative...
int minCountCorrect(){return minCountCorrect;}
private int pathSimilarityConstant=3;
private float pathSimilarityFraction=0.45f;//0.3
protected int errorExtensionReassemble=5;//default 2; higher is more conservative
protected int errorExtensionPincer=5;//default 5; higher is more conservative
protected int errorExtensionTail=9;//default 9; higher is more conservative
protected int deadZone=0;
protected int windowLen=12;
protected int windowCount=6;
protected int windowQualSum=80;
protected int windowCountHQ=2;
protected byte windowHQThresh=24;
protected byte qIncreasePincer=8;
protected byte qMinPincer=24;
protected byte qMaxPincer=32;
protected byte qIncreaseTail=4;
protected byte qMinTail=20;
protected byte qMaxTail=28;
public boolean showStats=true;
/** Has this class encountered errors while processing? */
public boolean errorState=false;
/** Input reads */
private ArrayList<String> in1=new ArrayList<String>(), in2=new ArrayList<String>();
/** Output reads */
private ArrayList<String> out1=new ArrayList<String>(), out2=new ArrayList<String>();
/** Output discarded reads */
private ArrayList<String> outd1=new ArrayList<String>(), outd2=new ArrayList<String>();
/** Output graph */
private String outDot=null;
// /** Extra reads */
// private ArrayList<String> extra=new ArrayList<String>();
// /** Contig output file */
// private String outContigs=null;
/** Insert size histogram */
private String outInsert=null;
/** Kmer count output file */
protected String outKmers=null;
/** Histogram output file */
protected String outHist=null;
/** Add gc information to kmer histogram */
protected boolean gcHist=false;
/** Histogram columns */
protected int histColumns=2;
/** Histogram rows */
protected int histMax=100000;
/** Print a histogram header */
protected boolean histHeader=true;
/** Histogram show rows with 0 count */
protected boolean histZeros=false;
protected boolean smoothHist=false;
/** Maximum input reads (or pairs) to process. Does not apply to references. -1 means unlimited. */
private long maxReads=-1;
long edgesMade=0;
long readsIn=0;
long basesIn=0;
long readsOut=0;
long basesOut=0;
long lowqReads=0;
long lowqBases=0;
long basesExtended=0;
long readsExtended=0;
long readsCorrected=0;
long basesCorrectedPincer=0;
long basesCorrectedTail=0;
long basesCorrectedReassemble=0;
long readsFullyCorrected=0;
long rollbacks=0;
long readsDetected=0;
long basesDetected=0;
long readsMarked=0;
long basesMarked=0;
long readsDiscarded=0;
long basesDiscarded=0;
long readsMerged=0;
long readsCorrectedEcco=0;
long basesCorrectedEcco=0;
protected boolean ECC_PINCER=false;
protected boolean ECC_TAIL=false;
protected boolean ECC_ALL=false;
protected boolean ECC_REASSEMBLE=true;
protected boolean ECC_AGGRESSIVE=false;
protected boolean ECC_CONSERVATIVE=false;
protected boolean ECC_ROLLBACK=true;
protected boolean ECC_REQUIRE_BIDIRECTIONAL=true;
/** Mark bases as bad if they are completely covered by kmers with a count below this */
protected int MARK_BAD_BASES=0;
/** Only mark bad bases that are adjacent to good bases */
protected boolean MARK_DELTA_ONLY=true;
/** Only mark bad bases in reads that appear to have errors */
protected boolean MARK_ERROR_READS_ONLY=true;
/** Assign this quality score to marked bases */
protected byte MARK_QUALITY=0;
/** Discard reads that cannot be assembled */
protected boolean tossJunk=false;
/** Discard reads with kmers below this depth */
protected int discardLowDepthReads=-1;
/** Only discard reads in which at least this fraction of kmers are low depth */
protected float lowDepthDiscardFraction=0f;
/** Only discard reads if both in a pair fail */
protected boolean requireBothBad=false;
/** Discard reads with uncorrectable errors */
protected boolean discardUncorrectable=false;
/** Look for contig-contig edges */
boolean processContigs=false;
/** Pop simple bubbles in contig graph */
boolean popBubbles=true;
int bubblePasses=1;
/** Expand simple tandem repeats in contig graph */
boolean expandTandemRepeats=false;
/*--------------------------------------------------------------*/
/*---------------- ThreadLocal Temps ----------------*/
/*--------------------------------------------------------------*/
protected final void initializeThreadLocals(){
if(localLeftCounts.get()!=null){return;}
localLeftCounts.set(new int[4]);
localRightCounts.set(new int[4]);
localExtraCounts.set(new int[4]);
localLongList.set(new LongList());
localIntList.set(new IntList());
localIntList2.set(new IntList());
localByteBuilder.set(new ByteBuilder());
localByteBuilder2.set(new ByteBuilder());
localBitSet.set(new BitSet(300));
localKmer.set(new Kmer(kbig));
localKmer2.set(new Kmer(kbig));
localTracker.set(new ErrorTracker());
}
protected ThreadLocal<int[]> localLeftCounts=new ThreadLocal<int[]>();
protected ThreadLocal<int[]> localRightCounts=new ThreadLocal<int[]>();
protected ThreadLocal<int[]> localExtraCounts=new ThreadLocal<int[]>();
protected ThreadLocal<LongList> localLongList=new ThreadLocal<LongList>();
protected ThreadLocal<IntList> localIntList=new ThreadLocal<IntList>();
protected ThreadLocal<IntList> localIntList2=new ThreadLocal<IntList>();
protected ThreadLocal<ByteBuilder> localByteBuilder=new ThreadLocal<ByteBuilder>();
protected ThreadLocal<ByteBuilder> localByteBuilder2=new ThreadLocal<ByteBuilder>();
protected ThreadLocal<BitSet> localBitSet=new ThreadLocal<BitSet>();
private ThreadLocal<Kmer> localKmer=new ThreadLocal<Kmer>();
private ThreadLocal<Kmer> localKmer2=new ThreadLocal<Kmer>();
protected ThreadLocal<ErrorTracker> localTracker=new ThreadLocal<ErrorTracker>();
protected Kmer getLocalKmer(){
Kmer local=localKmer.get();
local.clearFast();
return local;
}
protected Kmer getLocalKmer2(){
Kmer local=localKmer2.get();
local.clearFast();
return local;
}
/*--------------------------------------------------------------*/
/*---------------- Final Primitives ----------------*/
/*--------------------------------------------------------------*/
/** min kmer count to dump to text */
protected int minToDump=1;
/** max kmer count to dump to text */
protected int maxToDump=Integer.MAX_VALUE;
/** Correct via kmers */
final boolean ecc;
/** Correct via overlap */
final boolean ecco;
/** Use stricter settings for merging */
final boolean vstrict;
/** Merge, correct, and unmerge */
final boolean merge;
/** Check bordering counts to see if the merge seems correct */
final boolean testMerge;
int testMergeWidth=4;
long testMergeMult=80L;
int testMergeThresh=3;
/** For numbering contigs */
final AtomicLong contigNum=new AtomicLong(0);
int bubblesPopped=0;
int contigPasses=16;
double contigPassMult=1.7;
/** For controlling access to tables for contig-building */
final AtomicInteger nextTable[];
/** For controlling access to victim buffers for contig-building */
final AtomicInteger nextVictims[];
/*--------------------------------------------------------------*/
/*---------------- Static Fields ----------------*/
/*--------------------------------------------------------------*/
/** Permission to overwrite existing files */
public static boolean overwrite=true;
/** Permission to append to existing files */
public static boolean append=false;
/** Force output reads to stay in input order */
public static boolean ordered=false;
/** Print speed statistics upon completion */
public static boolean showSpeed=true;
/** Display progress messages such as memory usage */
public static boolean DISPLAY_PROGRESS=true;
/** Number of ProcessThreads */
public static int THREADS=Shared.threads();
/** Number of BuildThreads */
public static int BUILD_THREADS=-1;
/** Do garbage collection prior to printing memory usage */
private static final boolean GC_BEFORE_PRINT_MEMORY=false;
static boolean IGNORE_BAD_OWNER=false;
static boolean FORCE_TADPOLE2=false;
}
|