8
8
from __future__ import division
9
9
from json import dumps
10
10
from future .utils import viewitems
11
+ from collections import defaultdict
11
12
12
13
from tornado .web import authenticated , HTTPError
13
14
from tornado .gen import coroutine , Task
@@ -52,9 +53,9 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
52
53
The study to build information for
53
54
info : dict
54
55
Information from Study.get_info
55
- study_proc : dict of lists
56
+ study_proc : dict of dict of lists
56
57
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
58
59
proc_samples : dict of lists
59
60
Dictionary keyed on proc_data_id that lists all samples associated with
60
61
that processed data.
@@ -82,20 +83,23 @@ def _build_single_study_info(study, info, study_proc, proc_samples):
82
83
del info ["principal_investigator_id" ]
83
84
del info ["email" ]
84
85
# 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 ]
88
90
return info
89
91
90
92
91
- def _build_single_proc_data_info (proc_data_id , samples ):
93
+ def _build_single_proc_data_info (proc_data_id , data_type , samples ):
92
94
"""Build the proc data info list for the child row in datatable
93
95
94
96
Parameters
95
97
----------
96
98
proc_data_id : int
97
99
The processed data attached to he study, in the form
98
100
{study_id: [proc_data_id, proc_data_id, ...], ...}
101
+ data_type : str
102
+ Data type of the processed data
99
103
proc_samples : dict of lists
100
104
The samples available in the processed data, in the form
101
105
{proc_data_id: [samp1, samp2, ...], ...}
@@ -108,7 +112,7 @@ def _build_single_proc_data_info(proc_data_id, samples):
108
112
proc_data = ProcessedData (proc_data_id )
109
113
proc_info = proc_data .processing_info
110
114
proc_info ['pid' ] = proc_data_id
111
- proc_info ['data_type' ] = proc_data . data_type ()
115
+ proc_info ['data_type' ] = data_type
112
116
proc_info ['samples' ] = sorted (samples )
113
117
proc_info ['processed_date' ] = str (proc_info ['processed_date' ])
114
118
return proc_info
@@ -171,11 +175,13 @@ def _build_study_info(user, study_proc=None, proc_samples=None):
171
175
study = Study (info ['study_id' ])
172
176
# Build the processed data info for the study if none passed
173
177
if build_samples :
174
- proc_data = study .processed_data ()
178
+ proc_data_list = study .processed_data ()
175
179
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
179
185
180
186
study_info = _build_single_study_info (study , info , study_proc ,
181
187
proc_samples )
0 commit comments