| 1 |
|
| 2 |
|
| 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 |
|
| 20 |
srcDir = os.path.dirname(__file__) |
| 21 |
sys.path.append(os.path.join(srcDir, 'tools')) |
| 22 |
sys.path.append(os.path.join(srcDir, '../lib')) |
| 23 |
sys.path.append(os.path.join(srcDir, '../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 |
|
| 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: |
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
if os.path.isfile(dataFile): |
| 196 |
with open(dataFile, "r") as merFH: |
| 197 |
lines = merFH.readlines() |
| 198 |
|
| 199 |
|
| 200 |
t = lines[-1].split('\t') |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
totalMers = int(t[0]) |
| 205 |
|
| 206 |
|
| 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 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
allLines = open(reformatObqhistFile).readlines() |
| 266 |
for l in allLines[::-1]: |
| 267 |
l = l.strip() |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 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 |
| 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 |
|
| 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 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 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 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 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 |
| 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 |
|
| 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() |
| 657 |
|
| 658 |
|
| 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 |
|