Commit 837e80fc authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team

patient.py: Use JSON search on fused file.

Useful to get information that is only contained in the fused file (eg. reads-distribution).

We may want to get all information from the fused file. Or, at least, to
use more JSON that regex as JSON is less susceptible to changes in whitespaces than regex
parent 60471c5c
......@@ -184,10 +184,15 @@ def stats():
# main clone
'"name".*"(?P<main_clone>.*)"',
'"reads" : [[] (?P<main_clone_reads>\d+) ',
'"producer" : [[] "(?P<version>.*)"',
]
json_paths = {'reads distribution [1,9]': 'reads-distribution-1',
'reads distribution [10,99]': 'reads-distribution-10',
'reads distribution [100,999]': 'reads-distribution-100',
'reads distribution 1000+': 'reads-distribution-1000',
'producer': 'samples/producer',
}
keys = []
regex = []
for sr in stats_regex:
......@@ -195,14 +200,27 @@ def stats():
regex += [r]
keys += r.groupindex.keys()
keys += json_paths.keys()
d['stats'] = keys
for row in d['query']:
results_f = row.results_file.data_file
row_result = vidjil_utils.search_first_regex_in_file(regex, defs.DIR_RESULTS + results_f, STATS_READLINES)
fused_file = db((db.fused_file.sequence_file_list.contains('%d_' % row.sequence_file.id)) & (db.fused_file.config_id == row.results_file.config_id)).select(orderby = ~db.fused_file.id, limitby=(0,1))
if len(fused_file) > 0:
index_of_id = fused_file[0].sequence_file_list.find('%d_' % row.sequence_file.id)
pos_in_list = fused_file[0].sequence_file_list.count('_', 0, index_of_id)
row_fused = vidjil_utils.extract_fields_from_json(json_paths, pos_in_list, defs.DIR_RESULTS + fused_file[0].fused_file)
else:
row_fused = {}
for key in keys:
row[key] = ''
if key in row_result:
row[key] = row_result[key]
elif key in row_fused:
row[key] = row_fused[key]
else:
row[key] = ''
log.debug("patient/stats (%.3fs)" % (time.time()-start))
return d
......
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