diff --git a/qiita_db/test/test_util.py b/qiita_db/test/test_util.py index 6264cc895..8a455126d 100644 --- a/qiita_db/test/test_util.py +++ b/qiita_db/test/test_util.py @@ -799,6 +799,20 @@ def test_get_pubmed_ids_from_dois(self): self.assertEqual(obs, exp) def test_generate_study_list(self): + # creating a new study to make sure that empty studies are also + # returned + info = {"timeseries_type_id": 1, "metadata_complete": True, + "mixs_compliant": True, "number_samples_collected": 25, + "number_samples_promised": 28, "study_alias": "TST", + "study_description": "Some description of the study goes here", + "study_abstract": "Some abstract goes here", + "emp_person_id": qdb.study.StudyPerson(1), + "principal_investigator_id": qdb.study.StudyPerson(1), + "lab_person_id": qdb.study.StudyPerson(1)} + new_study = qdb.study.Study.create( + qdb.user.User('shared@foo.bar'), 'test_study_1', efo=[1], + info=info) + exp_info = [{ 'metadata_complete': True, 'ebi_submission_status': 'submitted', @@ -825,126 +839,70 @@ def test_generate_study_list(self): 'Soils'), 'number_samples_collected': 27, 'study_tags': None - }] - obs_info = qdb.util.generate_study_list([1, 2, 3, 4], False) + }, { + 'metadata_complete': True, + 'ebi_submission_status': 'not submitted', 'publication_pid': [], + 'study_abstract': 'Some abstract goes here', + 'pi': ('lab_dude@foo.bar', 'LabDude'), 'status': 'sandbox', + 'proc_data_info': [], 'study_tags': None, 'shared': [], + 'publication_doi': [], 'study_id': new_study.id, + 'ebi_study_accession': None, 'study_title': 'test_study_1', + 'number_samples_collected': 0}] + obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True) self.assertEqual(obs_info, exp_info) qdb.artifact.Artifact(4).visibility = 'public' exp_info[0]['status'] = 'public' exp_info[0]['proc_data_info'] = [ - {'data_type': '18S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 4, - 'processed_date': '2012-10-02 17:30:00', + {'data_type': '18S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 4, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Greengenes', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, u'sortmerna_coverage': 0.97, - 'reference_version': '13_8'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, - {'data_type': '18S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 5, - 'processed_date': '2012-10-02 17:30:00', + 'reference_version': '13_8'}}, + {'data_type': '18S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 5, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Greengenes', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': '13_8'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, - {'data_type': '16S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 6, - 'processed_date': '2012-10-02 17:30:00', + 'reference_version': '13_8'}}, + {'data_type': '16S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 6, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Silva', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': 'test'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}] - obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True, - public_only=True) + 'reference_version': 'test'}}] + obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True) self.assertEqual(obs_info, exp_info) exp_info[0]['proc_data_info'] = [ - {'data_type': '18S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 4, - 'processed_date': '2012-10-02 17:30:00', + {'data_type': '18S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 4, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Greengenes', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': '13_8'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, - {'data_type': '18S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 5, - 'processed_date': '2012-10-02 17:30:00', + 'reference_version': '13_8'}}, + {'data_type': '18S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 5, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Greengenes', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': '13_8'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, - {'data_type': '16S', - 'algorithm': 'QIIME (Pick closed-reference OTUs)', 'pid': 6, - 'processed_date': '2012-10-02 17:30:00', + 'reference_version': '13_8'}}, + {'data_type': '16S', 'name': 'BIOM', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', + 'pid': 6, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': 'Silva', 'sortmerna_e_value': 1, u'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': 'test'}, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']}, - {'processed_date': '2012-10-02 17:30:00', 'pid': 7, - 'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', - '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176', - '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200', - '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', - '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182', - '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197', - '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192'], + 'reference_version': 'test'}}, + {'processed_date': '2012-10-02 17:30:00', 'pid': 7, 'name': 'BIOM', 'data_type': '16S'}] - obs_info = qdb.util.generate_study_list([1, 2, 3, 4], True) + obs_info = qdb.util.generate_study_list([1, 2, 3, 4], False) self.assertEqual(obs_info, exp_info) diff --git a/qiita_db/util.py b/qiita_db/util.py index 18f2d39ce..275bcde07 100644 --- a/qiita_db/util.py +++ b/qiita_db/util.py @@ -1266,16 +1266,13 @@ def supported_filepath_types(artifact_type): return qdb.sql_connection.TRN.execute_fetchindex() -def generate_study_list(study_ids, build_samples, public_only=False): +def generate_study_list(study_ids, public_only=False): """Get general study information Parameters ---------- study_ids : list of ints The study ids to look for. Non-existing ids will be ignored - build_samples : bool - If true the sample information for each process artifact within each - study will be included public_only : bool, optional If true, return only public BIOM artifacts. Default: false. @@ -1334,6 +1331,13 @@ def generate_study_list(study_ids, build_samples, public_only=False): LEFT JOIN qiita.artifact_type USING (artifact_type_id) WHERE artifact_type='BIOM' AND study_id = qiita.study.study_id) AS artifact_biom_ts, + - all the BIOM names sorted by artifact_id that belong to the study + (SELECT array_agg(name ORDER BY artifact_id) + FROM qiita.study_artifact + LEFT JOIN qiita.artifact USING (artifact_id) + LEFT JOIN qiita.artifact_type USING (artifact_type_id) + WHERE artifact_type='BIOM' AND + study_id = qiita.study.study_id) AS artifact_biom_name, - all the BIOM visibility sorted by artifact_id that belong to the study (SELECT array_agg(visibility ORDER BY artifact_id) FROM qiita.study_artifact @@ -1408,6 +1412,12 @@ def generate_study_list(study_ids, build_samples, public_only=False): LEFT JOIN qiita.artifact_type USING (artifact_type_id) WHERE artifact_type='BIOM' AND study_id = qiita.study.study_id) AS artifact_biom_ts, + (SELECT array_agg(name ORDER BY artifact_id) + FROM qiita.study_artifact + LEFT JOIN qiita.artifact USING (artifact_id) + LEFT JOIN qiita.artifact_type USING (artifact_type_id) + WHERE artifact_type='BIOM' AND + study_id = qiita.study.study_id) AS artifact_biom_name, (SELECT array_agg(visibility ORDER BY artifact_id) FROM qiita.study_artifact LEFT JOIN qiita.artifact USING (artifact_id) @@ -1481,17 +1491,19 @@ def generate_study_list(study_ids, build_samples, public_only=False): del info["shared_with_email"] info['proc_data_info'] = [] - if build_samples and info['artifact_biom_ids']: + if info['artifact_biom_ids']: to_loop = zip( info['artifact_biom_ids'], info['artifact_biom_dts'], info['artifact_biom_ts'], info['artifact_biom_params'], - info['artifact_biom_cmd'], info['artifact_biom_vis']) - for artifact_id, dt, ts, params, cmd, vis in to_loop: + info['artifact_biom_cmd'], info['artifact_biom_vis'], + info['artifact_biom_name']) + for artifact_id, dt, ts, params, cmd, vis, name in to_loop: if public_only and vis != 'public': continue proc_info = {'processed_date': str(ts)} proc_info['pid'] = artifact_id proc_info['data_type'] = dt + proc_info['name'] = name # if cmd exists then we can get its parameters if cmd is not None: @@ -1503,6 +1515,7 @@ def generate_study_list(study_ids, build_samples, public_only=False): 'del_keys': [k for k, v in viewitems( c.parameters) if v[0] == 'artifact'], 'sfwn': c.software.name, + 'sfv': c.software.version, 'cmdn': c.name } for k in commands[cmd]['del_keys']: @@ -1526,31 +1539,27 @@ def generate_study_list(study_ids, build_samples, public_only=False): params['reference_version'] = refs[rid][ 'version'] - proc_info['algorithm'] = '%s (%s)' % ( - commands[cmd]['sfwn'], commands[cmd]['cmdn']) + proc_info['algorithm'] = '%s v%s (%s)' % ( + commands[cmd]['sfwn'], commands[cmd]['sfv'], + commands[cmd]['cmdn']) proc_info['params'] = params - # getting all samples - sql = """SELECT sample_id from qiita.prep_template_sample - WHERE prep_template_id = ( - SELECT prep_template_id - FROM qiita.prep_template - WHERE artifact_id IN ( - SELECT * - FROM qiita.find_artifact_roots(%s)))""" - qdb.sql_connection.TRN.add(sql, [proc_info['pid']]) - proc_info['samples'] = sorted( - qdb.sql_connection.TRN.execute_fetchflatten()) - info["proc_data_info"].append(proc_info) - del info["artifact_biom_ids"] - del info["artifact_biom_dts"] - del info["artifact_biom_ts"] - del info["artifact_biom_params"] - del info['artifact_biom_cmd'] - del info['artifact_biom_vis'] - - infolist.append(info) + infolist.append({ + 'metadata_complete': info['metadata_complete'], + 'publication_pid': info['publication_pid'], + 'ebi_submission_status': info['ebi_submission_status'], + 'shared': info['shared'], + 'study_abstract': info['study_abstract'], 'pi': info['pi'], + 'status': info['status'], + 'proc_data_info': info['proc_data_info'], + 'study_tags': info['study_tags'], + 'publication_doi': info['publication_doi'], + 'study_id': info['study_id'], + 'ebi_study_accession': info['ebi_study_accession'], + 'study_title': info['study_title'], + 'number_samples_collected': info['number_samples_collected'] + }) return infolist diff --git a/qiita_pet/handlers/api_proxy/__init__.py b/qiita_pet/handlers/api_proxy/__init__.py index 7d234967f..68a6956e1 100644 --- a/qiita_pet/handlers/api_proxy/__init__.py +++ b/qiita_pet/handlers/api_proxy/__init__.py @@ -31,7 +31,7 @@ from .artifact import (artifact_graph_get_req, artifact_types_get_req, artifact_post_req, artifact_get_req, artifact_status_put_req, artifact_delete_req, - artifact_summary_get_request, + artifact_summary_get_request, artifact_get_prep_req, artifact_summary_post_request, artifact_patch_request) from .ontology import ontology_patch_handler from .processing import ( @@ -48,7 +48,7 @@ 'study_get_req', 'sample_template_summary_get_req', 'sample_template_delete_req', 'sample_template_filepaths_get_req', 'prep_template_summary_get_req', 'prep_template_post_req', - 'prep_template_delete_req', + 'prep_template_delete_req', 'artifact_get_prep_req', 'prep_template_graph_get_req', 'prep_template_filepaths_get_req', 'artifact_get_req', 'artifact_status_put_req', 'artifact_delete_req', 'prep_template_get_req', 'study_delete_req', diff --git a/qiita_pet/handlers/api_proxy/artifact.py b/qiita_pet/handlers/api_proxy/artifact.py index 6034f41b3..d6e04e6b3 100644 --- a/qiita_pet/handlers/api_proxy/artifact.py +++ b/qiita_pet/handlers/api_proxy/artifact.py @@ -11,6 +11,7 @@ from future.utils import viewitems from moi import r_client +from skbio.util import flatten from qiita_core.util import execute_as_transaction from qiita_core.qiita_settings import qiita_config @@ -24,7 +25,6 @@ from qiita_db.software import Command, Parameters from qiita_db.processing_job import ProcessingJob - PREP_TEMPLATE_KEY_FORMAT = 'prep_template_%s' @@ -263,6 +263,39 @@ def artifact_get_req(user_id, artifact_id): 'is_submitted_vamps': is_submitted_vamps} +@execute_as_transaction +def artifact_get_prep_req(user_id, artifact_ids): + """Returns all prep info sample ids for the given artifact_ids + + Parameters + ---------- + user_id : str + user making the request + artifact_ids : list of int + list of artifact ids + + Returns + ------- + dict of objects + A dictionary containing the artifact information + {'status': status, + 'message': message, + 'data': {artifact_id: [prep info sample ids]} + """ + samples = {} + + for aid in artifact_ids: + artifact = Artifact(aid) + access_error = check_access(artifact.study.id, user_id) + if access_error: + return access_error + + samples[aid] = flatten( + [pt.keys() for pt in Artifact(aid).prep_templates]) + + return {'status': 'success', 'msg': '', 'data': samples} + + @execute_as_transaction def artifact_post_req(user_id, filepaths, artifact_type, name, prep_template_id, artifact_id=None): diff --git a/qiita_pet/handlers/api_proxy/tests/test_artifact.py b/qiita_pet/handlers/api_proxy/tests/test_artifact.py index 149d7456e..77a9dd09e 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_artifact.py +++ b/qiita_pet/handlers/api_proxy/tests/test_artifact.py @@ -29,7 +29,7 @@ artifact_get_req, artifact_status_put_req, artifact_graph_get_req, artifact_delete_req, artifact_types_get_req, artifact_post_req, artifact_summary_get_request, artifact_summary_post_request, - artifact_patch_request) + artifact_patch_request, artifact_get_prep_req) class TestArtifactAPIReadOnly(TestCase): @@ -405,6 +405,25 @@ def test_artifact_delete_req_no_access(self): 'message': 'User does not have access to study'} self.assertEqual(obs, exp) + def test_artifact_get_prep_req(self): + obs = artifact_get_prep_req('test@foo.bar', [4]) + exp = {'status': 'success', 'msg': '', 'data': { + 4: ['1.SKB2.640194', '1.SKM4.640180', '1.SKB3.640195', + '1.SKB6.640176', '1.SKD6.640190', '1.SKM6.640187', + '1.SKD9.640182', '1.SKM8.640201', '1.SKM2.640199', + '1.SKD2.640178', '1.SKB7.640196', '1.SKD4.640185', + '1.SKB8.640193', '1.SKM3.640197', '1.SKD5.640186', + '1.SKB1.640202', '1.SKM1.640183', '1.SKD1.640179', + '1.SKD3.640198', '1.SKB5.640181', '1.SKB4.640189', + '1.SKB9.640200', '1.SKM9.640192', '1.SKD8.640184', + '1.SKM5.640177', '1.SKM7.640188', '1.SKD7.640191']}} + self.assertEqual(obs, exp) + + obs = artifact_get_prep_req('demo@microbio.me', [4]) + exp = {'status': 'error', + 'message': 'User does not have access to study'} + self.assertEqual(obs, exp) + def test_artifact_post_req(self): # Create new prep template to attach artifact to pt = npt.assert_warns( diff --git a/qiita_pet/handlers/study_handlers/__init__.py b/qiita_pet/handlers/study_handlers/__init__.py index b95696fe8..423d6a66f 100644 --- a/qiita_pet/handlers/study_handlers/__init__.py +++ b/qiita_pet/handlers/study_handlers/__init__.py @@ -21,7 +21,8 @@ ListOptionsHandler, WorkflowHandler, WorkflowRunHandler, JobAJAX) from .artifact import (ArtifactGraphAJAX, NewArtifactHandler, - ArtifactAdminAJAX, ArtifactAJAX, ArtifactSummaryAJAX) + ArtifactAdminAJAX, ArtifactAJAX, ArtifactSummaryAJAX, + ArtifactGetSamples) from .sample_template import SampleTemplateAJAX, SampleAJAX __all__ = ['ListStudiesHandler', 'StudyApprovalList', 'ShareStudyAJAX', @@ -34,4 +35,5 @@ 'StudyDeleteAjax', 'ArtifactAJAX', 'NewPrepTemplateAjax', 'DataTypesMenuAJAX', 'StudyFilesAJAX', 'PrepTemplateSummaryAJAX', 'ArtifactSummaryAJAX', 'WorkflowHandler', 'WorkflowRunHandler', - 'JobAJAX', 'AutocompleteHandler', 'StudyGetTags', 'StudyTags'] + 'JobAJAX', 'AutocompleteHandler', 'StudyGetTags', 'StudyTags', + 'ArtifactGetSamples'] diff --git a/qiita_pet/handlers/study_handlers/artifact.py b/qiita_pet/handlers/study_handlers/artifact.py index d1063953d..3f1e3ccfa 100644 --- a/qiita_pet/handlers/study_handlers/artifact.py +++ b/qiita_pet/handlers/study_handlers/artifact.py @@ -16,7 +16,7 @@ artifact_graph_get_req, artifact_types_get_req, artifact_post_req, artifact_status_put_req, artifact_get_req, artifact_delete_req, artifact_summary_get_request, artifact_summary_post_request, - artifact_patch_request) + artifact_patch_request, artifact_get_prep_req) from qiita_core.util import execute_as_transaction from qiita_core.qiita_settings import qiita_config @@ -107,6 +107,16 @@ def patch(self): self.write(response) +class ArtifactGetSamples(BaseHandler): + @authenticated + def get(self): + aids = map(int, self.request.arguments.get('ids[]', [])) + + response = artifact_get_prep_req(self.current_user.id, aids) + + self.write(response) + + class ArtifactAdminAJAX(BaseHandler): @authenticated def get(self): diff --git a/qiita_pet/handlers/study_handlers/listing_handlers.py b/qiita_pet/handlers/study_handlers/listing_handlers.py index 1e1f2b5b2..b28c8b6fd 100644 --- a/qiita_pet/handlers/study_handlers/listing_handlers.py +++ b/qiita_pet/handlers/study_handlers/listing_handlers.py @@ -59,7 +59,6 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None): ----- Both study_proc and proc_samples must be passed, or neither passed. """ - build_samples = False # Logic check to make sure both needed parts passed if study_proc is not None and proc_samples is None: raise IncompetentQiitaDeveloperError( @@ -67,8 +66,6 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None): elif proc_samples is not None and study_proc is None: raise IncompetentQiitaDeveloperError( 'Must pass study_proc when proc_samples given') - elif study_proc is None: - build_samples = True # get list of studies for table user_study_set = user.user_studies.union(user.shared_studies) @@ -89,7 +86,7 @@ def _build_study_info(user, search_type, study_proc=None, proc_samples=None): # No studies left so no need to continue return [] - return generate_study_list([s.id for s in study_set], build_samples, + return generate_study_list([s.id for s in study_set], public_only=(search_type == 'public')) diff --git a/qiita_pet/handlers/study_handlers/tests/test_artifact.py b/qiita_pet/handlers/study_handlers/tests/test_artifact.py index 304dc2844..aaa9531d3 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_artifact.py +++ b/qiita_pet/handlers/study_handlers/tests/test_artifact.py @@ -140,6 +140,34 @@ def test_delete_artifact(self): wait_for_prep_information_job(1) +class ArtifactGetSamplesTest(TestHandlerBase): + def test_get(self): + response = self.get('/artifact/samples/', {'ids[]': [4, 5]}) + self.assertEqual(response.code, 200) + exp = ( + {"status": "success", "msg": "", + "data": + {"4": ["1.SKB2.640194", "1.SKM4.640180", "1.SKB3.640195", + "1.SKB6.640176", "1.SKD6.640190", "1.SKM6.640187", + "1.SKD9.640182", "1.SKM8.640201", "1.SKM2.640199", + "1.SKD2.640178", "1.SKB7.640196", "1.SKD4.640185", + "1.SKB8.640193", "1.SKM3.640197", "1.SKD5.640186", + "1.SKB1.640202", "1.SKM1.640183", "1.SKD1.640179", + "1.SKD3.640198", "1.SKB5.640181", "1.SKB4.640189", + "1.SKB9.640200", "1.SKM9.640192", "1.SKD8.640184", + "1.SKM5.640177", "1.SKM7.640188", "1.SKD7.640191"], + "5": ["1.SKB2.640194", "1.SKM4.640180", "1.SKB3.640195", + "1.SKB6.640176", "1.SKD6.640190", "1.SKM6.640187", + "1.SKD9.640182", "1.SKM8.640201", "1.SKM2.640199", + "1.SKD2.640178", "1.SKB7.640196", "1.SKD4.640185", + "1.SKB8.640193", "1.SKM3.640197", "1.SKD5.640186", + "1.SKB1.640202", "1.SKM1.640183", "1.SKD1.640179", + "1.SKD3.640198", "1.SKB5.640181", "1.SKB4.640189", + "1.SKB9.640200", "1.SKM9.640192", "1.SKD8.640184", + "1.SKM5.640177", "1.SKM7.640188", "1.SKD7.640191"]}}) + self.assertEqual(loads(response.body), exp) + + class ArtifactAdminAJAXTestsReadOnly(TestHandlerBase): def test_get_admin(self): response = self.get('/admin/artifact/', diff --git a/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py b/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py index f411481c4..e4de44bb5 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py +++ b/qiita_pet/handlers/study_handlers/tests/test_listing_handlers.py @@ -21,32 +21,28 @@ _build_study_info) from qiita_pet.handlers.base_handlers import BaseHandler - -SAMPLES = ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195', '1.SKB4.640189', - '1.SKB5.640181', '1.SKB6.640176', '1.SKB7.640196', '1.SKB8.640193', - '1.SKB9.640200', '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198', - '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190', '1.SKD7.640191', - '1.SKD8.640184', '1.SKD9.640182', '1.SKM1.640183', '1.SKM2.640199', - '1.SKM3.640197', '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187', - '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192'] GPARAMS = {'similarity': 0.97, 'reference_name': 'Greengenes', 'sortmerna_e_value': 1, 'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, 'reference_version': u'13_8'} PROC_DATA_INFO = [ - {'data_type': u'18S', 'algorithm': 'QIIME (Pick closed-reference OTUs)', + {'data_type': u'18S', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', 'pid': 4, 'processed_date': '2012-10-02 17:30:00', 'params': GPARAMS, - 'samples': SAMPLES}, - {'data_type': '18S', 'algorithm': 'QIIME (Pick closed-reference OTUs)', + 'name': 'BIOM'}, + {'data_type': '18S', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', 'pid': 5, 'processed_date': '2012-10-02 17:30:00', 'params': GPARAMS, - 'samples': SAMPLES}, - {'data_type': '16S', 'algorithm': 'QIIME (Pick closed-reference OTUs)', + 'name': 'BIOM'}, + {'data_type': '16S', + 'algorithm': 'QIIME v1.9.1 (Pick closed-reference OTUs)', 'pid': 6, 'processed_date': '2012-10-02 17:30:00', 'params': {'similarity': 0.97, 'reference_name': u'Silva', 'sortmerna_e_value': 1, 'sortmerna_max_pos': 10000, 'threads': 1, 'sortmerna_coverage': 0.97, - 'reference_version': 'test'}, 'samples': SAMPLES}, + 'reference_version': 'test'}, + 'name': 'BIOM'}, {'processed_date': '2012-10-02 17:30:00', 'pid': 7, 'data_type': '16S', - 'samples': SAMPLES}] + 'name': 'BIOM'}] class TestHelpers(TestHandlerBase): diff --git a/qiita_pet/static/js/qiita.js b/qiita_pet/static/js/qiita.js index f9d555fc2..8b8aa56e0 100644 --- a/qiita_pet/static/js/qiita.js +++ b/qiita_pet/static/js/qiita.js @@ -7,6 +7,9 @@ * @param timeout: OPTIONAL. When given, time (in ms) before alert fades out * */ + +var timeoutHandleForBoostrapAlert = null; + function bootstrapAlert(message, severity, timeout){ // Clear the previous alert - so they don't keep stacking on top of each other $('#bootstrap-alert').alert('close'); @@ -32,7 +35,13 @@ function bootstrapAlert(message, severity, timeout){ $('#qiita-main').prepend(alertDiv); if(timeout > 0) { - window.setTimeout(function() { $('#alert-message').alert('close'); }, timeout); + if (timeoutHandleForBoostrapAlert != null) { + window.clearTimeout(timeoutHandleForBoostrapAlert); + } + timeoutHandleForBoostrapAlert = window.setTimeout(function() { + $('#alert-message').alert('close'); + timeoutHandleForBoostrapAlert = null; + }, timeout); } } diff --git a/qiita_pet/templates/list_studies.html b/qiita_pet/templates/list_studies.html index 9dc8ea7e7..d3a4de4ac 100644 --- a/qiita_pet/templates/list_studies.html +++ b/qiita_pet/templates/list_studies.html @@ -18,31 +18,35 @@