Skip to content

fix #3300 #3309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions qiita_db/metadata_template/test/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
15 changes: 3 additions & 12 deletions qiita_db/support_files/populate_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 3 additions & 16 deletions qiita_db/test/test_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/test/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
33 changes: 9 additions & 24 deletions qiita_pet/handlers/api_proxy/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand All @@ -560,22 +545,22 @@ 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'}
self.assertEqual(obs, exp)
# 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)
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/test/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': ''}
Expand Down
6 changes: 2 additions & 4 deletions qiita_ware/test/test_ebi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" % (
Expand Down