File: AbstractMapper.java

package info (click to toggle)
bbmap 38.90%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,520 kB
  • sloc: java: 265,882; sh: 14,954; python: 5,247; ansic: 2,074; perl: 96; xml: 38; makefile: 37
file content (2902 lines) | stat: -rwxr-xr-x 127,991 bytes parent folder | download | duplicates (2)
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
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
package align2;

import java.io.File;
import java.io.PrintStream;
import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.Locale;

import bloom.BloomFilter;
import dna.ChromosomeArray;
import dna.Data;
import fileIO.FileFormat;
import fileIO.ReadWrite;
import fileIO.TextStreamWriter;
import jgi.CoveragePileup;
import shared.KillSwitch;
import shared.Parse;
import shared.Parser;
import shared.PreParser;
import shared.ReadStats;
import shared.Shared;
import shared.Timer;
import shared.Tools;
import stream.ConcurrentLegacyReadInputStream;
import stream.ConcurrentReadInputStream;
import stream.ConcurrentReadOutputStream;
import stream.FASTQ;
import stream.RandomReadInputStream3;
import stream.Read;
import stream.ReadStreamWriter;
import stream.SamLine;
import stream.SequentialReadInputStream;
import stream.SiteScore;

/**
 * Abstract superclass created from BBMap variants.
 * Handles argument parsing, I/O stream initialization and shutdown,
 * thread management, statistics collection and formatting.
 * @author Brian Bushnell
 * @date Oct 15, 2013
 *
 */
public abstract class AbstractMapper {

	public AbstractMapper(String[] args){
		CoveragePileup.printCommand=false;
		if(Shared.COMMAND_LINE==null){
			Shared.COMMAND_LINE=(args==null ? null : args.clone());
			Shared.BBMAP_CLASS=this.getClass().getName();
			int x=Shared.BBMAP_CLASS.lastIndexOf('.');
			if(x>=0){Shared.BBMAP_CLASS=Shared.BBMAP_CLASS.substring(x+1);}
		}
		setDefaults();
		String[] args2=preparse0(args);
		String[] args3=preparse(args2);
		parse(args3);
		postparse(args3);
		setup();
		checkFiles();
	}
	
	final void abort(AbstractMapThread[] mtts, String message){
//		System.err.println("Attempting to abort.");
		closeStreams(cris, rosA, rosM, rosU, rosB);
		KillSwitch.kill(message==null ? "" : message);
//		if(mtts!=null){int x=shutDownThreads(mtts, true);}
//		if(message==null){throw new RuntimeException();}
//		throw new RuntimeException(message);
	}
	
	/** In megabytes */
	final void adjustThreadsforMemory(long threadMem){
		Runtime rt=Runtime.getRuntime();
		long mmemory=rt.maxMemory()/1000000;
		long tmemory=rt.totalMemory()/1000000;
		long fmemory=rt.freeMemory()/1000000;
		long umemory=tmemory-fmemory;
		long amemory=mmemory-umemory;
//		System.err.println("mmemory="+mmemory+", tmemory="+tmemory+", fmemory="+fmemory+", umemory="+umemory+", amemory="+amemory);
//		int maxThreads=Tools.max(1, (int)((amemory-70)/threadMem));
		int maxThreads=(int)((amemory-100)/threadMem);
		if(Shared.threads()>maxThreads){
			System.err.println("\nMax Memory = "+mmemory+" MB\nAvailable Memory = "+amemory+" MB");
			if(maxThreads<1){abort(null, "\n\nNot enough memory.  Please run on a node with at least "+((long)((umemory+100+threadMem)*1.15))+" MB.\n");}
			System.err.println("Reducing threads from "+Shared.threads()+" to "+maxThreads+" due to low system memory.");
			Shared.setThreads(maxThreads);
		}
	}
	
	abstract void setDefaults();
	
	abstract String[] preparse(String[] args);
	
	abstract void postparse(String[] args);

	abstract void setup();
	
	abstract void loadIndex();
	
	abstract void processAmbig2();
	
	abstract void testSpeed(String[] args);
	
	abstract void setSemiperfectMode();
	
	abstract void setPerfectMode();

	abstract void printSettings(int k);
	
