Debian Codegraph @

meryl/kmer-mask.C

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "util++.H"
5 #include "bio++.H"
6 #include "libmeryl.H"
7 #include "existDB.H"
8
9 #include "seqCache.H"
10 #include "seqStream.H"
11 #include "merStream.H"
12
13 #include "sweatShop.H"
14
15
16
17
18 class fastqRecord {
19 public:
20 fastqRecord(uint32 ml) {
21 maxLength = ml;
22 alloc = new char [maxLength * 8];
23
24 a2 = alloc + 0 * maxLength;
25 af = alloc + 1 * maxLength;
26 am = alloc + 2 * maxLength;
27 a4 = alloc + 3 * maxLength;
28
29 a1[0] = 0;
30 a2[0] = 0;
31 af[0] = 0;
32 am[0] = 0;
33 a3[0] = 0;
34 a4[0] = 0;
35
36 aLength = 0;
37 aMasked = 0.0;
38 aLabel = 0;
39
40 b2 = alloc + 4 * maxLength;
41 bf = alloc + 5 * maxLength;
42 bm = alloc + 6 * maxLength;
43 b4 = alloc + 7 * maxLength;
44
45 b1[0] = 0;
46 b2[0] = 0;
47 bf[0] = 0;
48 bm[0] = 0;
49 b3[0] = 0;
50 b4[0] = 0;
51
52 bLength = 0;
53 bMasked = 0.0;
54 bLabel = 0;
55 };
56
57 ~fastqRecord() {
58 delete [] alloc;
59 };
60
61
62 bool load(FILE *FASTQ1, FILE *FASTQ2) {
63 bool tooShort = false;
64
65 a2[maxLength - 2] = 0;
66 b2[maxLength - 2] = 0;
67
68 if (FASTQ1) {
69 fgets(a1, 1024, FASTQ1); chomp(a1);
70 fgets(a2, maxLength, FASTQ1); chomp(a2);
71 fgets(a3, 1024, FASTQ1); chomp(a3);
72 fgets(a4, maxLength, FASTQ1); chomp(a4);
73
74 aLength = strlen(a2);
75 aMasked = 0.0;
76 aLabel = 0;
77
78 if (a2[maxLength - 2] != 0)
79 tooShort = true;
80 }
81
82 if (FASTQ2) {
83 fgets(b1, 1024, FASTQ2); chomp(b1);
84 fgets(b2, maxLength, FASTQ2); chomp(b2);
85 fgets(b3, 1024, FASTQ2); chomp(b3);
86 fgets(b4, maxLength, FASTQ2); chomp(b4);
87
88 bLength = strlen(b2);
89 bMasked = 0.0;
90 bLabel = 0;
91
92 if (b2[maxLength - 2] != 0)
93 tooShort = true;
94 }
95
96 if (tooShort) {
97 fprintf(stderr, "ERROR: -l too small for reads:\n");
98 fprintf(stderr, " a = '%s'\n", a1);
99 fprintf(stderr, " b = '%s'\n", b1);
100 exit(1);
101 }
102
103 return(!feof(FASTQ1));
104 };
105
106
107 void write(FILE *FASTQ1, FILE *FASTQ2) {
108
109 if (FASTQ1)
110 fprintf(FASTQ1, "%s fractionMasked=%.3f\n%s\n%s\n%s\n", a1, aMasked, am, a3, a4);
111
112 if (FASTQ2)
113 fprintf(FASTQ2, "%s fractionMasked=%.3f\n%s\n%s\n%s\n", b1, bMasked, bm, b3, b4);
114 };
115
116
117
118 public:
119 uint32 maxLength;
120 char *alloc;
121
122 char a1[1024];
123 char *a2;
124 char *af;
125 char *am;
126 char a3[1024];
127 char *a4;
128
129 uint32 aLength;
130 double aMasked;
131 uint32 aLabel;
132
133 char b1[1024];
134 char *b2;
135 char *bf;
136 char *bm;
137 char b3[1024];
138 char *b4;
139
140 uint32 bLength;
141 double bMasked;
142 uint32 bLabel;
143 };
144
145
146
147
148 class maskGlobal {
149 public:
150 maskGlobal() {
151 merName = NULL;
152
153 seq1Name = NULL;
154 seq2Name = NULL;
155
156 outPrefix = NULL;
157
158 merSize = 0;
159 maxLength = 512;
160
161 existName = NULL;
162 minSize = 0;
163 extend = 0;
164
165 cleaner = false;
166 dirtier = false;
167 discard = true;
168 unlink = false;
169
170 noMasking = false;
171
172 cleanThreshold = 1. / 3.;
173 matchThreshold = 2. / 3.;
174
175 for (uint32 ii=0; ii<1001; ii++)
176 scoreHistogram[ii] = 0;
177
178 for (uint32 ii=0; ii<4; ii++)
179 for (uint32 jj=0; jj<4; jj++)
180 thresholdCounts[ii][jj] = 0.0;
181
182 outputHistogram = NULL;
183
184 exist = NULL;
185
186 FASTQ1 = NULL;
187 FASTQ1pipe = false;
188
189 FASTQ2 = NULL;
190 FASTQ2pipe = false;
191
192 OUTPUT1[0] = NULL;
193 OUTPUT1[1] = NULL;
194 OUTPUT1[2] = NULL;
195
196 OUTPUT2[0] = NULL;
197 OUTPUT2[1] = NULL;
198 OUTPUT2[2] = NULL;
199 };
200
201 ~maskGlobal() {
202 };
203
204
205 public:
206 char *merName;
207
208 char *seq1Name;
209 char *seq2Name;
210
211 char *outPrefix;
212
213 uint32 merSize;
214 uint32 maxLength;
215
216 char *existName;
217 uint32 minSize;
218 uint32 extend;
219
220 bool cleaner;
221 bool dirtier;
222 bool discard;
223 bool unlink;
224
225 bool noMasking;
226
227 double cleanThreshold;
228 double matchThreshold;
229
230 uint32 scoreHistogram[1001];
231 uint64 thresholdCounts[4][4];
232
233 char *outputHistogram;
234
235 existDB *exist;
236
237 FILE *FASTQ1;
238 bool FASTQ1pipe;
239
240 FILE *FASTQ2;
241 bool FASTQ2pipe;
242
243 FILE *OUTPUT1[4];
244 FILE *OUTPUT2[4];
245 };
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 // Masks mers present in the database from the input sequences. Chains together
262 // across small bits of missing mer.
263
264 void
265 printBits(char *S, uint32 Slen, char *found, char *display, const char *label) {
266 for (uint32 i=0; i<Slen; i++)
267 display[i] = (found[i]) ? '1' : '0';
268
269 display[Slen] = 0;
270
271 fprintf(stdout, "%s\n%s\n", label, display);
272 }
273
274
275
276
277 // Scan the read for kmers that exist in the DB. Set a bit for each kmer that exists.
278 void
279 buildMask(char *S, uint32 Slen, char *found, existDB *exist, uint32 merSize) {
280 merStream MS(new kMerBuilder(merSize),
281 new seqStream(S, Slen),
282 true, true);
283
284 for (uint32 i=0; i<Slen; i++)
285 found[i] = false;
286
287 while (MS.nextMer())
288 if (exist->exists(MS.theFMer()) || exist->exists(MS.theRMer()))
289 found[MS.thePositionInSequence()] = true;
290 }
291
292
293
294
295 // Searched for isolated 'true' bits, and removes them. Isolated means fewer than minSize true
296 // bits are adjacent.
297 //
298 void
299 removeIsolatedMers(char *S, uint32 Slen, char *found, uint32 minSize) {
300 uint32 bgn = 0;
301 uint32 end = 0;
302 bool inRun = false;
303
304 for (uint32 ii=0; ii<Slen; ii++) {
305
306 // Start of a run of 'true'.
307 if ((found[ii] == true) && (inRun == false)) {
308 bgn = ii;
309 end = ii;
310 inRun = true;
311 }
312
313 // End of run of 'true'. If small, destroy it.
314 if ((found[ii] == false) && (inRun == true)) {
315 end = ii;
316
317 if (end - bgn < minSize)
318 for (uint32 jj=bgn; jj<end; jj++)
319 found[jj] = false;
320
321 inRun = false;
322 }
323 }
324 }
325
326
327
328 // Convert the mer-start-based mask to a base-covering mask, allowing an extra uncovered
329 // 'extension' bases in between two blocks to join.
330 void
331 convertToBases(char *S, uint32 Slen, char *found, uint32 merSize, uint32 extend) {
332 uint32 isMasking = 0;
333
334 for (uint32 ii=0; ii<Slen; ii++) {
335
336 if (found[ii])
337 isMasking = merSize;
338
339 // If the last mer we've found, see if we can extend over bases.
340 if ((isMasking == 1) &&
341 (extend > 0)) {
342 for (uint32 jj=ii; (jj<Slen) && (jj <= ii + extend + 1); jj++) {
343 if (found[jj] == true)
344 isMasking = jj - ii + 2;
345 }
346 }
347
348 if (isMasking > 0) {
349 found[ii] = true;
350 isMasking--;
351 }
352 }
353 }
354
355
356
357 // Assumes the found[] array represents base-based masking.
358 // Returns the fraction of the sequence that is masked.
359 double
360 maskSequence(char *S, uint32 Slen, char *found, bool noMasking, char *display) {
361 uint32 masked = 0;
362
363 // Flip the sense of the found[ii] test to mask kmers found in the database (true) or missing (false).
364
365 for (uint32 ii=0; ii<Slen; ii++) {
366 if (found[ii] == true) {
367 display[ii] = (noMasking == false) ? 'n' : S[ii];
368 masked++;
369 } else {
370 display[ii] = S[ii];
371 }
372 }
373
374 display[Slen] = 0;
375
376 return((double)masked / Slen);
377 }
378
379
380
381
382
383
384
385
386 void *
387 fastqLoader(void *G) {
388 maskGlobal *g = (maskGlobal *)G;
389 fastqRecord *s = new fastqRecord(g->maxLength);
390
391 if (s->load(g->FASTQ1, g->FASTQ2) == false) {
392 delete s;
393 s = NULL;
394 }
395
396 return(s);
397 }
398
399
400 void
401 maskWorker(void *G, void *T, void *S) {
402 maskGlobal *g = (maskGlobal *)G;
403 //maskThread *t = (maskThread *)T;
404 fastqRecord *s = (fastqRecord *)S;
405
406 buildMask(s->a2, s->aLength, s->af, g->exist, g->merSize);
407 buildMask(s->b2, s->bLength, s->bf, g->exist, g->merSize);
408 //printBits(S, found, display , "INITIAL");
409
410 removeIsolatedMers(s->a2, s->aLength, s->af, g->minSize);
411 removeIsolatedMers(s->b2, s->bLength, s->bf, g->minSize);
412 //printBits(S, found, display, "ISOLATED REMOVAL");
413
414 convertToBases(s->a2, s->aLength, s->af, g->merSize, g->extend);
415 convertToBases(s->b2, s->bLength, s->bf, g->merSize, g->extend);
416 //printBits(S, found, display, "BASE COVERAGE");
417
418 s->aMasked = maskSequence(s->a2, s->aLength, s->af, g->noMasking, s->am);
419 s->bMasked = maskSequence(s->b2, s->bLength, s->bf, g->noMasking, s->bm);
420
421 s->aLabel = (s->aMasked < g->cleanThreshold) ? 0 : ((s->aMasked < g->matchThreshold) ? 1 : 2);
422 s->bLabel = (s->bMasked < g->cleanThreshold) ? 0 : ((s->bMasked < g->matchThreshold) ? 1 : 2);
423
424 // If both reads exist, adjust labels.
425
426 if ((s->aLength > 0) && (s->bLength > 0)) {
427 if ((s->aLabel != s->bLabel) && (g->dirtier)) {
428 s->aLabel = MIN(s->aLabel, s->bLabel);
429 s->bLabel = MIN(s->aLabel, s->bLabel);
430 }
431
432 if ((s->aLabel != s->bLabel) && (g->cleaner)) {
433 s->aLabel = MAX(s->aLabel, s->bLabel);
434 s->bLabel = MAX(s->aLabel, s->bLabel);
435 }
436
437 if ((s->aLabel != s->bLabel) && (g->discard)) {
438 s->aLabel = 3;
439 s->bLabel = 3;
440 }
441 }
442 }
443
444
445 void
446 fastqWriter(void *G, void *S) {
447 maskGlobal *g = (maskGlobal *)G;
448 fastqRecord *s = (fastqRecord *)S;
449
450 s->write(g->OUTPUT1[s->aLabel], g->OUTPUT2[s->bLabel]);
451
452 g->thresholdCounts[s->aLabel][s->bLabel]++;
453
454 g->scoreHistogram[(uint32)(1000 * s->aMasked)]++;
455 g->scoreHistogram[(uint32)(1000 * s->bMasked)]++;
456
457 delete s;
458 }
459
460
461 FILE *
462 openInput(char *filename, bool &P) {
463 char C[2 * FILENAME_MAX];
464 FILE *F = NULL;
465 int32 L = (filename == NULL) ? 0 : strlen(filename);
466
467 if (filename == NULL)
468 return(NULL);
469
470 if (fileExists(filename) == false)
471 fprintf(stderr, "Failed to open Input file '%s' for reading: File not found.\n", filename), exit(1);
472
473 if ((L > 3) && (strcmp(filename + L - 3, ".gz") == 0)) {
474 sprintf(C, "gzip -dc %s", filename);
475 F = popen(C, "r");
476 P = true;
477 }
478
479 else if ((L > 4) && (strcmp(filename + L - 4, ".bz2") == 0)) {
480 sprintf(C, "bzip2 -dc %s", filename);
481 F = popen(C, "r");
482 P = true;
483 }
484
485 else if ((L > 3) && (strcmp(filename + L - 3, ".xz") == 0)) {
486 sprintf(C, "xz -dc %s", filename);
487 F = popen(C, "r");
488 P = true;
489 }
490
491 else {
492 errno = 0;
493 F = fopen(filename, "r");
494 if (errno)
495 fprintf(stderr, "Failed to open input file '%s' for reading: %s\n", filename, strerror(errno)), exit(1);
496 P = false;
497 }
498
499 return(F);
500 }
501
502
503 void
504 closeInput(FILE *F, char *filename, bool P) {
505 if (F == NULL)
506 return;
507
508 if (P)
509 pclose(F);
510 else
511 fclose(F);
512 }
513
514
515
516 FILE *
517 openOutput(char *prefix, const char *extension) {
518 char N[FILENAME_MAX];
519 FILE *F = NULL;
520
521 errno = 0;
522
523 sprintf(N, "%s.%s.fastq", prefix, extension);
524 F = fopen(N, "w");
525 if (errno)
526 fprintf(stderr, "ERROR: failed to open '%s': %s\n", N, strerror(errno)), exit(1);
527
528 return(F);
529 }
530
531
532 void
533 closeOutput(FILE *F, char *prefix, const char *extension) {
534 if (F)
535 fclose(F);
536 }
537
538
539
540 int
541 main(int argc, char **argv) {
542 maskGlobal *g = new maskGlobal();
543
544 uint32 numWorkers = 1;
545 bool beVerbose = false;
546
547 int32 arg=1;
548 int32 err=0;
549 while (arg < argc) {
550 if (strcmp(argv[arg], "-mdb") == 0) {
551 g->merName = argv[++arg];
552
553 } else if (strcmp(argv[arg], "-ms") == 0) {
554 g->merSize = atoi(argv[++arg]);
555
556 } else if (strcmp(argv[arg], "-l") == 0) {
557 g->maxLength = atoi(argv[++arg]);
558
559 } else if (strcmp(argv[arg], "-edb") == 0) {
560 g->existName = argv[++arg];
561
562 } else if (strcmp(argv[arg], "-1") == 0) {
563 g->seq1Name = argv[++arg];
564 } else if (strcmp(argv[arg], "-2") == 0) {
565 g->seq2Name = argv[++arg];
566
567 } else if (strcmp(argv[arg], "-o") == 0) {
568 g->outPrefix = argv[++arg];
569
570 } else if (strcmp(argv[arg], "-m") == 0) {
571 g->minSize = atoi(argv[++arg]);
572
573 } else if (strcmp(argv[arg], "-e") == 0) {
574 g->extend = atoi(argv[++arg]);
575
576 } else if (strcmp(argv[arg], "-t") == 0) {
577 numWorkers = atoi(argv[++arg]);
578 } else if (strcmp(argv[arg], "-v") == 0) {
579 beVerbose = true;
580
581 } else if (strcmp(argv[arg], "-cleaner") == 0) {
582 g->dirtier = false;
583 g->cleaner = true;
584 g->discard = false;
585 g->unlink = false;
586
587 } else if (strcmp(argv[arg], "-dirtier") == 0) {
588 g->dirtier = true;
589 g->cleaner = false;
590 g->discard = false;
591 g->unlink = false;
592
593 } else if (strcmp(argv[arg], "-discard") == 0) {
594 g->dirtier = false;
595 g->cleaner = false;
596 g->discard = true;
597 g->unlink = false;
598
599 } else if (strcmp(argv[arg], "-unlink") == 0) {
600 g->dirtier = false;
601 g->cleaner = false;
602 g->discard = false;
603 g->unlink = true;
604
605 } else if (strcmp(argv[arg], "-nomasking") == 0) {
606 g->noMasking = true;
607
608 } else if (strncmp(argv[arg], "-clean", 3) == 0) {
609 g->cleanThreshold = atof(argv[++arg]);
610 } else if (strncmp(argv[arg], "-match", 3) == 0) {
611 g->matchThreshold = atof(argv[++arg]);
612
613 } else if (strcmp(argv[arg], "-h") == 0) {
614 g->outputHistogram = argv[++arg];
615
616 } else {
617 err++;
618 }
619
620 arg++;
621 }
622 if ((g->outPrefix == NULL) && (g->seq1Name != NULL))
623 err++;
624 if ((g->merName == NULL) && (g->existName == NULL))
625 err++;
626 if (err) {
627 fprintf(stderr, "usage: %s -mdb mer-database -ms mer-size ...\n", argv[0]);
628 fprintf(stderr, "\n");
629 fprintf(stderr, "INPUTS:\n");
630 fprintf(stderr, "\n");
631 fprintf(stderr, " -mdb mer-database load masking kmers from meryl 'mer-database'\n");
632 fprintf(stderr, " -ms mer-size the mer size used to generate the meryl database\n");
633 fprintf(stderr, " -edb exist-database save masking kmers to 'exist-database', and reuse on\n");
634 fprintf(stderr, " future runs (optional)\n");
635 fprintf(stderr, "\n");
636 fprintf(stderr, " -1 in.1.fastq input reads - fastq, fastq.gz, fastq.bz2 or fastq.xz\n");
637 fprintf(stderr, " -2 in.2.fastq - optional, for mated reads\n");
638 fprintf(stderr, "\n");
639 fprintf(stderr, " -l length maximum length of input read (%u)\n", g->maxLength);
640 fprintf(stderr, " If too small, program will fail.\n");
641 fprintf(stderr, " If too large, program will use excessive memory.\n");
642 fprintf(stderr, "\n");
643 fprintf(stderr, "THRESHOLDS and OPTIONS:\n");
644 fprintf(stderr, "\n");
645 fprintf(stderr, " A read with fewer than 'c' bases masked is 'clean', while a read with more than 'd' bases\n");
646 fprintf(stderr, " masked is 'match'ed. Reads in between are 'murky'. See OUTPUTS.\n");
647 fprintf(stderr, "\n");
648 fprintf(stderr, " -clean c mark reads with less than this fraction masked as 'clean' (%.4f)\n", g->cleanThreshold);
649 fprintf(stderr, " -match d mark reads with more than this fraction masked as 'match' (%.4f)\n", g->matchThreshold);
650 fprintf(stderr, "\n");
651 fprintf(stderr, " -m min-size ignore database hits below this many consecutive kmers (%d)\n", g->minSize);
652 fprintf(stderr, " -e extend-size extend database hits across this many missing kmers (%d)\n", g->extend);
653 fprintf(stderr, "\n");
654 fprintf(stderr, " For mate pairs, how to handle reads with different classifications:\n");
655 fprintf(stderr, "\n");
656 fprintf(stderr, " -cleaner use the cleaner classification of the two reads\n");
657 fprintf(stderr, " -dirtier use the dirtier classification of the two reads\n");
658 fprintf(stderr, " -discard discard pairs with conflicting classifications (DEFAULT)\n");
659 fprintf(stderr, " -unlink leave conflicting status alone, output reads to different files\n");
660 fprintf(stderr, " NOTE: mate pairing will be broken\n");
661 fprintf(stderr, "\n");
662 fprintf(stderr, " -nomasking do not trim masked sequence; output the original read\n");
663 fprintf(stderr, "\n");
664 fprintf(stderr, "OUTPUTS:\n");
665 fprintf(stderr, "\n");
666 fprintf(stderr, " -o prefix output reads:\n");
667 fprintf(stderr, " prefix.clean.[12].fastq - clean (unmasked) reads\n");
668 fprintf(stderr, " prefix.murky.[12].fastq - reads in between\n");
669 fprintf(stderr, " prefix.match.[12].fastq - matching (masked) reads\n");
670 fprintf(stderr, " prefix.mixed.[12].fastq - reads with conflicting status (for mated reads)\n");
671 fprintf(stderr, " -h histogram write a histogram of the amount of sequence RETAINED\n");
672 fprintf(stderr, "\n");
673 fprintf(stderr, "COMPUTE CONFIGURATION and LOGGING\n");
674 fprintf(stderr, "\n");
675 fprintf(stderr, " -t t use 't' compute threads\n");
676 fprintf(stderr, " -v show progress\n");
677
678 if ((g->outPrefix == NULL) && (g->seq1Name != NULL))
679 fprintf(stderr, "ERROR: an output prefix (-o) must be supplied.\n");
680 if ((g->merName == NULL) && (g->existName == NULL))
681 fprintf(stderr, "ERROR: either a mer-database (-mdb) or an exist-database (-edb) must be supplied.\n");
682
683 exit(1);
684 }
685
686 // Open inputs and outputs
687
688 g->FASTQ1 = openInput(g->seq1Name, g->FASTQ1pipe);
689 g->FASTQ2 = openInput(g->seq2Name, g->FASTQ2pipe);
690
691 if (g->FASTQ1) {
692 g->OUTPUT1[0] = openOutput(g->outPrefix, "clean.1"); // Label == 0
693 g->OUTPUT1[1] = openOutput(g->outPrefix, "murky.1"); // Label == 1
694 g->OUTPUT1[2] = openOutput(g->outPrefix, "match.1"); // Label == 2
695 g->OUTPUT1[3] = openOutput(g->outPrefix, "mixed.1"); // Label == 3
696 }
697
698 if (g->FASTQ2) {
699 g->OUTPUT2[0] = openOutput(g->outPrefix, "clean.2");
700 g->OUTPUT2[1] = openOutput(g->outPrefix, "murky.2");
701 g->OUTPUT2[2] = openOutput(g->outPrefix, "match.2");
702 g->OUTPUT2[3] = openOutput(g->outPrefix, "mixed.2");
703 }
704
705 // Load data
706
707 if ((g->existName != NULL) && (fileExists(g->existName))) {
708 if (beVerbose)
709 fprintf(stderr, "Load existDB existName='%s'.\n", g->existName);
710 g->exist = new existDB(g->existName);
711
712 } else {
713 if (beVerbose)
714 fprintf(stderr, "Build existDB from merName='%s'.\n", g->merName);
715 g->exist = new existDB(g->merName, g->merSize, existDBnoFlags, 0, ~uint32ZERO);
716
717 if (g->existName != NULL) {
718 if (beVerbose)
719 fprintf(stderr, "Save existDB into existName='%s'.\n", g->existName);
720 g->exist->saveState(g->existName);
721 }
722 }
723
724 // Process!
725
726 if (g->FASTQ1) {
727 sweatShop *ss = new sweatShop(fastqLoader, maskWorker, fastqWriter);
728
729 ss->setNumberOfWorkers(numWorkers);
730
731 ss->setWorkerBatchSize(1024);
732
733 ss->setLoaderQueueSize(numWorkers * 81920);
734 ss->setWriterQueueSize(numWorkers * 81920);
735
736 ss->run(g, beVerbose);
737
738 closeInput(g->FASTQ1, g->seq1Name, g->FASTQ1pipe);
739 closeInput(g->FASTQ2, g->seq1Name, g->FASTQ2pipe);
740
741 closeOutput(g->OUTPUT1[0], g->outPrefix, "clean.1");
742 closeOutput(g->OUTPUT1[1], g->outPrefix, "murky.1");
743 closeOutput(g->OUTPUT1[2], g->outPrefix, "match.1");
744 closeOutput(g->OUTPUT1[3], g->outPrefix, "mixed.1");
745
746 closeOutput(g->OUTPUT2[0], g->outPrefix, "clean.2");
747 closeOutput(g->OUTPUT2[1], g->outPrefix, "murky.2");
748 closeOutput(g->OUTPUT2[2], g->outPrefix, "match.2");
749 closeOutput(g->OUTPUT2[3], g->outPrefix, "mixed.2");
750
751 #define FW uint64FMTW(8)
752
753 if (g->FASTQ2 == NULL) {
754 fprintf(stderr, "aClean "FW"\n", g->thresholdCounts[0][0]);
755 fprintf(stderr, "aMurky "FW"\n", g->thresholdCounts[1][0]);
756 fprintf(stderr, "aMatch "FW"\n", g->thresholdCounts[2][0]);
757 fprintf(stderr, "aMixed "FW"\n", g->thresholdCounts[3][0]);
758 } else {
759 fprintf(stderr, " bClean bMurky bMatch bMixed\n");
760 fprintf(stderr, "aClean "FW" "FW" "FW" "FW"\n", g->thresholdCounts[0][0], g->thresholdCounts[0][1], g->thresholdCounts[0][2], g->thresholdCounts[0][3]);
761 fprintf(stderr, "aMurky "FW" "FW" "FW" "FW"\n", g->thresholdCounts[1][0], g->thresholdCounts[1][1], g->thresholdCounts[1][2], g->thresholdCounts[1][3]);
762 fprintf(stderr, "aMatch "FW" "FW" "FW" "FW"\n", g->thresholdCounts[2][0], g->thresholdCounts[2][1], g->thresholdCounts[2][2], g->thresholdCounts[2][3]);
763 fprintf(stderr, "aMixed "FW" "FW" "FW" "FW"\n", g->thresholdCounts[3][0], g->thresholdCounts[3][1], g->thresholdCounts[3][2], g->thresholdCounts[3][3]);
764 }
765
766 #undef FW
767
768 if (g->outputHistogram != NULL) {
769 FILE *H = fopen(g->outputHistogram, "w");
770
771 fprintf(H, "# fraction-masked number-of-sequences\n");
772 for (uint32 i=0; i<1001; i++)
773 if (g->scoreHistogram[i] > 0)
774 fprintf(H, "%.4f\t%u\n", i / 1000.0, g->scoreHistogram[i]);
775
776 fclose(H);
777 }
778 }
779
780 delete g->exist;
781 delete g;
782
783 exit(0);
784 }