| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | #include "aHit.H" |
| 7 | #include "hitReader.H" |
| 8 | |
| 9 | |
| 10 | int |
| 11 | main(int argc, char **argv) { |
| 12 | |
| 13 | if (argc < 2) |
| 14 | fprintf(stderr, "ESTmapper utility function -- not for human use.\n"), exit(1); |
| 15 | |
| 16 | hitReader HR(argc); |
| 17 | double L = 0.2; |
| 18 | double H = 0.6; |
| 19 | double V = 0.7; |
| 20 | double M = 0.3; |
| 21 | double MC = 0.2; |
| 22 | uint32 ML = 150; |
| 23 | bool beVerbose = false; |
| 24 | |
| 25 | int arg = 1; |
| 26 | while (arg < argc) { |
| 27 | if (strncmp(argv[arg], "-v", 2) == 0) { |
| 28 | beVerbose = true; |
| 29 | } else if (strcmp(argv[arg], "-l") == 0) { |
| 30 | L = atof(argv[++arg]); |
| 31 | } else if (strcmp(argv[arg], "-h") == 0) { |
| 32 | H = atof(argv[++arg]); |
| 33 | } else if (strcmp(argv[arg], "-v") == 0) { |
| 34 | V = atof(argv[++arg]); |
| 35 | } else if (strcmp(argv[arg], "-m") == 0) { |
| 36 | M = atof(argv[++arg]); |
| 37 | } else if (strcmp(argv[arg], "-mc") == 0) { |
| 38 | MC = atof(argv[++arg]); |
| 39 | } else if (strcmp(argv[arg], "-ml") == 0) { |
| 40 | ML = atoi(argv[++arg]); |
| 41 | } else { |
| 42 | HR.addInputFile(argv[arg]); |
| 43 | } |
| 44 | |
| 45 | arg++; |
| 46 | } |
| 47 | |
| 48 | if (beVerbose) { |
| 49 | fprintf(stderr, "Filtering with:\n"); |
| 50 | fprintf(stderr, " score difference of %4.2f or less -> 100.0%% of best score\n", L); |
| 51 | fprintf(stderr, " score difference of %4.2f or more -> %5.1f%% of best score\n", H, 100*V); |
| 52 | fprintf(stderr, " scores at least %4.2f are always output\n", M); |
| 53 | fprintf(stderr, " scores at least %4.2f AND at least "uint32FMT" bases covered are always output\n", MC, ML); |
| 54 | } |
| 55 | |
| 56 | while (HR.loadHits()) { |
| 57 | HR.sortByCoverage(); |
| 58 | |
| 59 | double hiCov = HR[0].coverage; |
| 60 | double loCov = HR[0].coverage; |
| 61 | for (uint32 i=0; i < HR.numHits(); i++) |
| 62 | if ((HR[i].a._merged == false) && (loCov > HR[i].coverage)) |
| 63 | loCov = HR[i].coverage; |
| 64 | |
| 65 | double h = hiCov - loCov; |
| 66 | double p = 0.0; |
| 67 | |
| 68 | if (h <= L) p = 1.0; |
| 69 | if (h >= H) p = V; |
| 70 | if (p == 0.0) p = 1.0 - (1.0 - V) * (h - L) / (H - L); |
| 71 | |
| 72 | // check p; it should be between V and 1.0 |
| 73 | if ((p > 1.0) || (p < V)) |
| 74 | fprintf(stderr, "error in p; p=%f\n", p); |
| 75 | |
| 76 | // Output the top p% hits, by score. |
| 77 | |
| 78 | double cutL = HR[0].coverage - p * h; |
| 79 | if (cutL > M) |
| 80 | cutL = M; |
| 81 | |
| 82 | // Save the hit if it has good coverage and it's either above |
| 83 | // the minimum coverage or long. Also blindly save merged |
| 84 | // hits. |
| 85 | // |
| 86 | for (uint32 i=0; i < HR.numHits(); i++) |
| 87 | if (((cutL <= HR[i].coverage) && ((MC <= HR[i].coverage) || |
| 88 | (ML <= HR[i].a._covered))) || |
| 89 | (HR[i].a._merged)) |
| 90 | ahit_printASCII(&HR[i].a, stdout); |
| 91 | } |
| 92 | |
| 93 | return(0); |
| 94 | } |