	private final void parse(String[] args){
		
		{//Preparse block for help, config files, and outstream
			PreParser pp=new PreParser(args, getClass(), true);
			args=pp.args;
			outstream=pp.outstream;
		}
		
		Read.TO_UPPER_CASE=true;
		
		Timer t=new Timer();
		boolean setMaxIndel1=false, setMaxIndel2=false;
		boolean forceRebuild=false;
		Parser parser=new Parser();
		parser.minTrimLength=minTrimLength;
		
		for(int i=0; i<args.length; i++){
			final String arg=(args[i]==null ? "null" : args[i]);
			final String[] split=arg.split("=");
			final String a=split[0].toLowerCase();
			String b=split.length>1 ? split[1] : null;
			
			if(Parser.parseZip(arg, a, b)){
				if(a.equals("ziplevel") || a.equals("zl")){//Handle conflated term
					ziplevel=Integer.parseInt(b);
				}
			}else if(Parser.parseHist(arg, a, b)){
				//do nothing
			}else if(Parser.parseSam(arg, a, b)){
				//do nothing
			}else if(Parser.parseCommonStatic(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.parseCommon(arg, a, b)){
				//do nothing
			}else if(parser.parseMapping(arg, a, b)){
				//do nothing
			}else if(parser.parseTrim(arg, a, b)){
				//do nothing
			}else if(a.equals("printtoerr")){
				if(Parse.parseBoolean(b)){
					outstream=System.err;
					outstream=System.err;
				}
			}else if(a.equals("path") || a.equals("root")){
				Data.setPath(b);
			}else if(a.equals("ref") || a.equals("reference") || a.equals("fasta")){
				reference=b;
			}else if(a.equals("in") || a.equals("in1")){
				in1=b;
			}else if(a.equals("in2")){
				in2=b;
			}else if(a.equals("qfin") || a.equals("qfin1")){
				qfin1=b;
			}else if(a.equals("qfin2")){
				qfin2=b;
			}else if(a.equals("out")){
				if(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")){
					outFile=null;
				}else{
					outFile=b;
//					outFile=b.replace('#', '1');
//					outFile2=(b.contains("#") ? b.replace('#', '2') : null);
				}
			}else if(a.equals("out1")){
				outFile=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
				if(outFile==null){
					outFile=null;
				}
			}else if(a.equals("out2")){
				outFile2=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outm") || a.equals("outm1") || a.equals("outmapped") || a.equals("outmapped1")){
				outFileM=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outm2") || a.equals("outmapped2")){
				outFileM2=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outu") || a.equals("outu1") || a.equals("outunmapped") || a.equals("outunmapped1")){
				outFileU=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outu2") || a.equals("outunmapped2")){
				outFileU2=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outb") || a.equals("outb1") || a.equals("outblack") || a.equals("outblack1") || a.equals("outblacklist") || a.equals("outblacklist1")){
				outFileB=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("outb2") || a.equals("outblack2") || a.equals("outblacklist2")){
				outFileB2=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
			}else if(a.equals("blacklist") && !Data.scaffoldPrefixes){
				if(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")){blacklist=null;}
				else{
					if(blacklist==null){blacklist=new ArrayList<String>();}
					if(b.indexOf(',')<0 || new File(b).exists()){blacklist.add(b);}
					else{
						String[] temp=b.split(",");
						for(String tmp : temp){blacklist.add(tmp);}
					}
				}
			}else if(a.startsWith("out_") && b!=null){
				//ignore, it will be processed later
				if(splitterOutputs==null){splitterOutputs=new ArrayList<String>();}
				splitterOutputs.add(b);
			}else if(a.equals("bamscript") || a.equals("bs")){
				bamscript=b;
			}else if(a.equals("local")){
				LOCAL_ALIGN=Parse.parseBoolean(b);
			}else if(a.equals("averagepairdist") || a.equals("apd")){
				AbstractMapThread.INITIAL_AVERAGE_PAIR_DIST=Parse.parseIntKMG(b);
			}else if(a.equals("deterministic")){
				AbstractMapThread.DYNAMIC_INSERT_LENGTH=!Parse.parseBoolean(b);
			}else if(a.equals("skipreads")){
				AbstractMapThread.SKIP_INITIAL=Parse.parseKMG(b);
			}else if(a.equals("readlen") || a.equals("length") || a.equals("len")){
				synthReadlen=Integer.parseInt(b);
			}else if(a.equals("kfilter")){
				KFILTER=Integer.parseInt(b);
			}else if(a.equals("renamebyinsert")){
				RenameByInsert=Parse.parseBoolean(b);
			}else if(a.equals("msa")){
				MSA_TYPE=b;
			}else if(a.equals("bandwidth") || a.equals("bw")){
				int x=Tools.max(0, Integer.parseInt(b));
				MSA.bandwidth=x;
			}else if(a.equals("bandwidthratio") || a.equals("bwr")){
				float x=Tools.max(0, Float.parseFloat(b));
				MSA.bandwidthRatio=x;
				assert(x>=0) : "Bandwidth ratio should be at least 0.";
			}else if(a.equals("eono") || a.equals("erroronnooutput")){
				ERROR_ON_NO_OUTPUT=Parse.parseBoolean(b);
			}else if(a.equals("log")){
				RefToIndex.LOG=Parse.parseBoolean(b);
			}else if(a.equals("sitesonly") || a.equals("outputsitesonly")){
				outputSitesOnly=Parse.parseBoolean(b);
				outstream.println("Set outputSitesOnly to "+outputSitesOnly);
			}else if(a.equals("discardambiguous") || a.equals("tossambiguous")){
				REMOVE_DUPLICATE_BEST_ALIGNMENTS=Parse.parseBoolean(b);
				outstream.println("Set REMOVE_DUPLICATE_BEST_ALIGNMENTS to "+REMOVE_DUPLICATE_BEST_ALIGNMENTS);
			}else if(a.equals("ambiguous") || a.equals("ambig")){
				if(b==null){
					throw new RuntimeException(arg);
				}else if(b.equalsIgnoreCase("keep") || b.equalsIgnoreCase("best") || b.equalsIgnoreCase("first")){
					ambigMode=AMBIG_BEST;
				}else if(b.equalsIgnoreCase("all")){
					ambigMode=AMBIG_ALL;
				}else if(b.equalsIgnoreCase("random")){
					ambigMode=AMBIG_RANDOM;
				}else if(b.equalsIgnoreCase("toss") || b.equalsIgnoreCase("discard") || b.equalsIgnoreCase("remove")){
					ambigMode=AMBIG_TOSS;
				}else{
					throw new RuntimeException(arg);
				}
//				sysout.println("Set REMOVE_DUPLICATE_BEST_ALIGNMENTS to "+REMOVE_DUPLICATE_BEST_ALIGNMENTS);
			}else if(a.equals("penalizeambiguous") || a.equals("penalizeambig") || a.equals("pambig")){
				AbstractMapThread.PENALIZE_AMBIG=SamLine.PENALIZE_AMBIG=Parse.parseBoolean(b);
			}else if(a.equals("maxsites")){
				int x=Integer.parseInt(b);
				assert(x>0) : "maxsites must be at least 1.";
				MAX_SITESCORES_TO_PRINT=Tools.max(x, 1);
				AbstractMapThread.MAX_TRIM_SITES_TO_RETAIN=Tools.max(MAX_SITESCORES_TO_PRINT*2, AbstractMapThread.MAX_TRIM_SITES_TO_RETAIN);
			}else if(a.equals("maxsites2")){
				int x=Integer.parseInt(b);
				assert(x>1) : "maxsites2 must be at least 2.";
				AbstractMapThread.MAX_TRIM_SITES_TO_RETAIN=Tools.max(x, 2);
			}else if(a.equals("secondary")){
				PRINT_SECONDARY_ALIGNMENTS=Parse.parseBoolean(b);
				ReadStreamWriter.OUTPUT_SAM_SECONDARY_ALIGNMENTS=PRINT_SECONDARY_ALIGNMENTS;
			}else if(a.equals("sssr") || a.equals("secondarysitescoreratio")){
				AbstractMapThread.SECONDARY_SITE_SCORE_RATIO=Float.parseFloat(b);
			}else if(a.equals("ssao") || a.equals("secondarysiteasambiguousonly")){
				AbstractMapThread.PRINT_SECONDARY_ALIGNMENTS_ONLY_FOR_AMBIGUOUS_READS=Parse.parseBoolean(b);
			}else if(a.equals("quickmatch")){
				QUICK_MATCH_STRINGS=Parse.parseBoolean(b);
			}else if(a.equals("ambiguous2") || a.equals("ambig2")){
				if(b==null){
					throw new RuntimeException(arg);
				}else if(b.equalsIgnoreCase("split") || b.equalsIgnoreCase("stream")){
					BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_SPLIT;
				}else if(b.equalsIgnoreCase("keep") || b.equalsIgnoreCase("best") || b.equalsIgnoreCase("first")){
					BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_FIRST;
				}else if(b.equalsIgnoreCase("toss") || b.equalsIgnoreCase("discard") || b.equalsIgnoreCase("remove")){
					BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_TOSS;
				}else if(b.equalsIgnoreCase("random")){
					BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_RANDOM;
				}else if(b.equalsIgnoreCase("all")){
					BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_ALL;
				}else{
					throw new RuntimeException(arg);
				}
			}else if(a.equals("forbidselfmapping")){
				FORBID_SELF_MAPPING=Parse.parseBoolean(b);
				outstream.println("Set FORBID_SELF_MAPPING to "+FORBID_SELF_MAPPING);
			}else if(a.equals("match") || a.equals("cigar")){
				if(b!=null){b=b.toLowerCase();}else{b="true";}
				if(b.equals("long") || b.equals("normal")){
					MAKE_MATCH_STRING=true;
					Read.COMPRESS_MATCH_BEFORE_WRITING=false;
//					sysout.println("Writing long match strings.");
				}else if(b.equals("short") || b.equals("compressed")){
					MAKE_MATCH_STRING=true;
					Read.COMPRESS_MATCH_BEFORE_WRITING=true;
//					sysout.println("Writing short match strings.");
				}else{
					MAKE_MATCH_STRING=Parse.parseBoolean(b);
				}

				if(MAKE_MATCH_STRING){
					outstream.println("Cigar strings enabled.");
				}else{
					outstream.println("Cigar strings disabled.");
				}
			}else if(a.equals("semiperfectmode")){
				SEMIPERFECTMODE=Parse.parseBoolean(b);
				if(ziplevel==-1){ziplevel=2;}
			}else if(a.equals("perfectmode")){
				PERFECTMODE=Parse.parseBoolean(b);
				if(ziplevel==-1){ziplevel=2;}
			}else if(a.equals("trimlist")){
				TRIM_LIST=Parse.parseBoolean(b);
			}else if(a.equals("pairedrandom")){
				PAIRED_RANDOM_READS=Parse.parseBoolean(b);
			}else if(a.equals("ordered") || a.equals("ord")){
				ORDERED=Parse.parseBoolean(b);
				outstream.println("Set OUTPUT_ORDERED_READS to "+ORDERED);
			}else if(a.equals("outputunmapped")){
				OUTPUT_MAPPED_ONLY=!Parse.parseBoolean(b);
				outstream.println("Set OUTPUT_MAPPED_ONLY to "+OUTPUT_MAPPED_ONLY);
			}else if(a.equals("mappedonly")){
				OUTPUT_MAPPED_ONLY=Parse.parseBoolean(b);
				outstream.println("Set OUTPUT_MAPPED_ONLY to "+OUTPUT_MAPPED_ONLY);
			}else if(a.equals("outputblacklisted")){
				DONT_OUTPUT_BLACKLISTED_READS=!Parse.parseBoolean(b);
				outstream.println("Set DONT_OUTPUT_BLACKLISTED_READS to "+DONT_OUTPUT_BLACKLISTED_READS);
			}else if(a.equals("indexloaded")){
				INDEX_LOADED=Parse.parseBoolean(b);
			}else if(a.equals("build") || a.equals("genome") || a.equals("index")){
				build=Integer.parseInt(b);
			}else if(a.equals("minchrom")){
				minChrom=Integer.parseInt(b);
				maxChrom=Tools.max(minChrom, maxChrom);
			}else if(a.equals("maxchrom")){
				maxChrom=Byte.parseByte(b);
				minChrom=Tools.min(minChrom, maxChrom);
			}else if(a.equals("expectedsites")){
				expectedSites=Integer.parseInt(b);
			}else if(a.equals("targetsize")){
				targetGenomeSize=Parse.parseKMG(b);
			}else if(a.equals("fgte")){
				fractionGenomeToExclude=Float.parseFloat(b);
				outstream.println("Set fractionGenomeToExclude to "+String.format(Locale.ROOT, "%.4f",fractionGenomeToExclude));
			}else if(a.equals("minratio")){
				MINIMUM_ALIGNMENT_SCORE_RATIO=Float.parseFloat(b);
				outstream.println("Set MINIMUM_ALIGNMENT_SCORE_RATIO to "+String.format(Locale.ROOT, "%.3f",MINIMUM_ALIGNMENT_SCORE_RATIO));
				minid=-1;
			}else if(a.equals("minidentity") || a.equals("minid")){
				assert(b!=null) : "Bad parameter: "+arg;
				if(b.lastIndexOf('%')==b.length()-1){minid=Double.parseDouble(b.substring(b.length()-1))/100;}
				else{minid=Double.parseDouble(b);}
				assert(minid>=0 && minid<=100) : "min identity must be between 0 and 1.  Values from 1 to 100 will be assumed percent and divided by 100.";
			}else if(a.equals("rcompmate") || a.equals("reversecomplementmate")){
				rcompMate=Parse.parseBoolean(b);
				outstream.println("Set RCOMP_MATE to "+rcompMate);
			}else if(a.equals("rcomp") || a.equals("reversecomplement")){
				AbstractMapThread.RCOMP=Parse.parseBoolean(b);
				outstream.println("Set RCOMP to "+rcompMate);
			}else if(a.equals("verbose")){
				verbose=Parse.parseBoolean(b);
				Read.verbose=verbose;
				SiteScore.verbose=verbose;
				TranslateColorspaceRead.verbose=verbose;
				AbstractIndex.verbose2=verbose;
			}else if(a.equals("verbosestats")){
				if(b!=null && Tools.isDigit(b.charAt(0))){
					verbose_stats=Integer.parseInt(b);
				}else{
					verbose_stats=Parse.parseBoolean(b) ? 9 : 0;
				}
			}else if(a.equals("maxdellen")){
				maxDelLen=Integer.parseInt(b);
			}else if(a.equals("maxinslen")){
				maxInsLen=Integer.parseInt(b);
			}else if(a.equals("maxsublen")){
				maxSubLen=Integer.parseInt(b);
			}else if(a.equals("minqual")){
				minQuality=Byte.parseByte(b);
				midQuality=Tools.max(minQuality, midQuality);
				maxQuality=Tools.max(midQuality, maxQuality);
			}else if(a.equals("midqual")){
				midQuality=Byte.parseByte(b);
				maxQuality=Tools.max(midQuality, maxQuality);
				minQuality=Tools.min(minQuality, midQuality);
			}else if(a.equals("maxqual")){
				maxQuality=Byte.parseByte(b);
				midQuality=Tools.min(maxQuality, midQuality);
				minQuality=Tools.min(minQuality, midQuality);
			}else if(a.equals("matelen") || a.equals("pairlen")){
				int x=Integer.parseInt(b);
				AbstractMapThread.MAX_PAIR_DIST=x;
			}else if(a.equals("s") || a.equals("snps")){
				maxSnps=Integer.parseInt(b);
				baseSnpRate=1;
			}else if(a.equals("u") || a.equals("subs")){
				maxInss=Integer.parseInt(b);
				baseInsRate=1;
			}else if(a.equals("d") || a.equals("dels")){
				maxDels=Integer.parseInt(b);
				baseDelRate=1;
			}else if(a.equals("i") || a.equals("inss")){
				maxSubs=Integer.parseInt(b);
				baseSubRate=1;
			}else if(a.equals("sequentialoverlap")){
				sequentialOverlap=Integer.parseInt(b);
			}else if(a.equals("sequentialstrandalt")){
				sequentialStrandAlt=Parse.parseBoolean(b);
			}else if(a.equals("k") || a.equals("keylen")){
				keylen=Integer.parseInt(b);
				assert(keylen>0 && keylen<16) : "k must lie between 1 and 15, inclusive.";
			}else if(a.equals("genscaffoldinfo")){
				RefToIndex.genScaffoldInfo=Parse.parseBoolean(b);
			}else if(a.equals("loadscaffolds")){
				Data.LOAD_SCAFFOLDS=Parse.parseBoolean(b);
			}else if(a.equals("autoRefToIndex.chrombits")){
				if("auto".equalsIgnoreCase(b)){RefToIndex.AUTO_CHROMBITS=true;}
				else{RefToIndex.AUTO_CHROMBITS=Parse.parseBoolean(b);}
			}else if(a.equals("RefToIndex.chrombits") || a.equals("cbits")){
				if("auto".equalsIgnoreCase(b)){RefToIndex.AUTO_CHROMBITS=true;}
				else{
					RefToIndex.AUTO_CHROMBITS=false;
					RefToIndex.chrombits=Integer.parseInt(b);
				}
			}else if(a.equals("requirecorrectstrand") || a.equals("rcs")){
				REQUIRE_CORRECT_STRANDS_PAIRS=Parse.parseBoolean(b);
			}else if(a.equals("samestrandpairs") || a.equals("ssp")){
				SAME_STRAND_PAIRS=Parse.parseBoolean(b);
				if(SAME_STRAND_PAIRS){outstream.println("Warning! SAME_STRAND_PAIRS=true mode is not fully tested.");}
			}else if(a.equals("killbadpairs") || a.equals("kbp")){
				KILL_BAD_PAIRS=Parse.parseBoolean(b);
			}else if(a.equals("pairedonly") || a.equals("po")){
				AbstractMapThread.OUTPUT_PAIRED_ONLY=Parse.parseBoolean(b);
			}else if(a.equals("idmodulo") || a.equals("idmod")){
				idmodulo=Integer.parseInt(b);
			}else if(a.equals("minhits") || a.equals("minapproxhits")){
				minApproxHits=Integer.parseInt(b);
			}else if(a.equals("maxindel")){
				maxIndel1=(int)Tools.max(0, Parse.parseKMG(b));
				if(!setMaxIndel2){maxIndel2=2*maxIndel1;}
			}else if(a.equals("maxindel1") || a.equals("maxindelsingle")){
				maxIndel1=(int)Tools.max(0, Parse.parseKMG(b));
				maxIndel2=Tools.max(maxIndel1, maxIndel2);
				setMaxIndel1=true;
			}else if(a.equals("maxindel2") || a.equals("maxindelsum")){
				maxIndel2=(int)Tools.max(0, Parse.parseKMG(b));
				maxIndel1=Tools.min(maxIndel1, maxIndel2);
				setMaxIndel2=true;
			}else if(a.equals("strictmaxindel")){
				if(b!=null && Tools.isDigit(b.charAt(0))){
					maxIndel1=(int)Tools.max(0, Parse.parseKMG(b));
					if(!setMaxIndel2){maxIndel2=2*maxIndel1;}
					STRICT_MAX_INDEL=true;
				}else{
					STRICT_MAX_INDEL=Parse.parseBoolean(b);
				}
			}else if(a.equals("padding")){
				SLOW_ALIGN_PADDING=Integer.parseInt(b);
				SLOW_RESCUE_PADDING=SLOW_ALIGN_PADDING;
			}else if(a.equals("rescue")){
				RESCUE=Parse.parseBoolean(b);
			}else if(a.equals("rescuemismatches")){
				AbstractMapThread.MAX_RESCUE_MISMATCHES=Integer.parseInt(b);
			}else if(a.equals("rescuedist")){
				AbstractMapThread.MAX_RESCUE_DIST=Parse.parseIntKMG(b);
			}else if(a.equals("tipsearch")){
				if(b!=null && ("f".equalsIgnoreCase(b) || "false".equalsIgnoreCase(b))){TIP_SEARCH_DIST=0;}
				else{TIP_SEARCH_DIST=Tools.max(0, Integer.parseInt(b));}
			}else if(a.equals("dper") || a.equals("dprr")){
				DOUBLE_PRINT_ERROR_RATE=Parse.parseBoolean(b);
			}else if(a.equals("chromgz")){
				Data.CHROMGZ=Parse.parseBoolean(b);
			}else if(a.equals("nodisk")){
				RefToIndex.NODISK=Parse.parseBoolean(b);
			}else if(a.equals("maxchromlen")){
				RefToIndex.maxChromLen=Parse.parseKMG(b);
			}else if(a.equals("minscaf") || a.equals("mincontig")){
				RefToIndex.minScaf=Integer.parseInt(b);
			}else if(a.equals("midpad") || a.equals("interpad")){
				RefToIndex.midPad=Integer.parseInt(b);
			}else if(a.equals("startpad")){
				RefToIndex.startPad=Integer.parseInt(b);
			}else if(a.equals("stoppad")){
				RefToIndex.stopPad=Integer.parseInt(b);
			}else if(a.equals("forceanalyze")){
				forceanalyze=Parse.parseBoolean(b);
			}else if(a.equals("machineoutput") || a.equals("machineout")){
				MACHINE_OUTPUT=Parse.parseBoolean(b);
			}else if(a.equals("showprogress") || a.equals("showprogress2")){
				if(b!=null && Tools.isDigit(b.charAt(0))){
					long x=Parse.parseKMG(b);
					ConcurrentReadInputStream.PROGRESS_INCR=x;
					ConcurrentReadInputStream.SHOW_PROGRESS=(x>0);
				}else{
					ConcurrentReadInputStream.PROGRESS_INCR=ConcurrentReadInputStream.PROGRESS_INCR<1 ? 1000000 : ConcurrentReadInputStream.PROGRESS_INCR;
					ConcurrentReadInputStream.SHOW_PROGRESS=Parse.parseBoolean(b);
				}
				if(a.equals("showprogress2")){ConcurrentReadInputStream.SHOW_PROGRESS2=ConcurrentReadInputStream.SHOW_PROGRESS;}
			}else if(a.equals("scafstats") || a.equals("scaffoldstats")){
				if(b==null && arg.indexOf('=')<0){b="stdout";}
				if(b==null || b.equalsIgnoreCase("false") || b.equalsIgnoreCase("f") || b.equalsIgnoreCase("none") || b.equalsIgnoreCase("null")){
					BBSplitter.TRACK_SCAF_STATS=false;
					BBSplitter.SCAF_STATS_FILE=null;
					outstream.println("No file specified; not tracking scaffold statistics.");
				}else{
					BBSplitter.TRACK_SCAF_STATS=true;
					BBSplitter.SCAF_STATS_FILE=b;
					outstream.println("Scaffold statistics will be written to "+b);
				}
			}else if(a.equals("setstats") || a.equals("refstats")){
				if(b==null && arg.indexOf('=')<0){b="stdout";}
				if(b==null || b.equalsIgnoreCase("false") || b.equalsIgnoreCase("f") || b.equalsIgnoreCase("none") || b.equalsIgnoreCase("null")){
					BBSplitter.TRACK_SET_STATS=false;
					BBSplitter.SET_STATS_FILE=null;
					outstream.println("No file specified; not tracking reference set statistics.");
				}else{
					BBSplitter.TRACK_SET_STATS=true;
					BBSplitter.SET_STATS_FILE=b;
					outstream.println("Reference set statistics will be written to "+b);
				}
			}else if(a.equals("camelwalk")){
				AbstractIndex.USE_CAMELWALK=Parse.parseBoolean(b);
			}else if(a.equals("usequality") || a.equals("uq")){
				AbstractIndex.GENERATE_KEY_SCORES_FROM_QUALITY=AbstractIndex.GENERATE_BASE_SCORES_FROM_QUALITY=Parse.parseBoolean(b);
			}else if(a.equals("ignorequality")){
				AbstractIndex.GENERATE_KEY_SCORES_FROM_QUALITY=AbstractIndex.GENERATE_BASE_SCORES_FROM_QUALITY=!Parse.parseBoolean(b);
			}else if(a.equals("keepbadkeys") || a.equals("kbk")){
				KeyRing.KEEP_BAD_KEYS=Parse.parseBoolean(b);
			}else if(a.equals("usemodulo") || a.equals("um")){
				USE_MODULO=AbstractMapThread.USE_MODULO=IndexMaker4.USE_MODULO=IndexMaker5.USE_MODULO=Parse.parseBoolean(b);
			}else if(a.equals("lowmem") || a.equals("lowram") || a.equals("lowmemory")){
				boolean x=Parse.parseBoolean(b);
				if(x){
					Shared.LOW_MEMORY=true;
					USE_MODULO=AbstractMapThread.USE_MODULO=IndexMaker4.USE_MODULO=IndexMaker5.USE_MODULO=Parse.parseBoolean(b);
				}else{
					Shared.LOW_MEMORY=false;
				}
			}else if(a.equals("coverage") || a.equals("cov") || a.equals("calccov") || a.equals("calccoverage")){
				calcCov=Parse.parseBoolean(b);
			}else if(a.equals("coveragestats") || a.equals("covstats")){
				coverageStats=b;
			}else if(a.equals("coverageminscaf") || a.equals("covminscaf")){
				coverageMinScaf=Integer.parseInt(b);
			}else if(a.equals("binnedcoverage") || a.equals("bincov")){
				coverageBinned=b;
			}else if(a.equals("coverage") || a.equals("basecov")){
				coverageBase=b;
			}else if(a.equals("secondarycoverage") || a.equals("secondarycov")){
				CoveragePileup.USE_SECONDARY=Parse.parseBoolean(b);
			}else if(a.equals("coveragehistogram") || a.equals("covhist")){
				coverageHist=b;
			}else if(a.equals("normcov")){
				normcov=b;
			}else if(a.equals("normcovo")){
				normcovOverall=b;
			}else if(a.equals("normb") || a.equals("normbins")){
				CoveragePileup.NORMALIZE_LENGTH_BINS=Integer.parseInt(b);
			}else if(a.equals("rpkm") || a.equals("fpkm")){
				coverageRPKM=b;
			}else if(a.equals("physicalcoverage") || a.equals("physcov")){
				coveragePhysical=Parse.parseBoolean(b);
			}else if(a.equals("32bit") || a.equals("32bits") || a.equals("bits32")){
				cov32bit=Parse.parseBoolean(b);
			}else if(a.equals("bitset")){
				covBitset=Parse.parseBoolean(b);
				covSetbs=true;
			}else if(a.equals("arrays")){
				covArrays=Parse.parseBoolean(b);
				covSetbs=true;
			}else if(a.equals("nzo") || a.equals("nonzeroonly")){
				covNzo=scafNzo=Parse.parseBoolean(b);
			}else if(a.equals("sortstats") || a.equals("sortscafs")){
				sortStats=Parse.parseBoolean(b);
			}else if(a.equals("twocolumn")){
				covTwocolumn=Parse.parseBoolean(b);
			}else if(a.equals("ksb") || a.equals("keepshortbins")){
				covKsb=Parse.parseBoolean(b);
			}else if(a.equals("covbinsize")){
				covBinSize=Integer.parseInt(b);
			}else if(a.equals("covk") || a.equals("kcov")){
				covK=Integer.parseInt(b);
			}else if(a.equals("strandedcoverage") || a.equals("strandedcov") || a.equals("covstranded")){
				covStranded=Parse.parseBoolean(b);
			}else if(a.equals("startcov") || a.equals("covstart")){
				covStartOnly=Parse.parseBoolean(b);
			}else if(a.equals("stopcov") || a.equals("covstop")){
				covStartOnly=Parse.parseBoolean(b);
			}else if(a.equals("concisecov")){
				CoveragePileup.CONCISE=Parse.parseBoolean(b);
			}else if(a.equals("covwindow")){
				if(b==null || b.length()<1 || Character.isLetter(b.charAt(0))){
					CoveragePileup.USE_WINDOW=Parse.parseBoolean(b);
				}else{
					CoveragePileup.LOW_COV_WINDOW=Integer.parseInt(b);
					CoveragePileup.USE_WINDOW=(CoveragePileup.LOW_COV_WINDOW>0);
				}
			}else if(a.equals("covwindowavg")){
				CoveragePileup.LOW_COV_DEPTH=Double.parseDouble(b);
			}else if(a.equals("delcov") || a.equals("includedels") || a.equals("includedeletions") || a.equals("delcoverage")){
				CoveragePileup.INCLUDE_DELETIONS=Parse.parseBoolean(b);
			}else if(a.equals("rebuild")){
				forceRebuild=Parse.parseBoolean(b);
			}else if(a.equals("printunmappedcount")){
				PRINT_UNMAPPED_COUNT=Parse.parseBoolean(b);
			}else if(a.equals("timetag")){
				boolean x=Parse.parseBoolean(b);
				AbstractMapThread.TIME_TAG=x;
				SamLine.MAKE_TIME_TAG=x;
				if(x){AbstractMapThread.CLEAR_ATTACHMENT=false;}
			}else if(a.equals("correctthresh")){
				CORRECT_THRESH=Integer.parseInt(b);
			}else if(a.equals("statsfile")){
				statsOutputFile=b;
			}else if(a.equals("ignorefrequentkmers") || a.equals("ifk")){
				AbstractIndex.REMOVE_FREQUENT_GENOME_FRACTION=Parse.parseBoolean(b);
			}else if(a.equals("trimbygreedy") || a.equals("tbg") || a.equals("greedy")){
				AbstractIndex.TRIM_BY_GREEDY=Parse.parseBoolean(b);
			}else if(a.equals("printsettings")){
				printSettings=Parse.parseBoolean(b);
			}else if(a.equals("printstats")){
				printStats=Parse.parseBoolean(b);
			}
			
			else if(a.equalsIgnoreCase("bloom") || a.equalsIgnoreCase("bloomfilter")){
				makeBloomFilter=Parse.parseBoolean(b);
			}else if(a.equalsIgnoreCase("bloomHashes") || a.equalsIgnoreCase("bloomFilterHashes")){
				bloomFilterHashes=Integer.parseInt(b);
			}else if(a.equalsIgnoreCase("bloomMinHits") || a.equalsIgnoreCase("bloomFilterMinHits")){
				bloomFilterMinHits=Integer.parseInt(b);
			}else if(a.equalsIgnoreCase("bloomK") || a.equalsIgnoreCase("bloomFilterK")){
				bloomFilterK=Integer.parseInt(b);
			}else if(a.equalsIgnoreCase("bloomserial") || a.equalsIgnoreCase("serialbloom")){
				bloomSerial=Parse.parseBoolean(b);
			}else if(a.equalsIgnoreCase("forcereadonly")){
				RefToIndex.FORCE_READ_ONLY=Parse.parseBoolean(b);
			}
			
			else{
				throw new RuntimeException("Unknown parameter: "+arg);
			}
		}
		Parser.postparseReadgroup(in1);
		
		{//Process parser fields
			Parser.processQuality();
			
			qtrimLeft=parser.qtrimLeft;
			qtrimRight=parser.qtrimRight;
			TRIM_QUALITY=parser.trimq;
			AbstractMapThread.MIN_AVERAGE_QUALITY=parser.minAvgQuality;
			AbstractMapThread.MIN_AVERAGE_QUALITY_BASES=parser.minAvgQualityBases;
			AbstractMapThread.MIN_READ_LENGTH=parser.minReadLength;
			AbstractMapThread.MAX_READ_LENGTH=parser.maxReadLength;
			minTrimLength=parser.minTrimLength;
			untrim=parser.untrim;
			
			maxReads=parser.maxReads;
			overwrite=ReadStats.overwrite=CoveragePileup.overwrite=parser.overwrite;
			append=ReadStats.append=parser.append;
			setintron=SamLine.setintron;

			samplerate=parser.samplerate;
			sampleseed=parser.sampleseed;
			MIN_IDFILTER=parser.minIdFilter;
			build=parser.build;
			if(MIN_IDFILTER>0){
				if(MIN_IDFILTER==1f){PERFECTMODE=true;}
				MAKE_MATCH_STRING=true;
			}
			
			if(parser.nfilter>-1){AbstractMapThread.NFILTER=parser.nfilter;}
			if(parser.subfilter>-1){AbstractMapThread.SUBFILTER=parser.subfilter;}
			if(parser.delfilter>-1){AbstractMapThread.DELFILTER=parser.delfilter;}
			if(parser.insfilter>-1){AbstractMapThread.INSFILTER=parser.insfilter;}
			if(parser.indelfilter>-1){AbstractMapThread.INDELFILTER=parser.indelfilter;}
			if(parser.dellenfilter>-1){AbstractMapThread.DELLENFILTER=parser.dellenfilter;}
			if(parser.inslenfilter>-1){AbstractMapThread.INSLENFILTER=parser.inslenfilter;}
			if(parser.editfilter>-1){AbstractMapThread.EDITFILTER=parser.editfilter;}
			
			if(ReadStats.COLLECT_TIME_STATS){AbstractMapThread.TIME_TAG=true;}
		}
		
		{
			FileFormat ff1=FileFormat.testInput(in1, FileFormat.FASTQ, 0, 0, false, false, false);
			parser.validateStdio(ff1);
		}
		
		if(forceRebuild){
			String sf=RefToIndex.summaryLoc(build);
			if(sf!=null){
				File f=new File(sf);
				if(f.exists() && f.isFile()){f.delete();}
			}
		}
		
		ChromosomeArray.CHANGE_UNDEFINED_TO_N_ON_READ=(!INDEX_LOADED);
		
		if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_SPLIT && splitterOutputs!=null){
			ArrayList<String> clone=(ArrayList<String>) splitterOutputs.clone();
			for(String s : clone){
				splitterOutputs.add("AMBIGUOUS_"+s);
			}
		}
	}
	
	private final void checkFiles(){
		if(in1!=null && in1.contains("#") && !new File(in1).exists()){
			int pound=in1.lastIndexOf('#');
			String a=in1.substring(0, pound);
			String b=in1.substring(pound+1);
			in1=a+1+b;
			in2=a+2+b;
		}
		
		if(in2!=null && (in2.contains("=") || in2.equalsIgnoreCase("null"))){in2=null;}
		if(in2!=null){
			if(FASTQ.FORCE_INTERLEAVED){outstream.println("Reset INTERLEAVED to false because paired input files were specified.");}
			FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false;
		}
		in1=Tools.fixExtension(in1);
		in2=Tools.fixExtension(in2);
		qfin1=Tools.fixExtension(qfin1);
		qfin2=Tools.fixExtension(qfin2);

		if(outFile!=null && outFile2==null && outFile.contains("#") && !outFile.contains(".sam") && !outFile.contains(".bam") && outFile.contains(".")){
			int pound=outFile.lastIndexOf('#');
			String a=outFile.substring(0, pound);
			String b=outFile.substring(pound+1);
			outFile=a+1+b;
			outFile2=a+2+b;
		}

		if(outFileM!=null && outFileM2==null && outFileM.contains("#") && !outFileM.contains(".sam") && !outFileM.contains(".bam") && outFileM.contains(".")){
			int pound=outFileM.lastIndexOf('#');
			String a=outFileM.substring(0, pound);
			String b=outFileM.substring(pound+1);
			outFileM=a+1+b;
			outFileM2=a+2+b;
		}

		if(outFileU!=null && outFileU2==null && outFileU.contains("#") && !outFileU.contains(".sam") && !outFileU.contains(".bam") && outFileU.contains(".")){
			int pound=outFileU.lastIndexOf('#');
			String a=outFileU.substring(0, pound);
			String b=outFileU.substring(pound+1);
			outFileU=a+1+b;
			outFileU2=a+2+b;
		}
		
		if(OUTPUT_READS && !Tools.testOutputFiles(overwrite, append, false, outFile, outFile2)){
			throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+outFile+", "+outFile2+"\n");
		}
		
		if(maxReads>0 && maxReads<Long.MAX_VALUE){outstream.println("Max reads: "+maxReads);}
		
		ReadStats.testFiles(false);
		
		assert(synthReadlen<0 || synthReadlen>=keylen);
	}
	
