From d66a7778b7c9a1450e04f7b9057038d0eefc6896 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 Apr 2022 16:48:10 -0400 Subject: [PATCH] update cwl/updateCaseList.cwl to fix issues with empty string sample ids when no extra ids are passed in --- cwl/updateCaseList.cwl | 4 +-- tests/test_updateCaseList_cwl.py | 47 ++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/cwl/updateCaseList.cwl b/cwl/updateCaseList.cwl index e4721ad..8dc5fe0 100644 --- a/cwl/updateCaseList.cwl +++ b/cwl/updateCaseList.cwl @@ -6,13 +6,13 @@ baseCommand: ['bash', 'run.sh'] requirements: InlineJavascriptRequirement: {} DockerRequirement: - dockerPull: mskcc/helix:21.5.0 + dockerPull: mskcc/helix:21.5.1 InitialWorkDirRequirement: listing: - entryname: run.sh entry: |- set -eu - # get a comma-delim string of the sample names + # get a comma-delim string of the sample names ; returns an empty string if there are no sample id's ; updateCaseList ignores empty strings samples_arg="${ return inputs.sample_ids.join(',') ; }" input_file="${ return inputs.case_list.path ; }" output_file="${ return inputs.output_filename }" diff --git a/tests/test_updateCaseList_cwl.py b/tests/test_updateCaseList_cwl.py index f9c2b72..84b6136 100644 --- a/tests/test_updateCaseList_cwl.py +++ b/tests/test_updateCaseList_cwl.py @@ -17,21 +17,24 @@ class TestUpdateCaseList(PlutoTestCase): cwl_file = 'updateCaseList.cwl' - def test_update_caselist_1(self): - """ - """ + def setUp(self): + super().setUp() case_list_str = """case_list_category: all_cases_in_study stable_id: pi_123_all case_list_name: All Tumors case_list_description: All tumor samples cancer_study_identifier: pi_123 case_list_ids: Sample1\tSample2""" - input_file = os.path.join(self.tmpdir, "cases.txt") - with open(input_file, "w") as fout: + self.input_file = os.path.join(self.tmpdir, "cases.txt") + with open(self.input_file, "w") as fout: fout.write(case_list_str) + def test_update_caselist_1(self): + """ + Test simple case list update + """ self.input = { - "case_list": {"class": "File", "path": input_file}, + "case_list": {"class": "File", "path": self.input_file}, "sample_ids": ["Sample3", "Sample4"], "output_filename": "cases_all.txt" } @@ -58,6 +61,38 @@ def test_update_caselist_1(self): self.assertEqual(text, expected_text) + def test_update_caselist_2(self): + """ + Test update with no files passed + """ + self.input = { + "case_list": {"class": "File", "path": self.input_file}, + "sample_ids": [], + "output_filename": "cases_all.txt" + } + output_json, output_dir = self.run_cwl() + + output_file = os.path.join(output_dir, 'cases_all.txt') + + expected_output = { + "output_file": OFile(name = 'cases_all.txt', size = 192, hash = 'f1ad64f51beac01759ae690b2f787fe3978e8882', dir = output_dir) + } + + self.assertCWLDictEqual(output_json, expected_output) + + with open(output_file) as fin: + text = fin.read() + + expected_text = """case_list_category: all_cases_in_study +stable_id: pi_123_all +case_list_name: All Tumors +case_list_description: All tumor samples +cancer_study_identifier: pi_123 +case_list_ids: Sample1\tSample2 +""" + self.assertEqual(text, expected_text) + + if __name__ == "__main__":