Skip to content

Commit f94af55

Browse files
authored
Merge pull request #2246 from antgonza/fix-2210
Fix 2210
2 parents 39b2b84 + b7e2cc9 commit f94af55

File tree

6 files changed

+73
-52
lines changed

6 files changed

+73
-52
lines changed

qiita_db/test/test_util.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -852,20 +852,21 @@ def test_get_artifacts_information(self):
852852

853853
exp = [
854854
{'files': ['1_study_1001_closed_reference_otu_table.biom'],
855-
'target_subfragment': ['V4'], 'data_type': '18S',
855+
'target_subfragment': ['V4'], 'artifact_id': 4,
856+
'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 |'
857+
' barcode_type 8, defaults'),
858+
'data_type': '18S', 'prep_samples': 27,
856859
'parameters': {
857860
'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1,
858861
'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1,
859-
'sortmerna_coverage': 0.97}, 'name': 'BIOM',
860-
'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 '
861-
'| barcode_type 8, defaults'), 'artifact_id': 4},
862-
{'files': [], 'target_subfragment': ['V4'], 'data_type': '16S',
863-
'parameters': {}, 'name': 'BIOM', 'algorithm': '',
864-
'artifact_id': 7},
862+
'sortmerna_coverage': 0.97}, 'name': 'BIOM'},
863+
{'files': [], 'target_subfragment': ['V4'], 'algorithm': '',
864+
'artifact_id': 7, 'data_type': '16S', 'prep_samples': 27,
865+
'parameters': {}, 'name': 'BIOM'},
865866
{'files': ['biom_table.biom'], 'target_subfragment': [],
866-
'data_type': '18S', 'parameters': {}, 'name': 'noname',
867-
'algorithm': '', 'artifact_id': 8}]
868-
self.assertEqual(obs, exp)
867+
'algorithm': '', 'artifact_id': 8, 'data_type': '18S',
868+
'prep_samples': 0, 'parameters': {}, 'name': 'noname'}]
869+
self.assertItemsEqual(obs, exp)
869870

870871

871872
if __name__ == '__main__':

qiita_db/util.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ def get_artifacts_information(artifact_ids, only_biom=True):
13821382
WHERE table_name = 'prep_' || CAST(
13831383
prep_template_id AS TEXT)
13841384
AND column_name='target_subfragment')
1385-
THEN prep_template_id ELSE NULL END
1385+
THEN prep_template_id ELSE NULL END, prep_template_id
13861386
FROM main_query
13871387
LEFT JOIN qiita.prep_template pt ON (
13881388
main_query.root_id = pt.artifact_id)
@@ -1409,10 +1409,13 @@ def get_artifacts_information(artifact_ids, only_biom=True):
14091409
qdb.sql_connection.TRN.execute_fetchindex()}
14101410

14111411
# now let's get the actual artifacts
1412+
ts = {}
1413+
ps = {}
1414+
PT = qdb.metadata_template.prep_template.PrepTemplate
14121415
qdb.sql_connection.TRN.add(sql, [tuple(artifact_ids)])
14131416
for row in qdb.sql_connection.TRN.execute_fetchindex():
14141417
aid, name, cid, gt, aparams, dt, pid, pparams, filepaths, _, \
1415-
target = row
1418+
target, prep_template_id = row
14161419

14171420
# cleaning fields:
14181421
# - [0] due to the array_agg
@@ -1449,30 +1452,32 @@ def get_artifacts_information(artifact_ids, only_biom=True):
14491452

14501453
algorithm = '%s | %s' % (commands[cid], pparams)
14511454

