Skip to content

Commit 45fa66a

Browse files
authored
fix #3300 (#3309)
* fix #3300 * update populate_test_db.sql * fix errors * fix test_prep_template.py * fix test_setup.py * addressing @charles-cowart and @wasade comments
1 parent a412b45 commit 45fa66a

File tree

8 files changed

+36
-68
lines changed

8 files changed

+36
-68
lines changed

qiita_db/metadata_template/prep_template.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ def create(cls, md_template, study, data_type, investigation_type=None,
122122
If a required column is missing in md_template
123123
"""
124124
with qdb.sql_connection.TRN:
125-
# If the investigation_type is supplied, make sure it is one of
126-
# the recognized investigation types
127-
if investigation_type is not None:
128-
cls.validate_investigation_type(investigation_type)
129-
130125
# Check if the data_type is the id or the string
131126
if isinstance(data_type, int):
132127
data_type_id = data_type
@@ -136,6 +131,18 @@ def create(cls, md_template, study, data_type, investigation_type=None,
136131
data_type_id = qdb.util.convert_to_id(data_type, "data_type")
137132
data_type_str = data_type
138133

134+
# If the investigation_type is None let's add it based on the
135+
# data_type being created - if possible
136+
if investigation_type is None:
137+
if data_type_str in TARGET_GENE_DATA_TYPES:
138+
investigation_type = 'Amplicon'
139+
elif data_type_str == 'Metagenomic':
140+
investigation_type = 'WGS'
141+
elif data_type_str == 'Metatranscriptomic':
142+
investigation_type = 'RNA-Seq'
143+
if investigation_type is not None:
144+
cls.validate_investigation_type(investigation_type)
145+
139146
pt_cols = PREP_TEMPLATE_COLUMNS
140147
if data_type_str in TARGET_GENE_DATA_TYPES:
141148
pt_cols = deepcopy(PREP_TEMPLATE_COLUMNS)

qiita_db/metadata_template/test/test_prep_template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def _common_creation_checks(self, pt, fp_count, name):
911911
self.assertEqual(pt.data_type(), self.data_type)
912912
self.assertEqual(pt.data_type(ret_id=True), self.data_type_id)
913913
self.assertEqual(pt.artifact, None)
914-
self.assertEqual(pt.investigation_type, None)
914+
self.assertEqual(pt.investigation_type, 'Amplicon')
915915
self.assertEqual(pt.study_id, self.test_study.id)
916916
self.assertEqual(pt.status, "sandbox")
917917
exp_sample_ids = {'%s.SKB8.640193' % self.test_study.id,
@@ -1076,7 +1076,7 @@ def test_create_warning(self):
10761076
self.assertEqual(pt.data_type(), self.data_type)
10771077
self.assertEqual(pt.data_type(ret_id=True), self.data_type_id)
10781078
self.assertEqual(pt.artifact, None)
1079-
self.assertEqual(pt.investigation_type, None)
1079+
self.assertEqual(pt.investigation_type, 'Amplicon')
10801080
self.assertEqual(pt.study_id, self.test_study.id)
10811081
self.assertEqual(pt.status, 'sandbox')
10821082
exp_sample_ids = {'%s.SKB8.640193' % self.test_study.id,
@@ -1247,7 +1247,7 @@ def test_investigation_type_setter(self):
12471247
"""Able to update the investigation type"""
12481248
pt = qdb.metadata_template.prep_template.PrepTemplate.create(
12491249
self.metadata, self.test_study, self.data_type_id)
1250-
self.assertEqual(pt.investigation_type, None)
1250+
self.assertEqual(pt.investigation_type, 'Amplicon')
12511251
pt.investigation_type = "Other"
12521252
self.assertEqual(pt.investigation_type, 'Other')
12531253
with self.assertRaises(qdb.exceptions.QiitaDBColumnError):
@@ -1258,8 +1258,8 @@ def test_investigation_type_setter(self):
12581258

12591259
def test_investigation_type_instance_setter(self):
12601260
pt = qdb.metadata_template.prep_template.PrepTemplate(1)
1261-
pt.investigation_type = 'RNASeq'
1262-
self.assertEqual(pt.investigation_type, 'RNASeq')
1261+
pt.investigation_type = 'RNA-Seq'
1262+
self.assertEqual(pt.investigation_type, 'RNA-Seq')
12631263

12641264
def test_deprecated_setter(self):
12651265
pt = qdb.metadata_template.prep_template.PrepTemplate(1)

qiita_db/support_files/populate_test_db.sql

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,10 @@ INSERT INTO qiita.analysis_users (analysis_id, email) VALUES (1, 'shared@foo.bar
480480
INSERT INTO qiita.ontology (ontology_id, ontology, fully_loaded, fullname, query_url, source_url, definition, load_date) VALUES (999999999, E'ENA', E'1', E'European Nucleotide Archive Submission Ontology', NULL, E'http://www.ebi.ac.uk/embl/Documentation/ENA-Reads.html', E'The ENA CV is to be used to annotate XML submissions to the ENA.', '2009-02-23 00:00:00');
481481

482482
-- Add some ontology values
483-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508974, 999999999, E'Whole Genome Sequencing', E'ENA:0000059', NULL, NULL, NULL, NULL, NULL);
483+
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508974, 999999999, E'WGS', E'ENA:0000059', NULL, NULL, NULL, NULL, NULL);
484484
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508975, 999999999, E'Metagenomics', E'ENA:0000060', NULL, NULL, NULL, NULL, NULL);
485-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508976, 999999999, E'Transcriptome Analysis', E'ENA:0000061', NULL, NULL, NULL, NULL, NULL);
486-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508977, 999999999, E'Resequencing', E'ENA:0000062', NULL, NULL, NULL, NULL, NULL);
487-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508978, 999999999, E'Epigenetics', E'ENA:0000066', NULL, NULL, NULL, NULL, NULL);
488-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508979, 999999999, E'Synthetic Genomics', E'ENA:0000067', NULL, NULL, NULL, NULL, NULL);
489-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508980, 999999999, E'Forensic or Paleo-genomics', E'ENA:0000065', NULL, NULL, NULL, NULL, NULL);
490-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508981, 999999999, E'Gene Regulation Study', E'ENA:0000068', NULL, NULL, NULL, NULL, NULL);
491-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508982, 999999999, E'Cancer Genomics', E'ENA:0000063', NULL, NULL, NULL, NULL, NULL);
492-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508983, 999999999, E'Population Genomics', E'ENA:0000064', NULL, NULL, NULL, NULL, NULL);
493-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508984, 999999999, E'RNASeq', E'ENA:0000070', NULL, NULL, NULL, NULL, NULL);
494-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508985, 999999999, E'Exome Sequencing', E'ENA:0000071', NULL, NULL, NULL, NULL, NULL);
495-
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508986, 999999999, E'Pooled Clone Sequencing', E'ENA:0000072', NULL, NULL, NULL, NULL, NULL);
485+
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508976, 999999999, E'Amplicon', E'ENA:0000061', NULL, NULL, NULL, NULL, NULL);
486+
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508984, 999999999, E'RNA-Seq', E'ENA:0000070', NULL, NULL, NULL, NULL, NULL);
496487
INSERT INTO qiita.term (term_id, ontology_id, term, identifier, definition, namespace, is_obsolete, is_root_term, is_leaf) VALUES (2052508987, 999999999, E'Other', E'ENA:0000069', NULL, NULL, NULL, NULL, NULL);
497488

498489
-- Create the new sample_template_filepath

qiita_db/test/test_ontology.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,15 @@ def testShortNameProperty(self):
3434

3535
def testTerms(self):
3636
obs = self.ontology.terms
37-
self.assertEqual(obs, [
38-
'Whole Genome Sequencing',
39-
'Metagenomics',
40-
'Transcriptome Analysis',
41-
'Resequencing',
42-
'Epigenetics',
43-
'Synthetic Genomics',
44-
'Forensic or Paleo-genomics',
45-
'Gene Regulation Study',
46-
'Cancer Genomics',
47-
'Population Genomics',
48-
'RNASeq',
49-
'Exome Sequencing',
50-
'Pooled Clone Sequencing',
51-
'Other'])
37+
self.assertEqual(
38+
obs, ['WGS', 'Metagenomics', 'Amplicon', 'RNA-Seq', 'Other'])
5239

5340
def test_user_defined_terms(self):
5441
obs = self.ontology.user_defined_terms
5542
self.assertEqual(obs, [])
5643

5744
def test_term_type(self):
58-
obs = self.ontology.term_type('RNASeq')
45+
obs = self.ontology.term_type('RNA-Seq')
5946
self.assertEqual('ontology', obs)
6047

6148
obs = self.ontology.term_type('Sasquatch')

qiita_db/test/test_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_ontology(self):
7575
self.assertTrue(check_count('qiita.ontology', 1))
7676

7777
def test_ontology_terms(self):
78-
self.assertTrue(check_count('qiita.term', 14))
78+
self.assertTrue(check_count('qiita.term', 5))
7979

8080

8181
if __name__ == '__main__':

qiita_pet/handlers/api_proxy/tests/test_prep_template.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ class TestPrepAPIReadOnly(TestCase):
3838
def test_get_ENA_ontology(self):
3939
obs = _get_ENA_ontology()
4040
exp = {
41-
'ENA': ['Cancer Genomics', 'Epigenetics', 'Exome Sequencing',
42-
'Forensic or Paleo-genomics', 'Gene Regulation Study',
43-
'Metagenomics', 'Pooled Clone Sequencing',
44-
'Population Genomics', 'RNASeq', 'Resequencing',
45-
'Synthetic Genomics', 'Transcriptome Analysis',
46-
'Whole Genome Sequencing', 'Other'],
41+
'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS', 'Other'],
4742
'User': []}
4843
self.assertEqual(obs, exp)
4944

@@ -58,12 +53,7 @@ def test_new_prep_template_get_req(self):
5853
'Multiomic', 'Proteomic', 'Transcriptomics',
5954
'Viromics'],
6055
'ontology': {
61-
'ENA': ['Cancer Genomics', 'Epigenetics', 'Exome Sequencing',
62-
'Forensic or Paleo-genomics', 'Gene Regulation Study',
63-
'Metagenomics', 'Pooled Clone Sequencing',
64-
'Population Genomics', 'RNASeq', 'Resequencing',
65-
'Synthetic Genomics', 'Transcriptome Analysis',
66-
'Whole Genome Sequencing', 'Other'],
56+
'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS', 'Other'],
6757
'User': []}}
6858

6959
self.assertEqual(obs, exp)
@@ -83,12 +73,7 @@ def test_prep_template_ajax_get_req(self):
8373
'num_columns': 22,
8474
'investigation_type': 'Metagenomics',
8575
'ontology': {
86-
'ENA': ['Cancer Genomics', 'Epigenetics',
87-
'Exome Sequencing', 'Forensic or Paleo-genomics',
88-
'Gene Regulation Study', 'Metagenomics',
89-
'Pooled Clone Sequencing', 'Population Genomics',
90-
'RNASeq', 'Resequencing', 'Synthetic Genomics',
91-
'Transcriptome Analysis', 'Whole Genome Sequencing',
76+
'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS',
9277
'Other'],
9378
'User': []},
9479
'artifact_attached': True,
@@ -518,10 +503,10 @@ def test_prep_template_patch_req(self):
518503
# Update investigation type
519504
obs = prep_template_patch_req(
520505
'test@foo.bar', 'replace', '/%s/investigation_type' % pt.id,
521-
'Cancer Genomics')
506+
'RNA-Seq')
522507
exp = {'status': 'success', 'message': ''}
523508
self.assertEqual(obs, exp)
524-
self.assertEqual(pt.investigation_type, 'Cancer Genomics')
509+
self.assertEqual(pt.investigation_type, 'RNA-Seq')
525510
# Update prep template data
526511
obs = prep_template_patch_req(
527512
'test@foo.bar', 'replace', '/%s/data' % pt.id, 'update.txt')
@@ -551,7 +536,7 @@ def test_prep_template_patch_req(self):
551536
# Operation not supported
552537
obs = prep_template_patch_req(
553538
'test@foo.bar', 'add', '/1/investigation_type',
554-
'Cancer Genomics')
539+
'RNA-Seq')
555540
exp = {'status': 'error',
556541
'message': 'Operation "add" not supported. '
557542
'Current supported operations: replace, remove',
@@ -560,22 +545,22 @@ def test_prep_template_patch_req(self):
560545
# Incorrect path parameter
561546
obs = prep_template_patch_req(
562547
'test@foo.bar', 'replace', '/investigation_type',
563-
'Cancer Genomics')
548+
'RNA-Seq')
564549
exp = {'status': 'error',
565550
'message': 'Incorrect path parameter'}
566551
self.assertEqual(obs, exp)
567552
# Incorrect attribute
568553
obs = prep_template_patch_req(
569554
'test@foo.bar', 'replace', '/1/other_attribute',
570-
'Cancer Genomics')
555+
'RNA-Seq')
571556
exp = {'status': 'error',
572557
'message': 'Attribute "other_attribute" not found. '
573558
'Please, check the path parameter'}
574559
self.assertEqual(obs, exp)
575560
# User doesn't have access
576561
obs = prep_template_patch_req(
577562
'demo@microbio.me', 'replace', '/%s/investigation_type' % pt.id,
578-
'Cancer Genomics')
563+
'RNA-Seq')
579564
exp = {'status': 'error',
580565
'message': 'User has insufficient permissions'}
581566
self.assertEqual(obs, exp)

qiita_pet/test/test_prep_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_post_broken_header(self):
5757
def test_patch(self):
5858
arguments = {'op': 'replace',
5959
'path': '/1/investigation_type/',
60-
'value': 'Cancer Genomics'}
60+
'value': 'RNA-Seq'}
6161
response = self.patch('/prep_template/', data=arguments)
6262
self.assertEqual(response.code, 200)
6363
exp = {'status': 'success', 'message': ''}

qiita_ware/test/test_ebi.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,8 @@ def test_init_exceptions(self):
467467
# raise error as we are missing columns
468468
# artifact.prep_templates[0] cause there should only be 1
469469
exp_text = ("Errors found during EBI submission for study #1, "
470-
"artifact #%d and prep template #%d:\nUnrecognized "
471-
"investigation type: 'None'. This term is neither one of "
472-
"the official terms nor one of the user-defined terms in "
473-
"the ENA ontology.\nThese samples do not have a valid "
470+
"artifact #%d and prep template #%d:\n"
471+
"These samples do not have a valid "
474472
"platform (instrumet model wasn't checked): "
475473
"1.SKD6.640190\nThese samples do not have a valid "
476474
"instrument model: 1.SKM6.640187" % (

0 commit comments

Comments
 (0)