diff --git a/qiita_db/test/test_util.py b/qiita_db/test/test_util.py index 9ddacb845..b223bdee4 100644 --- a/qiita_db/test/test_util.py +++ b/qiita_db/test/test_util.py @@ -852,20 +852,21 @@ def test_get_artifacts_information(self): exp = [ {'files': ['1_study_1001_closed_reference_otu_table.biom'], - 'target_subfragment': ['V4'], 'data_type': '18S', + 'target_subfragment': ['V4'], 'artifact_id': 4, + 'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 |' + ' barcode_type 8, defaults'), + 'data_type': '18S', 'prep_samples': 27, 'parameters': { 'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1, 'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1, - 'sortmerna_coverage': 0.97}, 'name': 'BIOM', - 'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 ' - '| barcode_type 8, defaults'), 'artifact_id': 4}, - {'files': [], 'target_subfragment': ['V4'], 'data_type': '16S', - 'parameters': {}, 'name': 'BIOM', 'algorithm': '', - 'artifact_id': 7}, + 'sortmerna_coverage': 0.97}, 'name': 'BIOM'}, + {'files': [], 'target_subfragment': ['V4'], 'algorithm': '', + 'artifact_id': 7, 'data_type': '16S', 'prep_samples': 27, + 'parameters': {}, 'name': 'BIOM'}, {'files': ['biom_table.biom'], 'target_subfragment': [], - 'data_type': '18S', 'parameters': {}, 'name': 'noname', - 'algorithm': '', 'artifact_id': 8}] - self.assertEqual(obs, exp) + 'algorithm': '', 'artifact_id': 8, 'data_type': '18S', + 'prep_samples': 0, 'parameters': {}, 'name': 'noname'}] + self.assertItemsEqual(obs, exp) if __name__ == '__main__': diff --git a/qiita_db/util.py b/qiita_db/util.py index 6de4650ed..4adc16945 100644 --- a/qiita_db/util.py +++ b/qiita_db/util.py @@ -1382,7 +1382,7 @@ def get_artifacts_information(artifact_ids, only_biom=True): WHERE table_name = 'prep_' || CAST( prep_template_id AS TEXT) AND column_name='target_subfragment') - THEN prep_template_id ELSE NULL END + THEN prep_template_id ELSE NULL END, prep_template_id FROM main_query LEFT JOIN qiita.prep_template pt ON ( main_query.root_id = pt.artifact_id) @@ -1409,10 +1409,13 @@ def get_artifacts_information(artifact_ids, only_biom=True): qdb.sql_connection.TRN.execute_fetchindex()} # now let's get the actual artifacts + ts = {} + ps = {} + PT = qdb.metadata_template.prep_template.PrepTemplate qdb.sql_connection.TRN.add(sql, [tuple(artifact_ids)]) for row in qdb.sql_connection.TRN.execute_fetchindex(): aid, name, cid, gt, aparams, dt, pid, pparams, filepaths, _, \ - target = row + target, prep_template_id = row # cleaning fields: # - [0] due to the array_agg @@ -1449,9 +1452,27 @@ def get_artifacts_information(artifact_ids, only_biom=True): algorithm = '%s | %s' % (commands[cid], pparams) + if target is None: + target = [] + else: + if target not in ts: + qdb.sql_connection.TRN.add(sql_ts, [target]) + ts[target] = \ + qdb.sql_connection.TRN.execute_fetchflatten() + target = ts[target] + + if prep_template_id is None: + prep_samples = 0 + else: + if prep_template_id not in ps: + ps[prep_template_id] = len(list( + PT(prep_template_id).keys())) + prep_samples = ps[prep_template_id] + results.append({ 'artifact_id': aid, 'target_subfragment': target, + 'prep_samples': prep_samples, 'name': name, 'data_type': dt, 'timestamp': str(gt), @@ -1459,20 +1480,4 @@ def get_artifacts_information(artifact_ids, only_biom=True): 'algorithm': algorithm, 'files': filepaths}) - # let's get the values for target_subfragment from the - # prep_template, note that we have to do it in a separate sql - # doing crosstab is really difficult and in another loop cause we - # need to loop over all execute_fetchindex before doing another - # query - ts = {} - for i, r in enumerate(results): - pid = r['target_subfragment'] - if pid is None: - results[i]['target_subfragment'] = [] - else: - if pid not in ts: - qdb.sql_connection.TRN.add(sql_ts, [pid]) - ts[pid] = qdb.sql_connection.TRN.execute_fetchflatten() - results[i]['target_subfragment'] = ts[pid] - return results diff --git a/qiita_pet/handlers/api_proxy/tests/test_artifact.py b/qiita_pet/handlers/api_proxy/tests/test_artifact.py index 23ff33302..ec5d6d9a2 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_artifact.py +++ b/qiita_pet/handlers/api_proxy/tests/test_artifact.py @@ -223,27 +223,34 @@ def test_artifact_get_info(self): obs = artifact_get_info('test@foo.bar', [5, 6, 7]) data = [ {'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'], - 'target_subfragment': ['V4'], 'algorithm': ( - 'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, ' - 'defaults'), 'artifact_id': 6, 'data_type': '16S', - 'timestamp': '2012-10-02 17:30:00', 'parameters': { - 'reference': 2, 'similarity': 0.97, 'sortmerna_e_value': 1, + 'target_subfragment': ['V4'], + 'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 | ' + 'barcode_type 8, defaults'), + 'artifact_id': 6, 'data_type': '16S', + 'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27, + 'parameters': { + 'reference': 2, 'similarity': 0.97, u'sortmerna_e_value': 1, 'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1, 'sortmerna_coverage': 0.97}, 'name': 'BIOM'}, {'files': ['1_study_1001_closed_reference_otu_table.biom'], - 'target_subfragment': ['V4'], 'algorithm': ( - 'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, ' - 'defaults'), 'artifact_id': 5, 'data_type': '18S', - 'timestamp': '2012-10-02 17:30:00', 'parameters': { - 'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1, - 'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1, - 'sortmerna_coverage': 0.97}, 'name': 'BIOM'}, + 'target_subfragment': ['V4'], + 'algorithm': ('Pick closed-reference OTUs, QIIMEv1.9.1 | ' + 'barcode_type 8, defaults'), + 'artifact_id': 5, 'data_type': '18S', + 'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27, + 'parameters': { + 'reference': 1, 'similarity': 0.97, 'sortmerna_e_value': 1, + 'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1, + 'sortmerna_coverage': 0.97}, 'name': 'BIOM'}, {'files': [], 'target_subfragment': ['V4'], 'algorithm': '', 'artifact_id': 7, 'data_type': '16S', - 'timestamp': '2012-10-02 17:30:00', 'parameters': {}, - 'name': 'BIOM'}] + 'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27, + 'parameters': {}, 'name': 'BIOM'}] exp = {'status': 'success', 'msg': '', 'data': data} - self.assertEqual(obs, exp) + self.assertItemsEqual(obs.keys(), exp.keys()) + self.assertEqual(obs['status'], exp['status']) + self.assertEqual(obs['msg'], exp['msg']) + self.assertItemsEqual(obs['data'], exp['data']) def test_artifact_post_req(self): # Create new prep template to attach artifact to diff --git a/qiita_pet/handlers/study_handlers/tests/test_artifact.py b/qiita_pet/handlers/study_handlers/tests/test_artifact.py index 7cc8339fd..3b1bd1b2a 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_artifact.py +++ b/qiita_pet/handlers/study_handlers/tests/test_artifact.py @@ -164,19 +164,25 @@ def test_get(self): self.assertEqual(response.code, 200) data = [ {'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'], - 'target_subfragment': ['V4'], 'algorithm': ( - 'Pick closed-reference OTUs, QIIMEv1.9.1 | barcode_type 8, ' - 'defaults'), 'artifact_id': 6, 'data_type': '16S', - 'timestamp': '2012-10-02 17:30:00', 'parameters': { + 'target_subfragment': ['V4'], 'artifact_id': 6, + 'data_type': '16S', 'timestamp': '2012-10-02 17:30:00', + 'prep_samples': 27, + 'algorithm': 'Pick closed-reference OTUs, QIIMEv1.9.1 | ' + 'barcode_type 8, defaults', + 'parameters': { 'reference': 2, 'similarity': 0.97, 'sortmerna_e_value': 1, 'sortmerna_max_pos': 10000, 'input_data': 2, 'threads': 1, 'sortmerna_coverage': 0.97}, 'name': 'BIOM'}, - {'files': [], 'target_subfragment': ['V4'], 'algorithm': '', - 'artifact_id': 7, 'data_type': '16S', - 'timestamp': '2012-10-02 17:30:00', 'parameters': {}, + {'files': [], 'target_subfragment': ['V4'], 'artifact_id': 7, + 'data_type': '16S', 'timestamp': '2012-10-02 17:30:00', + 'prep_samples': 27, 'algorithm': '', 'parameters': {}, 'name': 'BIOM'}] exp = {'status': 'success', 'msg': '', 'data': data} - self.assertEqual(loads(response.body), exp) + obs = loads(response.body) + self.assertItemsEqual(obs.keys(), exp.keys()) + self.assertEqual(obs['status'], exp['status']) + self.assertEqual(obs['msg'], exp['msg']) + self.assertItemsEqual(obs['data'], exp['data']) class ArtifactAdminAJAXTestsReadOnly(TestHandlerBase): diff --git a/qiita_pet/templates/analysis_selected.html b/qiita_pet/templates/analysis_selected.html index 74ff6df01..b5c04206d 100644 --- a/qiita_pet/templates/analysis_selected.html +++ b/qiita_pet/templates/analysis_selected.html @@ -96,7 +96,7 @@
id | Datatype | Processed Date | Algorithm | Parameters | Samples | + | id | Datatype | Processed Date | Algorithm | Parameters | Samples selected from Prep Info | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Data type | '; proc_data_table += 'Processing method | '; proc_data_table += 'Parameters | '; + proc_data_table += 'Samples in Prep Info | '; proc_data_table += 'Files | '; proc_data_table += '' + params + ' | '; + proc_data_table += '' + info.prep_samples + ' | '; proc_data_table += '' + info.files.join(' ') + ' | ';
proc_data_table += '';