Skip to content

Commit 1cd30c4

Browse files
WIP: Added Qiita study reserved-word check (#91)
* Added Qiita study reserved-word check * Update
1 parent 1ff654e commit 1cd30c4

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

qp_klp/Step.py

+35
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,42 @@ def update_blanks_in_qiita(self, qclient):
950950
qclient.http_patch(f'/api/v1/study/{study_id}/samples',
951951
data=dumps(data))
952952

953+
def _project_metadata_check(self, qclient):
954+
# Let Pipeline() retrieve the needed qiita study ids from the user
955+
# input while this plugin queries for the existing set of column
956+
# names in each project's sample metadata. We'll let Pipeline()
957+
# decide (using its metapool dependency) which column names are
958+
# reserved.
959+
qiita_ids = [x['qiita_id'] for x in self.pipeline.get_project_info()]
960+
961+
results = []
962+
963+
for qiita_id in qiita_ids:
964+
categories = qclient.get(f"/api/v1/study/{qiita_id}/samples/info")[
965+
"categories"]
966+
967+
res = self.pipeline.identify_reserved_words(categories)
968+
969+
# if any reserved words were identified, generate an appropriate
970+
# error message for it and add it to the list of error messages
971+
# to return to the user.
972+
res = [f"'{x}' exists in Qiita study {qiita_id}'s sample metadata"
973+
for x in res]
974+
975+
results += res
976+
977+
if results:
978+
# return any error messages generated across all the projects.
979+
raise PipelineError("\n".join(results))
980+
953981
def precheck(self, qclient):
982+
# since one of the objectives of SPP is to generate prep-info files
983+
# and automatically load them into Qiita, confirm that all studies
984+
# mentioned in the sample-sheet/pre-prep do not contain sample
985+
# metadata that would cause an error in the pipeline after processing
986+
# has already completed but the results have not yet been loaded.
987+
self._project_metadata_check(qclient)
988+
954989
# compare sample-ids/tube-ids in sample-sheet/mapping file
955990
# against what's in Qiita. Results are a list of dictionaries, one
956991
# per project.

qp_klp/tests/test_step.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def test_compare_samples_against_qiita_error_handling(self):
977977
def test_precheck(self):
978978
fake_client = AnotherFakeClient()
979979

980-
# test that precheck() raises a PipelineError with the correct
980+
# test that Step.precheck() raises a PipelineError with the correct
981981
# message, given the configuration of Step() and AnotherFakeClient().
982982

983983
step = Step(self.another_pipeline, self.qiita_id, None)
@@ -991,6 +991,24 @@ def test_precheck(self):
991991
with self.assertRaisesRegex(PipelineError, msg):
992992
step.precheck(fake_client)
993993

994+
def test_project_metadata_check(self):
995+
fake_client = FakeClient()
996+
997+
# self.pipeline represents a metagenomic pathway.
998+
step = Step(self.pipeline, self.qiita_id, None)
999+
1000+
# _project_metadata_check() should return w/out raising an Error if
1001+
# step and fake_client is used.
1002+
step._project_metadata_check(fake_client)
1003+
1004+
fake_client.info_in_11661['categories'].append('well_id_384')
1005+
fake_client.info_in_13059['categories'].append('well_id_384')
1006+
1007+
msg = ("'well_id_384' exists in Qiita study 13059's sample metadata"
1008+
"\n'well_id_384' exists in Qiita study 11661's sample metadata")
1009+
with self.assertRaisesRegex(PipelineError, msg):
1010+
step._project_metadata_check(fake_client)
1011+
9941012
def test_conditional_fastqc_finder(self):
9951013
self._create_alternate_test_input()
9961014

0 commit comments

Comments
 (0)