Skip to content

Commit f774597

Browse files
committed
Merge branch 'fix-1084' of https://github.com/biocore/qiita into 1084-qiime-map
2 parents 9db35a5 + 42326b0 commit f774597

File tree

7 files changed

+106
-101
lines changed

7 files changed

+106
-101
lines changed

qiita_db/support_files/patches/python_patches/25.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
WHERE raw_data_id = %s AND study_id = %s"""
2727
sql_unlink = "DELETE FROM qiita.raw_filepath WHERE raw_data_id = %s"
2828
sql_delete = "DELETE FROM qiita.raw_data WHERE raw_data_id = %s"
29+
sql_studies = """SELECT study_id FROM qiita.study_raw_data
30+
WHERE raw_data_id = %s"""
2931
move_files = []
3032
for rd_id in rd_ids:
3133
rd = RawData(rd_id)
3234
filepaths = rd.get_filepaths()
33-
studies = sorted(rd.studies)
35+
studies = [s[0] for s in conn_handler.execute_fetchall(sql_studies,
36+
(rd_id,))]
3437
if filepaths:
3538
# we need to move the files to a study. We chose the one with lower
3639
# study id. Currently there is no case in the live database in which a

qiita_db/test/test_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def test_delete(self):
263263
# Clear the files so we can actually remove the RawData
264264
study_id = rd.studies[0]
265265
path_for_removal = join(get_mountpoint("uploads")[0][1], str(study_id))
266-
self._clean_up_files = [join(path_for_removal,
266+
self._clean_up_files.extend([join(path_for_removal,
267267
basename(f).split('_', 1)[1])
268-
for _, f, _ in rd.get_filepaths()]
268+
for _, f, _ in rd.get_filepaths()])
269269
rd.clear_filepaths()
270270

271271
RawData.delete(rd.id, self.pt1.id)
@@ -550,7 +550,7 @@ def test_get_filepaths(self):
550550
"preprocessed_fastq"),
551551
(5, join(self.db_test_ppd_dir, '1_seqs.demux'),
552552
"preprocessed_demux")]
553-
self.assertEqual(sorted(obs), sorted(exp))
553+
self.assertItemsEqual(obs, exp)
554554

555555
def test_processed_data(self):
556556
"""Correctly returns the processed data id"""

qiita_db/test/test_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ def test_move_upload_files_to_trash(self):
576576
# create file to move to trash
577577
fid, folder = get_mountpoint("uploads")[0]
578578
test_fp = join(folder, '1', test_filename)
579-
open(test_fp, 'w').write('test')
579+
with open(test_fp, 'w') as f:
580+
f.write('test')
580581

581582
self.files_to_remove.append(test_fp)
582583

qiita_pet/handlers/compute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def _split(x):
5555
fps.append((_split(reverse_reads_str), 'raw_reverse_seqs'))
5656
fps.append((_split(sff_str), 'raw_sff'))
5757

58+
# We need to retrieve the full path for all the files, as the
59+
# arguments only contain the file name. Since we don't know in which
60+
# mountpoint the data lives, we retrieve all of them and we loop
61+
# through all the files checking if they exist or not.
5862
for _, f in get_mountpoint("uploads", retrieve_all=True):
5963
f = join(f, str(study_id))
6064
for fp_set, filetype in fps:

qiita_pet/templates/study_description.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
}
220220

221221
function add_raw_data(prep_id) {
222-
raw_data_id = $("#previous-raw-data-" + prep_id).val()
222+
raw_data_id = $("#previous-raw-data-" + prep_id).val();
223223
if (raw_data_id === null){
224224
bootstrapAlert("You need to select a raw data used in a previous study");
225225
} else {

qiita_pet/templates/study_description_templates/prep_template_info_tab.html

Lines changed: 74 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h4 class="modal-title" id="myModalLabel">Choose preprocessing parameters</h4>
5151

5252
<!-- Prep Template tab pane -->
5353
<div class="tab-pane" id="prep_template_info_{{pt_id}}" style="padding: 10px;">
54-
<table border="0">
54+
<table border="0" style="width: 100%;">
5555
<tr>
5656
<td>
5757
{% if is_editable %}
@@ -104,87 +104,83 @@ <h4 class="modal-title" id="myModalLabel">Choose preprocessing parameters</h4>
104104
<!-- There is no raw data associated with the prep template, show options for adding raw data -->
105105
<tr>
106106
<td style="padding: 5px;">
107-
<button class="btn btn-primary glyphicon glyphicon-plus" type="button" data-toggle="collapse" data-target="#add-raw-data-{{pt_id}}" aria-expanded="false" aria-controls="add-raw-data-{{pt_id}}" style="word-spacing: -10px;">Add raw data</button>
108-
</td>
109-
</tr>
110-
<tr>
111-
<td style="padding: 5px;">
112-
<div class="collapse" id="add-raw-data-{{pt_id}}">
113-
<div class="panel-group" id="accordion-add-raw-{{pt_id}}" role="tablist" aria-multiselectable="true">
114-
<!-- Panel for creating a new raw data -->
115-
<div class="panel panel-default">
116-
<div class="panel-heading" role="tab" id="create-raw-{{pt_id}}">
117-
<h4 class="panel-title">
118-
<a class="collapsed" data-toggle="collapse" data-parent="#accordion-add-raw-{{pt_id}}" href="#collapse-new-{{pt_id}}" aria-expanded="false" aria-controls="collapse-new-{{pt_id}}">
119-
Add new raw data
120-
</a>
121-
</h4>
122-
</div>
123-
<div id="collapse-new-{{pt_id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="create-raw-{{pt_id}}">
124-
<div class="panel-body">
125-
What file type is your raw data?
126-
<select id="filetype-{{pt_id}}" onchange="$('.filesgroup').hide(); $('#files-{{pt_id}}-'+$('#filetype-{{pt_id}}').val()).show();">
127-
<option value="0">Not selected...</option>
128-
{% for name, value, _ in filetypes %}
129-
<option value="{{value}}">{{name}}</option>
130-
{% end %}
131-
</select>
132-
<div id="files-{{pt_id}}-0" class="filesgroup"></div>
133-
{% for _, value, filepath_types in filetypes %}
134-
<div id="files-{{pt_id}}-{{value}}" class="filesgroup">
135-
<table border="0">
136-
<tr><td><b>Choose the files to link to the raw data</b></td></tr>
107+
<div class="panel-group" id="accordion-add-raw-{{pt_id}}" role="tablist" aria-multiselectable="true">
108+
<!-- Panel for creating a new raw data -->
109+
<div class="panel panel-default">
110+
<div class="panel-heading" role="tab" id="create-raw-{{pt_id}}">
111+
<h4 class="panel-title">
112+
<a class="collapsed" data-toggle="collapse" data-parent="#accordion-add-raw-{{pt_id}}" href="#collapse-new-{{pt_id}}" aria-expanded="false" aria-controls="collapse-new-{{pt_id}}">
113+
Add new raw data
114+
</a>
115+
</h4>
116+
</div>
117+
<div id="collapse-new-{{pt_id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="create-raw-{{pt_id}}">
118+
<div class="panel-body">
119+
What file type is your raw data?
120+
<select id="filetype-{{pt_id}}" onchange="$('.filesgroup').hide(); $('#files-{{pt_id}}-'+$('#filetype-{{pt_id}}').val()).show();">
121+
<option value="0">Not selected...</option>
122+
{% for name, value, _ in filetypes %}
123+
<option value="{{value}}">{{name}}</option>
124+
{% end %}
125+
</select>
126+
<div id="files-{{pt_id}}-0" class="filesgroup"></div>
127+
{% for _, value, filepath_types in filetypes %}
128+
<div id="files-{{pt_id}}-{{value}}" class="filesgroup">
129+
<br/>
130+
<b>Choose the files to link to the raw data</b>
131+
<br/>
132+
<table class="table table-striped">
133+
<tr>
134+
<th>File</th>
135+
<th>&nbsp;&nbsp;&nbsp;</th>
136+
<th>File type</th>
137+
</tr>
138+
{% for f in files %}
137139
<tr>
138-
<th>File</th>
139-
<th>&nbsp;&nbsp;&nbsp;</th>
140-
<th>File type</th>
140+
<td>{{f}}</td>
141+
<td>&nbsp;</td>
142+
<td>
143+
<select id="{{f}}" name="upload_file_{{pt_id}}_{{value}}">
144+
<option value="">Ignore ...</option>
145+
{% for fp_type in filepath_types %}
146+
<option value="{{fp_type}}">{{fp_type}}</option>
147+
{% end %}
148+
</select>
149+
</td>
141150
</tr>
142-
{% for f in files %}
143-
<tr>
144-
<td>{{f}}</td>
145-
<td>&nbsp;</td>
146-
<td>
147-
<select id="{{f}}" name="upload_file_{{pt_id}}_{{value}}">
148-
<option value="">Ignore ...</option>
149-
{% for fp_type in filepath_types %}
150-
<option value="{{fp_type}}">{{fp_type}}</option>
151-
{% end %}
152-
</select>
153-
</td>
154-
</tr>
155-
{% end %}
156-
<tr><td><a class="btn btn-primary" onclick="create_raw_data({{pt_id}}, {{value}});">Add</a></td></tr>
157-
</table>
158-
</div>
159-
{% end %}
160-
</div>
151+
{% end %}
152+
</table>
153+
<a class="btn btn-primary" onclick="create_raw_data({{pt_id}}, {{value}});">Link</a>
154+
</div>
155+
{% end %}
161156
</div>
162157
</div>
163-
<!-- Panel for adding an existent raw data to the prep template -->
164-
<div class="panel panel-default">
165-
<div class="panel-heading" role="tab" id="use-existing-{{pt_id}}">
166-
<h4 class="panel-title">
167-
<a class="collapsed" data-toggle="collapse" data-parent="#accordion-add-raw-{{pt_id}}" href="#collapse-existing-{{pt_id}}" aria-expanded="false" aria-controls="collapse-existing-{{pt_id}}">
168-
Use existing raw data
169-
</a>
170-
</h4>
171-
</div>
172-
<div id="collapse-existing-{{pt_id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="use-existing-{{pt_id}}">
173-
<div class="panel-body">
174-
{% if other_studies_rd %}
175-
Choose raw data from studies that you have access to:
176-
<br/>
177-
<select class="chosen-select" id="previous-raw-data-{{pt_id}}" data-placeholder=" ">
178-
{% for rd_id, study_name in other_studies_rd %}
179-
<option value="{{rd_id}}">id: {{rd_id}}, study: {{study_name}}</option>
180-
{% end %}
181-
</select>
182-
<br/>
183-
<a class="btn btn-primary" onclick="add_raw_data({{pt_id}});">Add</a>
184-
{% else %}
185-
There is no existent raw data available.
186-
{% end %}
187-
</div>
158+
</div>
159+
<!-- Panel for adding an existent raw data to the prep template -->
160+
<div class="panel panel-default">
161+
<div class="panel-heading" role="tab" id="use-existing-{{pt_id}}">
162+
<h4 class="panel-title">
163+
<a class="collapsed" data-toggle="collapse" data-parent="#accordion-add-raw-{{pt_id}}" href="#collapse-existing-{{pt_id}}" aria-expanded="false" aria-controls="collapse-existing-{{pt_id}}">
164+
Use existing raw data
165+
</a>
166+
</h4>
167+
</div>
168+
<div id="collapse-existing-{{pt_id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="use-existing-{{pt_id}}">
169+
<div class="panel-body">
170+
{% if other_studies_rd %}
171+
Choose raw data from studies that you have access to:
172+
<br/>
173+
<select class="chosen-select" id="previous-raw-data-{{pt_id}}" data-placeholder=" ">
174+
{% for rd_id, study_name in other_studies_rd %}
175+
<option value="{{rd_id}}">id: {{rd_id}}, study: {{study_name}}</option>
176+
{% end %}
177+
</select>
178+
<br/>
179+
<br/>
180+
<a class="btn btn-primary" onclick="add_raw_data({{pt_id}});">Add</a>
181+
{% else %}
182+
There is no existent raw data available.
183+
{% end %}
188184
</div>
189185
</div>
190186
</div>

qiita_pet/uimodules/prep_template_tab.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
FASTQ=['barcodes', 'forward seqs', 'reverse seqs'])
3535

3636

37-
def get_accessible_raw_data(user):
37+
def _get_accessible_raw_data(user):
3838
"""Retrieves a tuple of raw_data_id and the last study title for that
3939
raw_data
4040
"""
@@ -45,34 +45,35 @@ def get_accessible_raw_data(user):
4545
return d
4646

4747

48-
def get_raw_data(rdis):
49-
"""Get all raw data objects from a list of raw_data_ids"""
50-
return [RawData(rdi) for rdi in rdis]
51-
52-
53-
def get_prep_templates(pt_ids):
54-
"""Get all the prep template objects from a list of ids
48+
def _template_generator(study, full_access):
49+
"""Generates tuples of prep template information
5550
5651
Parameters
5752
----------
58-
pt_ids : list of int
59-
The prep template ids
53+
study : Study
54+
The study to get all the prep templates
55+
full_access : boolean
56+
A boolean that indicates if the user has full access to the study
6057
6158
Returns
6259
-------
63-
list of PrepTemplate
60+
Generator of tuples of (int, str, PrepTemplate, (str, str, str))
61+
Each tuple contains the prep template id, the prep template data_type
62+
the PrepTemplate object and a tuple with 3 strings for the style of
63+
the prep template status icons
6464
"""
65-
return [PrepTemplate(pt_id) for pt_id in sorted(pt_ids)]
65+
for pt_id in study.prep_templates():
66+
pt = PrepTemplate(pt_id)
67+
if full_access or pt.status() == 'public':
68+
yield (pt.id, pt.data_type(), pt, STATUS_STYLER[pt.status])
6669

