diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index 45c4b387d..c3583518e 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -80,6 +80,7 @@ def get(self, artifact_id): with qdb.sql_connection.TRN: artifact = _get_artifact(artifact_id) study = artifact.study + analysis = artifact.analysis response = { 'name': artifact.name, 'timestamp': str(artifact.timestamp), @@ -90,7 +91,8 @@ def get(self, artifact_id): 'can_be_submitted_to_vamps': artifact.can_be_submitted_to_vamps, 'prep_information': [p.id for p in artifact.prep_templates], - 'study': study.id if study else None} + 'study': study.id if study else None, + 'analysis': analysis.id if analysis else None} params = artifact.processing_parameters response['processing_parameters'] = ( params.values if params is not None else None) diff --git a/qiita_db/handlers/tests/test_artifact.py b/qiita_db/handlers/tests/test_artifact.py index ce88c7155..ebfde2075 100644 --- a/qiita_db/handlers/tests/test_artifact.py +++ b/qiita_db/handlers/tests/test_artifact.py @@ -77,10 +77,36 @@ def test_get_artifact(self): 'is_submitted_to_vamps': None, 'prep_information': [1], 'study': 1, + 'analysis': None, 'processing_parameters': None, 'files': exp_fps} self.assertEqual(loads(obs.body), exp) + obs = self.get('/qiita_db/artifacts/9/', headers=self.header) + self.assertEqual(obs.code, 200) + db_test_raw_dir = qdb.util.get_mountpoint('analysis')[0][1] + path_builder = partial(join, db_test_raw_dir) + exp_fps = {"biom": [path_builder('1_analysis_18S.biom')]} + exp = { + 'name': 'noname', + 'visibility': 'sandbox', + 'type': 'BIOM', + 'data_type': '18S', + 'can_be_submitted_to_ebi': False, + 'ebi_run_accessions': None, + 'can_be_submitted_to_vamps': False, + 'is_submitted_to_vamps': None, + 'prep_information': [], + 'study': None, + 'analysis': 1, + 'processing_parameters': {'biom_table': 8, 'depth': 9000, + 'subsample_multinomial': False}, + 'files': exp_fps} + obs = loads(obs.body) + # The timestamp is genreated at patch time, so we can't check for it + del obs['timestamp'] + self.assertEqual(obs, exp) + def test_patch(self): arguments = {'op': 'add', 'path': '/html_summary/', 'value': self.html_fp} diff --git a/qiita_db/support_files/patches/python_patches/51.py b/qiita_db/support_files/patches/python_patches/51.py index 43f1b65a9..9d462d5c9 100644 --- a/qiita_db/support_files/patches/python_patches/51.py +++ b/qiita_db/support_files/patches/python_patches/51.py @@ -7,6 +7,8 @@ # 3) Transfer all the data in the old structures to the plugin structures # 4) Delete old structures +from string import ascii_letters, digits +from random import SystemRandom from os.path import join, exists, basename from os import makedirs from json import loads @@ -24,6 +26,24 @@ # trasnfer the data from the old structure to the new one +def get_random_string(length): + """Creates a random string of the given length with alphanumeric chars + + Parameters + ---------- + length : int + The desired length of the string + + Returns + ------- + str + The new random string + """ + sr = SystemRandom() + chars = ascii_letters + digits + return ''.join(sr.choice(chars) for i in range(length)) + + def create_non_rarefied_biom_artifact(analysis, biom_data, rarefied_table): """Creates the initial non-rarefied BIOM artifact of the analysis @@ -95,6 +115,7 @@ def create_non_rarefied_biom_artifact(analysis, biom_data, rarefied_table): TRN.add(sql, [analysis['timestamp'], biom_data['data_type_id'], 4, 7, False]) artifact_id = TRN.execute_fetchlast() + # Associate the artifact with the analysis sql = """INSERT INTO qiita.analysis_artifact (analysis_id, artifact_id) @@ -398,6 +419,9 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data, VALUES (%s, %s, %s, %s)""" sql_args = [(validate_cmd_id, 'files', 'string', True), (validate_cmd_id, 'artifact_type', 'string', True), + (validate_cmd_id, 'template', 'prep_template', False), + (validate_cmd_id, 'analysis', 'analysis', False), + (validate_cmd_id, 'provenance', 'string', False), (html_summary_cmd_id, 'input_data', 'artifact', True)] TRN.add(sql, sql_args, many=True) @@ -445,6 +469,18 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data, ['taxa_summary', 'taxa_summary', True, True]] TRN.add(sql, sql_args, many=True) + # Step 8: Give a new client id/client secret pair to the plugins + sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret) + VALUES (%s, %s)""" + # Each plugin needs a client id/secret pair, so we are generating it here + # at random + client_id = get_random_string(50) + client_secret = get_random_string(255) + TRN.add(sql, [client_id, client_secret]) + sql = """INSERT INTO qiita.oauth_software (client_id, software_id) + VALUES (%s, %s)""" + TRN.add(sql, [client_id, divtype_id]) + # Create the new commands that execute the current analyses. In qiita, # the only commands that where available are Summarize Taxa, Beta # Diversity and Alpha Rarefaction. The system was executing rarefaction @@ -491,8 +527,8 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data, (sum_taxa_cmd_id, 'sort', 'bool', False, 'False'), # Beta Diversity (bdiv_cmd_id, 'tree', 'string', False, ''), - (bdiv_cmd_id, 'metrics', - 'mchoice:["abund_jaccard","binary_chisq","binary_chord",' + (bdiv_cmd_id, 'metric', + 'choice:["abund_jaccard","binary_chisq","binary_chord",' '"binary_euclidean","binary_hamming","binary_jaccard",' '"binary_lennon","binary_ochiai","binary_otu_gain","binary_pearson",' '"binary_sorensen_dice","bray_curtis","bray_curtis_faith",' @@ -501,12 +537,21 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data, '"pearson","soergel","spearman_approx","specprof","unifrac",' '"unifrac_g","unifrac_g_full_tree","unweighted_unifrac",' '"unweighted_unifrac_full_tree","weighted_normalized_unifrac",' - '"weighted_unifrac"]', False, '["binary_jaccard","bray_curtis"]'), + '"weighted_unifrac"]', False, '"binary_jaccard"'), # Alpha rarefaction (arare_cmd_id, 'tree', 'string', False, ''), (arare_cmd_id, 'num_steps', 'integer', False, 10), (arare_cmd_id, 'min_rare_depth', 'integer', False, 10), (arare_cmd_id, 'max_rare_depth', 'integer', False, 'Default'), + (arare_cmd_id, 'metrics', + 'mchoice:["ace","berger_parker_d","brillouin_d","chao1","chao1_ci",' + '"dominance","doubles","enspie","equitability","esty_ci",' + '"fisher_alpha","gini_index","goods_coverage","heip_e",' + '"kempton_taylor_q","margalef","mcintosh_d","mcintosh_e",' + '"menhinick","michaelis_menten_fit","observed_otus",' + '"observed_species","osd","simpson_reciprocal","robbins",' + '"shannon","simpson","simpson_e","singles","strong","PD_whole_tree"]', + False, '["chao1","observed_otus"]'), # Single rarefaction (srare_cmd_id, 'depth', 'integer', True, None), (srare_cmd_id, 'subsample_multinomial', 'bool', False, 'False') @@ -553,6 +598,22 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data, TRN.add(sql, ['rarefied_table', srare_cmd_id, biom_atype_id]) srare_cmd_out_id = TRN.execute_fetchlast() + # Step 6: Add default parameter sets + sql = """INSERT INTO qiita.default_parameter_set + (command_id, parameter_set_name, parameter_set) + VALUES (%s, %s, %s)""" + sql_args = [ + [sum_taxa_cmd_id, 'Defaults', + '{"sort": false, "metadata_category": ""}'], + [bdiv_cmd_id, 'Unweighted UniFrac', + '{"metrics": "unweighted_unifrac", "tree": ""}'], + [arare_cmd_id, 'Defaults', + '{"max_rare_depth": "Default", "tree": "", "num_steps": 10, ' + '"min_rare_depth": 10, "metrics": ["chao1", "observed_otus"]}'], + [srare_cmd_id, 'Defaults', + '{"subsample_multinomial": "False"}']] + TRN.add(sql, sql_args, many=True) + # At this point we are ready to start transferring the data from the old # structures to the new structures. Overview of the procedure: # Step 1: Add initial set of artifacts up to rarefied table diff --git a/qiita_db/support_files/test_data/analysis/1_analysis_18S.biom b/qiita_db/support_files/test_data/analysis/1_analysis_18S.biom index 362529c07..32a3ca3a9 100644 Binary files a/qiita_db/support_files/test_data/analysis/1_analysis_18S.biom and b/qiita_db/support_files/test_data/analysis/1_analysis_18S.biom differ diff --git a/qiita_pet/handlers/artifact_handlers/__init__.py b/qiita_pet/handlers/artifact_handlers/__init__.py index 859fbcca1..707499994 100644 --- a/qiita_pet/handlers/artifact_handlers/__init__.py +++ b/qiita_pet/handlers/artifact_handlers/__init__.py @@ -7,5 +7,6 @@ # ----------------------------------------------------------------------------- from .base_handlers import ArtifactSummaryAJAX, ArtifactAJAX +from .process_handlers import ProcessArtifactHandler -__all__ = ['ArtifactSummaryAJAX', 'ArtifactAJAX'] +__all__ = ['ArtifactSummaryAJAX', 'ArtifactAJAX', 'ProcessArtifactHandler'] diff --git a/qiita_pet/templates/analysis_description.html b/qiita_pet/templates/analysis_description.html index df1d4949b..765c8c4e3 100644 --- a/qiita_pet/templates/analysis_description.html +++ b/qiita_pet/templates/analysis_description.html @@ -25,6 +25,28 @@ location.reload(); } + function reload_UI_post_workflow_submission(artifact_id) { + $("#processing-content-div").hide(); + $("#processing-content-div").html(""); + $("#analysis-content-div").show(); + populateContentArtifact(artifact_id); + } + + function load_process_artifact_ui(artifact_id) { + $("#analysis-content-div").hide() + $("#processing-content-div").show() + show_loading('{% raw qiita_config.portal_dir %}', 'processing-content-div'); + $.get('{% raw qiita_config.portal_dir %}/artifact/' + artifact_id + '/process/', function(data){ + $("#processing-content-div").html(data); + }) + .fail(function(object, status, error_msg) { + bootstrapAlert("Error loading processing page: " + status + " " + object.statusText, "danger"); + $("#analysis-content-div").show() + $("#processing-content-div").hide() + } + ) + }; + /** * Creates the HTML with the job information and adds it to `target` * @@ -193,6 +215,7 @@ // Add the vue object to the div, so we avoid to have global variables $("#analysis-network-div").data('data-graph-vue', vueGraph); + $("processing-content-div").hide(); {% if alert_msg %} bootstrapAlert("{{alert_msg}}", "{{alert_type}}"); {% end %} @@ -214,22 +237,25 @@