Skip to content

Commit

Permalink
Merge pull request #1141 from josenavas/add-check-restriction
Browse files Browse the repository at this point in the history
Adding check_restrictions functionality
  • Loading branch information
wasade committed May 5, 2015
2 parents 06e968f + 20eebdb commit 5ff115e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
18 changes: 18 additions & 0 deletions qiita_db/metadata_template/base_metadata_template.py
Expand Up @@ -1157,3 +1157,21 @@ def update_category(self, category, samples_and_values):
% (category, value_str, value_types_str, column_type))

raise e

def check_restrictions(self, restrictions):
"""Checks if the template fulfills the restrictions
Parameters
----------
restrictions : list of Restriction
The restrictions to test if the template fulfills
Returns
-------
set of str
The missing columns
"""
cols = {col for restriction in restrictions
for col in restriction.columns}

return cols.difference(self.categories())
17 changes: 16 additions & 1 deletion qiita_db/metadata_template/test/test_prep_template.py
Expand Up @@ -32,7 +32,8 @@
get_count)
from qiita_db.metadata_template.prep_template import PrepTemplate, PrepSample
from qiita_db.metadata_template.sample_template import SampleTemplate, Sample
from qiita_db.metadata_template.constants import PREP_TEMPLATE_COLUMNS
from qiita_db.metadata_template.constants import (
PREP_TEMPLATE_COLUMNS, PREP_TEMPLATE_COLUMNS_TARGET_GENE)


class BaseTestPrepSample(TestCase):
Expand Down Expand Up @@ -1299,6 +1300,20 @@ def test_qiime_map_fp(self):
'1_prep_1_qiime_19700101-000000.txt')
self.assertEqual(pt.qiime_map_fp, exp)

def test_check_restrictions(self):
obs = self.tester.check_restrictions([PREP_TEMPLATE_COLUMNS['EBI']])
self.assertEqual(obs, set())

del self.metadata['primer']
pt = npt.assert_warns(QiitaDBWarning, PrepTemplate.create,
self.metadata, self.new_raw_data,
self.test_study, self.data_type)

obs = pt.check_restrictions(
[PREP_TEMPLATE_COLUMNS['EBI'],
PREP_TEMPLATE_COLUMNS_TARGET_GENE['demultiplex']])
self.assertEqual(obs, {'primer'})


EXP_PREP_TEMPLATE = (
'sample_name\tbarcode\tcenter_name\tcenter_project_name\t'
Expand Down
10 changes: 10 additions & 0 deletions qiita_db/metadata_template/test/test_sample_template.py
Expand Up @@ -1955,6 +1955,16 @@ def test_to_dataframe(self):
'anonymized_name', 'tot_org_carb', 'description_duplicate',
'env_feature'})

def test_check_restrictions(self):
obs = self.tester.check_restrictions([SAMPLE_TEMPLATE_COLUMNS['EBI']])
self.assertEqual(obs, set())

del self.metadata['collection_timestamp']
st = npt.assert_warns(QiitaDBWarning, SampleTemplate.create,
self.metadata, self.new_study)
obs = st.check_restrictions([SAMPLE_TEMPLATE_COLUMNS['EBI']])
self.assertEqual(obs, {'collection_timestamp'})

EXP_SAMPLE_TEMPLATE = (
"sample_name\tcollection_timestamp\tdescription\tdna_extracted"
"\thost_subject_id\tint_column\tlatitude\tlongitude"
Expand Down

0 comments on commit 5ff115e

Please sign in to comment.