Skip to content

Commit b6c0f44

Browse files
committed
fix building study info to match search results
1 parent 179b582 commit b6c0f44

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

qiita_pet/handlers/study_handlers/listing_handlers.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import division
99
from json import dumps
1010
from future.utils import viewitems
11+
from collections import defaultdict
1112

1213
from tornado.web import authenticated, HTTPError
1314
from tornado.gen import coroutine, Task
@@ -52,9 +53,9 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
5253
The study to build information for
5354
info : dict
5455
Information from Study.get_info
55-
study_proc : dict of lists
56+
study_proc : dict of dict of lists
5657
Dictionary keyed on study_id that lists all processed data associated
57-
with that study.
58+
with that study. This list of processed data ids is keyed by data type
5859
proc_samples : dict of lists
5960
Dictionary keyed on proc_data_id that lists all samples associated with
6061
that processed data.
@@ -82,20 +83,23 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
8283
del info["principal_investigator_id"]
8384
del info["email"]
8485
# Build the proc data info list for the child row in datatable
85-
info["proc_data_info"] = [
86-
_build_single_proc_data_info(pd_id, proc_samples[pd_id])
87-
for pd_id in study_proc[study.id]]
86+
for data_type, proc_datas in viewitems(study_proc[study.id]):
87+
info["proc_data_info"] = [
88+
_build_single_proc_data_info(pd_id, data_type, proc_samples[pd_id])
89+
for pd_id in proc_datas]
8890
return info
8991

9092

91-
def _build_single_proc_data_info(proc_data_id, samples):
93+
def _build_single_proc_data_info(proc_data_id, data_type, samples):
9294
"""Build the proc data info list for the child row in datatable
9395
9496
Parameters
9597
----------
9698
proc_data_id : int
9799
The processed data attached to he study, in the form
98100
{study_id: [proc_data_id, proc_data_id, ...], ...}
101+
data_type : str
102+
Data type of the processed data
99103
proc_samples : dict of lists
100104
The samples available in the processed data, in the form
101105
{proc_data_id: [samp1, samp2, ...], ...}
@@ -108,7 +112,7 @@ def _build_single_proc_data_info(proc_data_id, samples):
108112
proc_data = ProcessedData(proc_data_id)
109113
proc_info = proc_data.processing_info
110114
proc_info['pid'] = proc_data_id
111-
proc_info['data_type'] = proc_data.data_type()
115+
proc_info['data_type'] = data_type
112116
proc_info['samples'] = sorted(samples)
113117
proc_info['processed_date'] = str(proc_info['processed_date'])
114118
return proc_info
@@ -171,11 +175,13 @@ def _build_study_info(user, study_proc=None, proc_samples=None):
171175
study = Study(info['study_id'])
172176
# Build the processed data info for the study if none passed
173177
if build_samples:
174-
proc_data = study.processed_data()
178+
proc_data_list = study.processed_data()
175179
proc_samples = {}
176-
study_proc = {study.id: proc_data}
177-
for pid in proc_data:
178-
proc_samples[pid] = ProcessedData(pid).samples
180+
study_proc = {study.id: defaultdict(list)}
181+
for pid in proc_data_list:
182+
proc_data = ProcessedData(pid)
183+
study_proc[study.id][proc_data.data_type()].append(pid)
184+
proc_samples[pid] = proc_data.samples
179185

180186
study_info = _build_single_study_info(study, info, study_proc,
181187
proc_samples)

0 commit comments

Comments
 (0)