From bae29561d9e95440390e07ee9752095babecabe4 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Thu, 17 Mar 2022 07:13:59 -0600 Subject: [PATCH] rm specimen_id --- .../base_metadata_template.py | 10 ---- .../test/test_sample_template.py | 13 ---- qiita_db/study.py | 57 ------------------ qiita_db/support_files/patches/85.sql | 5 ++ qiita_db/test/test_study.py | 41 ++----------- qiita_pet/handlers/api_proxy/studies.py | 8 --- .../handlers/api_proxy/tests/test_studies.py | 44 +------------- .../study_handlers/sample_template.py | 5 +- .../study_handlers/tests/test_base.py | 9 --- .../tests/test_sample_template.py | 9 +-- qiita_pet/static/js/sampleTemplateVue.js | 60 ------------------- 11 files changed, 16 insertions(+), 245 deletions(-) diff --git a/qiita_db/metadata_template/base_metadata_template.py b/qiita_db/metadata_template/base_metadata_template.py index b06138999..cb2bdba9e 100644 --- a/qiita_db/metadata_template/base_metadata_template.py +++ b/qiita_db/metadata_template/base_metadata_template.py @@ -726,8 +726,6 @@ def delete_column(self, column_name): If the `column_name` doesn't exist QiitaDBOperationNotPermittedError If a the info file can't be updated - If the column_name is selected as a specimen_id_column in the - study. """ if column_name not in self.categories: raise qdb.exceptions.QiitaDBColumnError( @@ -736,14 +734,6 @@ def delete_column(self, column_name): raise qdb.exceptions.QiitaDBOperationNotPermittedError( '%s cannot be deleted' % column_name) - # if a tube identifier column is selected disallow its deletion - specimen_id_column = qdb.study.Study(self.study_id).specimen_id_column - if specimen_id_column == column_name: - raise qdb.exceptions.QiitaDBOperationNotPermittedError( - '"%s" cannot be deleted, this column is currently selected' - ' as the tube identifier (specimen_id_column)' % - column_name) - with qdb.sql_connection.TRN: table_name = 'qiita.{0}{1}'.format(self._table_prefix, self._id) # deleting from all samples; note that (-) in pgsql jsonb means diff --git a/qiita_db/metadata_template/test/test_sample_template.py b/qiita_db/metadata_template/test/test_sample_template.py index cbdde85cc..33c2fca2d 100644 --- a/qiita_db/metadata_template/test/test_sample_template.py +++ b/qiita_db/metadata_template/test/test_sample_template.py @@ -2256,19 +2256,6 @@ def test_delete_column(self): st.delete_column('dna_extracted') self.assertNotIn('dna_extracted', st.categories) - def test_delete_column_specimen_id(self): - st = qdb.metadata_template.sample_template.SampleTemplate.create( - self.metadata, self.new_study) - self.new_study.specimen_id_column = 'latitude' - - with self.assertRaisesRegex( - qdb.exceptions.QiitaDBOperationNotPermittedError, - '"latitude" cannot be deleted, this column is currently ' - r'selected as the tube identifier \(specimen_id_column\)'): - st.delete_column('latitude') - - self.new_study.specimen_id_column = None - def test_delete_samples(self): QE = qdb.exceptions st = qdb.metadata_template.sample_template.SampleTemplate(1) diff --git a/qiita_db/study.py b/qiita_db/study.py index 2aa6111c5..30394853f 100644 --- a/qiita_db/study.py +++ b/qiita_db/study.py @@ -56,7 +56,6 @@ class Study(qdb.base.QiitaObject): status title owner - specimen_id_column autoloaded Methods @@ -778,62 +777,6 @@ def publications(self, values): qdb.sql_connection.TRN.add(sql, sql_args, many=True) qdb.sql_connection.TRN.execute() - @property - def specimen_id_column(self): - """Returns the specimen identifier column - - Returns - ------- - str - The name of the specimen id column - """ - with qdb.sql_connection.TRN: - sql = """SELECT specimen_id_column - FROM qiita.study - WHERE study_id = %s""" - qdb.sql_connection.TRN.add(sql, [self._id]) - return qdb.sql_connection.TRN.execute_fetchlast() - - @specimen_id_column.setter - def specimen_id_column(self, value): - """Sets the specimen identifier column - - Parameters - ---------- - value : str - The name of the column with the specimen identifiers. - - Raises - ------ - QiitaDBLookupError - If value is not in the sample information for this study. - If the study does not have sample information. - QiitaDBColumnError - Category is not unique. - """ - st = self.sample_template - if st is None: - raise qdb.exceptions.QiitaDBLookupError("Study does not have a " - "sample information.") - - if value is not None: - if value not in st.categories: - raise qdb.exceptions.QiitaDBLookupError("Category '%s' is not " - "present in the sample" - " information." - % value) - - observed_values = st.get_category(value) - if len(observed_values) != len(set(observed_values.values())): - raise qdb.exceptions.QiitaDBColumnError("The category does not" - " contain unique " - "values.") - - sql = """UPDATE qiita.study SET - specimen_id_column = %s - WHERE study_id = %s""" - qdb.sql_connection.perform_as_transaction(sql, [value, self._id]) - @property def investigation(self): """ Returns Investigation this study is part of diff --git a/qiita_db/support_files/patches/85.sql b/qiita_db/support_files/patches/85.sql index c4d1c2653..633158047 100644 --- a/qiita_db/support_files/patches/85.sql +++ b/qiita_db/support_files/patches/85.sql @@ -21,3 +21,8 @@ ALTER TABLE qiita.default_workflow FOREIGN KEY (artifact_type_id) REFERENCES qiita.artifact_type(artifact_type_id) ON UPDATE CASCADE; + +-- Mar 17, 2022 +-- deleting specimen_id_column from qiita.study + +ALTER TABLE qiita.study DROP COLUMN specimen_id_column; diff --git a/qiita_db/test/test_study.py b/qiita_db/test/test_study.py index 7cfcdd8d7..23663046d 100644 --- a/qiita_db/test/test_study.py +++ b/qiita_db/test/test_study.py @@ -150,8 +150,7 @@ def setUp(self): "study_abstract": "Exploring how a high fat diet changes the " "gut microbiome", "principal_investigator_id": qdb.study.StudyPerson(3), - "lab_person_id": qdb.study.StudyPerson(1), - 'specimen_id_column': None + "lab_person_id": qdb.study.StudyPerson(1) } self.infoexp = { @@ -165,7 +164,6 @@ def setUp(self): "gut microbiome", "principal_investigator": qdb.study.StudyPerson(3), "lab_person": qdb.study.StudyPerson(1), - 'specimen_id_column': None, 'public_raw_download': False } @@ -193,8 +191,7 @@ def setUp(self): 'study_description': 'Analysis of the Cannabis Plant Microbiome', 'study_alias': 'Cannabis Soils', 'most_recent_contact': datetime(2014, 5, 19, 16, 11), - 'lab_person': qdb.study.StudyPerson(1), - 'specimen_id_column': None} + 'lab_person': qdb.study.StudyPerson(1)} def tearDown(self): qiita_config.portal = self.portal @@ -251,8 +248,7 @@ def test_get_info(self): 'Soils', 'ebi_submission_status': 'submitted', 'ebi_study_accession': 'EBI123456-BB', - 'autoloaded': False, - 'specimen_id_column': None} + 'autoloaded': False} self.assertDictEqual(obs, exp) # Test get specific keys for single study @@ -446,8 +442,7 @@ def test_create_study_min_data(self): 'study_alias': 'FCM', 'most_recent_contact': None, 'lab_person': qdb.study.StudyPerson(1), - 'notes': '', - 'specimen_id_column': None} + 'notes': ''} self.assertEqual(obs_info, exp) # Check the timestamp separately, since it is set by the database # to the microsecond, and we can't predict it a priori @@ -529,8 +524,7 @@ def test_create_study_all_data(self): 'study_alias': 'FCM', 'most_recent_contact': None, 'lab_person': qdb.study.StudyPerson(1), - 'notes': 'an analysis was performed \n here and \n here', - 'specimen_id_column': None} + 'notes': 'an analysis was performed \n here and \n here'} self.assertEqual(obs.info, exp) self.assertEqual(obs.shared_with, []) self.assertEqual(obs.publications, []) @@ -912,31 +906,6 @@ def test_study_tags(self): self.assertEqual(study.tags, []) self.assertEqual(message, '') - def test_specimen_id_column_get_set(self): - self.assertEqual(self.study.specimen_id_column, None) - self.study.specimen_id_column = 'anonymized_name' - self.assertEqual(self.study.specimen_id_column, 'anonymized_name') - self.study.specimen_id_column = None - self.assertEqual(self.study.specimen_id_column, None) - - def test_specimen_id_column_not_unique(self): - with self.assertRaises(qdb.exceptions.QiitaDBColumnError): - self.study.specimen_id_column = 'dna_extracted' - - def test_specimen_id_column_doesnt_exist(self): - with self.assertRaises(qdb.exceptions.QiitaDBLookupError): - self.study.specimen_id_column = 'foo' - - def test_specimen_id_column_no_sample_information(self): - empty = qdb.study.Study.create( - qdb.user.User('test@foo.bar'), "Fried duck microbiome", - self.info) - with self.assertRaises(qdb.exceptions.QiitaDBLookupError): - empty.specimen_id_column = 'foo' - - # cleaning up the created study - qdb.study.Study.delete(empty._id) - if __name__ == "__main__": main() diff --git a/qiita_pet/handlers/api_proxy/studies.py b/qiita_pet/handlers/api_proxy/studies.py index ec65d6bcd..431583c57 100644 --- a/qiita_pet/handlers/api_proxy/studies.py +++ b/qiita_pet/handlers/api_proxy/studies.py @@ -455,14 +455,6 @@ def study_patch_request(user_id, study_id, message = study.update_tags(User(user_id), req_value) return {'status': 'success', 'message': message} - elif attribute == 'specimen_id_column': - try: - study.specimen_id_column = req_value - return {'status': 'success', - 'message': 'Successfully updated specimen id column'} - except (QiitaDBLookupError, QiitaDBColumnError) as e: - return {'status': 'error', - 'message': str(e)} elif attribute == 'toggle_public_raw_download': try: study.public_raw_download = not study.public_raw_download diff --git a/qiita_pet/handlers/api_proxy/tests/test_studies.py b/qiita_pet/handlers/api_proxy/tests/test_studies.py index d45173f77..ff70896ac 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_studies.py +++ b/qiita_pet/handlers/api_proxy/tests/test_studies.py @@ -73,7 +73,7 @@ def test_study_get_req(self): 'rhizospheres from the same location at different time ' 'points in the plant lifecycle.'), 'status': 'private', 'spatial_series': False, - 'specimen_id_column': None, 'public_raw_download': False, + 'public_raw_download': False, 'study_description': ( 'Analysis of the Cannabis Plant Microbiome'), 'shared_with': ['shared@foo.bar'], 'publication_doi': [ @@ -127,7 +127,7 @@ def test_study_get_req(self): 'email': 'PI_dude@foo.bar'}, 'study_alias': 'FCM', 'study_id': new_study.id, 'notes': '', 'most_recent_contact': datetime(2015, 5, 19, 16, 11), - 'ebi_study_accession': None, 'specimen_id_column': None, + 'ebi_study_accession': None, 'study_title': 'Some New Study for test'}, 'message': '', 'editable': True} self.assertCountEqual(obs, exp) @@ -465,38 +465,6 @@ def test_study_patch_request_errors(self): 'path parameter'), 'status': 'error'} self.assertEqual(obs, exp) - def test_study_patch_request_specimen_id(self): - obs = study_patch_request('shared@foo.bar', 1, - 'replace', '/specimen_id_column', - 'anonymized_name') - exp = {'status': 'success', 'message': 'Successfully updated ' - 'specimen id column'} - self.assertEqual(obs, exp) - - obs = study_patch_request('shared@foo.bar', 1, - 'replace', '/specimen_id_column', - 'host_subject_id') - exp = {'status': 'success', 'message': 'Successfully updated ' - 'specimen id column'} - self.assertEqual(obs, exp) - - qdb.study.Study(1).specimen_id_column = None - - def test_study_patch_request_specimen_id_errors(self): - obs = study_patch_request('shared@foo.bar', 1, - 'replace', '/specimen_id_column', - 'taxon_id') - exp = {'status': 'error', 'message': 'The category does not contain' - ' unique values.'} - self.assertEqual(obs, exp) - - obs = study_patch_request('shared@foo.bar', 1, - 'replace', '/specimen_id_column', - 'bleep_bloop') - exp = {'status': 'error', 'message': "Category 'bleep_bloop' is not" - " present in the sample information."} - self.assertEqual(obs, exp) - def test_study_patch_request_toggle_public_raw_download(self): study_id = 1 study = qdb.study.Study(study_id) @@ -508,14 +476,6 @@ def test_study_patch_request_toggle_public_raw_download(self): self.assertEqual(obs, exp) self.assertTrue(study.public_raw_download) - obs = study_patch_request('demo@microbio.me', study_id, - 'replace', '/specimen_id_column', - 'host_subject_id') - exp = {'status': 'error', - 'message': 'User does not have access to study'} - self.assertEqual(obs, exp) - self.assertTrue(study.public_raw_download) - # returning to default status study.public_raw_download = False diff --git a/qiita_pet/handlers/study_handlers/sample_template.py b/qiita_pet/handlers/study_handlers/sample_template.py index 3297074f8..8fa81f861 100644 --- a/qiita_pet/handlers/study_handlers/sample_template.py +++ b/qiita_pet/handlers/study_handlers/sample_template.py @@ -359,7 +359,6 @@ def sample_template_overview_handler_get_request(study_id, user): num_samples = 0 num_cols = 0 columns = [] - specimen_id_column = None sample_restrictions = '' if exists: # If it exists we need to provide: @@ -379,7 +378,6 @@ def sample_template_overview_handler_get_request(study_id, user): columns = st.categories # The number of columns num_cols = len(columns) - specimen_id_column = Study(study_id).specimen_id_column _, sample_restrictions = st.validate_restrictions() else: # It doesn't exist, we also need to provide the data_types in case @@ -396,8 +394,7 @@ def sample_template_overview_handler_get_request(study_id, user): 'num_samples': num_samples, 'num_columns': num_cols, 'columns': columns, - 'sample_restrictions': sample_restrictions, - 'specimen_id_column': specimen_id_column} + 'sample_restrictions': sample_restrictions} class SampleTemplateOverviewHandler(BaseHandler): diff --git a/qiita_pet/handlers/study_handlers/tests/test_base.py b/qiita_pet/handlers/study_handlers/tests/test_base.py index 66d84b246..9ea3c142e 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_base.py +++ b/qiita_pet/handlers/study_handlers/tests/test_base.py @@ -104,15 +104,6 @@ def test_patch_not_allowed(self): data=arguments, asjson=True) self.assertEqual(obs.code, 405) - def test_patch_specimen_id_column(self): - data = {'op': 'replace', 'path': '/specimen_id_column', - 'value': "anonymized_name"} - obs = self.patch('/study/1', headers=self.header, - data=data, asjson=True) - self.assertEqual(obs.code, 200) - self.assertEqual(json_decode(obs.body), {"status": "success", - "message": "Successfully updated specimen id column"}) - if __name__ == "__main__": main() diff --git a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py index f1573c62c..faf83f3a7 100644 --- a/qiita_pet/handlers/study_handlers/tests/test_sample_template.py +++ b/qiita_pet/handlers/study_handlers/tests/test_sample_template.py @@ -296,8 +296,7 @@ def test_sample_template_overview_handler_get_request(self): 'sample_type', 'collection_timestamp', 'host_subject_id', 'description', 'latitude', 'longitude', 'scientific_name', 'env_package']), - 'sample_restrictions': '', - 'specimen_id_column': None} + 'sample_restrictions': ''} self.assertEqual(obs, exp) # Test sample template doesn't exist @@ -317,8 +316,7 @@ def test_sample_template_overview_handler_get_request(self): 'num_samples': 0, 'num_columns': 0, 'columns': [], - 'sample_restrictions': '', - 'specimen_id_column': None} + 'sample_restrictions': ''} self.assertEqual(obs, exp) def test_sample_template_columns_get_req(self): @@ -511,8 +509,7 @@ def test_get(self): 'sample_type', 'collection_timestamp', 'host_subject_id', 'description', 'latitude', 'longitude', 'scientific_name', 'env_package']), - 'sample_restrictions': '', - 'specimen_id_column': None} + 'sample_restrictions': ''} self.assertDictEqual(obs, exp) diff --git a/qiita_pet/static/js/sampleTemplateVue.js b/qiita_pet/static/js/sampleTemplateVue.js index 1e621f0c0..3f6c87e59 100644 --- a/qiita_pet/static/js/sampleTemplateVue.js +++ b/qiita_pet/static/js/sampleTemplateVue.js @@ -206,34 +206,6 @@ Vue.component('sample-template-page', { }); }, - /** - * Callback to update the specimen_id_column via a patch request - */ - updateSpecimenIDColumn: function() { - let vm = this, value = $('#specimen-id-select').val(); - - // change the empty value to null so that Python understands it as None - if (value === '') { - value = null; - } - - $.ajax({ - url: vm.portal + '/study/' + vm.studyId, - contentType: "application/json", - method: 'PATCH', - dataType: 'json', - data: JSON.stringify({'op': 'replace', - 'path': '/specimen_id_column', - 'value': value}), - success: function(data) { - bootstrapAlert(data.message, data.status === 'error' ? 'danger' : 'success', 10000); - }, - error: function (object, status, error_msg) { - bootstrapAlert("Error updating specimen id column: " + error_msg, "danger") - } - }); - }, - /** * * Performs a call to the server API to delete a column from the sample template @@ -508,37 +480,6 @@ Vue.component('sample-template-page', { $('#update-btn-div').show() } }); - - // add a dropdown menu to select the tube identifier column - $row = $('
').attr('id', 'update-specimen-id-div').addClass('row form-group').appendTo($tab); - - // tube identifier's label with a help badge - $('