Commit 9ccbacd6 authored by Ryan Herbert's avatar Ryan Herbert

task.py more exception handling compute_extra

Make compute_extra more verbal so we can get a better idea of what is
happening should the function fail.
parent 3bea32f7
Pipeline #48684 passed with stages
in 6 minutes and 4 seconds
......@@ -98,26 +98,39 @@ def compute_extra(id_file, id_config, min_threshold):
(db.results_file.config_id == id_config)
).select(orderby=~db.results_file.run_date).first()
filename = defs.DIR_RESULTS+results_file.data_file
with open(filename, "rb") as rf:
try:
d = json.load(rf)
loci_min = {}
loci_totals = d['reads']['germline']
for locus in loci_totals:
if locus not in result:
result[locus] = [0]
loci_min[locus] = loci_totals[locus][0] * (min_threshold/100.0)
for clone in d["clones"]:
germline = clone['germline']
if clone['reads'][0] >= loci_min[germline]:
result[germline][0] += 1
except ValueError as e:
print('invalid_json')
return "FAIL"
try:
with open(filename, "rb") as rf:
try:
d = json.load(rf)
loci_min = {}
loci_totals = d['reads']['germline']
for locus in loci_totals:
if locus not in result:
result[locus] = [0]
loci_min[locus] = loci_totals[locus][0] * (min_threshold/100.0)
for clone in d["clones"]:
germline = clone['germline']
if clone['reads'][0] >= loci_min[germline]:
result[germline][0] += 1
except ValueError as e:
print('invalid_json')
return "FAIL"
except:
print('unknown error')
return 'FAIL'
except IOError as ioe:
print("I/O error opening %s" % filename)
except:
print("Unexpected error opening %s" % filename)
d['reads']['distribution'] = result
with open(filename, 'wb') as extra:
json.dump(d, extra)
try:
with open(filename, 'wb') as extra:
json.dump(d, extra)
except IOError as ioe:
print("I/o error writing to %s" % filename)
except:
print("Unexpected error writing to %s" % filename)
return "SUCCESS"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment