From a23270cd8c91de9163bb09ad817eee110862703d Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 12 Jan 2016 20:07:53 +0000 Subject: [PATCH] Add dataset collections to the outputs of Workflow.run() . Also: - Expose collection_type attribute of DatasetCollection. - Rework new tests. --- bioblend/galaxy/objects/wrappers.py | 14 ++++-- tests/TestGalaxyObjects.py | 62 +++++++++++++------------- tests/data/dataset_collection_run.ga | 65 ---------------------------- 3 files changed, 40 insertions(+), 101 deletions(-) delete mode 100644 tests/data/dataset_collection_run.ga diff --git a/bioblend/galaxy/objects/wrappers.py b/bioblend/galaxy/objects/wrappers.py index 2d6bf63b8..c5681117f 100644 --- a/bioblend/galaxy/objects/wrappers.py +++ b/bioblend/galaxy/objects/wrappers.py @@ -447,9 +447,17 @@ def run(self, input_map=None, history='', params=None, import_inputs=False, raise TypeError( 'history must be either a history wrapper or a string') res = self.gi.gi.workflows.run_workflow(self.id, **kwargs) - # res structure: {'history': HIST_ID, 'outputs': [DS_ID, DS_ID, ...]} + # res structure: {'history': HIST_ID, 'outputs': [CI_ID, CI_ID, ...]} out_hist = self.gi.histories.get(res['history']) - outputs = [out_hist.get_dataset(_) for _ in res['outputs']] + content_infos_dict = dict() + for ci in out_hist.content_infos: + content_infos_dict[ci.id] = ci + outputs = [] + for output_id in res['outputs']: + if content_infos_dict[output_id].type == 'file': + outputs.append(out_hist.get_dataset(output_id)) + elif content_infos_dict[output_id].type == 'collection': + outputs.append(out_hist.get_dataset_collection(output_id)) if wait: self.gi._wait_datasets(outputs, polling_interval=polling_interval, @@ -633,7 +641,7 @@ class DatasetCollection(Wrapper): Abstract base class for Galaxy dataset collections. """ BASE_ATTRS = Wrapper.BASE_ATTRS + ( - 'state', 'deleted' + 'state', 'deleted', 'collection_type' ) @abc.abstractmethod diff --git a/tests/TestGalaxyObjects.py b/tests/TestGalaxyObjects.py index b08d5c087..8e3cc3bee 100644 --- a/tests/TestGalaxyObjects.py +++ b/tests/TestGalaxyObjects.py @@ -559,15 +559,6 @@ def __check_dataset(self, hda): self.assertEqual(len(self.hist.dataset_ids), 1) self.assertEqual(self.hist.dataset_ids[0], hda.id) - def __check_dataset_collection(self, hdca): - self.assertIsInstance(hdca, wrappers.HistoryDatasetCollectionAssociation) - self.assertIs(hdca.container, self.hist) - self.assertEqual(len(self.hist.dataset_ids), 2) - dataset1 = self.hist.get_dataset(self.hist.dataset_ids[0]) - dataset2 = self.hist.get_dataset(self.hist.dataset_ids[1]) - self.assertEqual(dataset1.id, hdca.elements[0]['object']['id']) - self.assertEqual(dataset2.id, hdca.elements[1]['object']['id']) - def test_import_dataset(self): lib = self.gi.libraries.create('test_%s' % uuid.uuid4().hex) lds = lib.upload_data(FOO_DATA) @@ -629,28 +620,32 @@ def test_update(self): @test_util.skip_unless_galaxy('release_14.06') def test_create_dataset_collection(self): - collection_description = self._create_collection_description() - dataset_collection = self.hist.create_dataset_collection(collection_description) - self.__check_dataset_collection(dataset_collection) + self._create_collection_description() + hdca = self.hist.create_dataset_collection(self.collection_description) + self.assertIsInstance(hdca, wrappers.HistoryDatasetCollectionAssociation) + self.assertEqual(hdca.collection_type, 'list') + self.assertIs(hdca.container, self.hist) + self.assertEqual(len(hdca.elements), 2) + self.assertEqual(self.dataset1.id, hdca.elements[0]['object']['id']) + self.assertEqual(self.dataset2.id, hdca.elements[1]['object']['id']) @test_util.skip_unless_galaxy('release_14.06') def test_delete_dataset_collection(self): - collection_description = self._create_collection_description() - dataset_collection = self.hist.create_dataset_collection(collection_description) - dataset_collection.delete() - self.assertTrue(dataset_collection.deleted) + self._create_collection_description() + hdca = self.hist.create_dataset_collection(self.collection_description) + hdca.delete() + self.assertTrue(hdca.deleted) def _create_collection_description(self): - dataset1 = self.hist.paste_content(FOO_DATA) - dataset2 = self.hist.paste_content(FOO_DATA_2) - collection_description = dataset_collections.CollectionDescription( + self.dataset1 = self.hist.paste_content(FOO_DATA) + self.dataset2 = self.hist.paste_content(FOO_DATA_2) + self.collection_description = dataset_collections.CollectionDescription( name="MyDatasetList", elements=[ - dataset_collections.HistoryDatasetElement(name="sample1", id=dataset1.id), - dataset_collections.HistoryDatasetElement(name="sample2", id=dataset2.id), + dataset_collections.HistoryDatasetElement(name="sample1", id=self.dataset1.id), + dataset_collections.HistoryDatasetElement(name="sample2", id=self.dataset2.id), ] ) - return collection_description @test_util.skip_unless_galaxy() @@ -740,24 +735,22 @@ def test_params(self): self.__test(params=True) -@test_util.skip_unless_galaxy() +@test_util.skip_unless_galaxy('release_14.08') class TestRunDatasetCollectionWorkflow(GalaxyObjectsTestBase): def setUp(self): super(TestRunDatasetCollectionWorkflow, self).setUp() - wf_file = os.path.join(THIS_DIR, 'data', 'dataset_collection_run.ga') - with open(wf_file) as f: + with open(SAMPLE_WF_COLL_FN) as f: self.wf = self.gi.workflows.import_new(f.read()) - self.hist_name = 'test_%s' % uuid.uuid4().hex - self.hist = self.gi.histories.create(self.hist_name) + self.hist = self.gi.histories.create('test_%s' % uuid.uuid4().hex) def tearDown(self): self.wf.delete() + self.hist.delete(purge=True) - @test_util.skip_unless_galaxy('release_14.06') def test_run_workflow_with_dataset_collection(self): - dataset1 = self.hist.paste_content('foo\nbar\n') - dataset2 = self.hist.paste_content('foo2\nbar2\n') + dataset1 = self.hist.paste_content(FOO_DATA) + dataset2 = self.hist.paste_content(FOO_DATA_2) collection_description = dataset_collections.CollectionDescription( name="MyDatasetList", elements=[ @@ -766,12 +759,15 @@ def test_run_workflow_with_dataset_collection(self): ] ) dataset_collection = self.hist.create_dataset_collection(collection_description) - input_map = {"Input Dataset Collection": dataset_collection} + input_map = {"Input Dataset Collection": dataset_collection, + "Input 2": dataset1} outputs, out_hist = self.wf.run(input_map, self.hist, wait=True) - self.assertIsInstance(outputs[0], wrappers.HistoryDatasetCollectionAssociation) self.assertEqual(len(outputs), 1) + out_hdca = outputs[0] + self.assertIsInstance(out_hdca, wrappers.HistoryDatasetCollectionAssociation) + self.assertEqual(out_hdca.collection_type, 'list') + self.assertEqual(len(out_hdca.elements), 2) self.assertEqual(out_hist.id, self.hist.id) - out_hist.delete(purge=True) @test_util.skip_unless_galaxy() diff --git a/tests/data/dataset_collection_run.ga b/tests/data/dataset_collection_run.ga deleted file mode 100644 index a23d759dd..000000000 --- a/tests/data/dataset_collection_run.ga +++ /dev/null @@ -1,65 +0,0 @@ -{ - "a_galaxy_workflow": "true", - "annotation": "", - "format-version": "0.1", - "name": "DC Run", - "steps": { - "0": { - "annotation": "", - "id": 0, - "input_connections": {}, - "inputs": [ - { - "description": "", - "name": "Input Dataset Collection" - } - ], - "label": null, - "name": "Input dataset collection", - "outputs": [], - "position": { - "left": 338, - "top": 306 - }, - "tool_errors": null, - "tool_id": null, - "tool_state": "{\"collection_type\": \"list\", \"name\": \"Input Dataset Collection\"}", - "tool_version": null, - "type": "data_collection_input", - "user_outputs": [], - "uuid": "4a497708-240c-420e-9c7c-a2dc0200476e" - }, - "1": { - "annotation": "", - "id": 1, - "input_connections": { - "input": { - "id": 0, - "output_name": "output" - } - }, - "inputs": [], - "label": null, - "name": "Sort", - "outputs": [ - { - "name": "out_file1", - "type": "input" - } - ], - "position": { - "left": 676, - "top": 286 - }, - "post_job_actions": {}, - "tool_errors": null, - "tool_id": "sort1", - "tool_state": "{\"__page__\": 0, \"style\": \"\\\"num\\\"\", \"column\": \"\\\"1\\\"\", \"__rerun_remap_job_id__\": null, \"order\": \"\\\"DESC\\\"\", \"input\": \"null\", \"column_set\": \"[]\"}", - "tool_version": "1.0.3", - "type": "tool", - "user_outputs": [], - "uuid": "3c33333f-08ce-43bf-bc09-fa0b5776845b" - } - }, - "uuid": "fd34f048-e17a-4e06-85e8-ed391192d284" -} \ No newline at end of file