Skip to content

Commit

Permalink
Add dataset collections to the outputs of Workflow.run() .
Browse files Browse the repository at this point in the history
Also:
- Expose collection_type attribute of DatasetCollection.
- Rework new tests.
  • Loading branch information
nsoranzo committed Jan 12, 2016
1 parent 48b2564 commit a23270c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 101 deletions.
14 changes: 11 additions & 3 deletions bioblend/galaxy/objects/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
62 changes: 29 additions & 33 deletions tests/TestGalaxyObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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=[
Expand All @@ -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()
Expand Down
65 changes: 0 additions & 65 deletions tests/data/dataset_collection_run.ga

This file was deleted.

0 comments on commit a23270c

Please sign in to comment.