diff --git a/qiita_db/metadata_template/__init__.py b/qiita_db/metadata_template/__init__.py index 632f1acd8..ece9a5ff0 100644 --- a/qiita_db/metadata_template/__init__.py +++ b/qiita_db/metadata_template/__init__.py @@ -9,8 +9,11 @@ from .sample_template import SampleTemplate from .prep_template import PrepTemplate from .util import load_template_to_dataframe -from .constants import TARGET_GENE_DATA_TYPES +from .constants import (TARGET_GENE_DATA_TYPES, SAMPLE_TEMPLATE_COLUMNS, + PREP_TEMPLATE_COLUMNS, + PREP_TEMPLATE_COLUMNS_TARGET_GENE) __all__ = ['SampleTemplate', 'PrepTemplate', 'load_template_to_dataframe', - 'TARGET_GENE_DATA_TYPES'] + 'TARGET_GENE_DATA_TYPES', 'SAMPLE_TEMPLATE_COLUMNS', + 'PREP_TEMPLATE_COLUMNS', 'PREP_TEMPLATE_COLUMNS_TARGET_GENE'] diff --git a/qiita_db/metadata_template/test/test_prep_template.py b/qiita_db/metadata_template/test/test_prep_template.py index 49a29087c..bd940f34f 100644 --- a/qiita_db/metadata_template/test/test_prep_template.py +++ b/qiita_db/metadata_template/test/test_prep_template.py @@ -32,8 +32,8 @@ get_count) from qiita_db.metadata_template.prep_template import PrepTemplate, PrepSample from qiita_db.metadata_template.sample_template import SampleTemplate, Sample -from qiita_db.metadata_template.constants import ( - PREP_TEMPLATE_COLUMNS, PREP_TEMPLATE_COLUMNS_TARGET_GENE) +from qiita_db.metadata_template import (PREP_TEMPLATE_COLUMNS, + PREP_TEMPLATE_COLUMNS_TARGET_GENE) class BaseTestPrepSample(TestCase): diff --git a/qiita_pet/handlers/study_handlers/description_handlers.py b/qiita_pet/handlers/study_handlers/description_handlers.py index 0f68c63e8..f63901c18 100644 --- a/qiita_pet/handlers/study_handlers/description_handlers.py +++ b/qiita_pet/handlers/study_handlers/description_handlers.py @@ -22,7 +22,8 @@ from qiita_db.data import RawData, PreprocessedData, ProcessedData from qiita_db.ontology import Ontology from qiita_db.metadata_template import (PrepTemplate, SampleTemplate, - load_template_to_dataframe) + load_template_to_dataframe, + SAMPLE_TEMPLATE_COLUMNS) from qiita_db.util import convert_to_id, get_mountpoint from qiita_db.exceptions import (QiitaDBUnknownIDError, QiitaDBColumnError, QiitaDBExecutionError, QiitaDBDuplicateError, @@ -624,6 +625,18 @@ def display_template(self, study, user, msg, msg_level, full_access, user_level = user.level sample_template_exists = SampleTemplate.exists(study.id) + if sample_template_exists: + st = SampleTemplate(study.id) + missing_cols = st.check_restrictions( + [SAMPLE_TEMPLATE_COLUMNS['qiita_main']]) + allow_approval = len(missing_cols) == 0 + approval_deny_msg = ( + "Processed data approval request is disabled due to missing " + "columns in the sample template: %s" % ', '.join(missing_cols)) + else: + allow_approval = False + approval_deny_msg = "" + # The general information of the study can be changed if the study is # not public or if the user is an admin, in which case they can always # modify the information of the study @@ -638,6 +651,8 @@ def display_template(self, study, user, msg, msg_level, full_access, show_edit_btn=show_edit_btn, show_data_tabs=sample_template_exists, full_access=full_access, + allow_approval=allow_approval, + approval_deny_msg=approval_deny_msg, top_tab=top_tab, sub_tab=sub_tab, prep_tab=prep_tab) diff --git a/qiita_pet/handlers/study_handlers/ebi_handlers.py b/qiita_pet/handlers/study_handlers/ebi_handlers.py index 637121031..3e7a6f795 100644 --- a/qiita_pet/handlers/study_handlers/ebi_handlers.py +++ b/qiita_pet/handlers/study_handlers/ebi_handlers.py @@ -13,7 +13,9 @@ from qiita_ware.demux import stats as demux_stats from qiita_ware.dispatchable import submit_to_ebi from qiita_db.data import PreprocessedData -from qiita_db.metadata_template import PrepTemplate, SampleTemplate +from qiita_db.metadata_template import (PrepTemplate, SampleTemplate, + SAMPLE_TEMPLATE_COLUMNS, + PREP_TEMPLATE_COLUMNS) from qiita_db.study import Study from qiita_db.exceptions import QiitaDBUnknownIDError from qiita_pet.handlers.base_handlers import BaseHandler @@ -58,11 +60,33 @@ def display_template(self, preprocessed_data_id, msg, msg_level): stats.append(('Number of sequences', demux_file_stats.n)) msg_level = 'success' + # Check if the templates have all the required columns for EBI + pt_missing_cols = prep_template.check_restrictions( + [PREP_TEMPLATE_COLUMNS['EBI']]) + st_missing_cols = sample_template.check_restrictions( + [SAMPLE_TEMPLATE_COLUMNS['EBI']]) + allow_submission = (len(pt_missing_cols) == 0 and + len(st_missing_cols) == 0) + + if not allow_submission: + msg_list = ["Submission to EBI disabled due to missing columns:"] + if len(pt_missing_cols) > 0: + msg_list.append("Columns missing in prep template: %s" + % ', '.join(pt_missing_cols)) + if len(st_missing_cols) > 0: + msg_list.append("Columns missing in sample template: %s" + % ', '.join(st_missing_cols)) + ebi_disabled_msg = "
".join(msg_list) + else: + ebi_disabled_msg = None + self.render('ebi_submission.html', study_title=study.title, stats=stats, message=msg, study_id=study.id, level=msg_level, preprocessed_data_id=preprocessed_data_id, - investigation_type=prep_template.investigation_type) + investigation_type=prep_template.investigation_type, + allow_submission=allow_submission, + ebi_disabled_msg=ebi_disabled_msg) @authenticated def get(self, preprocessed_data_id): diff --git a/qiita_pet/templates/ebi_submission.html b/qiita_pet/templates/ebi_submission.html index e46501822..4a1c8221d 100644 --- a/qiita_pet/templates/ebi_submission.html +++ b/qiita_pet/templates/ebi_submission.html @@ -28,14 +28,18 @@

Submission summary for study: {{study_title}}



{% if investigation_type %} {% if level != 'danger' and maintenance is None %} -
- What kind of submission do you want to do? - -

- + {% if allow_submission %} +
+ What kind of submission do you want to do? + +

+ + {% else %} + {% raw ebi_disabled_msg %} + {% end %} {% end %} {% else %} You need to set an investigation type to continue! diff --git a/qiita_pet/templates/study_description.html b/qiita_pet/templates/study_description.html index 20f39ba01..d8f8f0de1 100644 --- a/qiita_pet/templates/study_description.html +++ b/qiita_pet/templates/study_description.html @@ -607,7 +607,7 @@

{{study_alias}}

{% module PreprocessedDataTab(study, full_access) %} - {% module ProcessedDataTab(study, full_access) %} + {% module ProcessedDataTab(study, full_access, allow_approval, approval_deny_msg) %} {% end %} diff --git a/qiita_pet/templates/study_description_templates/prep_template_panel.html b/qiita_pet/templates/study_description_templates/prep_template_panel.html index 777a5a991..9923b24cc 100644 --- a/qiita_pet/templates/study_description_templates/prep_template_panel.html +++ b/qiita_pet/templates/study_description_templates/prep_template_panel.html @@ -88,7 +88,11 @@


{% if not preprocessed_data or preprocessing_status.startswith('failed') %} {% if study_status == 'sandbox' %} - Preprocess + {% if show_preprocess_btn %} + Preprocess + {% else %} + {{ no_preprocess_msg }} + {% end %} {% end %}
Status: {{preprocessing_status}} diff --git a/qiita_pet/templates/study_description_templates/processed_data_info_tab.html b/qiita_pet/templates/study_description_templates/processed_data_info_tab.html index 532c70a56..e3174bf55 100644 --- a/qiita_pet/templates/study_description_templates/processed_data_info_tab.html +++ b/qiita_pet/templates/study_description_templates/processed_data_info_tab.html @@ -15,7 +15,11 @@ {% end %} {% if btn_to_show == 'request_approval' %} - Request making this data private + {% if allow_approval %} + Request making this data private + {% else %} + {{ approval_deny_msg }} + {% end %} {% elif btn_to_show == 'approve' %} Approve this data to be private {% elif btn_to_show == 'make_public' %} diff --git a/qiita_pet/templates/study_description_templates/processed_data_tab.html b/qiita_pet/templates/study_description_templates/processed_data_tab.html index 7709fbf9f..be2cec896 100644 --- a/qiita_pet/templates/study_description_templates/processed_data_tab.html +++ b/qiita_pet/templates/study_description_templates/processed_data_tab.html @@ -23,7 +23,7 @@ {% for pd_id, pd, _ in available_processed_data %} - {% module ProcessedDataInfoTab(study_id, pd) %} + {% module ProcessedDataInfoTab(study_id, pd, allow_approval, approval_deny_msg) %} {% end %} {% else %} diff --git a/qiita_pet/templates/study_description_templates/raw_data_editor_tab.html b/qiita_pet/templates/study_description_templates/raw_data_editor_tab.html index 0d02c6dfb..e8bd3ef21 100644 --- a/qiita_pet/templates/study_description_templates/raw_data_editor_tab.html +++ b/qiita_pet/templates/study_description_templates/raw_data_editor_tab.html @@ -73,7 +73,7 @@

Add prep template to this raw data

Prep templates uploaded

{% for prep in available_prep_templates %} - {% module PrepTemplatePanel(prep, study_id, is_editable, ena_terms, study_status, user_defined_terms) %} + {% module PrepTemplatePanel(prep, study_id, is_editable, ena_terms, study_status, user_defined_terms, raw_data_files) %} {% end %}
diff --git a/qiita_pet/uimodules/processed_data_tab.py b/qiita_pet/uimodules/processed_data_tab.py index f6b222b2d..247fd2b81 100644 --- a/qiita_pet/uimodules/processed_data_tab.py +++ b/qiita_pet/uimodules/processed_data_tab.py @@ -13,7 +13,7 @@ class ProcessedDataTab(BaseUIModule): - def render(self, study, full_access): + def render(self, study, full_access, allow_approval, approval_deny_msg): pd_gen = (ProcessedData(pd_id) for pd_id in study.processed_data()) avail_pd = [(pd.id, pd, STATUS_STYLER[pd.status]) for pd in pd_gen if full_access or pd.status == 'public'] @@ -21,11 +21,14 @@ def render(self, study, full_access): return self.render_string( "study_description_templates/processed_data_tab.html", available_processed_data=avail_pd, - study_id=study.id) + study_id=study.id, + allow_approval=allow_approval, + approval_deny_msg=approval_deny_msg) class ProcessedDataInfoTab(BaseUIModule): - def render(self, study_id, processed_data): + def render(self, study_id, processed_data, allow_approval, + approval_deny_msg): user = self.current_user # The request approval, approve processed data and make public buttons # are mutually exclusive. Only one of them will be shown, depending on @@ -65,4 +68,6 @@ def render(self, study_id, processed_data): filepaths=filepaths, is_local_request=is_local_request, btn_to_show=btn_to_show, - show_revert_btn=show_revert_btn) + show_revert_btn=show_revert_btn, + allow_approval=allow_approval, + approval_deny_msg=approval_deny_msg) diff --git a/qiita_pet/uimodules/raw_data_tab.py b/qiita_pet/uimodules/raw_data_tab.py index b58882eb2..495309bd3 100644 --- a/qiita_pet/uimodules/raw_data_tab.py +++ b/qiita_pet/uimodules/raw_data_tab.py @@ -16,7 +16,8 @@ from qiita_db.study import Study from qiita_db.data import RawData from qiita_db.ontology import Ontology -from qiita_db.metadata_template import PrepTemplate +from qiita_db.metadata_template import (PrepTemplate, TARGET_GENE_DATA_TYPES, + PREP_TEMPLATE_COLUMNS_TARGET_GENE) from qiita_db.parameters import (Preprocessed454Params, PreprocessedIlluminaParams) from qiita_pet.util import STATUS_STYLER @@ -166,7 +167,7 @@ def render(self, study, raw_data, full_access): class PrepTemplatePanel(BaseUIModule): def render(self, prep, study_id, is_editable, ena_terms, - study_status, user_defined_terms): + study_status, user_defined_terms, raw_data_files): # Check if the request came from a local source is_local_request = self._is_local() @@ -203,6 +204,23 @@ def render(self, prep, study_id, is_editable, ena_terms, if 'qiime' in basename(fp) else "Prep template") filepaths = [(id_, fp, _fp_type(fp)) for id_, fp in filepaths] + # Check if the template have all the required columns for preprocessing + if prep.data_type() in TARGET_GENE_DATA_TYPES: + key = ('demultiplex_multiple' if len(raw_data_files) > 2 + else 'demultiplex') + missing_cols = prep.check_restrictions( + [PREP_TEMPLATE_COLUMNS_TARGET_GENE[key]]) + show_preprocess_btn = len(missing_cols) == 0 + if not show_preprocess_btn: + no_preprocess_msg = ( + "Preprocessing disabled due to missing columns in the " + "prep template: %s" % ', '.join(missing_cols)) + else: + no_preprocess_msg = None + else: + show_preprocess_btn = True + no_preprocess_msg = None + return self.render_string( "study_description_templates/prep_template_panel.html", prep_id=prep_id, @@ -220,7 +238,9 @@ def render(self, prep, study_id, is_editable, ena_terms, ena_terms=ena_terms, study_status=study_status, user_defined_terms=user_defined_terms, - preprocess_options=preprocess_options) + preprocess_options=preprocess_options, + show_preprocess_btn=show_preprocess_btn, + no_preprocess_msg=no_preprocess_msg) class EditInvestigationType(BaseUIModule):