1455+
if target is None:
1456+
target = []
1457+
else:
1458+
if target not in ts:
1459+
qdb.sql_connection.TRN.add(sql_ts, [target])
1460+
ts[target] = \
1461+
qdb.sql_connection.TRN.execute_fetchflatten()
1462+
target = ts[target]
1463+
1464+
if prep_template_id is None:
1465+
prep_samples = 0
1466+
else:
1467+
if prep_template_id not in ps:
1468+
ps[prep_template_id] = len(list(
1469+
PT(prep_template_id).keys()))
1470+
prep_samples = ps[prep_template_id]
1471+
14521472
results.append({
14531473
'artifact_id': aid,
14541474
'target_subfragment': target,
1475+
'prep_samples': prep_samples,
14551476
'name': name,
14561477
'data_type': dt,
14571478
'timestamp': str(gt),
14581479
'parameters': aparams,
14591480
'algorithm': algorithm,
14601481
'files': filepaths})
14611482

1462-
# let's get the values for target_subfragment from the
1463-
# prep_template, note that we have to do it in a separate sql
1464-
# doing crosstab is really difficult and in another loop cause we
1465-
# need to loop over all execute_fetchindex before doing another
1466-
# query
1467-
ts = {}
1468-
for i, r in enumerate(results):
1469-
pid = r['target_subfragment']
1470-
if pid is None:
1471-
results[i]['target_subfragment'] = []
1472-
else:
1473-
if pid not in ts:
1474-
qdb.sql_connection.TRN.add(sql_ts, [pid])
1475-
ts[pid] = qdb.sql_connection.TRN.execute_fetchflatten()
1476-
results[i]['target_subfragment'] = ts[pid]
1477-
14781483
return results

qiita_pet/handlers/api_proxy/tests/test_artifact.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,34 @@ def test_artifact_get_info(self):
223223
obs = artifact_get_info('test@foo.bar', [5, 6, 7])
224224
data = [
225225
{'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'],
226-
'target_subfragment': ['V4'], 'algorithm': (
227-
'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, '
228-
'defaults'), 'artifact_id': 6, 'data_type': '16S',
229-
'timestamp': '2012-10-02 17:30:00', 'parameters': {
230-
'reference': 2, 'similarity': 0.97, 'sortmerna_e_value': 1,
226+
'target_subfragment': ['V4'],
227+
'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 | '
228+
'barcode_type 8, defaults'),
229+
'artifact_id': 6, 'data_type': '16S',
230+
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
231+
'parameters': {
232+
'reference': 2, 'similarity': 0.97, u'sortmerna_e_value': 1,
231233
'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1,
232234
'sortmerna_coverage': 0.97}, 'name': 'BIOM'},
233235
{'files': ['1_study_1001_closed_reference_otu_table.biom'],
234-
'target_subfragment': ['V4'], 'algorithm': (
235-
'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, '
236-
'defaults'), 'artifact_id': 5, 'data_type': '18S',
237-
'timestamp': '2012-10-02 17:30:00', 'parameters': {
238-
'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1,
239-
'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1,
240-
'sortmerna_coverage': 0.97}, 'name': 'BIOM'},
236+
'target_subfragment': ['V4'],
237+
'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 | '
238+
'barcode_type 8, defaults'),
239+
'artifact_id': 5, 'data_type': '18S',
240+
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
241+
'parameters': {
242+
'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1,
243+
'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1,
244+
'sortmerna_coverage': 0.97}, 'name': 'BIOM'},
241245
{'files': [], 'target_subfragment': ['V4'], 'algorithm': '',
242246
'artifact_id': 7, 'data_type': '16S',
243-
'timestamp': '2012-10-02 17:30:00', 'parameters': {},
244-
'name': 'BIOM'}]
247+
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
248+
'parameters': {}, 'name': 'BIOM'}]
245249
exp = {'status': 'success', 'msg': '', 'data': data}
246-
self.assertEqual(obs, exp)
250+
self.assertItemsEqual(obs.keys(), exp.keys())
251+
self.assertEqual(obs['status'], exp['status'])
252+
self.assertEqual(obs['msg'], exp['msg'])
253+
self.assertItemsEqual(obs['data'], exp['data'])
247254

248255
def test_artifact_post_req(self):
249256
# Create new prep template to attach artifact to

