comparison planemo/lib/python3.7/site-packages/bioblend/galaxy/objects/galaxy_instance.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 """
2 A representation of a Galaxy instance based on oo wrappers.
3 """
4
5 import time
6
7 import bioblend
8 import bioblend.galaxy
9 from bioblend.galaxy.datasets import TERMINAL_STATES
10 from . import client
11
12
13 def _get_error_info(hda):
14 msg = hda.id
15 try:
16 msg += ' (%s): ' % hda.name
17 msg += hda.wrapped['misc_info']
18 except Exception: # avoid 'error while generating an error report'
19 msg += ': error'
20 return msg
21
22
23 class GalaxyInstance(object):
24 """
25 A representation of an instance of Galaxy, identified by a URL and
26 a user's API key.
27
28 :type url: str
29 :param url: a FQDN or IP for a given instance of Galaxy. For example:
30 ``http://127.0.0.1:8080``
31
32 :type api_key: str
33 :param api_key: user's API key for the given instance of Galaxy, obtained
34 from the Galaxy web UI.
35
36 This is actually a factory class which instantiates the entity-specific
37 clients.
38
39 Example: get a list of all histories for a user with API key 'foo'::
40
41 from bioblend.galaxy.objects import *
42 gi = GalaxyInstance('http://127.0.0.1:8080', 'foo')
43 histories = gi.histories.list()
44 """
45 def __init__(self, url, api_key=None, email=None, password=None, verify=True):
46 self.gi = bioblend.galaxy.GalaxyInstance(url, api_key, email, password, verify)
47 self.log = bioblend.log
48 self.histories = client.ObjHistoryClient(self)
49 self.libraries = client.ObjLibraryClient(self)
50 self.workflows = client.ObjWorkflowClient(self)
51 self.tools = client.ObjToolClient(self)
52 self.jobs = client.ObjJobClient(self)
53
54 def _wait_datasets(self, datasets, polling_interval, break_on_error=True):
55 """
56 Wait for datasets to come out of the pending states.
57
58 :type datasets: :class:`~collections.Iterable` of
59 :class:`~.wrappers.Dataset`
60 :param datasets: datasets
61
62 :type polling_interval: float
63 :param polling_interval: polling interval in seconds
64
65 :type break_on_error: bool
66 :param break_on_error: if ``True``, raise a RuntimeError exception as
67 soon as at least one of the datasets is in the 'error' state.
68
69 .. warning::
70
71 This is a blocking operation that can take a very long time.
72 Also, note that this method does not return anything;
73 however, each input dataset is refreshed (possibly multiple
74 times) during the execution.
75 """
76 def poll(ds_list):
77 pending = []
78 for ds in ds_list:
79 ds.refresh()
80 if break_on_error and ds.state == 'error':
81 raise RuntimeError(_get_error_info(ds))
82 if not ds.state:
83 self.log.warning("Dataset %s has an empty state", ds.id)
84 elif ds.state not in TERMINAL_STATES:
85 self.log.info("Dataset {0.id} is in non-terminal state {0.state}".format(ds))
86 pending.append(ds)
87 return pending
88
89 self.log.info('Waiting for datasets')
90 while datasets:
91 datasets = poll(datasets)
92 time.sleep(polling_interval)