Debian Codegraph @

seagen/filtertest.C

raw symbols SCIP
1 #cxx . . $ `<file>/seagen/filtertest.C`/include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <errno.h>
6
7 #include "bio.h"cxx . . $ `<file>/libbio/bio.h`/
8
9 #define MAX_ESTScxx . . $ `seagen/filtertest.C:9:9`! (16 * 1024 * 1024)
10 #define MAX_HITScxx . . $ `seagen/filtertest.C:10:9`! (18474961) // for 20-03-5000-0.4
11
12 //#define SHOW_ONE
13
14 ////////////////////////////////////////
15
16 struct aHitcxx . . $ aHit# {
17 uint32cxx . . $ uint32# _forwardcxx . . $ aHit#_forward.;
18 uint32cxx . . $ uint32# _qsIdxcxx . . $ aHit#_qsIdx.;
19 uint32cxx . . $ uint32# _dsIdxcxx . . $ aHit#_dsIdx.;
20 uint32cxx . . $ uint32# _dsLocxx . . $ aHit#_dsLo.;
21 uint32cxx . . $ uint32# _dsHicxx . . $ aHit#_dsHi.;
22 uint32cxx . . $ uint32# _coveredcxx . . $ aHit#_covered.;
23 uint32cxx . . $ uint32# _matchedcxx . . $ aHit#_matched.;
24 uint32cxx . . $ uint32# _numMerscxx . . $ aHit#_numMers.;
25 uint32cxx . . $ uint32# _yesnocxx . . $ aHit#_yesno.;
26 uint32cxx . . $ uint32# _identitycxx . . $ aHit#_identity.;
27 uint32cxx . . $ uint32# _coveragecxx . . $ aHit#_coverage.;
28
29 float scoreCovcxx . . $ aHit#scoreCov.;
30 float scoreMultcxx . . $ aHit#scoreMult.;
31 };
32
33
34 void ahit_writeBinarycxx . . $ ahit_writeBinary(6c917abaf95665ca).(aHitcxx . . $ aHit# *a, FILE *F) {
35 fwrite(a, sizeof(aHitcxx . . $ aHit#), 1, F);
36 }
37
38 void ahit_readBinarycxx . . $ ahit_readBinary(6c917abaf95665ca).(aHitcxx . . $ aHit# *a, FILE *F) {
39 fread(a, sizeof(aHitcxx . . $ aHit#), 1, F);
40 }
41
42 void ahit_printASCIIcxx . . $ ahit_printASCII(6c917abaf95665ca).(aHitcxx . . $ aHit# *a, FILE *F) {
43 #ifdef TRUE64BITcxx . . $ `libutil/util.h:39:9`!
44 fprintf(F, "-%c -e %u -D %u %u %u -M %u %u %u %s %u %u\n",
45 a->_forwardcxx . . $ aHit#_forward. ? 'f' : 'r',
46 a->_qsIdxcxx . . $ aHit#_qsIdx.,
47 a->_dsIdxcxx . . $ aHit#_dsIdx.,
48 a->_dsLocxx . . $ aHit#_dsLo.,
49 a->_dsHicxx . . $ aHit#_dsHi.,
50 a->_coveredcxx . . $ aHit#_covered.,
51 a->_matchedcxx . . $ aHit#_matched.,
52 a->_numMerscxx . . $ aHit#_numMers.,
53 a->_yesnocxx . . $ aHit#_yesno. ? "-Y" : "-N",
54 a->_identitycxx . . $ aHit#_identity.,
55 a->_coveragecxx . . $ aHit#_coverage.);
56 #else
57 fprintf(F, "-%c -e %lu -D %lu %lu %lu -M %lu %lu %lu %s %lu %lu\n",
58 a->_forward ? 'f' : 'r',
59 a->_qsIdx,
60 a->_dsIdx,
61 a->_dsLo,
62 a->_dsHi,
63 a->_covered,
64 a->_matched,
65 a->_numMers,
66 a->_yesno ? "-Y" : "-N",
67 a->_identity,
68 a->_coverage);
69 #endif
70 }
71
72
73 void ahit_parseStringcxx . . $ ahit_parseString(e8f5be3781ac6c2f).(aHitcxx . . $ aHit# *a, char *b) {
74 char *c = b+1;
75
76 a->_forwardcxx . . $ aHit#_forward. = (*c == 'f');
77 c += 1;
78
79 if (c[2] != 'e') fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "'%s' didn't get -e\n", b);
80
81 c += 4;
82 a->_qsIdxcxx . . $ aHit#_qsIdx. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
83
84 if (c[2] != 'D') fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "'%s' didn't get -D\n", b);
85
86 c += 4;
87 a->_dsIdxcxx . . $ aHit#_dsIdx. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
88 a->_dsLocxx . . $ aHit#_dsLo. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
89 a->_dsHicxx . . $ aHit#_dsHi. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
90
91 if (c[2] == 'M') {
92 c += 4;
93 a->_coveredcxx . . $ aHit#_covered. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
94 a->_matchedcxx . . $ aHit#_matched. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
95 a->_numMerscxx . . $ aHit#_numMers. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
96 } else {
97 //fprintf(stderr, "'%s' didn't get -M\n", b);
98 a->_coveredcxx . . $ aHit#_covered. = 0;
99 a->_matchedcxx . . $ aHit#_matched. = 0;
100 a->_numMerscxx . . $ aHit#_numMers. = 0;
101 }
102
103 a->_yesnocxx . . $ aHit#_yesno. = 0;
104 a->_identitycxx . . $ aHit#_identity. = 0;
105 a->_coveragecxx . . $ aHit#_coverage. = 0;
106
107 if (c[2] == 'Y') {
108 c += 4;
109 a->_yesnocxx . . $ aHit#_yesno. = 1;
110 a->_identitycxx . . $ aHit#_identity. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
111 a->_coveragecxx . . $ aHit#_coverage. = (uint32cxx . . $ uint32#)strtoulcxx . . $ strtoul(335a43d87d12a1b6).(c, &c, 10);
112 }
113
114 #if 0
115 if (c[2] == 'N') {
116 c += 4;
117 a->_yesno = 0;
118 a->_identity = (uint32)strtoul(c, &c, 10);
119 a->_coverage = (uint32)strtoul(c, &c, 10);
120 }
121 #endif
122 }
123
124 ////////////////////////////////////////
125
126 int
127 hitComparecxx . . $ hitCompare(9148c8c3ff42c9d8).(const void *a, const void *b) {
128 const aHitcxx . . $ aHit# *A = (const aHitcxx . . $ aHit# *)a;
129 const aHitcxx . . $ aHit# *B = (const aHitcxx . . $ aHit# *)b;
130
131 if (A->scoreCovcxx . . $ aHit#scoreCov. > B->scoreCovcxx . . $ aHit#scoreCov.)
132 return(-1);
133 else
134 return(A->scoreCovcxx . . $ aHit#scoreCov. < B->scoreCovcxx . . $ aHit#scoreCov.);
135 }
136
137 int
138 hitCompareIDcxx . . $ hitCompareID(9148c8c3ff42c9d8).(const void *a, const void *b) {
139 const aHitcxx . . $ aHit# *A = (const aHitcxx . . $ aHit# *)a;
140 const aHitcxx . . $ aHit# *B = (const aHitcxx . . $ aHit# *)b;
141
142 if (A->_qsIdxcxx . . $ aHit#_qsIdx. < B->_qsIdxcxx . . $ aHit#_qsIdx.)
143 return(-1);
144 if (A->_qsIdxcxx . . $ aHit#_qsIdx. > B->_qsIdxcxx . . $ aHit#_qsIdx.)
145 return(1);
146 return(0);
147 }
148
149
150
151 int
152 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) {
153 aHitcxx . . $ aHit# *hits = new aHitcxx . . $ aHit# [MAX_HITScxx . . $ `seagen/filtertest.C:10:9`!];
154 uint32cxx . . $ uint32# hitsLen = 0;
155
156
157 // read all the hits from stdin -- assumes ascii format
158 //
159 char hitLine[1025];
160
161 while (!feof(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) {
162 fgets(hitLine, 1024, stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!);
163 if (!feof(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!)) {
164 ahit_parseStringcxx . . $ ahit_parseString(e8f5be3781ac6c2f).(hits + hitsLen, hitLine);
165
166 // These are the scores used by the filter
167 //
168 hits[hitsLen].scoreCovcxx . . $ aHit#scoreCov. = (float)hits[hitsLen]._coveredcxx . . $ aHit#_covered. / (float)hits[hitsLen]._numMerscxx . . $ aHit#_numMers.;
169 hits[hitsLen].scoreMultcxx . . $ aHit#scoreMult. = (float)hits[hitsLen]._matchedcxx . . $ aHit#_matched. / (float)hits[hitsLen]._coveredcxx . . $ aHit#_covered.;
170
171 // aHit->_covered is in bases, but aHit->_numMers is the
172 // number of mers. Possible for coverage to be > 1.0.
173 //
174 if (hits[hitsLen].scoreCovcxx . . $ aHit#scoreCov. > 1.0)
175 hits[hitsLen].scoreCovcxx . . $ aHit#scoreCov. = 1.0;
176
177 hitsLen++;
178
179 if ((hitsLen & 0xff) == 0) {
180 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "reading hits "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\r", hitsLen);
181 fflush(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
182 }
183 }
184 }
185
186 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "reading hits "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", hitsLen);
187
188
189 // Sort the hits by estid
190 //
191 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "sorting hits by cDNA\n");
192 qsortcxx . . $ qsort(ebb60b13a65e77d7).(hits, hitsLen, sizeof(aHitcxx . . $ aHit#), hitCompareIDcxx . . $ hitCompareID(9148c8c3ff42c9d8).);
193
194
195 // Sort the hits by score (scoreCov), in decreasing order.
196 //
197 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "sorting hits by score\n");
198 for (uint32cxx . . $ uint32# currentHit = 0; currentHit < hitsLen; ) {
199 uint32cxx . . $ uint32# estOfInterest = hits[currentHit]._qsIdxcxx . . $ aHit#_qsIdx.;
200 uint32cxx . . $ uint32# numHits = 0;
201 for (uint32cxx . . $ uint32# t=currentHit; (t < hitsLen) && (hits[t]._qsIdxcxx . . $ aHit#_qsIdx. == estOfInterest); t++)
202 numHits++;
203
204 qsortcxx . . $ qsort(ebb60b13a65e77d7).(hits + currentHit, numHits, sizeof(aHitcxx . . $ aHit#), hitComparecxx . . $ hitCompare(9148c8c3ff42c9d8).);
205
206 currentHit += numHits;
207 }
208
209 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "filtering hits\n");
210
211 double L = 0.0;
212 double H = 0.0;
213 double V = 0.1;
214 double M = 1.0;
215 double MC = 0.0;
216 uint32cxx . . $ uint32# ML = 0;
217
218 double minIdentity = 98.0;
219 double minCoverage = 96.0;
220
221 for (uint32cxx . . $ uint32# Hcnt = 10; Hcnt <= 100; Hcnt += 10) {
222 for (uint32cxx . . $ uint32# Lcnt = 10; Lcnt < Hcnt && Lcnt < 60; Lcnt += 10) {
223 for (uint32cxx . . $ uint32# Vcnt = 10; Vcnt < 100; Vcnt += 10) {
224 #ifdef SHOW_ONE
225 Lcnt = 30;
226 Hcnt = 40;
227 Vcnt = 100;
228 #endif
229 L = Lcnt / 100.0;
230 H = Hcnt / 100.0;
231 V = Vcnt / 100.0;
232
233 uint32cxx . . $ uint32# truepositive = 0;
234 uint32cxx . . $ uint32# falsepositive = 0;
235 uint32cxx . . $ uint32# truenegative = 0;
236 uint32cxx . . $ uint32# falsenegative = 0;
237
238 for (uint32cxx . . $ uint32# currentHit = 0; currentHit < hitsLen; ) {
239
240 // Find the number of hits for this ESTid
241 //
242 uint32cxx . . $ uint32# estOfInterest = hits[currentHit]._qsIdxcxx . . $ aHit#_qsIdx.;
243 uint32cxx . . $ uint32# numHits = 0;
244 for (uint32cxx . . $ uint32# t=currentHit; (t < hitsLen) && (hits[t]._qsIdxcxx . . $ aHit#_qsIdx. == estOfInterest); t++)
245 numHits++;
246
247 double h = hits[currentHit].scoreCovcxx . . $ aHit#scoreCov. - hits[currentHit + numHits - 1].scoreCovcxx . . $ aHit#scoreCov.;
248 double p = 0.0;
249
250 if (h <= L) p = 1.0;
251 if (h >= H) p = V;
252 if (p == 0.0) p = 1.0 - (1.0 - V) * (h - L) / (H - L);
253
254 // check p; it should be between V and 1.0
255 if (p > 1.0) {
256 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error in p; p=%f h=%f (%f %f %f)\n", p, h, L, H, V);
257 p = 1.0;
258 }
259
260 if (p < V) {
261 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error in p; p=%f h=%f (%f %f %f)\n", p, h, L, H, V);
262 p = V;
263 }
264
265 // Output the top p% hits, by score.
266 //
267 double cutL = hits[currentHit].scoreCovcxx . . $ aHit#scoreCov. - p * h;
268
269 if (cutL > M)
270 cutL = M;
271
272 #ifdef SHOW_ONE
273 fprintf(stdout, "LHV = %f %f %f p=%f h=%f cutL=%f\n", L, H, V, p, h, cutL);
274 #endif
275
276
277 for (uint32cxx . . $ uint32# i=currentHit; i < currentHit + numHits; i++) {
278 if ((cutL <= hits[i].scoreCovcxx . . $ aHit#scoreCov.) &&
279 ((MC <= hits[i].scoreCovcxx . . $ aHit#scoreCov.) || (ML <= hits[i]._coveredcxx . . $ aHit#_covered.))) {
280 #ifdef SHOW_ONE
281 fprintf(stdout, "POS: (%f)", hits[i].scoreCov);
282 ahit_printASCII(hits+i, stdout);
283 #endif
284 if ((hits[i]._yesnocxx . . $ aHit#_yesno. == 1) && (hits[i]._identitycxx . . $ aHit#_identity. >= minIdentity) && (hits[i]._coveragecxx . . $ aHit#_coverage. >= minCoverage))
285 truepositive++;
286 else
287 falsepositive++;
288 } else {
289 #ifdef SHOW_ONE
290 fprintf(stdout, "NEG: (%f)", hits[i].scoreCov);
291 ahit_printASCII(hits+i, stdout);
292 #endif
293 if ((hits[i]._yesnocxx . . $ aHit#_yesno. == 1) && (hits[i]._identitycxx . . $ aHit#_identity. >= minIdentity) && (hits[i]._coveragecxx . . $ aHit#_coverage. >= minCoverage))
294 falsenegative++;
295 else
296 truenegative++;
297 }
298 }
299
300 #ifdef SHOW_ONE
301 fprintf(stdout, "----\n");
302 #endif
303 currentHit += numHits;
304 }
305
306 // Print L, H, V, sensitivity, specificity
307 //
308 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%f %f %f %6.4f %6.4f "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n",
309 L, H, V,
310 (double)truepositive / (truepositive + falsenegative),
311 (double)truenegative / (truenegative + falsepositive),
312 truepositive, falsepositive,
313 truenegative, falsenegative);
314 fflush(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
315
316 #ifdef SHOW_ONE
317 exit(0);
318 #endif
319 }
320 }
321 }
322
323 return(0);
324 }
325