Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/bioblend/galaxy/jobs/__init__.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """ | |
2 Contains possible interactions with the Galaxy Jobs | |
3 """ | |
4 from bioblend.galaxy.client import Client | |
5 | |
6 | |
7 class JobsClient(Client): | |
8 | |
9 def __init__(self, galaxy_instance): | |
10 self.module = 'jobs' | |
11 super().__init__(galaxy_instance) | |
12 | |
13 def get_jobs(self): | |
14 """ | |
15 Get the list of jobs of the current user. | |
16 | |
17 :rtype: list | |
18 :return: list of dictionaries containing summary job information. | |
19 For example:: | |
20 | |
21 [{'create_time': '2014-03-01T16:16:48.640550', | |
22 'exit_code': 0, | |
23 'id': 'ebfb8f50c6abde6d', | |
24 'model_class': 'Job', | |
25 'state': 'ok', | |
26 'tool_id': 'fasta2tab', | |
27 'update_time': '2014-03-01T16:16:50.657399'}, | |
28 {'create_time': '2014-03-01T16:05:34.851246', | |
29 'exit_code': 0, | |
30 'id': '1cd8e2f6b131e891', | |
31 'model_class': 'Job', | |
32 'state': 'ok', | |
33 'tool_id': 'upload1', | |
34 'update_time': '2014-03-01T16:05:39.558458'}] | |
35 """ | |
36 return self._get() | |
37 | |
38 def show_job(self, job_id, full_details=False): | |
39 """ | |
40 Get details of a given job of the current user. | |
41 | |
42 :type job_id: str | |
43 :param job_id: job ID | |
44 | |
45 :type full_details: bool | |
46 :param full_details: when ``True``, the complete list of details for the | |
47 given job. | |
48 | |
49 :rtype: dict | |
50 :return: A description of the given job. | |
51 For example:: | |
52 | |
53 {'create_time': '2014-03-01T16:17:29.828624', | |
54 'exit_code': 0, | |
55 'id': 'a799d38679e985db', | |
56 'inputs': {'input': {'id': 'ebfb8f50c6abde6d', 'src': 'hda'}}, | |
57 'model_class': 'Job', | |
58 'outputs': {'output': {'id': 'a799d38679e985db', 'src': 'hda'}}, | |
59 'params': {'chromInfo': '"/opt/galaxy-central/tool-data/shared/ucsc/chrom/?.len"', | |
60 'dbkey': '"?"', | |
61 'seq_col': '"2"', | |
62 'title_col': '["1"]'}, | |
63 'state': 'ok', | |
64 'tool_id': 'tab2fasta', | |
65 'update_time': '2014-03-01T16:17:31.930728'} | |
66 """ | |
67 params = {} | |
68 if full_details: | |
69 params['full'] = full_details | |
70 | |
71 return self._get(id=job_id, params=params) | |
72 | |
73 def _build_for_rerun(self, job_id): | |
74 """ | |
75 Get details of a given job that can be used to rerun the corresponding tool. | |
76 | |
77 :type job_id: str | |
78 :param job_id: job ID | |
79 | |
80 :rtype: dict | |
81 :return: A description of the given job, with all parameters required to rerun. | |
82 | |
83 """ | |
84 url = '/'.join((self._make_url(job_id), 'build_for_rerun')) | |
85 return self._get(url=url) | |
86 | |
87 def rerun_job(self, job_id, remap=False, tool_inputs_update=None, history_id=None): | |
88 """ | |
89 Rerun a job. | |
90 | |
91 :type job_id: str | |
92 :param job_id: job ID | |
93 | |
94 :type remap: bool | |
95 :param remap: when ``True``, the job output(s) will be remapped onto the dataset(s) | |
96 created by the original job; if other jobs were waiting for this job to finish | |
97 successfully, they will be resumed using the new outputs of this tool run. When | |
98 ``False``, new job output(s) will be created. Note that if Galaxy does not permit | |
99 remapping for the job in question, specifying ``True`` will result in an error. | |
100 | |
101 :type tool_inputs_update: dict | |
102 :param tool_inputs_update: dictionary specifying any changes which should be | |
103 made to tool parameters for the rerun job. | |
104 | |
105 :type history_id: str | |
106 :param history_id: ID of the history in which the job should be executed; if | |
107 not specified, the same history will be used as the original job run. | |
108 | |
109 :rtype: dict | |
110 :return: Information about outputs and the rerun job | |
111 .. note:: | |
112 This method can only be used with Galaxy ``release_20.09`` or later. | |
113 """ | |
114 job_rerun_params = self._build_for_rerun(job_id) | |
115 job_inputs = job_rerun_params['state_inputs'] | |
116 | |
117 if remap: | |
118 if not job_inputs['job_remap']: | |
119 raise ValueError('remap was set to True, but this job is not remappable.') | |
120 job_inputs['rerun_remap_job_id'] = job_id | |
121 | |
122 if tool_inputs_update: | |
123 for input_param, input_value in tool_inputs_update.items(): | |
124 job_inputs[input_param] = input_value | |
125 url = '/'.join((self.gi.url, 'tools')) | |
126 payload = { | |
127 "history_id": history_id if history_id else job_rerun_params['history_id'], | |
128 "tool_id": job_rerun_params['id'], | |
129 "inputs": job_inputs, | |
130 "input_format": '21.01' | |
131 } | |
132 return self._post(url=url, payload=payload) | |
133 | |
134 def get_state(self, job_id): | |
135 """ | |
136 Display the current state for a given job of the current user. | |
137 | |
138 :type job_id: str | |
139 :param job_id: job ID | |
140 | |
141 :rtype: str | |
142 :return: state of the given job among the following values: `new`, | |
143 `queued`, `running`, `waiting`, `ok`. If the state cannot be | |
144 retrieved, an empty string is returned. | |
145 | |
146 .. versionadded:: 0.5.3 | |
147 """ | |
148 return self.show_job(job_id).get('state', '') | |
149 | |
150 def search_jobs(self, job_info): | |
151 """ | |
152 Return jobs for the current user based payload content. | |
153 | |
154 :type job_info: dict | |
155 :param job_info: dictionary containing description of the requested job. | |
156 This is in the same format as a request to POST /api/tools would take | |
157 to initiate a job | |
158 | |
159 :rtype: list | |
160 :return: list of dictionaries containing summary job information of | |
161 the jobs that match the requested job run | |
162 | |
163 This method is designed to scan the list of previously run jobs and find | |
164 records of jobs that had the exact some input parameters and datasets. | |
165 This can be used to minimize the amount of repeated work, and simply | |
166 recycle the old results. | |
167 | |
168 """ | |
169 | |
170 payload = job_info | |
171 url = self._make_url() + '/search' | |
172 return self._post(url=url, payload=payload) | |
173 | |
174 def get_metrics(self, job_id): | |
175 """ | |
176 Return job metrics for a given job. | |
177 | |
178 :type job_id: str | |
179 :param job_id: job ID | |
180 | |
181 :rtype: list | |
182 :return: list containing job metrics | |
183 | |
184 .. note:: | |
185 Calling ``show_job()`` with ``full_details=True`` also returns the | |
186 metrics for a job if the user is an admin. This method allows to fetch | |
187 metrics even as a normal user as long as the Galaxy instance has the | |
188 ``expose_potentially_sensitive_job_metrics`` option set to ``true`` in | |
189 the ``config/galaxy.yml`` configuration file. | |
190 """ | |
191 url = self._make_url(module_id=job_id) + '/metrics' | |
192 return self._get(url=url) | |
193 | |
194 def report_error(self, job_id, dataset_id, message, email=None): | |
195 """ | |
196 Report an error for a given job and dataset. | |
197 | |
198 :type job_id: str | |
199 :param job_id: job ID | |
200 | |
201 :type dataset_id: str | |
202 :param dataset_id: Dataset ID | |
203 | |
204 :type message: str | |
205 :param message: Error message | |
206 | |
207 :type email: str | |
208 :param email: Email to submit error report to | |
209 | |
210 :rtype: dict | |
211 :return: dict containing job error reply | |
212 """ | |
213 payload = { | |
214 "message": message, | |
215 "dataset_id": dataset_id, | |
216 } | |
217 if email is not None: | |
218 payload["email"] = email | |
219 | |
220 url = self._make_url(module_id=job_id) + '/error' | |
221 return self._post(url=url, payload=payload) |