diff --git a/qiita_db/metadata_template/prep_template.py b/qiita_db/metadata_template/prep_template.py index cf38644eb..527d30639 100644 --- a/qiita_db/metadata_template/prep_template.py +++ b/qiita_db/metadata_template/prep_template.py @@ -122,11 +122,6 @@ def create(cls, md_template, study, data_type, investigation_type=None, If a required column is missing in md_template """ with qdb.sql_connection.TRN: - # If the investigation_type is supplied, make sure it is one of - # the recognized investigation types - if investigation_type is not None: - cls.validate_investigation_type(investigation_type) - # Check if the data_type is the id or the string if isinstance(data_type, int): data_type_id = data_type @@ -136,6 +131,18 @@ def create(cls, md_template, study, data_type, investigation_type=None, data_type_id = qdb.util.convert_to_id(data_type, "data_type") data_type_str = data_type + # If the investigation_type is None let's add it based on the + # data_type being created - if possible + if investigation_type is None: + if data_type_str in TARGET_GENE_DATA_TYPES: + investigation_type = 'Amplicon' + elif data_type_str == 'Metagenomic': + investigation_type = 'WGS' + elif data_type_str == 'Metatranscriptomic': + investigation_type = 'RNA-Seq' + if investigation_type is not None: + cls.validate_investigation_type(investigation_type) + pt_cols = PREP_TEMPLATE_COLUMNS if data_type_str in TARGET_GENE_DATA_TYPES: pt_cols = deepcopy(PREP_TEMPLATE_COLUMNS) diff --git a/qiita_db/metadata_template/test/test_prep_template.py b/qiita_db/metadata_template/test/test_prep_template.py index e98afd0f1..eb42c64d4 100644 --- a/qiita_db/metadata_template/test/test_prep_template.py +++ b/qiita_db/metadata_template/test/test_prep_template.py @@ -911,7 +911,7 @@ def _common_creation_checks(self, pt, fp_count, name): self.assertEqual(pt.data_type(), self.data_type) self.assertEqual(pt.data_type(ret_id=True), self.data_type_id) self.assertEqual(pt.artifact, None) - self.assertEqual(pt.investigation_type, None) + self.assertEqual(pt.investigation_type, 'Amplicon') self.assertEqual(pt.study_id, self.test_study.id) self.assertEqual(pt.status, "sandbox") exp_sample_ids = {'%s.SKB8.640193' % self.test_study.id, @@ -1076,7 +1076,7 @@ def test_create_warning(self): self.assertEqual(pt.data_type(), self.data_type) self.assertEqual(pt.data_type(ret_id=True), self.data_type_id) self.assertEqual(pt.artifact, None) - self.assertEqual(pt.investigation_type, None) + self.assertEqual(pt.investigation_type, 'Amplicon') self.assertEqual(pt.study_id, self.test_study.id) self.assertEqual(pt.status, 'sandbox') exp_sample_ids = {'%s.SKB8.640193' % self.test_study.id, @@ -1247,7 +1247,7 @@ def test_investigation_type_setter(self): """Able to update the investigation type""" pt = qdb.metadata_template.prep_template.PrepTemplate.create( self.metadata, self.test_study, self.data_type_id) - self.assertEqual(pt.investigation_type, None) + self.assertEqual(pt.investigation_type, 'Amplicon') pt.investigation_type = "Other" self.assertEqual(pt.investigation_type, 'Other') with self.assertRaises(qdb.exceptions.QiitaDBColumnError): @@ -1258,8 +1258,8 @@ def test_investigation_type_setter(self): def test_investigation_type_instance_setter(self): pt = qdb.metadata_template.prep_template.PrepTemplate(1) - pt.investigation_type = 'RNASeq' - self.assertEqual(pt.investigation_type, 'RNASeq') + pt.investigation_type = 'RNA-Seq' + self.assertEqual(pt.investigation_type, 'RNA-Seq') def test_deprecated_setter(self): pt = qdb.metadata_template.prep_template.PrepTemplate(1) diff --git a/qiita_db/support_files/populate_test_db.sql b/qiita_db/support_files/populate_test_db.sql index 1db4a1d75..f8b5466b2 100644 --- a/qiita_db/support_files/populate_test_db.sql +++ b/qiita_db/support_files/populate_test_db.sql @@ -480,19 +480,10 @@ INSERT INTO qiita.analysis_users (analysis_id, email) VALUES (1, 'shared@foo.bar 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'); -- Add some ontology values -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); +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); 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); -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); -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); -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); -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); -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); -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); -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); -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); -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); -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); -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); +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); +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); 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); -- Create the new sample_template_filepath diff --git a/qiita_db/test/test_ontology.py b/qiita_db/test/test_ontology.py index 5144d0082..c7b1fca25 100644 --- a/qiita_db/test/test_ontology.py +++ b/qiita_db/test/test_ontology.py @@ -34,28 +34,15 @@ def testShortNameProperty(self): def testTerms(self): obs = self.ontology.terms - self.assertEqual(obs, [ - 'Whole Genome Sequencing', - 'Metagenomics', - 'Transcriptome Analysis', - 'Resequencing', - 'Epigenetics', - 'Synthetic Genomics', - 'Forensic or Paleo-genomics', - 'Gene Regulation Study', - 'Cancer Genomics', - 'Population Genomics', - 'RNASeq', - 'Exome Sequencing', - 'Pooled Clone Sequencing', - 'Other']) + self.assertEqual( + obs, ['WGS', 'Metagenomics', 'Amplicon', 'RNA-Seq', 'Other']) def test_user_defined_terms(self): obs = self.ontology.user_defined_terms self.assertEqual(obs, []) def test_term_type(self): - obs = self.ontology.term_type('RNASeq') + obs = self.ontology.term_type('RNA-Seq') self.assertEqual('ontology', obs) obs = self.ontology.term_type('Sasquatch') diff --git a/qiita_db/test/test_setup.py b/qiita_db/test/test_setup.py index bb6e01463..3cdabe255 100644 --- a/qiita_db/test/test_setup.py +++ b/qiita_db/test/test_setup.py @@ -75,7 +75,7 @@ def test_ontology(self): self.assertTrue(check_count('qiita.ontology', 1)) def test_ontology_terms(self): - self.assertTrue(check_count('qiita.term', 14)) + self.assertTrue(check_count('qiita.term', 5)) if __name__ == '__main__': diff --git a/qiita_pet/handlers/api_proxy/tests/test_prep_template.py b/qiita_pet/handlers/api_proxy/tests/test_prep_template.py index b9bf52a9c..a9f96ca9a 100644 --- a/qiita_pet/handlers/api_proxy/tests/test_prep_template.py +++ b/qiita_pet/handlers/api_proxy/tests/test_prep_template.py @@ -38,12 +38,7 @@ class TestPrepAPIReadOnly(TestCase): def test_get_ENA_ontology(self): obs = _get_ENA_ontology() exp = { - 'ENA': ['Cancer Genomics', 'Epigenetics', 'Exome Sequencing', - 'Forensic or Paleo-genomics', 'Gene Regulation Study', - 'Metagenomics', 'Pooled Clone Sequencing', - 'Population Genomics', 'RNASeq', 'Resequencing', - 'Synthetic Genomics', 'Transcriptome Analysis', - 'Whole Genome Sequencing', 'Other'], + 'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS', 'Other'], 'User': []} self.assertEqual(obs, exp) @@ -58,12 +53,7 @@ def test_new_prep_template_get_req(self): 'Multiomic', 'Proteomic', 'Transcriptomics', 'Viromics'], 'ontology': { - 'ENA': ['Cancer Genomics', 'Epigenetics', 'Exome Sequencing', - 'Forensic or Paleo-genomics', 'Gene Regulation Study', - 'Metagenomics', 'Pooled Clone Sequencing', - 'Population Genomics', 'RNASeq', 'Resequencing', - 'Synthetic Genomics', 'Transcriptome Analysis', - 'Whole Genome Sequencing', 'Other'], + 'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS', 'Other'], 'User': []}} self.assertEqual(obs, exp) @@ -83,12 +73,7 @@ def test_prep_template_ajax_get_req(self): 'num_columns': 22, 'investigation_type': 'Metagenomics', 'ontology': { - 'ENA': ['Cancer Genomics', 'Epigenetics', - 'Exome Sequencing', 'Forensic or Paleo-genomics', - 'Gene Regulation Study', 'Metagenomics', - 'Pooled Clone Sequencing', 'Population Genomics', - 'RNASeq', 'Resequencing', 'Synthetic Genomics', - 'Transcriptome Analysis', 'Whole Genome Sequencing', + 'ENA': ['Amplicon', 'Metagenomics', 'RNA-Seq', 'WGS', 'Other'], 'User': []}, 'artifact_attached': True, @@ -518,10 +503,10 @@ def test_prep_template_patch_req(self): # Update investigation type obs = prep_template_patch_req( 'test@foo.bar', 'replace', '/%s/investigation_type' % pt.id, - 'Cancer Genomics') + 'RNA-Seq') exp = {'status': 'success', 'message': ''} self.assertEqual(obs, exp) - self.assertEqual(pt.investigation_type, 'Cancer Genomics') + self.assertEqual(pt.investigation_type, 'RNA-Seq') # Update prep template data obs = prep_template_patch_req( 'test@foo.bar', 'replace', '/%s/data' % pt.id, 'update.txt') @@ -551,7 +536,7 @@ def test_prep_template_patch_req(self): # Operation not supported obs = prep_template_patch_req( 'test@foo.bar', 'add', '/1/investigation_type', - 'Cancer Genomics') + 'RNA-Seq') exp = {'status': 'error', 'message': 'Operation "add" not supported. ' 'Current supported operations: replace, remove', @@ -560,14 +545,14 @@ def test_prep_template_patch_req(self): # Incorrect path parameter obs = prep_template_patch_req( 'test@foo.bar', 'replace', '/investigation_type', - 'Cancer Genomics') + 'RNA-Seq') exp = {'status': 'error', 'message': 'Incorrect path parameter'} self.assertEqual(obs, exp) # Incorrect attribute obs = prep_template_patch_req( 'test@foo.bar', 'replace', '/1/other_attribute', - 'Cancer Genomics') + 'RNA-Seq') exp = {'status': 'error', 'message': 'Attribute "other_attribute" not found. ' 'Please, check the path parameter'} @@ -575,7 +560,7 @@ def test_prep_template_patch_req(self): # User doesn't have access obs = prep_template_patch_req( 'demo@microbio.me', 'replace', '/%s/investigation_type' % pt.id, - 'Cancer Genomics') + 'RNA-Seq') exp = {'status': 'error', 'message': 'User has insufficient permissions'} self.assertEqual(obs, exp) diff --git a/qiita_pet/test/test_prep_template.py b/qiita_pet/test/test_prep_template.py index 85557680c..2a19a9768 100644 --- a/qiita_pet/test/test_prep_template.py +++ b/qiita_pet/test/test_prep_template.py @@ -57,7 +57,7 @@ def test_post_broken_header(self): def test_patch(self): arguments = {'op': 'replace', 'path': '/1/investigation_type/', - 'value': 'Cancer Genomics'} + 'value': 'RNA-Seq'} response = self.patch('/prep_template/', data=arguments) self.assertEqual(response.code, 200) exp = {'status': 'success', 'message': ''} diff --git a/qiita_ware/test/test_ebi.py b/qiita_ware/test/test_ebi.py index 106c377f1..7ef1b0b08 100644 --- a/qiita_ware/test/test_ebi.py +++ b/qiita_ware/test/test_ebi.py @@ -467,10 +467,8 @@ def test_init_exceptions(self): # raise error as we are missing columns # artifact.prep_templates[0] cause there should only be 1 exp_text = ("Errors found during EBI submission for study #1, " - "artifact #%d and prep template #%d:\nUnrecognized " - "investigation type: 'None'. This term is neither one of " - "the official terms nor one of the user-defined terms in " - "the ENA ontology.\nThese samples do not have a valid " + "artifact #%d and prep template #%d:\n" + "These samples do not have a valid " "platform (instrumet model wasn't checked): " "1.SKD6.640190\nThese samples do not have a valid " "instrument model: 1.SKM6.640187" % (