Skip to content

Commit 5ff115e

Browse files
committed
Merge pull request #1141 from josenavas/add-check-restriction
Adding check_restrictions functionality
2 parents 06e968f + 20eebdb commit 5ff115e

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

qiita_db/metadata_template/base_metadata_template.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,3 +1157,21 @@ def update_category(self, category, samples_and_values):
11571157
% (category, value_str, value_types_str, column_type))
11581158

11591159
raise e
1160+
1161+
def check_restrictions(self, restrictions):
1162+
"""Checks if the template fulfills the restrictions
1163+
1164+
Parameters
1165+
----------
1166+
restrictions : list of Restriction
1167+
The restrictions to test if the template fulfills
1168+
1169+
Returns
1170+
-------
1171+
set of str
1172+
The missing columns
1173+
"""
1174+
cols = {col for restriction in restrictions
1175+
for col in restriction.columns}
1176+
1177+
return cols.difference(self.categories())

qiita_db/metadata_template/test/test_prep_template.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
get_count)
3333
from qiita_db.metadata_template.prep_template import PrepTemplate, PrepSample
3434
from qiita_db.metadata_template.sample_template import SampleTemplate, Sample
35-
from qiita_db.metadata_template.constants import PREP_TEMPLATE_COLUMNS
35+
from qiita_db.metadata_template.constants import (
36+
PREP_TEMPLATE_COLUMNS, PREP_TEMPLATE_COLUMNS_TARGET_GENE)
3637

3738

3839
class BaseTestPrepSample(TestCase):
@@ -1299,6 +1300,20 @@ def test_qiime_map_fp(self):
12991300
'1_prep_1_qiime_19700101-000000.txt')
13001301
self.assertEqual(pt.qiime_map_fp, exp)
13011302

1303+
def test_check_restrictions(self):
1304+
obs = self.tester.check_restrictions([PREP_TEMPLATE_COLUMNS['EBI']])
1305+
self.assertEqual(obs, set())
1306+
1307+
del self.metadata['primer']
1308+
pt = npt.assert_warns(QiitaDBWarning, PrepTemplate.create,
1309+
self.metadata, self.new_raw_data,
1310+
self.test_study, self.data_type)
1311+
1312+
obs = pt.check_restrictions(
1313+
[PREP_TEMPLATE_COLUMNS['EBI'],
1314+
PREP_TEMPLATE_COLUMNS_TARGET_GENE['demultiplex']])
1315+
self.assertEqual(obs, {'primer'})
1316+
13021317

13031318
EXP_PREP_TEMPLATE = (
13041319
'sample_name\tbarcode\tcenter_name\tcenter_project_name\t'

qiita_db/metadata_template/test/test_sample_template.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,16 @@ def test_to_dataframe(self):
19551955
'anonymized_name', 'tot_org_carb', 'description_duplicate',
19561956
'env_feature'})
19571957

1958+
def test_check_restrictions(self):
1959+
obs = self.tester.check_restrictions([SAMPLE_TEMPLATE_COLUMNS['EBI']])
1960+
self.assertEqual(obs, set())
1961+
1962+
del self.metadata['collection_timestamp']
1963+
st = npt.assert_warns(QiitaDBWarning, SampleTemplate.create,
1964+
self.metadata, self.new_study)
1965+
obs = st.check_restrictions([SAMPLE_TEMPLATE_COLUMNS['EBI']])
1966+
self.assertEqual(obs, {'collection_timestamp'})
1967+
19581968
EXP_SAMPLE_TEMPLATE = (
19591969
"sample_name\tcollection_timestamp\tdescription\tdna_extracted"
19601970
"\thost_subject_id\tint_column\tlatitude\tlongitude"

0 commit comments

Comments
 (0)