	private final String[] preparse0(String[] args){
		int nulls=0;
		boolean foundInput=false;
		for(int i=0; i<args.length; i++){
			if(args[i]==null){nulls++;}
			else{
				final String arg=args[i];
				final String[] split=arg.split("=");
				assert(split.length>0) : "\n= symbol must be adjacent to 2 terms, with no spaces.  E.g. 'out=mapped.sam'";
				String a=split[0].toLowerCase();
				String b=split.length>1 ? split[1] : null;
				String blc=(b==null ? null : b.toLowerCase()); 
				if("null".equalsIgnoreCase(blc)){blc=null;}
				if(blc!=null && (blc.equals("stdout") || blc.startsWith("stdout."))){
					outstream=System.err;
					outstream=System.err;
				}else if(a.equals("printtoerr")){
					if(Parse.parseBoolean(blc)){outstream=System.err; outstream=System.err;}
				}else if(blc!=null && (blc.equals("stdin") || blc.startsWith("stdin."))){
					SYSIN=true;
				}else if(a.equals("fast")){
					fast=Parse.parseBoolean(blc);
					if(fast){slow=false;}
					args[i]=null;
					nulls++;
				}else if(a.equals("slow")){
					slow=Parse.parseBoolean(blc);
					if(slow){fast=false;}
					args[i]=null;
					nulls++;
				}else if(a.equals("vslow")){
					vslow=Parse.parseBoolean(blc);
					if(vslow){fast=false;slow=true;}
					args[i]=null;
					nulls++;
				}else if(a.equals("vslow")){
					vslow=Parse.parseBoolean(blc);
					if(vslow){fast=false;slow=true;}
					args[i]=null;
					nulls++;
				}else if(a.equals("excludefraction") || a.equals("ef")){
					excludeFraction=Float.parseFloat(blc);
					args[i]=null;
					nulls++;
				}else if(a.equals("in")){
//					assert(b!=null) : "Null input file.";
					if(b!=null){
						assert(b.equals("stdin") || b.startsWith("stdin.") || new File(b).exists() || new File(b.replace('#', '1')).exists()) : "Invalid input file: '"+b+"'";
						foundInput=true;
//						FileFormat ff=FileFormat.testInput(b, FileFormat.FASTQ, null, false, false);
					}
				}else if(a.equals("ref")){
					assert(b!=null) : "Null reference file.";
					if(b.indexOf(',')<0){
						assert(b.equals("stdin") || b.startsWith("stdin.") || new File(b).exists()) : "Invalid input file: '"+b+"'";
						FileFormat ff=FileFormat.testInput(b, FileFormat.FASTA, null, true, true);
						assert(ff.stdin() || ff.fasta()) : "References must be in fasta format.";
					}
				}
			}
		}
//		assert(foundInput) : "No input file specified.";
		if(nulls>0){args=Tools.condenseStrict(args);}
		return args;
	}
	
	static final String padPercent(double value, int places){
		String x=String.format(Locale.ROOT, "%."+places+"f", value);
		int desired=3+(places<1 ? 0 : 1+places);
		while(x.length()<desired){x=" "+x;}
		return x;
	}
	
	static final String pad(long value, int places){
		String x=""+value;
		while(x.length()<places){x=" "+x;}
		return x;
	}
	
	static final String padPercentMachine(double value, int places){
		String x=String.format(Locale.ROOT, "%."+places+"f", value);
		return x;
	}
	

