Skip to content

Commit 47e97c8

Browse files
Merge pull request #3191 from antgonza/rm-specimen_id
rm specimen_id
2 parents 2a341b5 + bae2956 commit 47e97c8

File tree

11 files changed

+16
-245
lines changed

11 files changed

+16
-245
lines changed

qiita_db/metadata_template/base_metadata_template.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,6 @@ def delete_column(self, column_name):
726726
If the `column_name` doesn't exist
727727
QiitaDBOperationNotPermittedError
728728
If a the info file can't be updated
729-
If the column_name is selected as a specimen_id_column in the
730-
study.
731729
"""
732730
if column_name not in self.categories:
733731
raise qdb.exceptions.QiitaDBColumnError(
@@ -736,14 +734,6 @@ def delete_column(self, column_name):
736734
raise qdb.exceptions.QiitaDBOperationNotPermittedError(
737735
'%s cannot be deleted' % column_name)
738736

739-
# if a tube identifier column is selected disallow its deletion
740-
specimen_id_column = qdb.study.Study(self.study_id).specimen_id_column
741-
if specimen_id_column == column_name:
742-
raise qdb.exceptions.QiitaDBOperationNotPermittedError(
743-
'"%s" cannot be deleted, this column is currently selected'
744-
' as the tube identifier (specimen_id_column)' %
745-
column_name)
746-
747737
with qdb.sql_connection.TRN:
748738
table_name = 'qiita.{0}{1}'.format(self._table_prefix, self._id)
749739
# deleting from all samples; note that (-) in pgsql jsonb means

qiita_db/metadata_template/test/test_sample_template.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,19 +2256,6 @@ def test_delete_column(self):
22562256
st.delete_column('dna_extracted')
22572257
self.assertNotIn('dna_extracted', st.categories)
22582258

2259-
def test_delete_column_specimen_id(self):
2260-
st = qdb.metadata_template.sample_template.SampleTemplate.create(
2261-
self.metadata, self.new_study)
2262-
self.new_study.specimen_id_column = 'latitude'
2263-
2264-
with self.assertRaisesRegex(
2265-
qdb.exceptions.QiitaDBOperationNotPermittedError,
2266-
'"latitude" cannot be deleted, this column is currently '
2267-
r'selected as the tube identifier \(specimen_id_column\)'):
2268-
st.delete_column('latitude')
2269-
2270-
self.new_study.specimen_id_column = None
2271-
22722259
def test_delete_samples(self):
22732260
QE = qdb.exceptions
22742261
st = qdb.metadata_template.sample_template.SampleTemplate(1)

qiita_db/study.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class Study(qdb.base.QiitaObject):
5656
status
5757
title
5858
owner
59-
specimen_id_column
6059
autoloaded
6160
6261
Methods
@@ -778,62 +777,6 @@ def publications(self, values):
778777
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
779778
qdb.sql_connection.TRN.execute()
780779

781-
@property
782-
def specimen_id_column(self):
783-
"""Returns the specimen identifier column
784-
785-
Returns
786-
-------
787-
str
788-
The name of the specimen id column
789-
"""
790-
with qdb.sql_connection.TRN:
791-
sql = """SELECT specimen_id_column
792-
FROM qiita.study
793-
WHERE study_id = %s"""
794-
qdb.sql_connection.TRN.add(sql, [self._id])
795-
return qdb.sql_connection.TRN.execute_fetchlast()
796-
797-
@specimen_id_column.setter
798-
def specimen_id_column(self, value):
799-
"""Sets the specimen identifier column
800-
801-
Parameters
802-
----------
803-
value : str
804-
The name of the column with the specimen identifiers.
805-
806-
Raises
807-
------
808-
QiitaDBLookupError
809-
If value is not in the sample information for this study.
810-
If the study does not have sample information.
811-
QiitaDBColumnError
812-
Category is not unique.
813-
"""
814-
st = self.sample_template
815-
if st is None:
816-
raise qdb.exceptions.QiitaDBLookupError("Study does not have a "
817-
"sample information.")
818-
819-
if value is not None:
820-
if value not in st.categories:
821-
raise qdb.exceptions.QiitaDBLookupError("Category '%s' is not "
822-
"present in the sample"
823-
" information."
824-
% value)
825-
826-
observed_values = st.get_category(value)
827-
if len(observed_values) != len(set(observed_values.values())):
828-
raise qdb.exceptions.QiitaDBColumnError("The category does not"
829-
" contain unique "
830-
"values.")
831-
832-
sql = """UPDATE qiita.study SET
833-
specimen_id_column = %s
834-
WHERE study_id = %s"""
835-
qdb.sql_connection.perform_as_transaction(sql, [value, self._id])
836-
837780
@property
838781
def investigation(self):
839782
""" Returns Investigation this study is part of