6770

6871
class PrepTemplateTab(BaseUIModule):
6972
def render(self, study, full_access):
7073
files = [f for _, f in get_files_from_uploads_folders(str(study.id))]
7174
data_types = sorted(viewitems(get_data_types()), key=itemgetter(1))
7275
prep_templates_info = [
73-
(pt.id, pt.data_type(), pt, STATUS_STYLER[pt.status])
74-
for pt in get_prep_templates(study.prep_templates())
75-
if full_access or pt.status() == 'public']
76+
res for res in _template_generator(study, full_access)]
7677
# Get all the ENA terms for the investigation type
7778
ontology = Ontology(convert_to_id('ENA', 'ontology'))
7879
# make "Other" show at the bottom of the drop down menu
@@ -143,9 +144,9 @@ def render(self, study, prep_template, full_access, ena_terms,
143144
files = [f for _, f in get_files_from_uploads_folders(str(study.id))]
144145

145146
other_studies_rd = sorted(viewitems(
146-
get_accessible_raw_data(user)))
147+
_get_accessible_raw_data(user)))
147148

148-
# A prep template can be modified if it's status is sanbdox
149+
# A prep template can be modified if its status is sanbdox
149150
is_editable = prep_template.status == 'sanbdox'
150151

151152
raw_data_id = prep_template.raw_data

0 commit comments

Comments
 (0)