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): ...@@ -98,26 +98,39 @@ def compute_extra(id_file, id_config, min_threshold):
(db.results_file.config_id == id_config) (db.results_file.config_id == id_config)
).select(orderby=~db.results_file.run_date).first() ).select(orderby=~db.results_file.run_date).first()
filename = defs.DIR_RESULTS+results_file.data_file filename = defs.DIR_RESULTS+results_file.data_file
with open(filename, "rb") as rf: try:
try: with open(filename, "rb") as rf:
d = json.load(rf) try:
loci_min = {} d = json.load(rf)
loci_totals = d['reads']['germline'] loci_min = {}
for locus in loci_totals: loci_totals = d['reads']['germline']
if locus not in result: for locus in loci_totals:
result[locus] = [0] if locus not in result:
loci_min[locus] = loci_totals[locus][0] * (min_threshold/100.0) result[locus] = [0]
loci_min[locus] = loci_totals[locus][0] * (min_threshold/100.0)
for clone in d["clones"]:
germline = clone['germline'] for clone in d["clones"]:
if clone['reads'][0] >= loci_min[germline]: germline = clone['germline']
result[germline][0] += 1 if clone['reads'][0] >= loci_min[germline]:
except ValueError as e: result[germline][0] += 1
print('invalid_json') except ValueError as e:
return "FAIL" 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 d['reads']['distribution'] = result
with open(filename, 'wb') as extra: try:
json.dump(d, extra) 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" 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