qiita_db/support_files/patches/85.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ ALTER TABLE qiita.default_workflow
2121
FOREIGN KEY (artifact_type_id)
2222
REFERENCES qiita.artifact_type(artifact_type_id)
2323
ON UPDATE CASCADE;
24+
25+
-- Mar 17, 2022
26+
-- deleting specimen_id_column from qiita.study
27+
28+
ALTER TABLE qiita.study DROP COLUMN specimen_id_column;

qiita_db/test/test_study.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def setUp(self):
150150
"study_abstract": "Exploring how a high fat diet changes the "
151151
"gut microbiome",
152152
"principal_investigator_id": qdb.study.StudyPerson(3),
153-
"lab_person_id": qdb.study.StudyPerson(1),
154-
'specimen_id_column': None
153+
"lab_person_id": qdb.study.StudyPerson(1)
155154
}
156155

157156
self.infoexp = {
@@ -165,7 +164,6 @@ def setUp(self):
165164
"gut microbiome",
166165
"principal_investigator": qdb.study.StudyPerson(3),
167166
"lab_person": qdb.study.StudyPerson(1),
168-
'specimen_id_column': None,
169167
'public_raw_download': False
170168
}
171169

@@ -193,8 +191,7 @@ def setUp(self):
193191
'study_description': 'Analysis of the Cannabis Plant Microbiome',
194192
'study_alias': 'Cannabis Soils',
195193
'most_recent_contact': datetime(2014, 5, 19, 16, 11),
196-
'lab_person': qdb.study.StudyPerson(1),
197-
'specimen_id_column': None}
194+
'lab_person': qdb.study.StudyPerson(1)}
198195

199196
def tearDown(self):
200197
qiita_config.portal = self.portal
@@ -251,8 +248,7 @@ def test_get_info(self):
251248
'Soils',
252249
'ebi_submission_status': 'submitted',
253250
'ebi_study_accession': 'EBI123456-BB',
254-
'autoloaded': False,
255-
'specimen_id_column': None}
251+
'autoloaded': False}
256252
self.assertDictEqual(obs, exp)
257253

258254
# Test get specific keys for single study
@@ -446,8 +442,7 @@ def test_create_study_min_data(self):
446442
'study_alias': 'FCM',
447443
'most_recent_contact': None,
448444
'lab_person': qdb.study.StudyPerson(1),
449-
'notes': '',
450-
'specimen_id_column': None}
445+
'notes': ''}
451446
self.assertEqual(obs_info, exp)
452447
# Check the timestamp separately, since it is set by the database
453448
# to the microsecond, and we can't predict it a priori
@@ -529,8 +524,7 @@ def test_create_study_all_data(self):
529524
'study_alias': 'FCM',
530525
'most_recent_contact': None,
531526
'lab_person': qdb.study.StudyPerson(1),
532-
'notes': 'an analysis was performed \n here and \n here',
533-
'specimen_id_column': None}
527+
'notes': 'an analysis was performed \n here and \n here'}
534528
self.assertEqual(obs.info, exp)
535529
self.assertEqual(obs.shared_with, [])
536530
self.assertEqual(obs.publications, [])
@@ -912,31 +906,6 @@ def test_study_tags(self):
912906
self.assertEqual(study.tags, [])
913907
self.assertEqual(message, '')
914908

