Skip to content

Fix 2210 #2246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
41 changes: 23 additions & 18 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -1449,30 +1452,32 @@ 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),
'parameters': aparams,
'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
37 changes: 22 additions & 15 deletions qiita_pet/handlers/api_proxy/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions qiita_pet/handlers/study_handlers/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/analysis_selected.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h2><a href="{% raw qiita_config.portal_dir %}/study/description/{{study.id}}">{
<h4>Processed Data</h4>
<table class='table table-striped' id='study{{study.id}}-table'>
<tr>
<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>
<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>
</tr>
{% for pid, samples in viewitems(proc_datas) %}
<tr id="proc{{pid}}">
Expand Down
2 changes: 2 additions & 0 deletions qiita_pet/templates/list_studies.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
proc_data_table += '<th>Data type</th>';
proc_data_table += '<th>Processing method</th>';
proc_data_table += '<th>Parameters</th>';
proc_data_table += '<th>Samples in Prep Info</th>';
proc_data_table += '<th>Files</th>';
proc_data_table += '</tr>';

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

proc_data_table += '</tr>';
Expand Down