| 1 | #cxx . . $ `<file>/seagen/filterEST.C`/include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <string.h> |
| 5 | #include <errno.h> |
| 6 | #include "aHit.H"cxx . . $ `<file>/seagen/aHit.H`/ |
| 7 | #include "hitReader.H"cxx . . $ `<file>/seagen/hitReader.H`/ |
| 8 | |
| 9 | // XXX: Thread the filter! Really cool! Pretty neat hack! Usual |
| 10 | // thing, a thread to read hits, n threads to do filtering, and a |
| 11 | // thread to write filtered hits. Not trivial, but maybe a win. |
| 12 | |
| 13 | // Global statistics |
| 14 | // |
| 15 | uint32cxx . . $ uint32# hitsSavedcxx . . $ hitsSaved. = 0; |
| 16 | uint32cxx . . $ uint32# hitsFilteredcxx . . $ hitsFiltered. = 0; |
| 17 | uint32cxx . . $ uint32# hitsUnknowncxx . . $ hitsUnknown. = 0; |
| 18 | uint32cxx . . $ uint32# hitsTotalcxx . . $ hitsTotal. = 0; |
| 19 | |
| 20 | uint32cxx . . $ uint32# seqsMappedcxx . . $ seqsMapped. = 0; // Sequences that we mapped |
| 21 | uint32cxx . . $ uint32# seqsPartialcxx . . $ seqsPartial. = 0; // Sequences that we mapped, but missed a few good matches |
| 22 | uint32cxx . . $ uint32# seqsMissedcxx . . $ seqsMissed. = 0; // Sequences that we failed to map, but should have |
| 23 | |
| 24 | uint32cxx . . $ uint32# filterTPcxx . . $ filterTP. = 0; |
| 25 | uint32cxx . . $ uint32# filterFPcxx . . $ filterFP. = 0; |
| 26 | uint32cxx . . $ uint32# filterFNfiltcxx . . $ filterFNfilt. = 0; // false negatives from filtering |
| 27 | uint32cxx . . $ uint32# filterFNunkcxx . . $ filterFNunk. = 0; // false negatives from our failure to classify |
| 28 | uint32cxx . . $ uint32# filterTNcxx . . $ filterTN. = 0; |
| 29 | |
| 30 | uint32cxx . . $ uint32# goodPercentIDcxx . . $ goodPercentID. = 94; |
| 31 | uint32cxx . . $ uint32# goodCoveragecxx . . $ goodCoverage. = 50; |
| 32 | |
| 33 | // Command line options |
| 34 | // |
| 35 | uint32cxx . . $ uint32# uniqThreshcxx . . $ uniqThresh. = 200; // Used to be 100 |
| 36 | uint32cxx . . $ uint32# reptThreshcxx . . $ reptThresh. = 200; // Used to be 100 |
| 37 | |
| 38 | FILE *logFilecxx . . $ logFile. = 0L; |
| 39 | |
| 40 | // Filter results -- thread unsafe! |
| 41 | // |
| 42 | // bool decided -- true if the filter could decide on how to filter the hits |
| 43 | // char label -- if decided, the name of the decider |
| 44 | // uint32 hitsToSave -- the number of hits to save |
| 45 | // double qualToSave -- the quality threshold to filter at |
| 46 | // |
| 47 | bool decidedcxx . . $ decided.; |
| 48 | const char *labelcxx . . $ label.; |
| 49 | uint32cxx . . $ uint32# hitsToSavecxx . . $ hitsToSave.; |
| 50 | double qualToSavecxx . . $ qualToSave.; |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | void |
| 56 | reportcxx . . $ report(cb2f890c2fdad230).(uint32cxx . . $ uint32# iid |
| 57 | #ifdef WITH_ANSWERS |
| 58 | , |
| 59 | uint32 filterTP, |
| 60 | uint32 filterFP, |
| 61 | uint32 filterFNfilt, |
| 62 | uint32 filterFNunk, |
| 63 | uint32 filterTN, |
| 64 | uint32 seqsMapped, |
| 65 | uint32 seqsPartial, |
| 66 | uint32 seqsMissed |
| 67 | #endif |
| 68 | ) { |
| 69 | |
| 70 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 71 | uint32FMTWcxx . . $ `libutil/util.h:64:10`!(9)"]" |
| 72 | #ifdef WITH_ANSWERS |
| 73 | " tp="uint32FMTW(7)" fp="uint32FMTW(7)" fnfilt="uint32FMTW(7)" fnunkn="uint32FMTW(7)" tn="uint32FMTW(7) |
| 74 | " yea:"uint32FMTW(7)" may:"uint32FMTW(7)" nay:"uint32FMTW(7) |
| 75 | #endif |
| 76 | " hits saved:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(8)"/"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(8)" = %6.3f%%\r", |
| 77 | iid, |
| 78 | #ifdef WITH_ANSWERS |
| 79 | filterTP, filterFP, filterFNfilt, filterFNunk, filterTN, |
| 80 | seqsMapped, seqsPartial, seqsMissed, |
| 81 | #endif |
| 82 | hitsSavedcxx . . $ hitsSaved., hitsTotalcxx . . $ hitsTotal., |
| 83 | 100.0 * hitsSavedcxx . . $ hitsSaved. / hitsTotalcxx . . $ hitsTotal.); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | |
| 88 | void |
| 89 | complicatedFiltercxx . . $ complicatedFilter(3e702fd5c7abe76a).(hitReadercxx . . $ hitReader# &HR); |
| 90 | |
| 91 | |
| 92 | |
| 93 | // The simple filter just returns the top uniqThresh hits |
| 94 | // |
| 95 | void |
| 96 | simpleFiltercxx . . $ simpleFilter(3e702fd5c7abe76a).(hitReadercxx . . $ hitReader# &HR) { |
| 97 | |
| 98 | decidedcxx . . $ decided. = true; |
| 99 | labelcxx . . $ label. = "simple"; |
| 100 | qualToSavecxx . . $ qualToSave. = 0.0; |
| 101 | hitsToSavecxx . . $ hitsToSave. = HR.numHitscxx . . $ hitReader#numHits(db52760e79bf9054).(); |
| 102 | |
| 103 | if (HR.numHitscxx . . $ hitReader#numHits(db52760e79bf9054).() > uniqThreshcxx . . $ uniqThresh.) |
| 104 | hitsToSavecxx . . $ hitsToSave. = uniqThreshcxx . . $ uniqThresh.; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | int |
| 111 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) { |
| 112 | |
| 113 | if (argc == 1) { |
| 114 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ESTmapper utility function -- not for human use.\n"); |
| 115 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 116 | } |
| 117 | |
| 118 | hitReadercxx . . $ hitReader# HRcxx . . $ hitReader#hitReader(d4f767463ce0a6b3).(argc); |
| 119 | |
| 120 | int arg = 1; |
| 121 | while (arg < argc) { |
| 122 | if (strncmp(argv[arg], "-uniquethreshold", 2) == 0) { |
| 123 | uniqThreshcxx . . $ uniqThresh. = atoicxx . . $ atoi(f5ecf3191ed0cd93).(argv[++arg]); |
| 124 | } else if (strncmp(argv[arg], "-repeatthreshold", 2) == 0) { |
| 125 | reptThreshcxx . . $ reptThresh. = atoicxx . . $ atoi(f5ecf3191ed0cd93).(argv[++arg]); |
| 126 | } else if (strncmp(argv[arg], "-log", 2) == 0) { |
| 127 | ++arg; |
| 128 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 129 | logFilecxx . . $ logFile. = fopen(argv[arg], "w"); |
| 130 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) { |
| 131 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "filterEST: ERROR: couldn't open logFile '%s' for writing.\n%s\n", argv[arg], strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 132 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 133 | } |
| 134 | } else { |
| 135 | HR.addInputFilecxx . . $ hitReader#addInputFile(fda57c8427c60377).(argv[arg]); |
| 136 | } |
| 137 | |
| 138 | arg++; |
| 139 | } |
| 140 | |
| 141 | while (HR.loadHitscxx . . $ hitReader#loadHits(c9857a73d68e59ba).()) { |
| 142 | |
| 143 | // Not every filter we can think of needs the hits sorted, but |
| 144 | // it's nice to guarantee they are sorted. |
| 145 | // |
| 146 | HR.sortByCoveragecxx . . $ hitReader#sortByCoverage(49f6e7a06ebc5aa8).(); |
| 147 | |
| 148 | |
| 149 | //simpleFilter(HR); |
| 150 | complicatedFiltercxx . . $ complicatedFilter(3e702fd5c7abe76a).(HR); |
| 151 | |
| 152 | |
| 153 | #ifdef WITH_ANSWERS |
| 154 | int tp=0, tn=0, fn=0, fp=0; |
| 155 | #endif |
| 156 | |
| 157 | // If we still haven't figured out what to do, then the EST is |
| 158 | // labeled a repeat. Otherwise, write the (filtered) hits to the |
| 159 | // file. |
| 160 | // |
| 161 | if (!decidedcxx . . $ decided.) { |
| 162 | hitsUnknowncxx . . $ hitsUnknown. += HR.numHitscxx . . $ hitReader#numHits(db52760e79bf9054).(); |
| 163 | |
| 164 | #ifdef WITH_ANSWERS |
| 165 | // We've failed to classify all these hits, so anythig that looks good is a false negative |
| 166 | // |
| 167 | for (uint32 i=0; i < HR.numHits(); i++) |
| 168 | if ((HR[i].mappedCoverage >= goodCoverage) && (HR[i].mappedIdentity >= goodPercentID)) { |
| 169 | if (logFile) { |
| 170 | fprintf(logFile, "FAILUNKN hit="uint32FMTW(3)" id=%2d cv=%2d COV=%5.3f MUL=%5.3f: ", i, HR[i].mappedIdentity, HR[i].mappedCoverage, HR[i].coverage, HR[i].multiplicity); |
| 171 | ahit_printASCII(&HR[i].a, logFile); |
| 172 | } |
| 173 | filterFNunk++; |
| 174 | fn++; |
| 175 | } else { |
| 176 | tn++; |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | } else { |
| 181 | for (uint32cxx . . $ uint32# i=0; i < HR.numHitscxx . . $ hitReader#numHits(db52760e79bf9054).(); i++) { |
| 182 | if ((i < hitsToSavecxx . . $ hitsToSave.) && (qualToSavecxx . . $ qualToSave. <= HR[cxx . . $ hitReader#`operator[]`(38191595156c9293).i].coveragecxx . . $ $anonymous_type_cf7e7b12f763008e_1#coverage.)) { |
| 183 | hitsSavedcxx . . $ hitsSaved.++; |
| 184 | ahit_printASCIIcxx . . $ ahit_printASCII(6c917abaf95665ca).(&HR[cxx . . $ hitReader#`operator[]`(38191595156c9293).i].acxx . . $ $anonymous_type_cf7e7b12f763008e_1#a., stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 185 | |
| 186 | #ifdef WITH_ANSWERS |
| 187 | if ((HR[i].mappedCoverage >= goodCoverage) && (HR[i].mappedIdentity >= goodPercentID)) { |
| 188 | tp++; |
| 189 | } else { |
| 190 | fp++; |
| 191 | } |
| 192 | #endif |
| 193 | } else if (HR[cxx . . $ hitReader#`operator[]`(38191595156c9293).i].acxx . . $ $anonymous_type_cf7e7b12f763008e_1#a.._mergedcxx . . $ aHit#_merged.) { |
| 194 | // We merged this hit, so scores are incorrect. Give it |
| 195 | // the benefit of the doubt and report it. |
| 196 | // |
| 197 | hitsSavedcxx . . $ hitsSaved.++; |
| 198 | ahit_printASCIIcxx . . $ ahit_printASCII(6c917abaf95665ca).(&HR[cxx . . $ hitReader#`operator[]`(38191595156c9293).i].acxx . . $ $anonymous_type_cf7e7b12f763008e_1#a., stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 199 | } else { |
| 200 | hitsFilteredcxx . . $ hitsFiltered.++; |
| 201 | #ifdef WITH_ANSWERS |
| 202 | // Report hits that are false negatives |
| 203 | // |
| 204 | if ((HR[i].mappedCoverage >= goodCoverage) && (HR[i].mappedIdentity >= goodPercentID)) { |
| 205 | if (logFile) { |
| 206 | fprintf(logFile, "FAILFILT hit="uint32FMTW(3)" id=%2d cv=%2d COV=%5.3f MUL=%5.3f: ", i, HR[i].mappedIdentity, HR[i].mappedCoverage, HR[i].coverage, HR[i].multiplicity); |
| 207 | ahit_printASCII(&HR[i].a, logFile); |
| 208 | } |
| 209 | filterFNfilt++; |
| 210 | fn++; |
| 211 | } else { |
| 212 | tn++; |
| 213 | } |
| 214 | #endif |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | #ifdef WITH_ANSWERS |
| 220 | filterTP += tp; |
| 221 | filterTN += tn; |
| 222 | filterFP += fp; |
| 223 | |
| 224 | if (tp > 0) |
| 225 | seqsMapped++; |
| 226 | |
| 227 | if (fn > 0) |
| 228 | seqsPartial++; |
| 229 | |
| 230 | if ((tp == 0) && (fn > 0)) |
| 231 | seqsMissed++; |
| 232 | #endif |
| 233 | |
| 234 | hitsTotalcxx . . $ hitsTotal. += HR.numHitscxx . . $ hitReader#numHits(db52760e79bf9054).(); |
| 235 | |
| 236 | #ifdef WITH_ANSWERS |
| 237 | // Report if we saw falsenegatives (we should have printed FAIL into the log, too) |
| 238 | // |
| 239 | if (fn > 0) |
| 240 | if (logFile) |
| 241 | fprintf(logFile, uint32FMT"] %sFALSENEGATIVE %10.10s tp="uint32FMTW(7)" fp="uint32FMTW(7)" fn="uint32FMTW(7)" tn="uint32FMTW(7)"\n", |
| 242 | HR.iid(), |
| 243 | (tp > 0) ? "partial" : "fatal", |
| 244 | label, |
| 245 | tp, fp, fn, tn); |
| 246 | #endif |
| 247 | |
| 248 | |
| 249 | if ((HR.iidcxx . . $ hitReader#iid(db52760e79bf9054).() % 500) == 0) { |
| 250 | reportcxx . . $ report(cb2f890c2fdad230).(HR.iidcxx . . $ hitReader#iid(db52760e79bf9054).() |
| 251 | #ifdef WITH_ANSWERS |
| 252 | , |
| 253 | filterTP, filterFP, filterFNfilt, filterFNunk, filterTN, |
| 254 | seqsMapped, seqsPartial, seqsMissed |
| 255 | #endif |
| 256 | ); |
| 257 | fflush(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (logFilecxx . . $ logFile.) |
| 262 | fclose(logFilecxx . . $ logFile.); |
| 263 | |
| 264 | |
| 265 | reportcxx . . $ report(cb2f890c2fdad230).(HR.iidcxx . . $ hitReader#iid(db52760e79bf9054).() |
| 266 | #ifdef WITH_ANSWERS |
| 267 | , |
| 268 | filterTP, filterFP, filterFNfilt, filterFNunk, filterTN, |
| 269 | seqsMapped, seqsPartial, seqsMissed |
| 270 | #endif |
| 271 | ); |
| 272 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 273 | |
| 274 | return(0); |
| 275 | } |