qiita_pet/handlers/study_handlers/tests/test_artifact.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,25 @@ def test_get(self):
164164
self.assertEqual(response.code, 200)
165165
data = [
166166
{'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'],
167-
'target_subfragment': ['V4'], 'algorithm': (
168-
'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, '
169-
'defaults'), 'artifact_id': 6, 'data_type': '16S',
170-
'timestamp': '2012-10-02 17:30:00', 'parameters': {
167+
'target_subfragment': ['V4'], 'artifact_id': 6,
168+
'data_type': '16S', 'timestamp': '2012-10-02 17:30:00',
169+
'prep_samples': 27,
170+
'algorithm': 'Pick closed-reference OTUs, QIIMEv1.9.1 | '
171+
'barcode_type 8, defaults',
172+
'parameters': {
171173
'reference': 2, 'similarity': 0.97, 'sortmerna_e_value': 1,
172174
'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1,
173175
'sortmerna_coverage': 0.97}, 'name': 'BIOM'},
174-
{'files': [], 'target_subfragment': ['V4'], 'algorithm': '',
175-
'artifact_id': 7, 'data_type': '16S',
176-
'timestamp': '2012-10-02 17:30:00', 'parameters': {},
176+
{'files': [], 'target_subfragment': ['V4'], 'artifact_id': 7,
177+
'data_type': '16S', 'timestamp': '2012-10-02 17:30:00',
178+
'prep_samples': 27, 'algorithm': '', 'parameters': {},
177179
'name': 'BIOM'}]
178180
exp = {'status': 'success', 'msg': '', 'data': data}
179-
self.assertEqual(loads(response.body), exp)
181+
obs = loads(response.body)
182+
self.assertItemsEqual(obs.keys(), exp.keys())
183+
self.assertEqual(obs['status'], exp['status'])
184+
self.assertEqual(obs['msg'], exp['msg'])
185+
self.assertItemsEqual(obs['data'], exp['data'])
180186

181187

182188
class ArtifactAdminAJAXTestsReadOnly(TestHandlerBase):

qiita_pet/templates/analysis_selected.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ <h2><a href="{% raw qiita_config.portal_dir %}/study/description/{{study.id}}">{
9696
<h4>Processed Data</h4>
9797
<table class='table table-striped' id='study{{study.id}}-table'>
9898
<tr>
99-
<th class="col-sm-1">id</th><th class="col-sm-1">Datatype</th><th class="col-sm-2">Processed Date</th><th class="col-sm-2">Algorithm</th><th class="col-sm-2">Parameters</th><th class="col-sm-1">Samples</th><th></th><th></th>
99+
<th class="col-sm-1">id</th><th class="col-sm-1">Datatype</th><th class="col-sm-2">Processed Date</th><th class="col-sm-2">Algorithm</th><th class="col-sm-2">Parameters</th><th class="col-sm-1">Samples selected from Prep Info</th><th></th><th></th>
100100
</tr>
101101
{% for pid, samples in viewitems(proc_datas) %}
102102
<tr id="proc{{pid}}">

qiita_pet/templates/list_studies.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
proc_data_table += '<th>Data type</th>';
9191
proc_data_table += '<th>Processing method</th>';
9292
proc_data_table += '<th>Parameters</th>';
93+
proc_data_table += '<th>Samples in Prep Info</th>';
9394
proc_data_table += '<th>Files</th>';
9495
proc_data_table += '</tr>';
9596

@@ -106,6 +107,7 @@
106107
params += '<i>' + key + '</i>: ' + info.parameters[key] + '<br/>';
107108
}
108109
proc_data_table += '<td><small>' + params + '</small></td>';
110+
proc_data_table += '<td>' + info.prep_samples + '</td>';
109111
proc_data_table += '<td><small>' + info.files.join('<br/>') + '</small></td>';
110112

111113
proc_data_table += '</tr>';

0 commit comments

Comments
 (0)