Debian Codegraph @

pytools/lib/readqc_report.py

raw symbols SCIP
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 Readqc report: record stat key-value in readqc-stats.txt
6
7 ### JGI_Analysis_Utility_Illumina::illumina_read_level_report
8
9 Created: Jul 24 2013
10
11 sulsj ([email protected])
12
13 """
14
15
16 import os
17 import sys
18
19 ## custom libs in "../lib/"
20 srcDir = os.path.dirname(__file__)
21 sys.path.append(os.path.join(srcDir, 'tools')) ## ./tools
22 sys.path.append(os.path.join(srcDir, '../lib')) ## rqc-pipeline/lib
23 sys.path.append(os.path.join(srcDir, '../tools')) ## rqc-pipeline/tools
24
25 from readqc_constants import RQCReadQcConfig, ReadqcStats
26 from rqc_constants import RQCExitCodes
27 from os_utility import run_sh_command
28 from common import append_rqc_stats, append_rqc_file
29
30
31 statsFile = RQCReadQcConfig.CFG["stats_file"]
32 filesFile = RQCReadQcConfig.CFG["files_file"]
33
34
35 """
36 Title : read_megablast_hits
37 Function : This function generates tophit list of megablast against different databases.
38 Usage : read_megablast_hits(db_name, log)
39 Args : blast db name or full path
40 Returns : SUCCESS
41 FAILURE
42 Comments :
43
44 """
45 def read_megablast_hits(db, log):
46 currentDir = RQCReadQcConfig.CFG["output_path"]
47 megablastDir = "megablast"
48 megablastPath = os.path.join(currentDir, megablastDir)
49
50 statsFile = RQCReadQcConfig.CFG["stats_file"]
51 filesFile = RQCReadQcConfig.CFG["files_file"]
52
53
54 ##
55 ## Process blast output files
56 ##
57 matchings = 0
58 hitCount = 0
59 parsedFile = os.path.join(megablastPath, "megablast.*.%s*.parsed" % (db))
60 matchings, _, exitCode = run_sh_command("grep -v '^#' %s 2>/dev/null | wc -l " % (parsedFile), True, log)
61
62 if exitCode == 0: ## if parsed file found.
63 t = matchings.split()
64
65 if len(t) == 1 and t[0].isdigit():
66 hitCount = int(t[0])
67
68 append_rqc_stats(statsFile, ReadqcStats.ILLUMINA_READ_MATCHING_HITS + " " + db, hitCount, log)
69
70 ##
71 ## add .parsed file
72 ##
73 parsedFileFound, _, exitCode = run_sh_command("ls %s" % (parsedFile), True, log)
74
75 if parsedFileFound:
76 parsedFileFound = parsedFileFound.strip()
77 append_rqc_file(filesFile, ReadqcStats.ILLUMINA_READ_PARSED_FILE + " " + db, os.path.join(megablastPath, parsedFileFound), log)
78 else:
79 log.error("- Failed to add megablast parsed file of %s." % (db))
80 return RQCExitCodes.JGI_FAILURE
81
82 ##
83 ## wc the top hits
84 ##
85 topHit = 0
86 tophitFile = os.path.join(megablastPath, "megablast.*.%s*.parsed.tophit" % (db))
87 tophits, _, exitCode = run_sh_command("grep -v '^#' %s 2>/dev/null | wc -l " % (tophitFile), True, log)
88
89 t = tophits.split()
90
91 if len(t) == 1 and t[0].isdigit():
92 topHit = int(t[0])
93
94 append_rqc_stats(statsFile, ReadqcStats.ILLUMINA_READ_TOP_HITS + " " + db, topHit, log)
95
96 ##
97 ## wc the taxonomic species
98 ##
99 spe = 0
100 taxlistFile = os.path.join(megablastPath, "megablast.*.%s*.parsed.taxlist" % (db))
101 species, _, exitCode = run_sh_command("grep -v '^#' %s 2>/dev/null | wc -l " % (taxlistFile), True, log)
102
103 t = species.split()
104
105 if len(t) == 1 and t[0].isdigit():
106 spe = int(t[0])
107
108 append_rqc_stats(statsFile, ReadqcStats.ILLUMINA_READ_TAX_SPECIES + " " + db, spe, log)
109
110 ##
111 ## wc the top 100 hit
112 ##
113 top100hits = 0
114 top100hitFile = os.path.join(megablastPath, "megablast.*.%s*.parsed.top100hit" % (db))
115 species, _, exitCode = run_sh_command("grep -v '^#' %s 2>/dev/null | wc -l " % (top100hitFile), True, log)
116
117 t = species.split()
118
119 if len(t) == 1 and t[0].isdigit():
120 top100hits = int(t[0])
121
122 append_rqc_stats(statsFile, ReadqcStats.ILLUMINA_READ_TOP_100HITS + " " + db, top100hits, log)
123
124 ##
125 ## Find and add taxlist file
126 ##
127 taxListFound, _, exitCode = run_sh_command("ls %s" % (taxlistFile), True, log)
128 taxListFound = taxListFound.strip()
129
130 if taxListFound:
131 append_rqc_file(filesFile, ReadqcStats.ILLUMINA_READ_TAXLIST_FILE + " " + db, os.path.join(megablastPath, taxListFound), log)
132 else:
133 log.error("- Failed to add megablast taxlist file of %s." % (db))
134 return RQCExitCodes.JGI_FAILURE
135
136 ##
137 ## Find and add tophit file
138 ##
139 tophitFound, _, exitCode = run_sh_command("ls %s" % (tophitFile), True, log)
140 tophitFound = tophitFound.strip()
141
142 if tophitFound:
143 append_rqc_file(filesFile, ReadqcStats.ILLUMINA_READ_TOPHIT_FILE + " " + db, os.path.join(megablastPath, tophitFound), log)
144 else:
145 log.error("- Failed to add megablast tophit file of %s." % (db))
146 return RQCExitCodes.JGI_FAILURE
147
148 ##
149 ## Find and add top100hit file
150 ##
151 top100hitFound, _, exitCode = run_sh_command("ls %s" % (top100hitFile), True, log)
152 top100hitFound = top100hitFound.strip()
153
154 if top100hitFound:
155 append_rqc_file(filesFile, ReadqcStats.ILLUMINA_READ_TOP100HIT_FILE + " " + db, os.path.join(megablastPath, top100hitFound), log)
156 else:
157 log.error("- Failed to add megablast top100hit file of %s." % (db))
158 return RQCExitCodes.JGI_FAILURE
159
160 else:
161 log.info("- No blast hits for %s." % (db))
162
163
164 return RQCExitCodes.JGI_SUCCESS
165
166
167
168 """
169 Title : read_level_qual_stats
170 Function : Generate qual scores and plots of read level 20mer sampling
171 Usage : read_level_mer_sampling($analysis, $summary_file_dir)
172 Args : 1) A reference to an JGI_Analysis object
173 2) current working folder wkdir/uniqueness
174 Returns : JGI_SUCCESS: Illumina read level report could be successfully generated.
175 JGI_FAILURE: Illumina read level report could not be generated.
176 Comments : This function is intended to be called at the very end of the illumina read level data processing script.
177
178 """
179 def read_level_mer_sampling(dataToRecordDict, dataFile, log):
180 retCode = RQCExitCodes.JGI_FAILURE
181
182 ## Old data
183 #nSeq nStartUniMer fracStartUniMer nRandUniMer fracRandUniMer
184 ## 0 1 2 3 4
185 ##25000 2500 0.1 9704 0.3882
186
187 ## New data
188 #count first rand first_cnt rand_cnt
189 # 0 1 2 3 4
190 #25000 66.400 76.088 16600 19022
191 #50000 52.148 59.480 13037 14870
192 #75000 46.592 53.444 11648 13361
193 #100000 43.072 49.184 10768 12296 ...
194
195 if os.path.isfile(dataFile):
196 with open(dataFile, "r") as merFH:
197 lines = merFH.readlines()
198
199 ## last line
200 t = lines[-1].split('\t')
201 # breaks 2016-09-07
202 #assert len(t) == 5
203
204 totalMers = int(t[0])
205
206 ## new by bbcountunique
207 uniqStartMerPer = float("%.2f" % (float(t[1])))
208 uniqRandtMerPer = float("%.2f" % (float(t[2])))
209
210 dataToRecordDict[ReadqcStats.ILLUMINA_READ_20MER_SAMPLE_SIZE] = totalMers
211 dataToRecordDict[ReadqcStats.ILLUMINA_READ_20MER_PERCENTAGE_STARTING_MERS] = uniqStartMerPer
212 dataToRecordDict[ReadqcStats.ILLUMINA_READ_20MER_PERCENTAGE_RANDOM_MERS] = uniqRandtMerPer
213
214 retCode = RQCExitCodes.JGI_SUCCESS
215
216 else:
217 log.error("- qhist file not found: %s" % (dataFile))
218
219
220 return retCode
221
222
223
224
225 """
226 Title : base_level_qual_stats
227 Function : Generate qual scores and plots of read level QC
228 Usage : base_level_qual_stats($analysis, $)
229 Args : 1) A reference to an JGI_Analysis object
230 2) current working folder wkdir/qual
231 Returns : JGI_SUCCESS: Illumina read level report could be successfully generated.
232 JGI_FAILURE: Illumina read level report could not be generated.
233 Comments : This function is intended to be called at the very end of the illumina base level data processing script.
234
235 """
236 def base_level_qual_stats(dataToRecordDict, reformatObqhistFile, log):
237 cummlatPer = 0
238 cummlatBase = 0
239
240 statsPerc = {30:0, 25:0, 20:0, 15:0, 10:0, 5:0}
241 statsBase = {30:0, 25:0, 20:0, 15:0, 10:0, 5:0}
242
243 Q30_seen = 0
244 Q25_seen = 0
245 Q20_seen = 0
246 Q15_seen = 0
247 Q10_seen = 0
248 Q5_seen = 0
249
250 ## New format
251 ##Median 38
252 ##Mean 37.061
253 ##STDev 4.631
254 ##Mean_30 37.823
255 ##STDev_30 1.699
256 ##Quality bases fraction
257 #0 159 0.00008
258 #1 0 0.00000
259 #2 12175 0.00593
260 #3 0 0.00000
261 #4 0 0.00000
262 #5 0 0.00000
263 #6 0 0.00000
264
265 allLines = open(reformatObqhistFile).readlines()
266 for l in allLines[::-1]:
267 l = l.strip()
268
269 ##
270 ## obqhist file format example
271 ##
272 # #Median 36
273 # #Mean 33.298
274 # #STDev 5.890
275 # #Mean_30 35.303
276 # #STDev_30 1.517
277 # #Quality bases fraction
278 # 0 77098 0.00043
279 # 1 0 0.00000
280 # 2 0 0.00000
281 # 3 0 0.00000
282 # 4 0 0.00000
283 # 5 0 0.00000
284 # 6 0 0.00000
285
286 if len(l) > 0:
287 if l.startswith("#"):
288 if l.startswith("#Mean_30"):
289 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q30_SCORE_MEAN] = l.split('\t')[1]
290
291 elif l.startswith("#STDev_30"):
292 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q30_SCORE_STD] = l.split('\t')[1]
293
294 elif l.startswith("#Mean"):
295 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_OVERALL_BASES_Q_SCORE_MEAN] = l.split('\t')[1]
296
297 elif l.startswith("#STDev"):
298 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_OVERALL_BASES_Q_SCORE_STD] = l.split('\t')[1]
299
300 continue
301
302
303 qavg = None
304 nbase = None
305 percent = None
306
307 t = l.split()
308
309 try:
310 qavg = int(t[0])
311 nbase = int(t[1])
312 percent = float(t[2])
313 except IndexError:
314 log.warn("parse error in base_level_qual_stats: %s %s %s %s" % (l, qavg, nbase, percent))
315 continue
316
317 log.debug("base_level_qual_stats(): qavg and nbase and percent: %s %s %s" % (qavg, nbase, percent))
318
319 cummlatPer += percent * 100.0
320 cummlatPer = float("%.f" % (cummlatPer))
321
322 if cummlatPer > 100:
323 cummlatPer = 100.0 ## RQC-621
324
325 cummlatBase += nbase
326
327 if qavg == 30:
328 Q30_seen = 1
329 statsPerc[30] = cummlatPer
330 statsBase[30] = cummlatBase
331
332 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q30] = cummlatPer
333 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C30] = cummlatBase
334
335 elif qavg == 25:
336 Q25_seen = 1
337 statsPerc[25] = cummlatPer
338 statsBase[25] = cummlatBase
339
340 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q25] = cummlatPer
341 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C25] = cummlatBase
342
343 elif qavg == 20:
344 Q20_seen = 1
345 statsPerc[20] = cummlatPer
346 statsBase[20] = cummlatBase
347
348 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q20] = cummlatPer
349 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C20] = cummlatBase
350
351 elif qavg == 15:
352 Q15_seen = 1
353 statsPerc[15] = cummlatPer
354 statsBase[15] = cummlatBase
355
356 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q15] = cummlatPer
357 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C15] = cummlatBase
358
359 elif qavg == 10:
360 Q10_seen = 1
361 statsPerc[10] = cummlatPer
362 statsBase[10] = cummlatBase
363
364 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q10] = cummlatPer
365 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C10] = cummlatBase
366
367 elif qavg == 5:
368 Q5_seen = 1
369 statsPerc[5] = cummlatPer
370 statsBase[5] = cummlatBase
371
372 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q5] = cummlatPer
373 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C5] = cummlatBase
374
375 ## Double check that no value is missing.
376 if Q25_seen == 0 and Q30_seen != 0:
377 Q25_seen = 1
378 statsPerc[25] = statsPerc[30]
379 statsBase[25] = statsBase[30]
380 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q25] = cummlatPer
381 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C25] = cummlatBase
382
383 if Q20_seen == 0 and Q25_seen != 0:
384 Q20_seen = 1
385 statsPerc[20] = statsPerc[25]
386 statsBase[20] = statsBase[25]
387 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q20] = cummlatPer
388 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C20] = cummlatBase
389
390 if Q15_seen == 0 and Q20_seen != 0:
391 Q15_seen = 1
392 statsPerc[15] = statsPerc[20]
393 statsBase[15] = statsBase[20]
394 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q15] = cummlatPer
395 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C15] = cummlatBase
396
397 if Q10_seen == 0 and Q15_seen != 0:
398 Q10_seen = 1
399 statsPerc[10] = statsPerc[15]
400 statsBase[10] = statsBase[15]
401 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q10] = cummlatPer
402 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C10] = cummlatBase
403
404 if Q5_seen == 0 and Q10_seen != 0:
405 Q5_seen = 1
406 statsPerc[5] = statsPerc[10]
407 statsBase[5] = statsBase[10]
408 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_Q5] = cummlatPer
409 dataToRecordDict[ReadqcStats.ILLUMINA_BASE_C5] = cummlatBase
410
411 if Q30_seen == 0:
412 log.error("Q30 is 0. Base quality values are ZERO.")
413
414 log.debug("Q and C values: %s" % (dataToRecordDict))
415
416
417 return RQCExitCodes.JGI_SUCCESS
418
419
420 """
421
422 Title : q20_score
423 Function : this method returns Q20 using a qrpt file as input
424 Usage : JGI_QC_Utility::qc20_score($qrpt)
425 Args : $_[0] : qrpt file.
426 Returns : a number of Q20 score
427 Comments :
428
429 """
430 # def q20_score(qrpt, log):
431 # log.debug("qrpt file %s" % (qrpt))
432 #
433 # q20 = None
434 # num = 0
435 #
436 # if os.path.isfile(qrpt):
437 # with open(qrpt, "r") as qrptFH:
438 # for l in qrptFH:
439 # num += 1
440 #
441 # if num == 1:
442 # continue
443 #
444 # ##############
445 # ## Old format
446 # ## READ1.qrpt
447 # ## column count min max sum mean Q1 med Q3 IQR lW rW A_Count C_Count G_Count T_Count N_Count Max_count
448 # ## 1 378701 2 34 12447306 32.87 31 34 34 3 27 34 108573 83917 81999 104127 85 378701
449 # ## 2 378701 2 34 12515957 33.05 33 34 34 1 32 34 112178 83555 84449 98519 0 378701
450 # ## 3 378701 2 34 12519460 33.06 33 34 34 1 32 34 104668 72341 80992 120700 0 378701
451 # ## 4 378701 2 37 13807944 36.46 37 37 37 0 37 37 96935 95322 83958 102440 46 378701
452 # ## 5 378701 2 37 13790443 36.42 37 37 37 0 37 37 114586 68297 78020 117740 58 378701
453 # ##
454 # ## or
455 # ##
456 # ## READ2.qrpt
457 # ## column count min max sum mean Q1 med Q3 IQR lW rW A_Count C_Count G_Count T_Count N_Count Max_count
458 # ## 1 378701 2 34 8875097 23.44 25 26 28 3 21 32 106904 84046 81795 105956 0 378701
459 # ## 2 378701 2 34 6543224 17.28 15 16 26 11 2 34 107573 77148 97953 88998 7029 378701
460 # ## 3 378701 2 34 7131741 18.83 16 16 26 10 2 34 96452 83003 107891 91355 0 378701
461 # ## 4 378701 2 37 9686653 25.58 19 32 33 14 2 37 97835 78304 87944 114618 0 378701
462 # ## 5 378701 2 37 10208226 26.96 25 33 35 10 10 37 98021 90611 89040 101029 0 378701
463 #
464 # pos = None
465 # mean = None
466 # t = l.split("\t")
467 # assert len(t) > 6
468 # pos = int(t[0])
469 # mean = float(t[5])
470 #
471 # if mean and pos:
472 # if mean < 20:
473 # return pos - 1
474 # else:
475 # q20 = pos
476 #
477 # else:
478 # log.error("- qhist file not found: %s" % (qrpt))
479 # return None
480 #
481 #
482 # return q20
483
484
485 def q20_score_new(bqHist, readNum, log):
486 log.debug("q20_score_new(): bqHist file = %s" % (bqHist))
487
488 q20 = None
489
490 if os.path.isfile(bqHist):
491 with open(bqHist, "r") as qrptFH:
492 for l in qrptFH:
493 if l.startswith('#'):
494 continue
495
496 ## New data
497 # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
498 ##BaseNum count_1 min_1 max_1 mean_1 Q1_1 med_1 Q3_1 LW_1 RW_1 count_2 min_2 max_2 mean_2 Q1_2 med_2 Q3_2 LW_2 RW_2
499 # 0 6900 0 36 33.48 33 34 34 29 36 6900 0 36 33.48 33 34 34 29 36
500
501 pos = None
502 mean = None
503 t = l.split("\t")
504 pos = int(t[0]) + 1
505
506 if readNum == 1:
507 mean = float(t[4])
508 else:
509 mean = float(t[13])
510
511 if mean and pos:
512 if mean < 20:
513 return pos - 1
514 else:
515 q20 = pos
516
517 else:
518 log.error("- bqHist file not found: %s" % (bqHist))
519 return None
520
521 return q20
522
523
524 """
525 Title : read_level_qual_stats
526 Function : Generate qual scores and plots of read level QC
527 Usage : read_level_qual_stats($analysis, $)
528 Args : 1) A reference to an JGI_Analysis object
529 2) current working folder wkdir/qual
530 Returns : JGI_SUCCESS: Illumina read level report could be successfully generated.
531 JGI_FAILURE: Illumina read level report could not be generated.
532 Comments : This function is intended to be called at the very end of the illumina read level data processing script.
533
534
535 """
536 def read_level_qual_stats(dataToRecordDict, qhistTxtFullPath, log):
537 retCode = RQCExitCodes.JGI_FAILURE
538
539 cummlatPer = 0.0
540 Q30_seen = 0
541 Q25_seen = 0
542 Q20_seen = 0
543 Q15_seen = 0
544 Q10_seen = 0
545 Q5_seen = 0
546
547 if os.path.isfile(qhistTxtFullPath):
548 stats = {30:0, 25:0, 20:0, 15:0, 10:0, 5:0}
549
550 allLines = open(qhistTxtFullPath).readlines()
551
552 for l in allLines[::-1]:
553 if not l:
554 break
555 if l.startswith('#'):
556 continue
557
558 t = l.split()
559 assert len(t) == 3
560 qavg = int(t[0])
561 percent = float(t[2]) * 100.0 ## 20140826 Changed for bbtools
562
563 cummlatPer = cummlatPer + percent
564 cummlatPer = float("%.2f" % cummlatPer)
565
566 if qavg <= 30 and qavg > 25 and Q30_seen == 0:
567 Q30_seen = 1
568 stats[30] = cummlatPer
569 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q30] = cummlatPer
570
571 elif qavg <= 25 and qavg > 20 and Q25_seen == 0:
572 Q25_seen = 1
573 stats[25] = cummlatPer
574 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q25] = cummlatPer
575
576 elif qavg <= 20 and qavg > 15 and Q20_seen == 0:
577 Q20_seen = 1
578 stats[20] = cummlatPer
579 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q20] = cummlatPer
580
581 elif qavg <= 15 and qavg > 10 and Q15_seen == 0:
582 Q15_seen = 1
583 stats[15] = cummlatPer
584 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q15] = cummlatPer
585
586 elif qavg <= 10 and qavg > 5 and Q10_seen == 0:
587 Q10_seen = 1
588 stats[10] = cummlatPer
589 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q10] = cummlatPer
590
591 elif qavg <= 5 and Q5_seen == 0:
592 Q5_seen = 1
593 stats[5] = cummlatPer
594 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q5] = cummlatPer
595
596 ### Double check that no value is missing.
597 if Q25_seen == 0 and Q30_seen != 0:
598 Q25_seen = 1
599 stats[25] = stats[30]
600
601 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q25] = cummlatPer
602 if Q20_seen == 0 and Q25_seen != 0:
603 Q20_seen = 1
604 stats[20] = stats[25]
605
606 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q20] = cummlatPer
607 if Q15_seen == 0 and Q20_seen != 0:
608 Q15_seen = 1
609 stats[15] = stats[20]
610
611 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q15] = cummlatPer
612 if Q10_seen == 0 and Q15_seen != 0:
613 Q10_seen = 1
614 stats[10] = stats[15]
615
616 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q10] = cummlatPer
617 if Q5_seen == 0 and Q10_seen != 0:
618 Q5_seen = 1
619 stats[5] = stats[10]
620
621 dataToRecordDict[ReadqcStats.ILLUMINA_READ_Q5] = cummlatPer
622 if Q30_seen == 0:
623 log.error("Q30 is 0 . Read quality values are ZERO.")
624
625 log.debug("Q30 %s, Q25 %s, Q20 %s, Q15 %s, Q10 %s, Q5 %s" % \
626 (stats[30], stats[25], stats[20], stats[15], stats[10], stats[5]))
627
628
629 retCode = RQCExitCodes.JGI_SUCCESS
630
631 else:
632 log.error("- qhist file not found: %s" % (qhistTxtFullPath))
633
634
635 return retCode
636
637
638 """
639
640 Title : read_gc_mean
641 Function : This function generates average GC content % and its standard deviation and put them into database.
642 Usage : read_gc_mean($analysis)
643 Args : 1) A reference to an JGI_Analysis object
644 Returns : JGI_SUCCESS:
645 JGI_FAILURE:
646 Comments :
647
648 """
649 def read_gc_mean(histFile, log):
650 mean = 0.0
651 stdev = 0.0
652 retCode = RQCExitCodes.JGI_FAILURE
653
654 if os.path.isfile(histFile):
655 with open(histFile, "r") as histFH:
656 line = histFH.readline() ## we only need the first line
657
658 # Ex) #Found 1086 total values totalling 420.3971. <0.387106 +/- 0.112691>
659 if len(line) == 0 or not line.startswith("#Found"):
660 log.error("- GC content hist text file does not contains right results: %s, %s" % (histFile, line))
661 retCode = RQCExitCodes.JGI_FAILURE
662
663 else:
664 toks = line.split()
665 assert len(toks) == 9
666 mean = float(toks[6][1:]) * 100.0
667 stdev = float(toks[8][:-1]) * 100.0
668 log.debug("mean, stdev = %.2f, %.2f" % (mean, stdev))
669
670 retCode = RQCExitCodes.JGI_SUCCESS
671 else:
672 log.error("- gc hist file not found: %s" % (histFile))
673
674
675 return retCode, mean, stdev
676
677
678 if __name__ == "__main__":
679
680 exit(0)
681
682
683 ## EOF