915-
def test_specimen_id_column_get_set(self):
916-
self.assertEqual(self.study.specimen_id_column, None)
917-
self.study.specimen_id_column = 'anonymized_name'
918-
self.assertEqual(self.study.specimen_id_column, 'anonymized_name')
919-
self.study.specimen_id_column = None
920-
self.assertEqual(self.study.specimen_id_column, None)
921-
922-
def test_specimen_id_column_not_unique(self):
923-
with self.assertRaises(qdb.exceptions.QiitaDBColumnError):
924-
self.study.specimen_id_column = 'dna_extracted'
925-
926-
def test_specimen_id_column_doesnt_exist(self):
927-
with self.assertRaises(qdb.exceptions.QiitaDBLookupError):
928-
self.study.specimen_id_column = 'foo'
929-
930-
def test_specimen_id_column_no_sample_information(self):
931-
empty = qdb.study.Study.create(
932-
qdb.user.User('[email protected]'), "Fried duck microbiome",
933-
self.info)
934-
with self.assertRaises(qdb.exceptions.QiitaDBLookupError):
935-
empty.specimen_id_column = 'foo'
936-
937-
# cleaning up the created study
938-
qdb.study.Study.delete(empty._id)
939-
940909

941910
if __name__ == "__main__":
942911
main()

qiita_pet/handlers/api_proxy/studies.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,6 @@ def study_patch_request(user_id, study_id,
455455
message = study.update_tags(User(user_id), req_value)
456456
return {'status': 'success',
457457
'message': message}
458-
elif attribute == 'specimen_id_column':
459-
try:
460-
study.specimen_id_column = req_value
461-
return {'status': 'success',
462-
'message': 'Successfully updated specimen id column'}
463-
except (QiitaDBLookupError, QiitaDBColumnError) as e:
464-
return {'status': 'error',
465-
'message': str(e)}
466458
elif attribute == 'toggle_public_raw_download':
467459
try:
468460
study.public_raw_download = not study.public_raw_download

qiita_pet/handlers/api_proxy/tests/test_studies.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_study_get_req(self):
7373
'rhizospheres from the same location at different time '
7474
'points in the plant lifecycle.'),
7575
'status': 'private', 'spatial_series': False,
76-
'specimen_id_column': None, 'public_raw_download': False,
76+
'public_raw_download': False,
7777
'study_description': (
7878
'Analysis of the Cannabis Plant Microbiome'),
7979
'shared_with': ['[email protected]'], 'publication_doi': [
@@ -127,7 +127,7 @@ def test_study_get_req(self):
127127
'email': '[email protected]'}, 'study_alias': 'FCM',
128128
'study_id': new_study.id, 'notes': '',
129129
'most_recent_contact': datetime(2015, 5, 19, 16, 11),
130-
'ebi_study_accession': None, 'specimen_id_column': None,
130+
'ebi_study_accession': None,
131131
'study_title': 'Some New Study for test'}, 'message': '',
132132
'editable': True}
133133
self.assertCountEqual(obs, exp)
@@ -465,38 +465,6 @@ def test_study_patch_request_errors(self):
465465
'path parameter'), 'status': 'error'}
466466
self.assertEqual(obs, exp)
467467

468-
def test_study_patch_request_specimen_id(self):
469-
obs = study_patch_request('[email protected]', 1,
470-
'replace', '/specimen_id_column',
471-
'anonymized_name')
472-
exp = {'status': 'success', 'message': 'Successfully updated '
473-
'specimen id column'}
474-
self.assertEqual(obs, exp)
475-
476-
obs = study_patch_request('[email protected]', 1,
477-
'replace', '/specimen_id_column',
478-
'host_subject_id')
479-
exp = {'status': 'success', 'message': 'Successfully updated '
480-
'specimen id column'}
481-
self.assertEqual(obs, exp)
482-
483-
qdb.study.Study(1).specimen_id_column = None
484-
485-
def test_study_patch_request_specimen_id_errors(self):
486-
obs = study_patch_request('[email protected]', 1,
487-
'replace', '/specimen_id_column',
488-
'taxon_id')
489-
exp = {'status': 'error', 'message': 'The category does not contain'
490-
' unique values.'}
491-
self.assertEqual(obs, exp)
492-
493-
obs = study_patch_request('[email protected]', 1,
494-
'replace', '/specimen_id_column',
495-
'bleep_bloop')
496-
exp = {'status': 'error', 'message': "Category 'bleep_bloop' is not"
497-
" present in the sample information."}
498-
self.assertEqual(obs, exp)
499-
500468
def test_study_patch_request_toggle_public_raw_download(self):
501469
study_id = 1
502470
study = qdb.study.Study(study_id)
@@ -508,14 +476,6 @@ def test_study_patch_request_toggle_public_raw_download(self):
508476
self.assertEqual(obs, exp)
509477
self.assertTrue(study.public_raw_download)
510478