	boolean openStreams(Timer t, String[] args){
		
		cris=getReadInputStream(in1, in2, qfin1, qfin2);
		final boolean paired=cris.paired();
		cris.setSampleRate(samplerate, sampleseed);
		
		final int buff=(!ORDERED ? 12 : Tools.max(32, 2*Shared.threads()));
		if(OUTPUT_READS){
			ReadStreamWriter.MINCHROM=minChrom;
			ReadStreamWriter.MAXCHROM=maxChrom;
			
			AbstractMapThread.OUTPUT_SAM=false;
			if(outFile!=null){
				FileFormat ff1=FileFormat.testOutput(outFile, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				FileFormat ff2=outFile2==null ? null : FileFormat.testOutput(outFile2, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				rosA=ConcurrentReadOutputStream.getStream(ff1, ff2, qfout, qfout2, buff, null, false);
				rosA.start();
				t.stop();
				outstream.println("Started output stream:\t"+t);
				t.start();
				AbstractMapThread.OUTPUT_SAM|=ff1.samOrBam();
			}
			if(outFileM!=null){
				FileFormat ff1=FileFormat.testOutput(outFileM, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				FileFormat ff2=outFileM2==null ? null : FileFormat.testOutput(outFileM2, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				rosM=ConcurrentReadOutputStream.getStream(ff1, ff2, qfoutM, qfoutM2, buff, null, false);
				rosM.start();
				t.stop();
				outstream.println("Started output stream:\t"+t);
				t.start();
				AbstractMapThread.OUTPUT_SAM|=ff1.samOrBam();
			}
			if(outFileU!=null){
				FileFormat ff1=FileFormat.testOutput(outFileU, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				FileFormat ff2=outFileU2==null ? null : FileFormat.testOutput(outFileU2, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				rosU=ConcurrentReadOutputStream.getStream(ff1, ff2, qfoutU, qfoutU2, buff, null, false);
				rosU.start();
				t.stop();
				outstream.println("Started output stream:\t"+t);
				t.start();
				AbstractMapThread.OUTPUT_SAM|=ff1.samOrBam();
			}
			if(outFileB!=null && !Data.scaffoldPrefixes){
				FileFormat ff1=FileFormat.testOutput(outFileB, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				FileFormat ff2=outFileB2==null ? null : FileFormat.testOutput(outFileB2, DEFAULT_OUTPUT_FORMAT, 0, 0, true, overwrite, append, ORDERED);
				rosB=ConcurrentReadOutputStream.getStream(ff1, ff2, qfoutB, qfoutB2, buff, null, false);
				rosB.start();
				t.stop();
				outstream.println("Started output stream:\t"+t);
				t.start();
				AbstractMapThread.OUTPUT_SAM|=ff1.samOrBam();
			}
		}

		if(Data.scaffoldPrefixes){
			BBSplitter.streamTable=BBSplitter.makeOutputStreams(args, OUTPUT_READS, ORDERED, buff, paired, overwrite, append, false);
			if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_SPLIT){
				BBSplitter.streamTableAmbiguous=BBSplitter.makeOutputStreams(args, OUTPUT_READS, ORDERED, buff, paired, overwrite, append, true);
			}
		}else{
			BBSplitter.TRACK_SET_STATS=false;
		}

		if(BBSplitter.TRACK_SET_STATS){
			outstream.print("Creating ref-set statistics table: ");
			BBSplitter.makeSetCountTable();
			t.stop();
			outstream.println("   \t"+t);
			t.start();
		}
		if(BBSplitter.TRACK_SCAF_STATS){
			outstream.print("Creating scaffold statistics table:");
			BBSplitter.makeScafCountTable();
			t.stop();
			outstream.println("   \t"+t);
			t.start();
		}

		{
			String syncObj=new String("syncObj");
			synchronized(syncObj){
				System.gc();
				Thread.yield();
//				if(waitForMemoryClear){
					try {syncObj.wait(waitForMemoryClear ? 1000 : 100);}
					catch (InterruptedException e) {e.printStackTrace();}
//				}
			}

			t.stop();
			outstream.println("Cleared Memory:    \t"+t);
		}
		
		return paired;
	}
	
	static final int shutDownThreads(AbstractMapThread[] mtts, boolean force){
		int broken=0;
		long millis=force ? 500 : 8000;
		for(int i=0; i<mtts.length; i++){
			AbstractMapThread mtt=mtts[i];
			if(mtt==null){broken++;}
			else{
				synchronized(mtt){
					while(mtt.working()){
						State st=mtt.getState();
						if(st==State.TERMINATED){
							if(mtt.working()){
								broken++;
								break;
							}
						}
						try {
							mtt.wait(millis);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						if(force && mtt.working()){
							mtt.interrupt();
							broken++;
							break;
						}
					}
				}
				if(i==0){
					outstream.print("Detecting finished threads: 0");
				}else{
					outstream.print(", "+i);
				}
			}
		}
		
		if(broken>0){
			System.err.println("\n\n**************************************************************************\n" +
					"Warning!  "+broken+" mapping thread"+(broken==1 ? "" : "s")+" did not terminate normally.\n" +
					"Check the error log; the output may be corrupt or incomplete.\n" +
					"Please submit the full stderr output as a bug report, not just this message.\n" +
					"**************************************************************************\n\n");
		}
		return broken;
	}
	
	static final boolean closeStreams(ConcurrentReadInputStream cris, ConcurrentReadOutputStream rosA, ConcurrentReadOutputStream rosM, ConcurrentReadOutputStream rosU, ConcurrentReadOutputStream rosB){
		errorState|=ReadWrite.closeStreams(cris, rosA, rosM, rosU, rosB);
		if(BBSplitter.streamTable!=null){
			for(ConcurrentReadOutputStream tros : BBSplitter.streamTable.values()){
				errorState|=ReadWrite.closeStream(tros);
			}
		}
		if(BBSplitter.streamTableAmbiguous!=null){
			for(ConcurrentReadOutputStream tros : BBSplitter.streamTableAmbiguous.values()){
				errorState|=ReadWrite.closeStream(tros);
			}
		}
		return errorState;
	}
	
	static final ConcurrentReadInputStream getReadInputStream(String in1, String in2, String qf1, String qf2){
		
		assert(in1!=null);
		assert(!in1.equalsIgnoreCase(in2)) : in1+", "+in2;
		
		final ConcurrentReadInputStream cris;

		FileFormat ff1=FileFormat.testInput(in1, FileFormat.FASTQ, 0, 0, true, true, false);
		FileFormat ff2=FileFormat.testInput(in2, FileFormat.FASTQ, 0, 0, true, true, false);
		
		if(ff1.fastq() || ff1.fasta() || ff1.samOrBam() || ff1.scarf() || ff1.bread()){
			cris=ConcurrentReadInputStream.getReadInputStream(maxReads, ff1.samOrBam(), ff1, ff2, qf1, qf2);
		}else if(ff1.sequential()){
			if(maxReads<0){maxReads=Long.MAX_VALUE;}
//			assert(false) : trials;
			SequentialReadInputStream ris=new SequentialReadInputStream(maxReads, synthReadlen, Tools.max(50, synthReadlen/2), sequentialOverlap, sequentialStrandAlt);
			cris=new ConcurrentLegacyReadInputStream(ris, maxReads);
			
		}else if(ff1.random()){
			
			useRandomReads=true;
			assert(synthReadlen>0);
			
			RandomReads3.PERFECT_READ_RATIO=PERFECT_READ_RATIO;
			
			RandomReadInputStream3 ris=new RandomReadInputStream3(maxReads, synthReadlen, synthReadlen,
					maxSnps, maxInss, maxDels, maxSubs,
					baseSnpRate, baseInsRate, baseDelRate, baseSubRate,
					maxInsLen, maxDelLen, maxSubLen,
					minChrom, maxChrom, PAIRED_RANDOM_READS,
					minQuality, midQuality, maxQuality);
			cris=new ConcurrentLegacyReadInputStream(ris, maxReads);
		}else{
			throw new RuntimeException("Can't determine read input source: ff1="+ff1+", ff2="+ff2);
		}
		return cris;
	}
	
	void printOutput(final AbstractMapThread[] mtts, final Timer t, final int keylen, final boolean paired, final boolean SKIMMER, final CoveragePileup pile,
			boolean nzoStats, boolean sortStats, String dest){
		
		if(printStats){
			printOutputStats(mtts, t, keylen, paired, SKIMMER, nzoStats, sortStats, dest);
		}
		
		errorState|=ReadStats.writeAll();
		
		if(pile!=null){
			CoveragePileup.overwrite=overwrite;
			CoveragePileup.append=append;
			outstream.println();
			pile.printOutput();
		}
		
	}
	
	static void printOutputStats(final AbstractMapThread[] mtts, final Timer t, final int keylen, final boolean paired, final boolean SKIMMER,
			boolean nzoStats, boolean sortStats, String dest){
		if(MACHINE_OUTPUT){
			printOutput_Machine(mtts, t, keylen, paired, SKIMMER, nzoStats, sortStats, dest);
			return;
		}
		if(dest==null){dest="stderr.txt";}
		TextStreamWriter tswStats=new TextStreamWriter(dest, overwrite, append, false);
		tswStats.start();

		long readsUsed1=0;
		long readsUsed2=0;
		long readsIn1=0;
		long readsIn2=0;
		
		long lowQualityReadsDiscarded1=0;
		long lowQualityReadsDiscarded2=0;
		long lowQualityBasesDiscarded1=0;
		long lowQualityBasesDiscarded2=0;
		
		long msaIterationsLimited=0;
		long msaIterationsUnlimited=0;

		long basesUsed1=0;
		long basesUsed2=0;
		long basesIn1=0;
		long basesIn2=0;
		long readsPassedBloomFilter=0;
		long basesPassedBloomFilter=0;
		long keysUsed=0;
		long bothUnmapped=0;
		long bothUnmappedBases=0;
		long eitherMapped=0;
		long eitherMappedBases=0;
		
		long syntheticReads=0;
		long numMated=0;
		long numMatedBases=0;
		long badPairs=0;
		long badPairBases=0;
		long innerLengthSum=0;
		long outerLengthSum=0;
		long insertSizeSum=0;
		
		long callsToScore=0;
		long callsToExtend=0;
		long initialKeys=0;
		long initialKeyIterations=0;
		long usedKeys=0;
		long usedKeyIterations=0;

		long[] hist_hits=new long[41];
		long[] hist_hits_score=new long[41];
		long[] hist_hits_extend=new long[41];
		
		long initialSiteSum1=0;
		long postTrimSiteSum1=0;
		long postRescueSiteSum1=0;
		long siteSum1=0;
		long topSiteSum1=0;
		
		long matchCountS1=0;
		long matchCountI1=0;
		long matchCountD1=0;
		long matchCountM1=0;
		long matchCountN1=0;
		
		long readCountS1=0;
		long readCountI1=0;
		long readCountD1=0;
		long readCountN1=0;
		long readCountSplice1=0;
		long readCountE1=0;
		
		
		long mapped1=0;
		long mappedRetained1=0;
		long mappedRetainedBases1=0;
		long rescuedP1=0;
		long rescuedM1=0;
		long truePositiveP1=0;
		long truePositiveM1=0;
		long falsePositive1=0;
		long totalCorrectSites1=0;
		long firstSiteCorrectP1=0;
		long firstSiteCorrectM1=0;
		long firstSiteIncorrect1=0;
		long firstSiteCorrectLoose1=0;
		long firstSiteIncorrectLoose1=0;
		long firstSiteCorrectPaired1=0;
		long firstSiteCorrectSolo1=0;
		long firstSiteCorrectRescued1=0;
		long perfectHit1=0; //Highest score is max score
		long uniqueHit1=0; //Only one hit has highest score
		long correctUniqueHit1=0; //unique highest hit on answer site
		long correctMultiHit1=0;  //non-unique highest hit on answer site (non-skimmer only)
		long correctLowHit1=0;  //hit on answer site, but not highest scorer
		long noHit1=0;
		long perfectMatch1=0; //Highest slow score is max slow score
		long semiperfectMatch1=0;
		long perfectMatchBases1=0;
		long semiperfectMatchBases1=0;
		long perfectHitCount1=0;
		long semiPerfectHitCount1=0;
		long duplicateBestAlignment1=0;
		long duplicateBestAlignmentBases1=0;
		
		long totalNumCorrect1=0; //Only for skimmer
		long totalNumIncorrect1=0; //Only for skimmer
		long totalNumIncorrectPrior1=0; //Only for skimmer
		long totalNumCapturedAllCorrect1=0; //Only for skimmer
		long totalNumCapturedAllCorrectTop1=0; //Only for skimmer
		long totalNumCapturedAllCorrectOnly1=0; //Only for skimmer

		long initialSiteSum2=0;
		long postTrimSiteSum2=0;
		long postRescueSiteSum2=0;
		long siteSum2=0;
		long topSiteSum2=0;
		
		long mapped2=0;
		long mappedRetained2=0;
		long mappedRetainedBases2=0;
		long rescuedP2=0;
		long rescuedM2=0;
		long truePositiveP2=0;
		long truePositiveM2=0;
		long falsePositive2=0;
		long totalCorrectSites2=0;
		long firstSiteCorrectP2=0;
		long firstSiteCorrectM2=0;
		long firstSiteIncorrect2=0;
		long firstSiteCorrectLoose2=0;
		long firstSiteIncorrectLoose2=0;
		long firstSiteCorrectPaired2=0;
		long firstSiteCorrectSolo2=0;
		long firstSiteCorrectRescued2=0;
		long perfectHit2=0; //Highest score is max score
		long perfectHitCount2=0;
		long semiPerfectHitCount2=0;
		
		long uniqueHit2=0; //Only one hit has highest score
		long correctUniqueHit2=0; //unique highest hit on answer site
		long correctMultiHit2=0;  //non-unique highest hit on answer site (non-skimmer only)
		long correctLowHit2=0;  //hit on answer site, but not highest scorer
		long noHit2=0;
		long perfectMatch2=0; //Highest slow score is max slow score
		long semiperfectMatch2=0;
		long perfectMatchBases2=0;
		long semiperfectMatchBases2=0;
		long duplicateBestAlignment2=0;
		long duplicateBestAlignmentBases2=0;
		
		long totalNumCorrect2=0; //Only for skimmer
		long totalNumIncorrect2=0; //Only for skimmer
		long totalNumIncorrectPrior2=0; //Only for skimmer
		long totalNumCapturedAllCorrect2=0; //Only for skimmer
		long totalNumCapturedAllCorrectTop2=0; //Only for skimmer
		long totalNumCapturedAllCorrectOnly2=0; //Only for skimmer
		
		long matchCountS2=0;
		long matchCountI2=0;
		long matchCountD2=0;
		long matchCountM2=0;
		long matchCountN2=0;
		
		long readCountS2=0;
		long readCountI2=0;
		long readCountD2=0;
		long readCountN2=0;
		long readCountSplice2=0;
		long readCountE2=0;

		readsUsed1=0;
		readsUsed2=0;
		readsIn1=0;
		readsIn2=0;
		for(int i=0; i<mtts.length; i++){
			AbstractMapThread mtt=mtts[i];
			
			if(mtt.msa!=null){
				msaIterationsLimited+=mtt.msa.iterationsLimited;
				msaIterationsUnlimited+=mtt.msa.iterationsUnlimited;
			}

			readsUsed1+=mtt.readsUsed1;
			readsUsed2+=mtt.readsUsed2;
			readsIn1+=mtt.readsIn1;
			readsIn2+=mtt.readsIn2;
			syntheticReads+=mtt.syntheticReads;
			numMated+=mtt.numMated;
			numMatedBases+=mtt.numMatedBases;
			badPairs+=mtt.badPairs;
			badPairBases+=mtt.badPairBases;
			innerLengthSum+=mtt.innerLengthSum;
			outerLengthSum+=mtt.outerLengthSum;
			insertSizeSum+=mtt.insertSizeSum;
			basesUsed1+=mtt.basesUsed1;
			basesUsed2+=mtt.basesUsed2;
			basesIn1+=mtt.basesIn1;
			basesIn2+=mtt.basesIn2;
			readsPassedBloomFilter+=mtt.readsPassedBloomFilter;
			basesPassedBloomFilter+=mtt.basesPassedBloomFilter;
			keysUsed+=mtt.keysUsed;
			bothUnmapped+=mtt.bothUnmapped;
			bothUnmappedBases+=mtt.bothUnmappedBases;
			eitherMapped+=mtt.eitherMapped;
			eitherMappedBases+=mtt.eitherMappedBases;
			
			mapped1+=mtt.mapped1;
			mappedRetained1+=mtt.mappedRetained1;
			mappedRetainedBases1+=mtt.mappedRetainedBases1;
			rescuedP1+=mtt.rescuedP1;
			rescuedM1+=mtt.rescuedM1;
			lowQualityReadsDiscarded1+=mtt.lowQualityReadsDiscarded1;
			lowQualityBasesDiscarded1+=mtt.lowQualityBasesDiscarded1;
			truePositiveP1+=mtt.truePositiveP1;
			truePositiveM1+=mtt.truePositiveM1;
			falsePositive1+=mtt.falsePositive1;
//			System.err.println("Adding "+mtt.falsePositive+" false positives -> "+falsePositive);
			totalCorrectSites1+=mtt.totalCorrectSites1;

//			assert(false) : mtt.firstSiteCorrectP1;
			firstSiteCorrectP1+=mtt.firstSiteCorrectP1;
			firstSiteCorrectM1+=mtt.firstSiteCorrectM1;
			firstSiteIncorrect1+=mtt.firstSiteIncorrect1;
			firstSiteCorrectLoose1+=mtt.firstSiteCorrectLoose1;
			firstSiteIncorrectLoose1+=mtt.firstSiteIncorrectLoose1;
			firstSiteCorrectPaired1+=mtt.firstSiteCorrectPaired1;
			firstSiteCorrectSolo1+=mtt.firstSiteCorrectSolo1;
			firstSiteCorrectRescued1+=mtt.firstSiteCorrectRescued1;
			
			perfectHit1+=mtt.perfectHit1; //Highest score is max score
			perfectHitCount1+=mtt.perfectHitCount1;
			semiPerfectHitCount1+=mtt.semiPerfectHitCount1;
			uniqueHit1+=mtt.uniqueHit1; //Only one hit has highest score
			correctUniqueHit1+=mtt.correctUniqueHit1; //unique highest hit on answer site
			correctMultiHit1+=mtt.correctMultiHit1;  //non-unique highest hit on answer site
			correctLowHit1+=mtt.correctLowHit1;  //hit on answer site, but not highest scorer
			noHit1+=mtt.noHit1;
			
			totalNumCorrect1+=mtt.totalNumCorrect1; //Skimmer only
			totalNumIncorrect1+=mtt.totalNumIncorrect1; //Skimmer only
			totalNumIncorrectPrior1+=mtt.totalNumIncorrectPrior1; //Skimmer only
			totalNumCapturedAllCorrect1+=mtt.totalNumCapturedAllCorrect1; //Skimmer only
			totalNumCapturedAllCorrectTop1+=mtt.totalNumCapturedAllCorrectTop1; //Skimmer only
			totalNumCapturedAllCorrectOnly1+=mtt.totalNumCapturedAllCorrectOnly1; //Skimmer only
			
			perfectMatch1+=mtt.perfectMatch1; //Highest slow score is max slow score
			semiperfectMatch1+=mtt.semiperfectMatch1; //A semiperfect mapping was found
			perfectMatchBases1+=mtt.perfectMatchBases1;
			semiperfectMatchBases1+=mtt.semiperfectMatchBases1;
			
			duplicateBestAlignment1+=mtt.ambiguousBestAlignment1;
			duplicateBestAlignmentBases1+=mtt.ambiguousBestAlignmentBases1;

			initialSiteSum1+=mtt.initialSiteSum1;
			postTrimSiteSum1+=mtt.postTrimSiteSum1;
			postRescueSiteSum1+=mtt.postRescueSiteSum1;
			siteSum1+=mtt.siteSum1;
			topSiteSum1+=mtt.topSiteSum1;
			
			AbstractIndex index=mtt.index();
			callsToScore+=index.callsToScore;
			callsToExtend+=index.callsToExtendScore;
			initialKeys+=index.initialKeys;
			initialKeyIterations+=index.initialKeyIterations;
			usedKeys+=index.usedKeys;
			usedKeyIterations+=index.usedKeyIterations;
			
			for(int j=0; j<index.hist_hits.length; j++){
				int x=Tools.min(hist_hits.length-1, j);
				hist_hits[x]+=index.hist_hits[j];
				hist_hits_score[x]+=index.hist_hits_score[j];
				hist_hits_extend[x]+=index.hist_hits_extend[j];
			}
			
			matchCountS1+=mtt.matchCountS1;
			matchCountI1+=mtt.matchCountI1;
			matchCountD1+=mtt.matchCountD1;
			matchCountM1+=mtt.matchCountM1;
			matchCountN1+=mtt.matchCountN1;
			
			readCountS1+=mtt.readCountS1;
			readCountI1+=mtt.readCountI1;
			readCountD1+=mtt.readCountD1;
			readCountN1+=mtt.readCountN1;
			readCountSplice1+=mtt.readCountSplice1;
			readCountE1+=mtt.readCountE1;

			mapped2+=mtt.mapped2;
			mappedRetained2+=mtt.mappedRetained2;
			mappedRetainedBases2+=mtt.mappedRetainedBases2;
			rescuedP2+=mtt.rescuedP2;
			rescuedM2+=mtt.rescuedM2;
			lowQualityReadsDiscarded2+=mtt.lowQualityReadsDiscarded2;
			lowQualityBasesDiscarded2+=mtt.lowQualityBasesDiscarded2;
			truePositiveP2+=mtt.truePositiveP2;
			truePositiveM2+=mtt.truePositiveM2;
			falsePositive2+=mtt.falsePositive2;
//			System.err.println("Adding "+mtt.falsePositive+" false positives -> "+falsePositive);
			totalCorrectSites2+=mtt.totalCorrectSites2;

			firstSiteCorrectP2+=mtt.firstSiteCorrectP2;
			firstSiteCorrectM2+=mtt.firstSiteCorrectM2;
			firstSiteIncorrect2+=mtt.firstSiteIncorrect2;
			firstSiteCorrectLoose2+=mtt.firstSiteCorrectLoose2;
			firstSiteIncorrectLoose2+=mtt.firstSiteIncorrectLoose2;
			firstSiteCorrectPaired2+=mtt.firstSiteCorrectPaired2;
			firstSiteCorrectSolo2+=mtt.firstSiteCorrectSolo2;
			firstSiteCorrectRescued2+=mtt.firstSiteCorrectRescued2;
			
			perfectHit2+=mtt.perfectHit2; //Highest score is max score
			perfectHitCount2+=mtt.perfectHitCount2;
			semiPerfectHitCount2+=mtt.semiPerfectHitCount2;
			uniqueHit2+=mtt.uniqueHit2; //Only one hit has highest score
			correctUniqueHit2+=mtt.correctUniqueHit2; //unique highest hit on answer site
			correctMultiHit2+=mtt.correctMultiHit2;  //non-unique highest hit on answer site
			correctLowHit2+=mtt.correctLowHit2;  //hit on answer site, but not highest scorer
			noHit2+=mtt.noHit2;
			
			totalNumCorrect2+=mtt.totalNumCorrect2; //Skimmer only
			totalNumIncorrect2+=mtt.totalNumIncorrect2; //Skimmer only
			totalNumIncorrectPrior2+=mtt.totalNumIncorrectPrior2; //Skimmer only
			totalNumCapturedAllCorrect2+=mtt.totalNumCapturedAllCorrect2; //Skimmer only
			totalNumCapturedAllCorrectTop2+=mtt.totalNumCapturedAllCorrectTop2; //Skimmer only
			totalNumCapturedAllCorrectOnly2+=mtt.totalNumCapturedAllCorrectOnly2; //Skimmer only
			
			perfectMatch2+=mtt.perfectMatch2; //Highest slow score is max slow score
			semiperfectMatch2+=mtt.semiperfectMatch2; //A semiperfect mapping was found
			perfectMatchBases2+=mtt.perfectMatchBases2;
			semiperfectMatchBases2+=mtt.semiperfectMatchBases2;
			
			duplicateBestAlignment2+=mtt.ambiguousBestAlignment2;
			duplicateBestAlignmentBases2+=mtt.ambiguousBestAlignmentBases2;

			initialSiteSum2+=mtt.initialSiteSum2;
			postTrimSiteSum2+=mtt.postTrimSiteSum2;
			postRescueSiteSum2+=mtt.postRescueSiteSum2;
			siteSum2+=mtt.siteSum2;
			topSiteSum2+=mtt.topSiteSum2;
			
			matchCountS2+=mtt.matchCountS2;
			matchCountI2+=mtt.matchCountI2;
			matchCountD2+=mtt.matchCountD2;
			matchCountM2+=mtt.matchCountM2;
			matchCountN2+=mtt.matchCountN2;
			
			readCountS2+=mtt.readCountS2;
			readCountI2+=mtt.readCountI2;
			readCountD2+=mtt.readCountD2;
			readCountN2+=mtt.readCountN2;
			readCountSplice2+=mtt.readCountSplice2;
			readCountE2+=mtt.readCountE2;
			
		}
		maxReads=readsUsed1;
		if(syntheticReads>0){SYNTHETIC=true;}
		
		t.stop();
		long nanos=t.elapsed;
		
		if(verbose_stats>1){
			StringBuilder sb=new StringBuilder(1000);
			sb.append("\n\n###################\n#hits\tcount\tscore\textend\n");
			for(int i=0; i<hist_hits.length; i++){
				sb.append(i+"\t"+hist_hits[i]+"\t"+hist_hits_score[i]+"\t"+hist_hits_extend[i]+"\n");
			}
			try {
				ReadWrite.writeString(sb, "hist_hits.txt", true);
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		final long basesUsed=basesUsed1+basesUsed2;
		
		final double invTrials=1d/maxReads;
		final double invTrials100=100d/maxReads;
		final double invBases100=100d/(basesUsed);
		final double invBases100_1=100d/basesUsed1;
		final double invBases100_2=100d/basesUsed2;
		double invSites100=100d/siteSum1;
		
		final double matedPercent=(numMated*invTrials100);
		final double badPairsPercent=(badPairs*invTrials100);
		final double matedPercentBases=(numMatedBases*invBases100);
		final double badPairsPercentBases=(badPairBases*invBases100);
		final double innerLengthAvg=(innerLengthSum*1d/numMated);
		final double outerLengthAvg=(outerLengthSum*1d/numMated);
		final double insertSizeAvg=(insertSizeSum*1d/numMated);
		
		final double readsPerSecond=((readsUsed1+readsUsed2)*1000000000d)/nanos;
		final double fragsPerSecond=(keysUsed*1000000000d)/nanos;
		final double kiloBasesPerSecond=(basesUsed*1000000d)/nanos;
		
		double perfectHitPercent=(perfectHit1*invTrials100); //Highest score is max score
		double perfectMatchPercent=(perfectMatch1*invTrials100);
		double semiperfectMatchPercent=(semiperfectMatch1*invTrials100);
		double perfectMatchPercentBases=(perfectMatchBases1*invBases100_1);
		double semiperfectMatchPercentBases=(semiperfectMatchBases1*invBases100_1);
		
		double perfectHitCountPercent=perfectHitCount1*invSites100;
		double semiPerfectHitCountPercent=semiPerfectHitCount1*invSites100;
		
		double uniqueHitPercent=(uniqueHit1*invTrials100); //Only one hit has highest score
		double correctUniqueHitPercent=(correctUniqueHit1*invTrials100); //unique highest hit on answer site
		double correctMultiHitPercent=(correctMultiHit1*invTrials100);  //non-unique highest hit on answer site
		double correctLowHitPercent=(correctLowHit1*invTrials100);  //hit on answer site, but not highest scorer
		double ambiguousFound=(duplicateBestAlignment1*invTrials100);
		double ambiguousBasesFound=(duplicateBestAlignmentBases1*invBases100_1);
		double correctHighHitPercent=((correctMultiHit1+correctUniqueHit1)*invTrials100);
		double correctHitPercent=((correctLowHit1+correctMultiHit1+correctUniqueHit1)*invTrials100);

		double mappedB=(mapped1*invTrials100);
		double mappedRetainedB=(mappedRetained1*invTrials100);
		double mappedRetainedBasesB=(mappedRetainedBases1*invBases100_1);
		double rescuedPB=(rescuedP1*invTrials100);
		double rescuedMB=(rescuedM1*invTrials100);
		
		double falsePositiveB=(firstSiteIncorrect1*invTrials100);
		double falsePositiveLooseB=(firstSiteIncorrectLoose1*invTrials100);
		double truePositivePB=(firstSiteCorrectP1*invTrials100);
		double truePositiveMB=(firstSiteCorrectM1*invTrials100);
		double truePositiveStrict=((firstSiteCorrectP1+firstSiteCorrectM1)*invTrials100);
		double truePositiveLoose=(firstSiteCorrectLoose1*invTrials100);
		double snrStrict=10*Math.log10((firstSiteCorrectM1+firstSiteCorrectP1+0.1)/(firstSiteIncorrect1+0.1));
		double snrLoose=10*Math.log10((firstSiteCorrectLoose1+0.1)/(firstSiteIncorrectLoose1+0.1));
		double truePositivePMRatio=(truePositivePB/truePositiveMB);
		double truePositivePairedB=(firstSiteCorrectPaired1*100d/numMated);
		double truePositiveSoloB=(firstSiteCorrectSolo1*100d/(mappedRetained1-numMated));
		double truePositiveRescuedB=(firstSiteCorrectRescued1*100d/(rescuedP1+rescuedM1));
		
		double noHitPercent=(noHit1*invTrials100);
		
		long mappedReads, unambiguousReads, mappedBases, unambiguousBases;
		if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
			mappedReads=mappedRetained1+duplicateBestAlignment1;
			unambiguousReads=mappedRetained1;
			mappedBases=mappedRetainedBases1+duplicateBestAlignmentBases1;
			unambiguousBases=mappedRetainedBases1;
		}else{
			mappedReads=mappedRetained1;
			unambiguousReads=mappedRetained1-duplicateBestAlignment1;
			mappedBases=mappedRetainedBases1;
			unambiguousBases=mappedRetainedBases1-duplicateBestAlignmentBases1;
		}
		
		double avgNumCorrect=(SKIMMER ? totalNumCorrect1*invTrials : (totalCorrectSites1/(1d*(truePositiveP1+truePositiveM1))));
		double avgNumIncorrect=totalNumIncorrect1*invTrials; //Skimmer only
		double avgNumIncorrectPrior=totalNumIncorrectPrior1*invTrials; //Skimmer only

		double rateCapturedAllCorrect=totalNumCapturedAllCorrect1*invTrials100; //Skimmer only
		double rateCapturedAllTop=totalNumCapturedAllCorrectTop1*invTrials100; //Skimmer only
		double rateCapturedAllOnly=totalNumCapturedAllCorrectOnly1*invTrials100; //Skimmer only

		double avgCallsToScore=(callsToScore*invTrials);
		double avgCallsToExtendScore=(callsToExtend*invTrials);
		double avgInitialKeys=(initialKeys*1d/initialKeyIterations);
		double avgUsedKeys=(usedKeys*1d/usedKeyIterations);
		
		double avgInitialSites=(initialSiteSum1*invTrials);
		double avgPostTrimSites=(postTrimSiteSum1*invTrials);
		double avgPostRescueSites=(postRescueSiteSum1*invTrials);
		double avgSites=(siteSum1*invTrials);
		double avgPerfectSites=(perfectHitCount1*invTrials);
		double avgSemiPerfectSites=(semiPerfectHitCount1*invTrials);
		double avgTopSites=(topSiteSum1*invTrials);
		double lowQualityReadsDiscardedPercent=(lowQualityReadsDiscarded1*invTrials100);
		double lowQualityBasesDiscardedPercent=(lowQualityBasesDiscarded1*invBases100_1);

		long matchErrors=matchCountS1+matchCountI1+matchCountD1;
		long baseLen=matchCountM1+matchCountI1+matchCountS1+matchCountN1;
		long matchLen=matchCountM1+matchCountI1+matchCountS1+matchCountN1+matchCountD1;
		long refLen=matchCountM1+matchCountS1+matchCountN1+matchCountD1;
		double errorRate=matchErrors*100d/matchLen;
		double matchRate=matchCountM1*100d/matchLen;
		double subRate=matchCountS1*100d/matchLen;
		double delRate=matchCountD1*100d/matchLen;
		double insRate=matchCountI1*100d/matchLen;
		double nRate=matchCountN1*100d/matchLen;
		double readSubRate=readCountS1*100d/mapped1;
		double readDelRate=readCountD1*100d/mapped1;
		double readInsRate=readCountI1*100d/mapped1;
		double readNRate=readCountN1*100d/mapped1;
		double readSpliceRate=readCountSplice1*100d/mapped1;
		double readErrorRate=readCountE1*100d/mapped1;
		
		if(SYNTHETIC && verbose_stats==-1){verbose_stats=Tools.max(verbose_stats,9);}
		
		tswStats.println("Reads Used:           \t"+(readsUsed1+readsUsed2)+"\t("+(basesUsed)+" bases)");
		tswStats.println();
		
		if(useRandomReads){
			tswStats.println("Read Length:          \t"+synthReadlen);
			tswStats.println("SNP rate:             \t"+baseSnpRate+"\t(max = "+maxSnps+")");
			tswStats.println("INS rate:             \t"+baseInsRate+"\t(max = "+maxInss+", maxLen = "+maxInsLen+")");
			tswStats.println("DEL rate:             \t"+baseDelRate+"\t(max = "+maxDels+", maxLen = "+maxDelLen+")");
			tswStats.println("SUB rate:             \t"+baseSubRate+"\t(max = "+maxSubs+", maxLen = "+maxSubLen+")");
			tswStats.println("minQuality:           \t"+minQuality);
			tswStats.println("midQuality:           \t"+midQuality);
			tswStats.println("maxQuality:           \t"+maxQuality);
			tswStats.println("prefect fraction:     \t"+PERFECT_READ_RATIO);
			tswStats.println();
		}

		tswStats.println("Mapping:          \t"+t);
		tswStats.println(String.format(Locale.ROOT, "Reads/sec:       \t%.2f", readsPerSecond));
		tswStats.println(String.format(Locale.ROOT, "kBases/sec:      \t%.2f", kiloBasesPerSecond));
		double milf=msaIterationsLimited*invTrials;
		double milu=msaIterationsUnlimited*invTrials;
		if(verbose_stats>=1){tswStats.println("MSA iterations:   \t"+String.format(Locale.ROOT, "%.2fL + %.2fU = %.2f", milf,milu,milf+milu));}
		
		if(paired){
			tswStats.println("\n\nPairing data:   \tpct pairs\tnum pairs \tpct bases\t   num bases");
			tswStats.println();
			if(paired){
				tswStats.println("mated pairs:     \t"+padPercent(matedPercent,4)+"% \t"+pad(numMated,9)+" \t"+padPercent(matedPercentBases,4)+"% \t"+pad(numMatedBases,12));
				tswStats.println("bad pairs:       \t"+padPercent(badPairsPercent,4)+"% \t"+pad(badPairs,9)+" \t"+padPercent(badPairsPercentBases,4)+"% \t"+pad(badPairBases,12));
			}

			tswStats.println("insert size avg: \t  "+padPercent(insertSizeAvg,2));
			if(ReadStats.COLLECT_INSERT_STATS){
				if(ReadStats.merged==null){ReadStats.mergeAll();}
				long[] array=ReadStats.merged.insertHist.array;
				double median=Tools.medianHistogram(array);
				double q1=Tools.percentileHistogram(array, 0.25);
				double q3=Tools.percentileHistogram(array, 0.75);
				double stdev=Tools.standardDeviationHistogram(array);
				//TODO: Quartiles
				tswStats.println("insert 25th %:   \t  "+padPercent(q1,2));
				tswStats.println("insert median:   \t  "+padPercent(median,2));
				tswStats.println("insert 75th %:   \t  "+padPercent(q3,2));
				tswStats.println("insert std dev:  \t  "+padPercent(stdev,2));
				tswStats.println("insert mode:     \t  "+Tools.calcModeHistogram(array));
			}
			if(verbose_stats>=1){
				tswStats.println(String.format(Locale.ROOT, "avg inner length:\t  %.2f", innerLengthAvg));
				tswStats.println(String.format(Locale.ROOT, "avg insert size: \t  %.2f", outerLengthAvg));
			}
		}
		
		/** For RQCFilter */
		lastBothUnmapped=bothUnmapped;
		lastBothUnmappedBases=bothUnmappedBases;
		lastEitherMapped=eitherMapped;
		lastEitherMappedBases=eitherMappedBases;
		lastReadsUsed=readsUsed1+readsUsed2;
		lastBasesUsed=basesUsed;
		lastReadsIn=readsIn1+readsIn2;
		lastBasesIn=basesIn1+basesIn2;
		lastReadsPassedBloomFilter=readsPassedBloomFilter;
		lastBasesPassedBloomFilter=basesPassedBloomFilter;
		
		if(PRINT_UNMAPPED_COUNT){
			double invReadsUsed100=100.0/(readsUsed1+readsUsed2);
			double invBasesUsed100=100.0/basesUsed;
			double x=bothUnmapped*invReadsUsed100;
			double y=bothUnmappedBases*invBasesUsed100;
			if(!paired){tswStats.println();}
			tswStats.println("unmapped:        \t"+padPercent(x,4)+"% \t"+pad(bothUnmapped,9)+" \t"+padPercent(y,4)+"% \t"+pad(bothUnmappedBases,12));
		}
		
		tswStats.println();
		tswStats.println("\nRead 1 data:      \tpct reads\tnum reads \tpct bases\t   num bases");
		if(verbose_stats>=1){
			if(avgInitialKeys>0){tswStats.println(String.format(Locale.ROOT, "Avg Initial Keys:      \t"+(avgInitialKeys<100?" ":"")+"%.3f",
					avgInitialKeys));}
			if(avgUsedKeys>0){tswStats.println(String.format(Locale.ROOT, "Avg Used Keys:         \t"+(avgUsedKeys<100?" ":"")+"%.3f",
					avgUsedKeys));}
			if(avgCallsToScore>0){tswStats.println(String.format(Locale.ROOT, "Avg Calls to Score: \t"+(avgCallsToScore<100?" ":"")+"%.3f",
					avgCallsToScore));}
			if(avgCallsToExtendScore>0){tswStats.println(String.format(Locale.ROOT, "Avg Calls to Extend:\t"+(avgCallsToExtendScore<100?" ":"")+"%.3f",
					avgCallsToExtendScore));}
			tswStats.println();

			tswStats.println(String.format(Locale.ROOT, "Avg Initial Sites:  \t"+(avgInitialSites<10?" ":"")+"%.3f", avgInitialSites));
			if(TRIM_LIST){tswStats.println(String.format(Locale.ROOT, "Avg Post-Trim:      \t"+(avgPostTrimSites<10?" ":"")+"%.3f", avgPostTrimSites));}
			if(paired){tswStats.println(String.format(Locale.ROOT, "Avg Post-Rescue:    \t"+(avgPostRescueSites<10?" ":"")+"%.3f", avgPostRescueSites));}
			tswStats.println(String.format(Locale.ROOT, "Avg Final Sites:    \t"+(avgSites<10?" ":"")+"%.3f", avgSites));
			tswStats.println(String.format(Locale.ROOT, "Avg Top Sites:      \t"+(avgTopSites<10?" ":"")+"%.3f", avgTopSites));
			if(verbose_stats>1){
				tswStats.println(String.format(Locale.ROOT, "Avg Perfect Sites:  \t"+(avgPerfectSites<10?" ":"")+"%.3f    \t"+
						(perfectHitCountPercent<10?" ":"")+"%.3f%%", avgPerfectSites, perfectHitCountPercent));
				tswStats.println(String.format(Locale.ROOT, "Avg Semiperfect Sites:\t"+(avgSemiPerfectSites<10?" ":"")+"%.3f    \t"+
						(semiPerfectHitCountPercent<10?" ":"")+"%.3f%%", avgSemiPerfectSites, semiPerfectHitCountPercent));
			}

			if(SYNTHETIC){
				tswStats.println(String.format(Locale.ROOT, "Avg Correct Sites:  \t"+(avgNumCorrect<10?" ":"")+"%.3f", avgNumCorrect));
				if(SKIMMER){
					tswStats.println(String.format(Locale.ROOT, "Avg Incorrect Sites:\t"+(avgNumIncorrect<10?" ":"")+"%.3f", avgNumIncorrect));
					tswStats.println(String.format(Locale.ROOT, "Avg IncorrectP Sites:\t"+(avgNumIncorrectPrior<10?" ":"")+"%.3f", avgNumIncorrectPrior));
				}
			}
		}
		
		tswStats.println();
		if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
			double x=ambiguousFound+mappedRetainedB;
			double y=ambiguousBasesFound+mappedRetainedBasesB;
			tswStats.println("mapped:          \t"+padPercent(x,4)+"% \t"+pad(mappedReads,9)+" \t"+padPercent(y,4)+"% \t"+pad(mappedBases,12));
			tswStats.println("unambiguous:     \t"+padPercent(mappedRetainedB,4)+"% \t"+pad(unambiguousReads,9)+" \t"+padPercent(mappedRetainedBasesB,4)+"% \t"+pad(unambiguousBases,12));
		}else{
			double x=mappedRetainedB-ambiguousFound;
			double y=mappedRetainedBasesB-ambiguousBasesFound;
			tswStats.println("mapped:          \t"+padPercent(mappedRetainedB,4)+"% \t"+pad(mappedReads,9)+" \t"+padPercent(mappedRetainedBasesB,4)+"% \t"+pad(mappedBases,12));
			tswStats.println("unambiguous:     \t"+padPercent(x,4)+"% \t"+pad(unambiguousReads,9)+" \t"+padPercent(y,4)+"% \t"+pad(unambiguousBases,12));
		}
		tswStats.println("ambiguous:       \t"+padPercent(ambiguousFound,4)+"% \t"+pad(duplicateBestAlignment1,9)+
				" \t"+padPercent(ambiguousBasesFound,4)+"% \t"+pad(duplicateBestAlignmentBases1,12));
		tswStats.println("low-Q discards:  \t"+padPercent(lowQualityReadsDiscardedPercent,4)+"% \t"+pad(lowQualityReadsDiscarded1,9)+
				" \t"+padPercent(lowQualityBasesDiscardedPercent,4)+"% \t"+pad(lowQualityBasesDiscarded1,12));
		
		tswStats.println();
		tswStats.println("perfect best site:\t"+padPercent(perfectMatchPercent,4)+"% \t"+pad(perfectMatch1,9)+
				" \t"+padPercent(perfectMatchPercentBases,4)+"% \t"+pad(perfectMatchBases1,12));
		tswStats.println("semiperfect site:\t"+padPercent(semiperfectMatchPercent,4)+"% \t"+pad(semiperfectMatch1,9)+
				" \t"+padPercent(semiperfectMatchPercentBases,4)+"% \t"+pad(semiperfectMatchBases1,12));
		if(paired){
			tswStats.println("rescued:         \t"+padPercent(rescuedPB+rescuedMB,4)+"% \t"+pad(rescuedP1+rescuedM1,9));
		}
		
		if(MAKE_MATCH_STRING){
			
			tswStats.println();
//			tswStats.println("                 \tpct reads\tnum reads \tpct bases\t   num bases");
			tswStats.println("Match Rate:      \t      NA \t       NA \t"+padPercent(matchRate,4)+"% \t"+pad(matchCountM1,12));
			tswStats.println("Error Rate:      \t"+padPercent(readErrorRate,4)+"% \t"+pad(readCountE1,9)+" \t"+padPercent(errorRate,4)+"% \t"+pad(matchErrors,12));
			tswStats.println("Sub Rate:        \t"+padPercent(readSubRate,4)+"% \t"+pad(readCountS1,9)+" \t"+padPercent(subRate,4)+"% \t"+pad(matchCountS1,12));
			tswStats.println("Del Rate:        \t"+padPercent(readDelRate,4)+"% \t"+pad(readCountD1,9)+" \t"+padPercent(delRate,4)+"% \t"+pad(matchCountD1,12));
			tswStats.println("Ins Rate:        \t"+padPercent(readInsRate,4)+"% \t"+pad(readCountI1,9)+" \t"+padPercent(insRate,4)+"% \t"+pad(matchCountI1,12));
			tswStats.println("N Rate:          \t"+padPercent(readNRate,4)+"% \t"+pad(readCountN1,9)+" \t"+padPercent(nRate,4)+"% \t"+pad(matchCountN1,12));
			if(SamLine.INTRON_LIMIT<Integer.MAX_VALUE){
				tswStats.println("Splice Rate:     \t"+padPercent(readSpliceRate,4)+"% \t"+pad(readCountSplice1,9)+" \t(splices at least "+SamLine.INTRON_LIMIT+" bp)");
			}
			
			if(DOUBLE_PRINT_ERROR_RATE){
				System.err.println();
				System.err.println(String.format(Locale.ROOT, "Match Rate:      \t"+(matchRate<10?" ":"")+"%.4f", matchRate)+"% \t"+matchCountM1);
				System.err.println(String.format(Locale.ROOT, "Error Rate:      \t"+(errorRate<10?" ":"")+"%.4f", errorRate)+"% \t"+matchErrors);
				System.err.println(String.format(Locale.ROOT, "Sub Rate:        \t"+(subRate<10?" ":"")+"%.4f", subRate)+"% \t"+matchCountS1);
				System.err.println(String.format(Locale.ROOT, "Del Rate:        \t"+(delRate<10?" ":"")+"%.4f", delRate)+"% \t"+matchCountD1);
				System.err.println(String.format(Locale.ROOT, "Ins Rate:        \t"+(insRate<10?" ":"")+"%.4f", insRate)+"% \t"+matchCountI1);
				System.err.println(String.format(Locale.ROOT, "N Rate:          \t"+(nRate<10?" ":"")+"%.4f", nRate)+"% \t"+matchCountN1);
			}
		}
		
		if(SYNTHETIC){
			tswStats.println();
			tswStats.println("true positive:   \t"+padPercent(truePositiveStrict,4)+"%\t(loose: "+padPercent(truePositiveLoose,4)+"%)");
			tswStats.println("false positive:  \t"+padPercent(falsePositiveB,4)+"%\t(loose: "+padPercent(falsePositiveLooseB,4)+"%)");
			tswStats.println("false negative:  \t"+padPercent(noHitPercent,4)+"%");
			tswStats.println("SNR:             \t"+padPercent(snrStrict,4)+" \t(loose: "+padPercent(snrLoose,4)+")");
			if(verbose_stats>0){
				tswStats.println("correctLowHit:   \t"+padPercent(correctLowHitPercent,4)+"%");
				tswStats.println(String.format(Locale.ROOT, "Plus/Minus ratio:\t %1.4f", truePositivePMRatio));
			}
			
			if(paired){
				tswStats.println("correct pairs:   \t"+padPercent(truePositivePairedB,4)+"%\t(of mated)");
				tswStats.println("correct singles: \t"+padPercent(truePositiveSoloB,4)+"%");
				tswStats.println("correct rescued: \t"+padPercent(truePositiveRescuedB,4)+"%");
			}
			
			if(SKIMMER){
				tswStats.println("found all correct:\t"+padPercent(rateCapturedAllCorrect,4)+"%)");
				tswStats.println("all correct top:  \t"+padPercent(rateCapturedAllTop,4)+"%)");
				tswStats.println("all correct only: \t"+padPercent(rateCapturedAllOnly,4)+"%)");
			}
		}
		
		if(paired){
			
			invSites100=100d/siteSum2;
			
			perfectHitPercent=(perfectHit2*invTrials100); //Highest score is max score
			perfectMatchPercent=(perfectMatch2*invTrials100);
			semiperfectMatchPercent=(semiperfectMatch2*invTrials100);
			perfectMatchPercentBases=(perfectMatchBases2*invBases100_2);
			semiperfectMatchPercentBases=(semiperfectMatchBases2*invBases100_2);
			
			perfectHitCountPercent=perfectHitCount2*invSites100;
			semiPerfectHitCountPercent=semiPerfectHitCount2*invSites100;
			
			uniqueHitPercent=(uniqueHit2*invTrials100); //Only one hit has highest score
			correctUniqueHitPercent=(correctUniqueHit2*invTrials100); //unique highest hit on answer site
			correctMultiHitPercent=(correctMultiHit2*invTrials100);  //non-unique highest hit on answer site
			correctLowHitPercent=(correctLowHit2*invTrials100);  //hit on answer site, but not highest scorer
			ambiguousFound=(duplicateBestAlignment2*invTrials100);
			ambiguousBasesFound=(duplicateBestAlignmentBases2*invBases100_2);
			correctHighHitPercent=((correctMultiHit2+correctUniqueHit2)*invTrials100);
			correctHitPercent=((correctLowHit2+correctMultiHit2+correctUniqueHit2)*invTrials100);

			mappedB=(mapped2*invTrials100);
			mappedRetainedB=(mappedRetained2*invTrials100);
			mappedRetainedBasesB=(mappedRetainedBases2*invBases100_2);
			rescuedPB=(rescuedP2*invTrials100);
			rescuedMB=(rescuedM2*invTrials100);
			falsePositiveB=(firstSiteIncorrect2*invTrials100);
			falsePositiveLooseB=(firstSiteIncorrectLoose2*invTrials100);
			truePositivePB=(firstSiteCorrectP2*invTrials100);
			truePositiveMB=(firstSiteCorrectM2*invTrials100);
			truePositiveStrict=((firstSiteCorrectP2+firstSiteCorrectM2)*invTrials100);
			truePositiveLoose=(firstSiteCorrectLoose2*invTrials100);
			snrStrict=10*Math.log10((firstSiteCorrectM2+firstSiteCorrectP2+0.1)/(firstSiteIncorrect2+0.1));
			snrLoose=10*Math.log10((firstSiteCorrectLoose2+0.1)/(firstSiteIncorrectLoose2+0.1));
			truePositivePMRatio=(truePositivePB/truePositiveMB);
			truePositivePairedB=(firstSiteCorrectPaired2*100d/numMated);
			truePositiveSoloB=(firstSiteCorrectSolo2*100d/(mappedRetained2-numMated));
			truePositiveRescuedB=(firstSiteCorrectRescued2*100d/(rescuedP2+rescuedM2));
			noHitPercent=(noHit2*invTrials100);
			
			if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
				mappedReads=mappedRetained2+duplicateBestAlignment2;
				unambiguousReads=mappedRetained2;
				mappedBases=mappedRetainedBases2+duplicateBestAlignmentBases2;
				unambiguousBases=mappedRetainedBases2;
			}else{
				mappedReads=mappedRetained2;
				unambiguousReads=mappedRetained2-duplicateBestAlignment2;
				mappedBases=mappedRetainedBases2;
				unambiguousBases=mappedRetainedBases2-duplicateBestAlignmentBases2;
			}
			
			avgNumCorrect=(SKIMMER ? totalNumCorrect2*invTrials : (totalCorrectSites2/(2d*(truePositiveP2+truePositiveM2))));
			avgNumIncorrect=totalNumIncorrect2*invTrials; //Skimmer only
			avgNumIncorrectPrior=totalNumIncorrectPrior2*invTrials; //Skimmer only

			rateCapturedAllCorrect=totalNumCapturedAllCorrect2*invTrials100; //Skimmer only
			rateCapturedAllTop=totalNumCapturedAllCorrectTop2*invTrials100; //Skimmer only
			rateCapturedAllOnly=totalNumCapturedAllCorrectOnly2*invTrials100; //Skimmer only

			avgCallsToScore=(callsToScore*invTrials);
			avgCallsToExtendScore=(callsToExtend*invTrials);
			avgInitialKeys=(initialKeys*2d/initialKeyIterations);
			avgUsedKeys=(usedKeys*2d/usedKeyIterations);
			
			avgInitialSites=(initialSiteSum2*invTrials);
			avgPostTrimSites=(postTrimSiteSum2*invTrials);
			avgPostRescueSites=(postRescueSiteSum2*invTrials);
			avgSites=(siteSum2*invTrials);
			avgPerfectSites=(perfectHitCount2*invTrials);
			avgSemiPerfectSites=(semiPerfectHitCount2*invTrials);
			avgTopSites=(topSiteSum2*invTrials);
			lowQualityReadsDiscardedPercent=(lowQualityReadsDiscarded2*invTrials100);
			lowQualityBasesDiscardedPercent=(lowQualityBasesDiscarded2*invBases100_2);

			matchErrors=matchCountS2+matchCountI2+matchCountD2;
			baseLen=matchCountM2+matchCountI2+matchCountS2+matchCountN2;
			matchLen=matchCountM2+matchCountI2+matchCountS2+matchCountN2+matchCountD2;
			refLen=matchCountM2+matchCountS2+matchCountN2+matchCountD2;
			errorRate=matchErrors*100d/matchLen;
			matchRate=matchCountM2*100d/matchLen;
			subRate=matchCountS2*100d/matchLen;
			delRate=matchCountD2*100d/matchLen;
			insRate=matchCountI2*100d/matchLen;
			nRate=matchCountN2*100d/matchLen;
			readSubRate=readCountS2*100d/mapped2;
			readDelRate=readCountD2*100d/mapped2;
			readInsRate=readCountI2*100d/mapped2;
			readNRate=readCountN2*100d/mapped2;
			readSpliceRate=readCountSplice2*100d/mapped2;
			readErrorRate=readCountE2*100d/mapped2;
			
			tswStats.println();
			tswStats.println("\nRead 2 data:      \tpct reads\tnum reads \tpct bases\t   num bases");
			if(verbose_stats>=1){
				if(avgInitialKeys>0){tswStats.println(String.format(Locale.ROOT, "Avg Initial Keys:      \t"+(avgInitialKeys<100?" ":"")+"%.3f",
						avgInitialKeys));}
				if(avgUsedKeys>0){tswStats.println(String.format(Locale.ROOT, "Avg Used Keys:         \t"+(avgUsedKeys<100?" ":"")+"%.3f",
						avgUsedKeys));}
				if(avgCallsToScore>0){tswStats.println(String.format(Locale.ROOT, "Avg Calls to Score: \t"+(avgCallsToScore<100?" ":"")+"%.3f",
						avgCallsToScore));}
				if(avgCallsToExtendScore>0){tswStats.println(String.format(Locale.ROOT, "Avg Calls to Extend:\t"+(avgCallsToExtendScore<100?" ":"")+"%.3f",
						avgCallsToExtendScore));}
				tswStats.println();

				tswStats.println(String.format(Locale.ROOT, "Avg Initial Sites:  \t"+(avgInitialSites<10?" ":"")+"%.3f", avgInitialSites));
				if(TRIM_LIST){tswStats.println(String.format(Locale.ROOT, "Avg Post-Trim:      \t"+(avgPostTrimSites<10?" ":"")+"%.3f", avgPostTrimSites));}
				if(paired){tswStats.println(String.format(Locale.ROOT, "Avg Post-Rescue:    \t"+(avgPostRescueSites<10?" ":"")+"%.3f", avgPostRescueSites));}
				tswStats.println(String.format(Locale.ROOT, "Avg Final Sites:    \t"+(avgSites<10?" ":"")+"%.3f", avgSites));
				tswStats.println(String.format(Locale.ROOT, "Avg Top Sites:      \t"+(avgTopSites<10?" ":"")+"%.3f", avgTopSites));
				if(verbose_stats>1){
					tswStats.println(String.format(Locale.ROOT, "Avg Perfect Sites:  \t"+(avgPerfectSites<10?" ":"")+"%.3f    \t"+
							(perfectHitCountPercent<10?" ":"")+"%.3f%%", avgPerfectSites, perfectHitCountPercent));
					tswStats.println(String.format(Locale.ROOT, "Avg Semiperfect Sites:\t"+(avgSemiPerfectSites<10?" ":"")+"%.3f    \t"+
							(semiPerfectHitCountPercent<10?" ":"")+"%.3f%%", avgSemiPerfectSites, semiPerfectHitCountPercent));
				}

				if(SYNTHETIC){
					tswStats.println(String.format(Locale.ROOT, "Avg Correct Sites:  \t"+(avgNumCorrect<10?" ":"")+"%.3f", avgNumCorrect));
					if(SKIMMER){
						tswStats.println(String.format(Locale.ROOT, "Avg Incorrect Sites:\t"+(avgNumIncorrect<10?" ":"")+"%.3f", avgNumIncorrect));
						tswStats.println(String.format(Locale.ROOT, "Avg IncorrectP Sites:\t"+(avgNumIncorrectPrior<10?" ":"")+"%.3f", avgNumIncorrectPrior));
					}
				}
			}
			
			tswStats.println();
			if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
				double x=ambiguousFound+mappedRetainedB;
				double y=ambiguousBasesFound+mappedRetainedBasesB;
				tswStats.println("mapped:          \t"+padPercent(x,4)+"% \t"+pad(mappedReads,9)+" \t"+padPercent(y,4)+"% \t"+pad(mappedBases,12));
				tswStats.println("unambiguous:     \t"+padPercent(mappedRetainedB,4)+"% \t"+pad(unambiguousReads,9)+" \t"+padPercent(mappedRetainedBasesB,4)+"% \t"+pad(unambiguousBases,12));
			}else{
				double x=mappedRetainedB-ambiguousFound;
				double y=mappedRetainedBasesB-ambiguousBasesFound;
				tswStats.println("mapped:          \t"+padPercent(mappedRetainedB,4)+"% \t"+pad(mappedReads,9)+" \t"+padPercent(mappedRetainedBasesB,4)+"% \t"+pad(mappedBases,12));
				tswStats.println("unambiguous:     \t"+padPercent(x,4)+"% \t"+pad(unambiguousReads,9)+" \t"+padPercent(y,4)+"% \t"+pad(unambiguousBases,12));
			}
			tswStats.println("ambiguous:       \t"+padPercent(ambiguousFound,4)+"% \t"+pad(duplicateBestAlignment2,9)+
					" \t"+padPercent(ambiguousBasesFound,4)+"% \t"+pad(duplicateBestAlignmentBases2,12));
			tswStats.println("low-Q discards:  \t"+padPercent(lowQualityReadsDiscardedPercent,4)+"% \t"+pad(lowQualityReadsDiscarded2,9)+
					" \t"+padPercent(lowQualityBasesDiscardedPercent,4)+"% \t"+pad(lowQualityBasesDiscarded2,12));
			
			tswStats.println();
			tswStats.println("perfect best site:\t"+padPercent(perfectMatchPercent,4)+"% \t"+pad(perfectMatch2,9)+
					" \t"+padPercent(perfectMatchPercentBases,4)+"% \t"+pad(perfectMatchBases2,12));
			tswStats.println("semiperfect site:\t"+padPercent(semiperfectMatchPercent,4)+"% \t"+pad(semiperfectMatch2,9)+
					" \t"+padPercent(semiperfectMatchPercentBases,4)+"% \t"+pad(semiperfectMatchBases2,12));
			if(paired){
				tswStats.println("rescued:         \t"+padPercent(rescuedPB+rescuedMB,4)+"% \t"+pad(rescuedP2+rescuedM2,9));
			}
			
			if(MAKE_MATCH_STRING){
				
				tswStats.println();
//				tswStats.println("                 \tpct reads\tnum reads \tpct bases\t   num bases");
				tswStats.println("Match Rate:      \t      NA \t       NA \t"+padPercent(matchRate,4)+"% \t"+pad(matchCountM2,12));
				tswStats.println("Error Rate:      \t"+padPercent(readErrorRate,4)+"% \t"+pad(readCountE2,9)+" \t"+padPercent(errorRate,4)+"% \t"+pad(matchErrors,12));
				tswStats.println("Sub Rate:        \t"+padPercent(readSubRate,4)+"% \t"+pad(readCountS2,9)+" \t"+padPercent(subRate,4)+"% \t"+pad(matchCountS2,12));
				tswStats.println("Del Rate:        \t"+padPercent(readDelRate,4)+"% \t"+pad(readCountD2,9)+" \t"+padPercent(delRate,4)+"% \t"+pad(matchCountD2,12));
				tswStats.println("Ins Rate:        \t"+padPercent(readInsRate,4)+"% \t"+pad(readCountI2,9)+" \t"+padPercent(insRate,4)+"% \t"+pad(matchCountI2,12));
				tswStats.println("N Rate:          \t"+padPercent(readNRate,4)+"% \t"+pad(readCountN2,9)+" \t"+padPercent(nRate,4)+"% \t"+pad(matchCountN2,12));
				if(SamLine.INTRON_LIMIT<Integer.MAX_VALUE){
					tswStats.println("Splice Rate:     \t"+padPercent(readSpliceRate,4)+"% \t"+pad(readCountSplice2,9)+" \t(splices at least "+SamLine.INTRON_LIMIT+" bp)");
				}
				
				if(DOUBLE_PRINT_ERROR_RATE){
					System.err.println();
					System.err.println(String.format(Locale.ROOT, "Match Rate:      \t"+(matchRate<10?" ":"")+"%.4f", matchRate)+"% \t"+matchCountM2);
					System.err.println(String.format(Locale.ROOT, "Error Rate:      \t"+(errorRate<10?" ":"")+"%.4f", errorRate)+"% \t"+matchErrors);
					System.err.println(String.format(Locale.ROOT, "Sub Rate:        \t"+(subRate<10?" ":"")+"%.4f", subRate)+"% \t"+matchCountS2);
					System.err.println(String.format(Locale.ROOT, "Del Rate:        \t"+(delRate<10?" ":"")+"%.4f", delRate)+"% \t"+matchCountD2);
					System.err.println(String.format(Locale.ROOT, "Ins Rate:        \t"+(insRate<10?" ":"")+"%.4f", insRate)+"% \t"+matchCountI2);
					System.err.println(String.format(Locale.ROOT, "N Rate:          \t"+(nRate<10?" ":"")+"%.4f", nRate)+"% \t"+matchCountN2);
				}
			}
			
			if(SYNTHETIC){
				tswStats.println();
				tswStats.println("true positive:   \t"+padPercent(truePositiveStrict,4)+"%\t(loose: "+padPercent(truePositiveLoose,4)+"%)");
				tswStats.println("false positive:  \t"+padPercent(falsePositiveB,4)+"%\t(loose: "+padPercent(falsePositiveLooseB,4)+"%)");
				tswStats.println("false negative:  \t"+padPercent(noHitPercent,4)+"%");
				tswStats.println("SNR:             \t"+padPercent(snrStrict,4)+" \t(loose: "+padPercent(snrLoose,4)+")");
				if(verbose_stats>0){
					tswStats.println("correctLowHit:   \t"+padPercent(correctLowHitPercent,4)+"%");
					tswStats.println(String.format(Locale.ROOT, "Plus/Minus ratio:\t %2.4f", truePositivePMRatio));
				}
				
				if(paired){
					tswStats.println("correct pairs:   \t"+padPercent(truePositivePairedB,4)+"%\t(of mated)");
					tswStats.println("correct singles: \t"+padPercent(truePositiveSoloB,4)+"%");
					tswStats.println("correct rescued: \t"+padPercent(truePositiveRescuedB,4)+"%");
				}
				
				if(SKIMMER){
					tswStats.println("found all correct:\t"+padPercent(rateCapturedAllCorrect,4)+"%)");
					tswStats.println("all correct top:  \t"+padPercent(rateCapturedAllTop,4)+"%)");
					tswStats.println("all correct only: \t"+padPercent(rateCapturedAllOnly,4)+"%)");
				}
			}
		}
		errorState|=tswStats.poisonAndWait();
		
		if(BBSplitter.TRACK_SCAF_STATS){
			BBSplitter.printCounts(BBSplitter.SCAF_STATS_FILE, BBSplitter.scafCountTable, true, readsUsed1+readsUsed2, nzoStats, sortStats);
		}
		
		if(BBSplitter.TRACK_SET_STATS){
			BBSplitter.printCounts(BBSplitter.SET_STATS_FILE, BBSplitter.setCountTable, true, readsUsed1+readsUsed2, nzoStats, sortStats);
		}
		
		final long pbf2=(readsUsed2==0 ? readsPassedBloomFilter : readsPassedBloomFilter/2);
		final long readSum=truePositiveP1+truePositiveM1+falsePositive1+noHit1+lowQualityReadsDiscarded1+pbf2;
		assert(!CALC_STATISTICS || readSum==maxReads) :
			"\nThe number of reads out does not add up to the number of reads in.\nThis may indicate that a mapping thread crashed." +
			"\nIf you submit a bug report, include the entire console output, not just this error message.\n"+
			truePositiveP1+"+"+truePositiveM1+"+"+falsePositive1+"+"+noHit1+"+"+lowQualityReadsDiscarded1+"+"+pbf2+" = "+
			readSum+" != "+maxReads;
		if(!SKIMMER){
			assert(!CALC_STATISTICS || truePositiveP1+truePositiveM1==correctLowHit1+correctMultiHit1+correctUniqueHit1);
		}else{
			assert(!CALC_STATISTICS || truePositiveP1+truePositiveM1==correctLowHit1+correctUniqueHit1);
		}
	}
	
	
	static void printOutput_Machine(final AbstractMapThread[] mtts, final Timer t, final int keylen, final boolean paired, final boolean SKIMMER,
			boolean nzoStats, boolean sortStats, String dest){
		if(dest==null){dest="stderr.txt";}
		TextStreamWriter tswStats=new TextStreamWriter(dest, overwrite, append, false);
		tswStats.start();
		
		long readsUsed1=0;
		long readsUsed2=0;
		long readsIn1=0;
		long readsIn2=0;
		
		long lowQualityReadsDiscarded1=0;
		long lowQualityReadsDiscarded2=0;
		long lowQualityBasesDiscarded1=0;
		long lowQualityBasesDiscarded2=0;
		
		long msaIterationsLimited=0;
		long msaIterationsUnlimited=0;

		long basesUsed1=0;
		long basesUsed2=0;
		long basesIn1=0;
		long basesIn2=0;
		long readsPassedBloomFilter=0;
		long basesPassedBloomFilter=0;
		long basesAtQuickmap=0;
		long keysUsed=0;
		long bothUnmapped=0;
		long bothUnmappedBases=0;
		long eitherMapped=0;
		long eitherMappedBases=0;
		
		long syntheticReads=0;
		long numMated=0;
		long badPairs=0;
		long innerLengthSum=0;
		long outerLengthSum=0;
		long insertSizeSum=0;
		
		long callsToScore=0;
		long callsToExtend=0;
		long initialKeys=0;
		long initialKeyIterations=0;
		long usedKeys=0;
		long usedKeyIterations=0;

		long[] hist_hits=new long[41];
		long[] hist_hits_score=new long[41];
		long[] hist_hits_extend=new long[41];
		
		long initialSiteSum1=0;
		long postTrimSiteSum1=0;
		long postRescueSiteSum1=0;
		long siteSum1=0;
		long topSiteSum1=0;
		
		long matchCountS1=0;
		long matchCountI1=0;
		long matchCountD1=0;
		long matchCountM1=0;
		long matchCountN1=0;
		
		
		long mapped1=0;
		long mappedRetained1=0;
		long rescuedP1=0;
		long rescuedM1=0;
		long truePositiveP1=0;
		long truePositiveM1=0;
		long falsePositive1=0;
		long totalCorrectSites1=0;
		long firstSiteCorrectP1=0;
		long firstSiteCorrectM1=0;
		long firstSiteIncorrect1=0;
		long firstSiteCorrectLoose1=0;
		long firstSiteIncorrectLoose1=0;
		long firstSiteCorrectPaired1=0;
		long firstSiteCorrectSolo1=0;
		long firstSiteCorrectRescued1=0;
		long perfectHit1=0; //Highest score is max score
		long uniqueHit1=0; //Only one hit has highest score
		long correctUniqueHit1=0; //unique highest hit on answer site
		long correctMultiHit1=0;  //non-unique highest hit on answer site (non-skimmer only)
		long correctLowHit1=0;  //hit on answer site, but not highest scorer
		long noHit1=0;
		long perfectMatch1=0; //Highest slow score is max slow score
		long semiperfectMatch1=0;
		long perfectMatchBases1=0;
		long semiperfectMatchBases1=0;
		long perfectHitCount1=0;
		long semiPerfectHitCount1=0;
		long duplicateBestAlignment1=0;
		
		long totalNumCorrect1=0; //Only for skimmer
		long totalNumIncorrect1=0; //Only for skimmer
		long totalNumIncorrectPrior1=0; //Only for skimmer
		long totalNumCapturedAllCorrect1=0; //Only for skimmer
		long totalNumCapturedAllCorrectTop1=0; //Only for skimmer
		long totalNumCapturedAllCorrectOnly1=0; //Only for skimmer

		long initialSiteSum2=0;
		long postTrimSiteSum2=0;
		long postRescueSiteSum2=0;
		long siteSum2=0;
		long topSiteSum2=0;
		
		long mapped2=0;
		long mappedRetained2=0;
		long rescuedP2=0;
		long rescuedM2=0;
		long truePositiveP2=0;
		long truePositiveM2=0;
		long falsePositive2=0;
		long totalCorrectSites2=0;
		long firstSiteCorrectP2=0;
		long firstSiteCorrectM2=0;
		long firstSiteIncorrect2=0;
		long firstSiteCorrectLoose2=0;
		long firstSiteIncorrectLoose2=0;
		long firstSiteCorrectPaired2=0;
		long firstSiteCorrectSolo2=0;
		long firstSiteCorrectRescued2=0;
		long perfectHit2=0; //Highest score is max score
		long perfectHitCount2=0;
		long semiPerfectHitCount2=0;
		
		long uniqueHit2=0; //Only one hit has highest score
		long correctUniqueHit2=0; //unique highest hit on answer site
		long correctMultiHit2=0;  //non-unique highest hit on answer site (non-skimmer only)
		long correctLowHit2=0;  //hit on answer site, but not highest scorer
		long noHit2=0;
		long perfectMatch2=0; //Highest slow score is max slow score
		long semiperfectMatch2=0;
		long perfectMatchBases2=0;
		long semiperfectMatchBases2=0;
		long duplicateBestAlignment2=0;
		
		long totalNumCorrect2=0; //Only for skimmer
		long totalNumIncorrect2=0; //Only for skimmer
		long totalNumIncorrectPrior2=0; //Only for skimmer
		long totalNumCapturedAllCorrect2=0; //Only for skimmer
		long totalNumCapturedAllCorrectTop2=0; //Only for skimmer
		long totalNumCapturedAllCorrectOnly2=0; //Only for skimmer
		
		long matchCountS2=0;
		long matchCountI2=0;
		long matchCountD2=0;
		long matchCountM2=0;
		long matchCountN2=0;

		readsUsed1=0;
		readsUsed2=0;
		readsIn1=0;
		readsIn2=0;
		for(int i=0; i<mtts.length; i++){
			AbstractMapThread mtt=mtts[i];
			
			if(mtt.msa!=null){
				msaIterationsLimited+=mtt.msa.iterationsLimited;
				msaIterationsUnlimited+=mtt.msa.iterationsUnlimited;
			}

			readsUsed1+=mtt.readsUsed1;
			readsUsed2+=mtt.readsUsed2;
			readsIn1+=mtt.readsIn1;
			readsIn2+=mtt.readsIn2;
			syntheticReads+=mtt.syntheticReads;
			numMated+=mtt.numMated;
//			numMatedBases+=mtt.numMatedBases;
			badPairs+=mtt.badPairs;
//			badPairBases+=mtt.badPairBases;
			innerLengthSum+=mtt.innerLengthSum;
			outerLengthSum+=mtt.outerLengthSum;
			insertSizeSum+=mtt.insertSizeSum;
			basesUsed1+=mtt.basesUsed1;
			basesUsed2+=mtt.basesUsed2;
			basesIn1+=mtt.basesIn1;
			basesIn2+=mtt.basesIn2;
			readsPassedBloomFilter+=mtt.readsPassedBloomFilter;
			basesPassedBloomFilter+=mtt.basesPassedBloomFilter;
			keysUsed+=mtt.keysUsed;
			bothUnmapped+=mtt.bothUnmapped;
			bothUnmappedBases+=mtt.bothUnmappedBases;
			eitherMapped+=mtt.eitherMapped;
			eitherMappedBases+=mtt.eitherMappedBases;
			
			mapped1+=mtt.mapped1;
			mappedRetained1+=mtt.mappedRetained1;
			rescuedP1+=mtt.rescuedP1;
			rescuedM1+=mtt.rescuedM1;
			lowQualityReadsDiscarded1+=mtt.lowQualityReadsDiscarded1;
			truePositiveP1+=mtt.truePositiveP1;
			truePositiveM1+=mtt.truePositiveM1;
			falsePositive1+=mtt.falsePositive1;
//			System.err.println("Adding "+mtt.falsePositive+" false positives -> "+falsePositive);
			totalCorrectSites1+=mtt.totalCorrectSites1;

			firstSiteCorrectP1+=mtt.firstSiteCorrectP1;
			firstSiteCorrectM1+=mtt.firstSiteCorrectM1;
			firstSiteIncorrect1+=mtt.firstSiteIncorrect1;
			firstSiteCorrectLoose1+=mtt.firstSiteCorrectLoose1;
			firstSiteIncorrectLoose1+=mtt.firstSiteIncorrectLoose1;
			firstSiteCorrectPaired1+=mtt.firstSiteCorrectPaired1;
			firstSiteCorrectSolo1+=mtt.firstSiteCorrectSolo1;
			firstSiteCorrectRescued1+=mtt.firstSiteCorrectRescued1;
			
			perfectHit1+=mtt.perfectHit1; //Highest score is max score
			perfectHitCount1+=mtt.perfectHitCount1;
			semiPerfectHitCount1+=mtt.semiPerfectHitCount1;
			uniqueHit1+=mtt.uniqueHit1; //Only one hit has highest score
			correctUniqueHit1+=mtt.correctUniqueHit1; //unique highest hit on answer site
			correctMultiHit1+=mtt.correctMultiHit1;  //non-unique highest hit on answer site
			correctLowHit1+=mtt.correctLowHit1;  //hit on answer site, but not highest scorer
			noHit1+=mtt.noHit1;
			
			totalNumCorrect1+=mtt.totalNumCorrect1; //Skimmer only
			totalNumIncorrect1+=mtt.totalNumIncorrect1; //Skimmer only
			totalNumIncorrectPrior1+=mtt.totalNumIncorrectPrior1; //Skimmer only
			totalNumCapturedAllCorrect1+=mtt.totalNumCapturedAllCorrect1; //Skimmer only
			totalNumCapturedAllCorrectTop1+=mtt.totalNumCapturedAllCorrectTop1; //Skimmer only
			totalNumCapturedAllCorrectOnly1+=mtt.totalNumCapturedAllCorrectOnly1; //Skimmer only
			
			perfectMatch1+=mtt.perfectMatch1; //Highest slow score is max slow score
			semiperfectMatch1+=mtt.semiperfectMatch1; //A semiperfect mapping was found
			perfectMatchBases1+=mtt.perfectMatchBases1;
			semiperfectMatchBases1+=mtt.semiperfectMatchBases1;
			
			duplicateBestAlignment1+=mtt.ambiguousBestAlignment1;

			initialSiteSum1+=mtt.initialSiteSum1;
			postTrimSiteSum1+=mtt.postTrimSiteSum1;
			postRescueSiteSum1+=mtt.postRescueSiteSum1;
			siteSum1+=mtt.siteSum1;
			topSiteSum1+=mtt.topSiteSum1;
			
			AbstractIndex index=mtt.index();
			callsToScore+=index.callsToScore;
			callsToExtend+=index.callsToExtendScore;
			initialKeys+=index.initialKeys;
			initialKeyIterations+=index.initialKeyIterations;
			usedKeys+=index.usedKeys;
			usedKeyIterations+=index.usedKeyIterations;
			
			for(int j=0; j<index.hist_hits.length; j++){
				int x=Tools.min(hist_hits.length-1, j);
				hist_hits[x]+=index.hist_hits[j];
				hist_hits_score[x]+=index.hist_hits_score[j];
				hist_hits_extend[x]+=index.hist_hits_extend[j];
			}
			
			matchCountS1+=mtt.matchCountS1;
			matchCountI1+=mtt.matchCountI1;
			matchCountD1+=mtt.matchCountD1;
			matchCountM1+=mtt.matchCountM1;
			matchCountN1+=mtt.matchCountN1;

			mapped2+=mtt.mapped2;
			mappedRetained2+=mtt.mappedRetained2;
			rescuedP2+=mtt.rescuedP2;
			rescuedM2+=mtt.rescuedM2;
			lowQualityReadsDiscarded2+=mtt.lowQualityReadsDiscarded2;
			truePositiveP2+=mtt.truePositiveP2;
			truePositiveM2+=mtt.truePositiveM2;
			falsePositive2+=mtt.falsePositive2;
//			System.err.println("Adding "+mtt.falsePositive+" false positives -> "+falsePositive);
			totalCorrectSites2+=mtt.totalCorrectSites2;

			firstSiteCorrectP2+=mtt.firstSiteCorrectP2;
			firstSiteCorrectM2+=mtt.firstSiteCorrectM2;
			firstSiteIncorrect2+=mtt.firstSiteIncorrect2;
			firstSiteCorrectLoose2+=mtt.firstSiteCorrectLoose2;
			firstSiteIncorrectLoose2+=mtt.firstSiteIncorrectLoose2;
			firstSiteCorrectPaired2+=mtt.firstSiteCorrectPaired2;
			firstSiteCorrectSolo2+=mtt.firstSiteCorrectSolo2;
			firstSiteCorrectRescued2+=mtt.firstSiteCorrectRescued2;
			
			perfectHit2+=mtt.perfectHit2; //Highest score is max score
			perfectHitCount2+=mtt.perfectHitCount2;
			semiPerfectHitCount2+=mtt.semiPerfectHitCount2;
			uniqueHit2+=mtt.uniqueHit2; //Only one hit has highest score
			correctUniqueHit2+=mtt.correctUniqueHit2; //unique highest hit on answer site
			correctMultiHit2+=mtt.correctMultiHit2;  //non-unique highest hit on answer site
			correctLowHit2+=mtt.correctLowHit2;  //hit on answer site, but not highest scorer
			noHit2+=mtt.noHit2;
			
			totalNumCorrect2+=mtt.totalNumCorrect2; //Skimmer only
			totalNumIncorrect2+=mtt.totalNumIncorrect2; //Skimmer only
			totalNumIncorrectPrior2+=mtt.totalNumIncorrectPrior2; //Skimmer only
			totalNumCapturedAllCorrect2+=mtt.totalNumCapturedAllCorrect2; //Skimmer only
			totalNumCapturedAllCorrectTop2+=mtt.totalNumCapturedAllCorrectTop2; //Skimmer only
			totalNumCapturedAllCorrectOnly2+=mtt.totalNumCapturedAllCorrectOnly2; //Skimmer only
			
			perfectMatch2+=mtt.perfectMatch2; //Highest slow score is max slow score
			semiperfectMatch2+=mtt.semiperfectMatch2; //A semiperfect mapping was found
			perfectMatchBases1+=mtt.perfectMatchBases1;
			semiperfectMatchBases1+=mtt.semiperfectMatchBases1;
			
			duplicateBestAlignment2+=mtt.ambiguousBestAlignment2;

			initialSiteSum2+=mtt.initialSiteSum2;
			postTrimSiteSum2+=mtt.postTrimSiteSum2;
			postRescueSiteSum2+=mtt.postRescueSiteSum2;
			siteSum2+=mtt.siteSum2;
			topSiteSum2+=mtt.topSiteSum2;
			
			matchCountS2+=mtt.matchCountS2;
			matchCountI2+=mtt.matchCountI2;
			matchCountD2+=mtt.matchCountD2;
			matchCountM2+=mtt.matchCountM2;
			matchCountN2+=mtt.matchCountN2;
			
		}
		maxReads=readsUsed1;
		if(syntheticReads>0){SYNTHETIC=true;}
		
		t.stop();
		long nanos=t.elapsed;
		
		if(verbose_stats>1){
			StringBuilder sb=new StringBuilder(1000);
			sb.append("\n\n###################\n#hits\tcount\tscore\textend\n");
			for(int i=0; i<hist_hits.length; i++){
				sb.append(i+"\t"+hist_hits[i]+"\t"+hist_hits_score[i]+"\t"+hist_hits_extend[i]+"\n");
			}
			try {
				ReadWrite.writeString(sb, "hist_hits.txt", true);
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		final long basesUsed=(basesUsed1+basesUsed2);

		final double invTrials=1d/maxReads;
		final double invTrials100=100d/maxReads;
		double invSites100=100d/siteSum1;

		final double matedPercent=(numMated*invTrials100);
		final double badPairsPercent=(badPairs*invTrials100);
		final double innerLengthAvg=(innerLengthSum*1d/numMated);
		final double outerLengthAvg=(outerLengthSum*1d/numMated);
		final double insertSizeAvg=(insertSizeSum*1d/numMated);
		
		final double readsPerSecond=((readsUsed1+readsUsed2)*1000000000d)/nanos;
		final double fragsPerSecond=(keysUsed*1000000000d)/nanos;
		final double kiloBasesPerSecond=(basesUsed*1000000d)/nanos;
		
		double perfectHitPercent=(perfectHit1*invTrials100); //Highest score is max score
		double perfectMatchPercent=(perfectMatch1*invTrials100);
		double semiperfectMatchPercent=(semiperfectMatch1*invTrials100);
		
		double perfectHitCountPercent=perfectHitCount1*invSites100;
		double semiPerfectHitCountPercent=semiPerfectHitCount1*invSites100;
		
		double uniqueHitPercent=(uniqueHit1*invTrials100); //Only one hit has highest score
		double correctUniqueHitPercent=(correctUniqueHit1*invTrials100); //unique highest hit on answer site
		double correctMultiHitPercent=(correctMultiHit1*invTrials100);  //non-unique highest hit on answer site
		double correctLowHitPercent=(correctLowHit1*invTrials100);  //hit on answer site, but not highest scorer
		double ambiguousFound=(duplicateBestAlignment1*invTrials100);
		double correctHighHitPercent=((correctMultiHit1+correctUniqueHit1)*invTrials100);
		double correctHitPercent=((correctLowHit1+correctMultiHit1+correctUniqueHit1)*invTrials100);

		double mappedB=(mapped1*invTrials100);
		double mappedRetainedB=(mappedRetained1*invTrials100);
		double rescuedPB=(rescuedP1*invTrials100);
		double rescuedMB=(rescuedM1*invTrials100);
		double falsePositiveB=(firstSiteIncorrect1*invTrials100);
		double falsePositiveLooseB=(firstSiteIncorrectLoose1*invTrials100);
		double truePositivePB=(firstSiteCorrectP1*invTrials100);
		double truePositiveMB=(firstSiteCorrectM1*invTrials100);
		double truePositiveStrict=((firstSiteCorrectP1+firstSiteCorrectM1)*invTrials100);
		double truePositiveLoose=(firstSiteCorrectLoose1*invTrials100);
		double snrStrict=10*Math.log10((firstSiteCorrectM1+firstSiteCorrectP1+0.1)/(firstSiteIncorrect1+0.1));
		double snrLoose=10*Math.log10((firstSiteCorrectLoose1+0.1)/(firstSiteIncorrectLoose1+0.1));
		double truePositivePMRatio=(truePositivePB/truePositiveMB);
		double truePositivePairedB=(firstSiteCorrectPaired1*100d/numMated);
		double truePositiveSoloB=(firstSiteCorrectSolo1*100d/(mappedRetained1-numMated));
		double truePositiveRescuedB=(firstSiteCorrectRescued1*100d/(rescuedP1+rescuedM1));
		double noHitPercent=(noHit1*invTrials100);
		
		long mappedReads, unambiguousReads;
		if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
			mappedReads=mappedRetained1+duplicateBestAlignment1;
			unambiguousReads=mappedRetained1;
		}else{
			mappedReads=mappedRetained1;
			unambiguousReads=mappedRetained1-duplicateBestAlignment1;
		}
		
		double avgNumCorrect=(SKIMMER ? totalNumCorrect1*invTrials : (totalCorrectSites1/(1d*(truePositiveP1+truePositiveM1))));
		double avgNumIncorrect=totalNumIncorrect1*invTrials; //Skimmer only
		double avgNumIncorrectPrior=totalNumIncorrectPrior1*invTrials; //Skimmer only

		double rateCapturedAllCorrect=totalNumCapturedAllCorrect1*invTrials100; //Skimmer only
		double rateCapturedAllTop=totalNumCapturedAllCorrectTop1*invTrials100; //Skimmer only
		double rateCapturedAllOnly=totalNumCapturedAllCorrectOnly1*invTrials100; //Skimmer only

		double avgCallsToScore=(callsToScore*invTrials);
		double avgCallsToExtendScore=(callsToExtend*invTrials);
		double avgInitialKeys=(initialKeys*1d/initialKeyIterations);
		double avgUsedKeys=(usedKeys*1d/usedKeyIterations);
		
		double avgInitialSites=(initialSiteSum1*invTrials);
		double avgPostTrimSites=(postTrimSiteSum1*invTrials);
		double avgPostRescueSites=(postRescueSiteSum1*invTrials);
		double avgSites=(siteSum1*invTrials);
		double avgPerfectSites=(perfectHitCount1*invTrials);
		double avgSemiPerfectSites=(semiPerfectHitCount1*invTrials);
		double avgTopSites=(topSiteSum1*invTrials);
		double lowQualityReadsDiscardedPercent=(lowQualityReadsDiscarded1*invTrials100);

		long matchErrors=matchCountS1+matchCountI1+matchCountD1;
		long baseLen=matchCountM1+matchCountI1+matchCountS1+matchCountN1;
		long matchLen=matchCountM1+matchCountI1+matchCountS1+matchCountN1+matchCountD1;
		long refLen=matchCountM1+matchCountS1+matchCountN1+matchCountD1;
		double errorRate=matchErrors*100d/matchLen;
		double matchRate=matchCountM1*100d/matchLen;//baseLen;
		double subRate=matchCountS1*100d/matchLen;//baseLen;
		double delRate=matchCountD1*100d/matchLen;
		double insRate=matchCountI1*100d/matchLen;//baseLen;
		double nRate=matchCountN1*100d/matchLen;//baseLen;
		
		if(SYNTHETIC && verbose_stats==-1){verbose_stats=Tools.max(verbose_stats,9);}
		
		tswStats.println("Reads_Used"+DELIMITER+(readsUsed1+readsUsed2));
		tswStats.println("Bases_Used"+DELIMITER+(basesUsed));
		tswStats.println(String.format(Locale.ROOT, "Reads/sec"+DELIMITER+"%.2f", readsPerSecond));
		tswStats.println(String.format(Locale.ROOT, "kBases/sec"+DELIMITER+"%.2f", kiloBasesPerSecond));
		double milf=msaIterationsLimited*invTrials;
		double milu=msaIterationsUnlimited*invTrials;
		if(verbose_stats>=1){tswStats.println("MSA_iterations"+DELIMITER+String.format(Locale.ROOT, "%.2fL + %.2fU = %.2f", milf,milu,milf+milu));}
		
//		tswStats.println();
//		tswStats.println("\nRead 1 data:");
		
		tswStats.println();
		
		if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
			double x=ambiguousFound+mappedRetainedB;
			tswStats.println("R1_Mapped_Percent"+DELIMITER+padPercentMachine(x,4)+"%");
			tswStats.println("R1_Unambiguous_Percent"+DELIMITER+padPercentMachine(mappedRetainedB,4)+"%");
			tswStats.println("R1_Mapped_Reads"+DELIMITER+mappedReads);
			tswStats.println("R1_Unambiguous_Reads"+DELIMITER+unambiguousReads);
		}else{
			double x=mappedRetainedB-ambiguousFound;
			tswStats.println("R1_Mapped_Percent"+DELIMITER+padPercentMachine(mappedRetainedB,4)+"%");
			tswStats.println("R1_Unambiguous_Percent"+DELIMITER+padPercentMachine(x,4)+"%");
			tswStats.println("R1_Mapped_Reads"+DELIMITER+mappedReads);
			tswStats.println("R1_Unambiguous_Reads"+DELIMITER+unambiguousReads);
		}
		
		tswStats.println();
		if(paired){
			tswStats.println(String.format(Locale.ROOT, "Mated_Pairs"+DELIMITER+"%.4f%%", matedPercent));
			tswStats.println(String.format(Locale.ROOT, "Bad_Pairs"+DELIMITER+"%.3f%%", badPairsPercent));
		}
		if(paired){
			tswStats.println(String.format(Locale.ROOT, "R1_Rescued"+DELIMITER+"%.3f", rescuedPB+rescuedMB)+"%");
			tswStats.println(String.format(Locale.ROOT, "Avg_Insert_Size"+DELIMITER+"%.2f", insertSizeAvg));
		}
		tswStats.println();
		tswStats.println(String.format(Locale.ROOT, "R1_Perfect_Best_Site"+DELIMITER+"%.4f", perfectMatchPercent)+"%");
		tswStats.println(String.format(Locale.ROOT, "R1_Semiperfect_Site"+DELIMITER+"%.4f", semiperfectMatchPercent)+"%");
		tswStats.println(String.format(Locale.ROOT, "R1_Ambiguous_Mapping"+DELIMITER+"%.4f", ambiguousFound)+"%");
//				+(REMOVE_DUPLICATE_BEST_ALIGNMENTS ? " (Removed)" : " (Kept)"));
		tswStats.println(String.format(Locale.ROOT, "R1_Low_Quality_Discards"+DELIMITER+"%.4f", lowQualityReadsDiscardedPercent)+"%");
		
		if(MAKE_MATCH_STRING){
			tswStats.println();
			tswStats.println("R1_Match_Rate"+DELIMITER+padPercentMachine(matchRate,4)+"%");
			tswStats.println("R1_Error_Rate"+DELIMITER+padPercentMachine(errorRate,4)+"%");
			tswStats.println("R1_Sub_Rate"+DELIMITER+padPercentMachine(subRate,4)+"%");
			tswStats.println("R1_Del_Rate"+DELIMITER+padPercentMachine(delRate,4)+"%");
			tswStats.println("R1_Ins_Rate"+DELIMITER+padPercentMachine(insRate,4)+"%");
			tswStats.println("R1_N_Rate"+DELIMITER+padPercentMachine(nRate,4)+"%");
			
			tswStats.println("R1_Match_Count"+DELIMITER+matchCountM1);
			tswStats.println("R1_Error_Count"+DELIMITER+matchErrors);
			tswStats.println("R1_Sub_Count"+DELIMITER+matchCountS1);
			tswStats.println("R1_Del_Count"+DELIMITER+matchCountD1);
			tswStats.println("R1_Ins_Count"+DELIMITER+matchCountI1);
			tswStats.println("R1_N_Count"+DELIMITER+matchCountN1);
		}
		
		if(paired){
			invSites100=100d/siteSum2;
			
			perfectHitPercent=perfectHit2*invTrials100; //Highest score is max score
			perfectMatchPercent=perfectMatch2*invTrials100;
			semiperfectMatchPercent=semiperfectMatch2*invTrials100;
			
			perfectHitCountPercent=perfectHitCount2*invSites100;
			semiPerfectHitCountPercent=semiPerfectHitCount2*invSites100;
			
			uniqueHitPercent=uniqueHit2*invTrials100; //Only one hit has highest score
			correctUniqueHitPercent=correctUniqueHit2*invTrials100; //unique highest hit on answer site
			correctMultiHitPercent=correctMultiHit2*invTrials100;  //non-unique highest hit on answer site
			correctLowHitPercent=correctLowHit2*invTrials100;  //hit on answer site, but not highest scorer
			ambiguousFound=(duplicateBestAlignment2*invTrials100);
			correctHighHitPercent=(correctMultiHit2+correctUniqueHit2)*invTrials100;
			correctHitPercent=(correctLowHit2+correctMultiHit2+correctUniqueHit2)*invTrials100;

			mappedB=(mapped2*invTrials100);
			mappedRetainedB=(mappedRetained2*invTrials100);
			rescuedPB=(rescuedP2*invTrials100);
			rescuedMB=(rescuedM2*invTrials100);
			falsePositiveB=(firstSiteIncorrect2*invTrials100);
			falsePositiveLooseB=(firstSiteIncorrectLoose2*invTrials100);
			truePositivePB=(firstSiteCorrectP2*invTrials100);
			truePositiveMB=(firstSiteCorrectM2*invTrials100);
			truePositiveStrict=((firstSiteCorrectP2+firstSiteCorrectM2)*invTrials100);
			truePositiveLoose=(firstSiteCorrectLoose2*invTrials100);
			snrStrict=10*Math.log10((firstSiteCorrectM2+firstSiteCorrectP2+0.1)/(firstSiteIncorrect2+0.1));
			snrLoose=10*Math.log10((firstSiteCorrectLoose2+0.1)/(firstSiteIncorrectLoose2+0.1));
			truePositivePMRatio=(truePositivePB/truePositiveMB);
			truePositivePairedB=(firstSiteCorrectPaired2*100d/numMated);
			truePositiveSoloB=(firstSiteCorrectSolo2*100d/(mappedRetained2-numMated));
			truePositiveRescuedB=(firstSiteCorrectRescued2*100d/(rescuedP2+rescuedM2));
			avgNumCorrect=(totalCorrectSites2/(1d*(truePositiveP2+truePositiveM2)));
			noHitPercent=noHit2*invTrials100;
			
			avgNumCorrect=(SKIMMER ? totalNumCorrect2*invTrials : (totalCorrectSites2/(1d*(truePositiveP2+truePositiveM2))));
			avgNumIncorrect=totalNumIncorrect1*invTrials; //Skimmer only
			avgNumIncorrectPrior=totalNumIncorrectPrior1*invTrials; //Skimmer only

			rateCapturedAllCorrect=totalNumCapturedAllCorrect2*invTrials100; //Skimmer only
			rateCapturedAllTop=totalNumCapturedAllCorrectTop2*invTrials100; //Skimmer only
			rateCapturedAllOnly=totalNumCapturedAllCorrectOnly2*invTrials100; //Skimmer only
			
			if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
				mappedReads=mappedRetained2+duplicateBestAlignment2;
				unambiguousReads=mappedRetained2;
			}else{
				mappedReads=mappedRetained2;
				unambiguousReads=mappedRetained2-duplicateBestAlignment2;
			}

			avgInitialSites=initialSiteSum2*invTrials;
			avgPostTrimSites=postTrimSiteSum2*invTrials;
			avgPostRescueSites=postRescueSiteSum2*invTrials;
			avgSites=siteSum2*invTrials;
			avgPerfectSites=(perfectHitCount1*invTrials);
			avgSemiPerfectSites=(semiPerfectHitCount1*invTrials);
			avgTopSites=topSiteSum2*invTrials;
			lowQualityReadsDiscardedPercent=lowQualityReadsDiscarded2*invTrials100;

			matchErrors=matchCountS2+matchCountI2+matchCountD2;
			baseLen=matchCountM2+matchCountI2+matchCountS2+matchCountN2;
			matchLen=matchCountM2+matchCountI2+matchCountS2+matchCountN2+matchCountD2;
			refLen=matchCountM2+matchCountS2+matchCountN2+matchCountD2;
			errorRate=matchErrors*100d/matchLen;
			matchRate=matchCountM2*100d/matchLen;//baseLen;
			subRate=matchCountS2*100d/matchLen;//baseLen;
			delRate=matchCountD2*100d/matchLen;
			insRate=matchCountI2*100d/matchLen;//baseLen;
			nRate=matchCountN2*100d/matchLen;//baseLen;
			
//			tswStats.println("\n\nRead 2 data:");
			tswStats.println();
//			tswStats.println(String.format(Locale.ROOT, "perfectHit"+DELIMITER+"%.2f", perfectHitPercent)+"%");
//			tswStats.println(String.format(Locale.ROOT, "uniqueHit"+DELIMITER+"%.2f", uniqueHitPercent)+"%");
//			tswStats.println(String.format(Locale.ROOT, "correctUniqueHit"+DELIMITER+"%.2f", correctUniqueHitPercent)+"%");
//			tswStats.println(String.format(Locale.ROOT, "correctMultiHit"+DELIMITER+"%.2f", correctMultiHitPercent)+"%");
//			tswStats.println(String.format(Locale.ROOT, "correctHighHit"+DELIMITER+"%.2f", correctHighHitPercent)+"%");
//			tswStats.println(String.format(Locale.ROOT, "correctHit"+DELIMITER+"%.2f", correctHitPercent)+"%");
			
			//tswStats.println(String.format(Locale.ROOT, "mapped"+DELIMITER+(mappedB<10?" ":"")+"%.3f", mappedB)+"%");
			if(REMOVE_DUPLICATE_BEST_ALIGNMENTS){
				double x=ambiguousFound+mappedRetainedB;
				tswStats.println("R2_Mapped_Percent"+DELIMITER+padPercentMachine(x,4)+"%");
				tswStats.println("R2_Unambiguous_Percent"+DELIMITER+padPercentMachine(mappedRetainedB,4)+"%");
				tswStats.println("R2_Mapped_Reads"+DELIMITER+mappedReads);
				tswStats.println("R2_Unambiguous_Reads"+DELIMITER+unambiguousReads);
			}else{
				double x=mappedRetainedB-ambiguousFound;
				tswStats.println("R2_Mapped_Percent"+DELIMITER+padPercentMachine(mappedRetainedB,4)+"%");
				tswStats.println("R2_Unambiguous_Percent"+DELIMITER+padPercentMachine(x,4)+"%");
				tswStats.println("R2_Mapped_Reads"+DELIMITER+mappedReads);
				tswStats.println("R2_Unambiguous_Reads"+DELIMITER+unambiguousReads);
			}
			tswStats.println();
			if(paired){
				tswStats.println(String.format(Locale.ROOT, "R2_Rescued"+DELIMITER+"%.3f", rescuedPB+rescuedMB)+"%");
			}
			tswStats.println();
			tswStats.println(String.format(Locale.ROOT, "R2_Perfect_Best_Site"+DELIMITER+"%.4f", perfectMatchPercent)+"%");
			tswStats.println(String.format(Locale.ROOT, "R2_Semiperfect_Site"+DELIMITER+"%.4f", semiperfectMatchPercent)+"%");
			tswStats.println(String.format(Locale.ROOT, "R2_Ambiguous_Mapping"+DELIMITER+"%.4f", ambiguousFound)+"%");
								//(REMOVE_DUPLICATE_BEST_ALIGNMENTS ? "(Removed)" : "(Kept)"));
			tswStats.println(String.format(Locale.ROOT, "R2_Low_Quality_Discards"+DELIMITER+"%.4f", lowQualityReadsDiscardedPercent)+"%");
			
			if(MAKE_MATCH_STRING){
				tswStats.println();
				tswStats.println("R2_Match_Rate"+DELIMITER+padPercentMachine(matchRate,4)+"%");
				tswStats.println("R2_Error_Rate"+DELIMITER+padPercentMachine(errorRate,4)+"%");
				tswStats.println("R2_Sub_Rate"+DELIMITER+padPercentMachine(subRate,4)+"%");
				tswStats.println("R2_Del_Rate"+DELIMITER+padPercentMachine(delRate,4)+"%");
				tswStats.println("R2_Ins_Rate"+DELIMITER+padPercentMachine(insRate,4)+"%");
				tswStats.println("R2_N_Rate"+DELIMITER+padPercentMachine(nRate,4)+"%");
				
				tswStats.println("R2_Match_Count"+DELIMITER+matchCountM2);
				tswStats.println("R2_Error_Count"+DELIMITER+matchErrors);
				tswStats.println("R2_Sub_Count"+DELIMITER+matchCountS2);
				tswStats.println("R2_Del_Count"+DELIMITER+matchCountD2);
				tswStats.println("R2_Ins_Count"+DELIMITER+matchCountI2);
				tswStats.println("R2_N_Count"+DELIMITER+matchCountN2);
			}
		}
		errorState|=tswStats.poisonAndWait();
		
		/** For RQCFilter */
		lastBothUnmapped=bothUnmapped;
		lastBothUnmappedBases=bothUnmappedBases;
		lastEitherMapped=eitherMapped;
		lastEitherMappedBases=eitherMappedBases;
		lastReadsUsed=readsUsed1+readsUsed2;
		lastBasesUsed=basesUsed;
		lastReadsIn=readsIn1+readsIn2;
		lastBasesIn=basesIn1+basesIn2;
		lastReadsPassedBloomFilter=readsPassedBloomFilter;
		lastBasesPassedBloomFilter=basesPassedBloomFilter;
		
		if(BBSplitter.TRACK_SCAF_STATS){
			BBSplitter.printCounts(BBSplitter.SCAF_STATS_FILE, BBSplitter.scafCountTable, true, readsUsed1+readsUsed2, nzoStats, sortStats);
		}
		
		if(BBSplitter.TRACK_SET_STATS){
			BBSplitter.printCounts(BBSplitter.SET_STATS_FILE, BBSplitter.setCountTable, true, readsUsed1+readsUsed2, nzoStats, sortStats);
		}
		
		final long pbf2=(readsUsed2==0 ? readsPassedBloomFilter : readsPassedBloomFilter/2);
		final long readSum=truePositiveP1+truePositiveM1+falsePositive1+noHit1+lowQualityReadsDiscarded1+pbf2;
		assert(!CALC_STATISTICS || readSum==maxReads) :
			"\nThe number of reads out does not add up to the number of reads in.\nThis may indicate that a mapping thread crashed." +
			"\nIf you submit a bug report, include the entire console output, not just this error message.\n"+
			truePositiveP1+"+"+truePositiveM1+"+"+falsePositive1+"+"+noHit1+"+"+lowQualityReadsDiscarded1+"+"+pbf2+" = "+
			readSum+" != "+maxReads;
		if(!SKIMMER){
			assert(!CALC_STATISTICS || truePositiveP1+truePositiveM1==correctLowHit1+correctMultiHit1+correctUniqueHit1);
		}else{
			assert(!CALC_STATISTICS || truePositiveP1+truePositiveM1==correctLowHit1+correctUniqueHit1);
		}
	}
	
	static final void printSettings0(int k, int maxindel, float minratio){
		if(MACHINE_OUTPUT){
			outstream.println("Genome"+DELIMITER+Data.GENOME_BUILD);
			outstream.println("Key_Length"+DELIMITER+k);
			outstream.println("Max_Indel"+DELIMITER+maxindel);
			outstream.println("Minimum_Score_Ratio"+DELIMITER+minratio);
			outstream.println("Mapping_Mode"+DELIMITER+(PERFECTMODE ? "perfect" : SEMIPERFECTMODE ? "semiperfect" : "normal"));
		}else{
			outstream.println("Genome:                \t"+Data.GENOME_BUILD);
			outstream.println("Key Length:            \t"+k);
			outstream.println("Max Indel:             \t"+maxindel);
			outstream.println("Minimum Score Ratio:  \t"+minratio);
			outstream.println("Mapping Mode:         \t"+(PERFECTMODE ? "perfect" : SEMIPERFECTMODE ? "semiperfect" : "normal"));
		}
	}
	
	
	static final int absdif(int a, int b){
		return a>b ? a-b : b-a;
	}
	
	static void clearStatics(){
		maxReads=-1;
//		readsUsed=0;
//		readsUsed2=0;
//		lowQualityReadsDiscarded1=0;
//		lowQualityReadsDiscarded2=0;
//		lowQualityBasesDiscarded1=0;
//		lowQualityBasesDiscarded2=0;
		
		outFile=null;
		outFile2=null;
		outFileM=null;
		outFileM2=null;
		outFileU=null;
		outFileU2=null;
		outFileB=null;
		outFileB2=null;
		blacklist=null;
		
		errorState=false;
		
		BBSplitter.clearStatics();
	}
	
	/* ------------ Non-static fields ----------- */
	

	ConcurrentReadInputStream cris;
	ConcurrentReadOutputStream rosA=null, rosM=null, rosU=null, rosB=null;
	
	float fractionGenomeToExclude=-1;
	int maxIndel1=-1;
	int maxIndel2=-1;
	int minApproxHits=-1;
	int expectedSites=-1;
	int ambigMode=AMBIG_BEST;
//	int ambigMode2=AMBIG_BEST;
	boolean fast=false;
	boolean slow=false;
	boolean vslow=false;
	float excludeFraction=-1;
	boolean verbose=false;
	boolean rcompMate=false;
	boolean outputSitesOnly=false;
	long targetGenomeSize=-1;
	int ziplevel=-1;
	int build=1;
	String reference=null;
	int keylen=13;
	boolean printSettings=true;
	boolean printStats=true;
	int idmodulo=1;
	float samplerate=1f;
	double minid=-1;
	long sampleseed=1;
	boolean ambiguousRandom=false, ambiguousAll=false;
	boolean forceanalyze=false;
//	private boolean gunzip=false;
//	private boolean gzip=false;
//	private boolean pigz=false;
//	private boolean unpigz=false;
	boolean setxs=false, setintron=false;
	String bamscript=null;
	String in1=null, in2=null, qfin1=null, qfin2=null;
	String qfout=null, qfout2=null, qfoutM=null, qfoutM2=null, qfoutU=null, qfoutU2=null, qfoutB=null, qfoutB2=null;
	
	/** Scores below the (max possible alignment score)*(MINIMUM_ALIGNMENT_SCORE_RATIO) will be discarded.
	 * Default: 0.4 ~ 0.5 for clean data against raw PacBio data.
	 * Very sensitive!  A value of 0.2 will potentially produce many false positives. */
	float MINIMUM_ALIGNMENT_SCORE_RATIO;

	float keyDensity;//Normal key density
	float maxKeyDensity; //For situations where some of the read is too low quality, this is the max for the rest of the read.
	float minKeyDensity;
	int maxDesiredKeys; //Don't go above this number of keys except to maintain minKeyDensity.
	
	/** Additional ref bases on each end of site mapping location in alignment window.
	 * If there are no insertions or deletions, 0 is fine. */
	int SLOW_ALIGN_PADDING;
	int SLOW_RESCUE_PADDING;
	int TIP_SEARCH_DIST;
	
	/** Class name of MSA to use */
	String MSA_TYPE;
	int MAX_SITESCORES_TO_PRINT;
	boolean PRINT_SECONDARY_ALIGNMENTS;
	
	
	boolean makeBloomFilter=false;
	int bloomFilterHashes=2;
	int bloomFilterMinHits=3;
	int bloomFilterK=31;
	BloomFilter bloomFilter;
	boolean bloomSerial=true;
	
	/* ------------ Coverage ----------- */
	
	CoveragePileup pileup;
	String coverageStats=null, coverageBinned=null, coverageBase=null, coverageHist=null, coverageRPKM=null, normcov=null, normcovOverall=null;
	/** Force coverage calculation even if there is no output file */
	boolean calcCov=false;
	int coverageMinScaf=0;
	boolean coveragePhysical=false;
	boolean cov32bit=false;
	boolean covBitset=false;
	boolean covSetbs=false;
	boolean covArrays=true;
	boolean covNzo=false;
	boolean scafNzo=true;
	boolean sortStats=true;
	boolean covTwocolumn=false;
	boolean covKsb=true;
	boolean covStranded=false;
	boolean covStartOnly=false;
	boolean covStopOnly=false;
	int covBinSize=1000;
	int covK=0;
	
	
	/* ------------ Static fields ----------- */

	public static long lastBothUnmapped=0;
	public static long lastBothUnmappedBases=0;
	
	public static long lastEitherMapped=0;
	public static long lastEitherMappedBases=0;

	public static long lastReadsUsed=0;
	public static long lastBasesUsed=0;

	public static long lastReadsIn=0;
	public static long lastBasesIn=0;

	public static long lastReadsPassedBloomFilter=0;
	public static long lastBasesPassedBloomFilter=0;
	
	static final int AMBIG_BEST=0;
	static final int AMBIG_TOSS=1;
	static final int AMBIG_RANDOM=2;
	static final int AMBIG_ALL=3;
	
	static int CORRECT_THRESH=0; //Threshold for calculating true positives on synthetic data, or something.
	
	static int synthReadlen=150;

	static int maxInsLen=30; //Default 40
	static int maxSubLen=30; //Default 40
	static int maxDelLen=40; //Default 8000
	
	static byte minQuality=3;
	static byte midQuality=23;
	static byte maxQuality=35;
	
	static int maxSnps=4;//4;
	static int maxInss=3;//2;
	static int maxDels=3;
	static int maxSubs=3;//2;
	
	static float baseSnpRate=0.50f;
	static float baseInsRate=0.30f;
	static float baseDelRate=0.30f;
	static float baseSubRate=0.30f;//0.3f;
	static float PERFECT_READ_RATIO=0.0f;//0.2f;//0.8f
	
	//Extra work for rare cases in human only.
	static boolean SAVE_AMBIGUOUS_XY=false;
	

	static boolean TRIM_LIST=true; //Increases speed many times; reduces accuracy a bit

	static boolean PAIRED_RANDOM_READS=false;
	static boolean REQUIRE_CORRECT_STRANDS_PAIRS=true;
	static boolean SAME_STRAND_PAIRS=false;
	static boolean KILL_BAD_PAIRS=false;
	
	static boolean INDEX_LOADED=false;
	static final boolean SLOW_ALIGN=true; //Do a more accurate scoring pass with MSA
	static boolean MAKE_MATCH_STRING=SLOW_ALIGN;
	
	/** Rescue paired reads by searching near mate */
	static boolean RESCUE=true;
	
	/** Generally should be set to false unless SLOW_ALIGN==true */
	static boolean REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;

	/** Forbid alignments with indels longer than MAX_INDEL */
	static boolean STRICT_MAX_INDEL=false;
	/** Don't allow reads to map to their origin location in the reference. Useful for self-correcting reads. */
	static boolean FORBID_SELF_MAPPING=false;
	/** Only allow perfect and semiperfect mappings */
	static boolean SEMIPERFECTMODE=false;
	/** Only allow perfect mappings */
	static boolean PERFECTMODE=false;
	/** Only allow sites with at least this many contiguous matches */
	static int KFILTER=-1;
	/** Only allow sites with identity of at least this */
	static float MIN_IDFILTER=0f;
	
	/** Rename reads to indicate their mapped insert size */
	static boolean RenameByInsert=false;
	
	/** Quality-trim left side of read before mapping */
	static boolean qtrimLeft=false;
	/** Quality-trim right side of read before mapping */
	static boolean qtrimRight=false;
	/** Restore read to untrimmed state after mapping (and destroy match string) */
	static boolean untrim=false;
	/** Trim bases with quality less than or equal to this value */
	static float TRIM_QUALITY=6;
	/** Don't trim reads to be shorter than this */
	static int minTrimLength=60;
	/** Produce local alignments instead of global alignments */
	static boolean LOCAL_ALIGN=false;
	
	public static int minChrom=1;
	public static int maxChrom=Integer.MAX_VALUE;

	static long maxReads=-1;
	
	static boolean CALC_STATISTICS=true;

	static boolean QUICK_MATCH_STRINGS=false;
	static boolean OUTPUT_READS=false;
	static boolean OUTPUT_MAPPED_ONLY=false;
	static boolean DONT_OUTPUT_BLACKLISTED_READS=false;
	
	static boolean ORDERED=false;
	static boolean DOUBLE_PRINT_ERROR_RATE=false;
	static boolean PRINT_UNMAPPED_COUNT=false;
	
	static String outFile=null;
	static String outFile2=null;
	static String outFileM=null;
	static String outFileM2=null;
	static String outFileU=null;
	static String outFileU2=null;
	static String outFileB=null;
	static String outFileB2=null;
	static ArrayList<String> blacklist=null;
	static ArrayList<String> splitterOutputs=null;

	static boolean useRandomReads=false;
	static int sequentialOverlap=5;
	static boolean sequentialStrandAlt=false;

	static boolean overwrite=false;
	static boolean append=false;
	static boolean SYNTHETIC=false;
	static boolean ERROR_ON_NO_OUTPUT=false;
	static boolean MACHINE_OUTPUT=false;
	static boolean USE_MODULO=false;
	static String statsOutputFile="stderr.txt";
	final static String DELIMITER="=";
	
	static PrintStream outstream=System.err;
	static boolean SYSIN=false;
	static int verbose_stats=0;
	static boolean waitForMemoryClear=false;
	static int DEFAULT_OUTPUT_FORMAT=FileFormat.SAM;
	
	public static boolean errorState=false;
	
}