diff --git a/qiita_pet/handlers/qiita_redbiom.py b/qiita_pet/handlers/qiita_redbiom.py index 74e18e1cc..eb5a56bd9 100644 --- a/qiita_pet/handlers/qiita_redbiom.py +++ b/qiita_pet/handlers/qiita_redbiom.py @@ -6,6 +6,7 @@ # The full license is in the file LICENSE, distributed with this software. # ----------------------------------------------------------------------------- +from future.utils import viewitems from requests import ConnectionError import redbiom.summarize import redbiom.search @@ -83,42 +84,81 @@ def _redbiom_search(self, query, search_on, callback): (prep_template_id) JOIN qiita.study USING (study_id) WHERE sample_id IN %s - GROUP BY study_title, study_id, artifact_id) - SELECT study_title, study_id, samples, - name, command_id, - (main_query.children).artifact_id AS artifact_id - FROM main_query - JOIN qiita.artifact a ON - (main_query.children).artifact_id = a.artifact_id - JOIN qiita.artifact_type at ON ( - at.artifact_type_id = a.artifact_type_id - AND artifact_type = 'BIOM') - ORDER BY artifact_id + GROUP BY study_title, study_id, artifact_id), + artifact_query AS ( + SELECT study_title, study_id, samples, + name, command_id, + (main_query.children).artifact_id AS + artifact_id + FROM main_query + JOIN qiita.artifact a ON + (main_query.children).artifact_id = + a.artifact_id + JOIN qiita.artifact_type at ON ( + at.artifact_type_id = a.artifact_type_id + AND artifact_type = 'BIOM')), + parent_query AS ( + SELECT artifact_query.*, + array_agg(parent_params) as parent_parameters + FROM artifact_query + LEFT JOIN qiita.parent_artifact pa ON ( + artifact_query.artifact_id = pa.artifact_id) + LEFT JOIN qiita.artifact a ON ( + pa.parent_id = a.artifact_id), + json_each_text(command_parameters) + parent_params + GROUP BY artifact_query.study_title, + artifact_query.study_id, + artifact_query.samples, artifact_query.name, + artifact_query.command_id, + artifact_query.artifact_id) + SELECT * FROM parent_query + ORDER BY parent_parameters, artifact_id """ + + sql_params = """ + SELECT parameter_set_name, array_agg(ps) AS param_set + FROM qiita.default_parameter_set, + json_each_text(parameter_set) ps + GROUP BY parameter_set_name""" + with qdbsc.TRN: - qdbsc.TRN.add(sql, [tuple(features)]) results = [] commands = {} + # obtaining all existing parameters, note that + # they are not that many (~40) and we don't expect + # to have a huge growth in the near future + qdbsc.TRN.add(sql_params) + params = {pname: eval(params) for pname, params + in qdbsc.TRN.execute_fetchindex()} + + # now let's get the actual artifacts + qdbsc.TRN.add(sql, [tuple(features)]) for row in qdbsc.TRN.execute_fetchindex(): - title, sid, samples, name, cid, aid = row + title, sid, samples, name, cid, aid, pp = row nr = {'study_title': title, 'study_id': sid, 'artifact_id': aid, 'aname': name, 'samples': samples} if cid is not None: if cid not in commands: c = qdb.software.Command(cid) - commands[cid] = { - 'sfwn': c.software.name, - 'sfv': c.software.version, - 'cmdn': c.name - } - nr['command'] = commands[cid]['cmdn'] - nr['software'] = commands[cid]['sfwn'] - nr['version'] = commands[cid]['sfv'] + commands[cid] = '%s - %s v%s' % ( + c.name, c.software.name, + c.software.version) + + # [-1] taking the last cause it's sorted by + # the number of overlapping parameters + # [0] then taking the first element that is + # the name of the parameter set + ppc = sorted( + [[k, len(eval(pp) & v)] + for k, v in viewitems(params)], + key=lambda x: x[1])[-1][0] + + nr['command'] = '%s @ %s' % ( + commands[cid], ppc) else: - nr['command'] = None - nr['software'] = None - nr['version'] = None + nr['command'] = '' results.append(nr) else: sql = """ diff --git a/qiita_pet/static/js/qiita.js b/qiita_pet/static/js/qiita.js index a2a20c6e7..04c9b199a 100644 --- a/qiita_pet/static/js/qiita.js +++ b/qiita_pet/static/js/qiita.js @@ -301,17 +301,3 @@ function display_number_of_samples_added(num_samples) { bootstrapAlert(num_samples + ' samples selected.', "success", 10000); $('#dflt-sel-info').css('color', 'rgb(0, 160, 0)'); } - -/** - * - * Function to show the loading gif in a given div - * - * @param div_name string with the name of the div to populate with the loading gif - * - * This function replaces the content of the given div with the - * gif to show that the section of page is loading - * - */ -function show_loading(div_name) { - $("#" + div_name).html(""); -} diff --git a/qiita_pet/templates/redbiom.html b/qiita_pet/templates/redbiom.html index bf352a7e8..d38f2c10d 100644 --- a/qiita_pet/templates/redbiom.html +++ b/qiita_pet/templates/redbiom.html @@ -36,15 +36,34 @@ { "data": null, "width": "20%" }, { "data": null, "width": "10%" } ], + "order": [[ 3, 'asc' ]], + // "displayLength": 25, + "drawCallback": function ( settings ) { + var api = this.api(); + var rows = api.rows( {page:'current'} ).nodes(); + var last=null; + + api.column(3, {page:'current'} ).data().each( function ( data, i ) { + group = data.command; + if ( last !== group ) { + $(rows).eq( i ).before( + '