511-
obs = study_patch_request('[email protected]', study_id,
512-
'replace', '/specimen_id_column',
513-
'host_subject_id')
514-
exp = {'status': 'error',
515-
'message': 'User does not have access to study'}
516-
self.assertEqual(obs, exp)
517-
self.assertTrue(study.public_raw_download)
518-
519479
# returning to default status
520480
study.public_raw_download = False
521481

qiita_pet/handlers/study_handlers/sample_template.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ def sample_template_overview_handler_get_request(study_id, user):
359359
num_samples = 0
360360
num_cols = 0
361361
columns = []
362-
specimen_id_column = None
363362
sample_restrictions = ''
364363
if exists:
365364
# If it exists we need to provide:
@@ -379,7 +378,6 @@ def sample_template_overview_handler_get_request(study_id, user):
379378
columns = st.categories
380379
# The number of columns
381380
num_cols = len(columns)
382-
specimen_id_column = Study(study_id).specimen_id_column
383381
_, sample_restrictions = st.validate_restrictions()
384382
else:
385383
# 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):
396394
'num_samples': num_samples,
397395
'num_columns': num_cols,
398396
'columns': columns,
399-
'sample_restrictions': sample_restrictions,
400-
'specimen_id_column': specimen_id_column}
397+
'sample_restrictions': sample_restrictions}
401398

402399

403400
class SampleTemplateOverviewHandler(BaseHandler):

qiita_pet/handlers/study_handlers/tests/test_base.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ def test_patch_not_allowed(self):
104104
data=arguments, asjson=True)
105105
self.assertEqual(obs.code, 405)
106106

107-
def test_patch_specimen_id_column(self):
108-
data = {'op': 'replace', 'path': '/specimen_id_column',
109-
'value': "anonymized_name"}
110-
obs = self.patch('/study/1', headers=self.header,
111-
data=data, asjson=True)
112-
self.assertEqual(obs.code, 200)
113-
self.assertEqual(json_decode(obs.body), {"status": "success",
114-
"message": "Successfully updated specimen id column"})
115-
116107

117108
if __name__ == "__main__":
118109
main()

qiita_pet/handlers/study_handlers/tests/test_sample_template.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ def test_sample_template_overview_handler_get_request(self):
296296
'sample_type', 'collection_timestamp',
297297
'host_subject_id', 'description', 'latitude',
298298
'longitude', 'scientific_name', 'env_package']),
299-
'sample_restrictions': '',
300-
'specimen_id_column': None}
299+
'sample_restrictions': ''}
301300
self.assertEqual(obs, exp)
302301

303302
# Test sample template doesn't exist
@@ -317,8 +316,7 @@ def test_sample_template_overview_handler_get_request(self):
317316
'num_samples': 0,
318317
'num_columns': 0,
319318
'columns': [],
320-
'sample_restrictions': '',
321-
'specimen_id_column': None}
319+
'sample_restrictions': ''}
322320
self.assertEqual(obs, exp)
323321

324322
def test_sample_template_columns_get_req(self):
@@ -511,8 +509,7 @@ def test_get(self):
511509
'sample_type', 'collection_timestamp',
512510
'host_subject_id', 'description', 'latitude',
513511
'longitude', 'scientific_name', 'env_package']),
514-
'sample_restrictions': '',
515-
'specimen_id_column': None}
512+
'sample_restrictions': ''}
516513
self.assertDictEqual(obs, exp)
517514

518515

0 commit comments

Comments
 (0)