Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/bioblend/toolshed/repositories/__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 Interaction with a Tool Shed instance repositories | |
3 """ | |
4 from bioblend.galaxy.client import Client | |
5 from bioblend.util import attach_file | |
6 | |
7 | |
8 class ToolShedRepositoryClient(Client): | |
9 | |
10 def __init__(self, toolshed_instance): | |
11 self.module = 'repositories' | |
12 super().__init__(toolshed_instance) | |
13 | |
14 def get_repositories(self): | |
15 """ | |
16 Get a list of all the repositories in a Galaxy Tool Shed. | |
17 | |
18 :rtype: list | |
19 :return: Returns a list of dictionaries containing information about | |
20 repositories present in the Tool Shed. | |
21 For example:: | |
22 | |
23 [{'category_ids': ['c1df3132f6334b0e', 'f6d7b0037d901d9b'], | |
24 'deleted': False, | |
25 'deprecated': False, | |
26 'description': 'Order Contigs', | |
27 'homepage_url': '', | |
28 'id': '287bd69f724b99ce', | |
29 'name': 'best_tool_ever', | |
30 'owner': 'billybob', | |
31 'private': False, | |
32 'remote_repository_url': '', | |
33 'times_downloaded': 0, | |
34 'type': 'unrestricted', | |
35 'url': '/api/repositories/287bd69f724b99ce', | |
36 'user_id': '5cefd48bc04af6d4'}] | |
37 | |
38 .. versionchanged:: 0.4.1 | |
39 Changed method name from ``get_tools`` to ``get_repositories`` to | |
40 better align with the Tool Shed concepts. | |
41 """ | |
42 return self._get() | |
43 | |
44 def search_repositories(self, q, page=1, page_size=10): | |
45 """ | |
46 Search for repositories in a Galaxy Tool Shed. | |
47 | |
48 :type q: str | |
49 :param q: query string for searching purposes | |
50 | |
51 :type page: int | |
52 :param page: page requested | |
53 | |
54 :type page_size: int | |
55 :param page_size: page size requested | |
56 | |
57 :rtype: dict | |
58 :return: dictionary containing search hits as well as metadata for the | |
59 search. | |
60 For example:: | |
61 | |
62 {'hits': [{'matched_terms': [], | |
63 'repository': {'approved': 'no', | |
64 'description': 'Convert export file to fastq', | |
65 'full_last_updated': '2015-01-18 09:48 AM', | |
66 'homepage_url': '', | |
67 'id': 'bdfa208f0cf6504e', | |
68 'last_updated': 'less than a year', | |
69 'long_description': 'This is a simple too to convert Solexas Export files to FASTQ files.', | |
70 'name': 'export_to_fastq', | |
71 'remote_repository_url': '', | |
72 'repo_owner_username': 'louise', | |
73 'times_downloaded': 164}, | |
74 'score': 4.92}, | |
75 {'matched_terms': [], | |
76 'repository': {'approved': 'no', | |
77 'description': 'Convert BAM file to fastq', | |
78 'full_last_updated': '2015-04-07 11:57 AM', | |
79 'homepage_url': '', | |
80 'id': '175812cd7caaf439', | |
81 'last_updated': 'less than a month', | |
82 'long_description': 'Use Picards SamToFastq to convert a BAM file to fastq. Useful for storing reads as BAM in Galaxy and converting to fastq when needed for analysis.', | |
83 'name': 'bam_to_fastq', | |
84 'remote_repository_url': '', | |
85 'repo_owner_username': 'brad-chapman', | |
86 'times_downloaded': 138}, | |
87 'score': 4.14}], | |
88 'hostname': 'https://testtoolshed.g2.bx.psu.edu/', | |
89 'page': '1', | |
90 'page_size': '2', | |
91 'total_results': '64'} | |
92 """ | |
93 params = dict(q=q, page=page, page_size=page_size) | |
94 return self._get(params=params) | |
95 | |
96 def show_repository(self, toolShed_id): | |
97 """ | |
98 Display information of a repository from Tool Shed | |
99 | |
100 :type toolShed_id: str | |
101 :param toolShed_id: Encoded Tool Shed ID | |
102 | |
103 :rtype: dict | |
104 :return: Information about the tool. | |
105 For example:: | |
106 | |
107 {'category_ids': ['c1df3132f6334b0e', 'f6d7b0037d901d9b'], | |
108 'deleted': False, | |
109 'deprecated': False, | |
110 'description': 'Order Contigs', | |
111 'homepage_url': '', | |
112 'id': '287bd69f724b99ce', | |
113 'long_description': '', | |
114 'name': 'best_tool_ever', | |
115 'owner': 'billybob', | |
116 'private': False, | |
117 'remote_repository_url': '', | |
118 'times_downloaded': 0, | |
119 'type': 'unrestricted', | |
120 'url': '/api/repositories/287bd69f724b99ce', | |
121 'user_id': '5cefd48bc04af6d4'} | |
122 | |
123 .. versionchanged:: 0.4.1 | |
124 Changed method name from ``show_tool`` to ``show_repository`` to | |
125 better align with the Tool Shed concepts. | |
126 """ | |
127 return self._get(id=toolShed_id) | |
128 | |
129 def get_ordered_installable_revisions(self, name, owner): | |
130 """ | |
131 Returns the ordered list of changeset revision hash strings that are | |
132 associated with installable revisions. As in the changelog, the list is | |
133 ordered oldest to newest. | |
134 | |
135 :type name: str | |
136 :param name: the name of the repository | |
137 | |
138 :type owner: str | |
139 :param owner: the owner of the repository | |
140 | |
141 :rtype: list | |
142 :return: List of changeset revision hash strings from oldest to newest | |
143 """ | |
144 url = self._make_url() + '/get_ordered_installable_revisions' | |
145 params = { | |
146 'name': name, | |
147 'owner': owner | |
148 } | |
149 r = self._get(url=url, params=params) | |
150 | |
151 return r | |
152 | |
153 def get_repository_revision_install_info(self, name, owner, | |
154 changeset_revision): | |
155 """ | |
156 Return a list of dictionaries of metadata about a certain changeset | |
157 revision for a single tool. | |
158 | |
159 :type name: str | |
160 :param name: the name of the repository | |
161 | |
162 :type owner: str | |
163 :param owner: the owner of the repository | |
164 | |
165 :type changeset_revision: str | |
166 :param changeset_revision: the changeset_revision of the | |
167 RepositoryMetadata object associated with the repository | |
168 | |
169 :rtype: List of dictionaries | |
170 :return: Returns a list of the following dictionaries: | |
171 | |
172 #. a dictionary defining the repository | |
173 #. a dictionary defining the repository revision (RepositoryMetadata) | |
174 #. a dictionary including the additional information required to | |
175 install the repository | |
176 | |
177 For example:: | |
178 | |
179 [{'deleted': False, | |
180 'deprecated': False, | |
181 'description': 'Galaxy Freebayes Bayesian genetic variant detector tool', | |
182 'homepage_url': '', | |
183 'id': '491b7a3fddf9366f', | |
184 'long_description': 'Galaxy Freebayes Bayesian genetic variant detector tool originally included in the Galaxy code distribution but migrated to the tool shed.', | |
185 'name': 'freebayes', | |
186 'owner': 'devteam', | |
187 'private': False, | |
188 'remote_repository_url': '', | |
189 'times_downloaded': 269, | |
190 'type': 'unrestricted', | |
191 'url': '/api/repositories/491b7a3fddf9366f', | |
192 'user_id': '1de29d50c3c44272'}, | |
193 {'changeset_revision': 'd291dc763c4c', | |
194 'do_not_test': False, | |
195 'downloadable': True, | |
196 'has_repository_dependencies': False, | |
197 'id': '504be8aaa652c154', | |
198 'includes_datatypes': False, | |
199 'includes_tool_dependencies': True, | |
200 'includes_tools': True, | |
201 'includes_tools_for_display_in_tool_panel': True, | |
202 'includes_workflows': False, | |
203 'malicious': False, | |
204 'repository_id': '491b7a3fddf9366f', | |
205 'url': '/api/repository_revisions/504be8aaa652c154'}, | |
206 {'freebayes': ['Galaxy Freebayes Bayesian genetic variant detector tool', | |
207 'http://testtoolshed.g2.bx.psu.edu/repos/devteam/freebayes', | |
208 'd291dc763c4c', | |
209 '9', | |
210 'devteam', | |
211 {}, | |
212 {'freebayes/0.9.6_9608597d12e127c847ae03aa03440ab63992fedf': {'changeset_revision': 'd291dc763c4c', | |
213 'name': 'freebayes', | |
214 'repository_name': 'freebayes', | |
215 'repository_owner': 'devteam', | |
216 'type': 'package', | |
217 'version': '0.9.6_9608597d12e127c847ae03aa03440ab63992fedf'}, | |
218 'samtools/0.1.18': {'changeset_revision': 'd291dc763c4c', | |
219 'name': 'samtools', | |
220 'repository_name': 'freebayes', | |
221 'repository_owner': 'devteam', | |
222 'type': 'package', | |
223 'version': '0.1.18'}}]}] | |
224 """ | |
225 url = self._make_url() + '/get_repository_revision_install_info' | |
226 params = { | |
227 'name': name, | |
228 'owner': owner, | |
229 'changeset_revision': changeset_revision | |
230 } | |
231 return self._get(url=url, params=params) | |
232 | |
233 def repository_revisions(self, downloadable=None, malicious=None, | |
234 tools_functionally_correct=None, | |
235 missing_test_components=None, do_not_test=None, | |
236 includes_tools=None, test_install_error=None, | |
237 skip_tool_test=None): | |
238 """ | |
239 Returns a (possibly filtered) list of dictionaries that include | |
240 information about all repository revisions. The following parameters can | |
241 be used to filter the list. | |
242 | |
243 :type downloadable: bool | |
244 :param downloadable: Can the tool be downloaded | |
245 | |
246 :type malicious: bool | |
247 :param malicious: | |
248 | |
249 :type tools_functionally_correct: bool | |
250 :param tools_functionally_correct: | |
251 | |
252 :type missing_test_components: bool | |
253 :param missing_test_components: | |
254 | |
255 :type do_not_test: bool | |
256 :param do_not_test: | |
257 | |
258 :type includes_tools: bool | |
259 :param includes_tools: | |
260 | |
261 :type test_install_error: bool | |
262 :param test_install_error: | |
263 | |
264 :type skip_tool_test: bool | |
265 :param skip_tool_test: | |
266 | |
267 :rtype: List of dictionaries | |
268 :return: Returns a (possibly filtered) list of dictionaries that include | |
269 information about all repository revisions. | |
270 For example:: | |
271 | |
272 [{'changeset_revision': '6e26c5a48e9a', | |
273 'do_not_test': False, | |
274 'downloadable': True, | |
275 'has_repository_dependencies': False, | |
276 'id': '92250afff777a169', | |
277 'includes_datatypes': False, | |
278 'includes_tool_dependencies': False, | |
279 'includes_tools': True, | |
280 'includes_tools_for_display_in_tool_panel': True, | |
281 'includes_workflows': False, | |
282 'malicious': False, | |
283 'missing_test_components': False, | |
284 'repository_id': '78f2604ff5e65707', | |
285 'test_install_error': False, | |
286 'time_last_tested': None, | |
287 'tools_functionally_correct': False, | |
288 'url': '/api/repository_revisions/92250afff777a169'}, | |
289 {'changeset_revision': '15a54fa11ad7', | |
290 'do_not_test': False, | |
291 'downloadable': True, | |
292 'has_repository_dependencies': False, | |
293 'id': 'd3823c748ae2205d', | |
294 'includes_datatypes': False, | |
295 'includes_tool_dependencies': False, | |
296 'includes_tools': True, | |
297 'includes_tools_for_display_in_tool_panel': True, | |
298 'includes_workflows': False, | |
299 'malicious': False, | |
300 'missing_test_components': False, | |
301 'repository_id': 'f9662009da7bfce0', | |
302 'test_install_error': False, | |
303 'time_last_tested': None, | |
304 'tools_functionally_correct': False, | |
305 'url': '/api/repository_revisions/d3823c748ae2205d'}] | |
306 """ | |
307 # Not using '_make_url' or '_get' to create url since the module id used | |
308 # to create url is not the same as needed for this method | |
309 url = self.gi.url + '/repository_revisions' | |
310 params = {} | |
311 if downloadable: | |
312 params['downloadable'] = True | |
313 if malicious: | |
314 params['malicious'] = True | |
315 if tools_functionally_correct: | |
316 params['tools_functionally_correct'] = True | |
317 if missing_test_components: | |
318 params['missing_test_components'] = True | |
319 if do_not_test: | |
320 params['do_not_test'] = True | |
321 if includes_tools: | |
322 params['includes_tools'] = True | |
323 if test_install_error: | |
324 params['test_install_error'] = True | |
325 if skip_tool_test: | |
326 params['skip_tool_test'] = True | |
327 return self._get(url=url, params=params) | |
328 | |
329 def show_repository_revision(self, metadata_id): | |
330 ''' | |
331 Returns a dictionary that includes information about a specified | |
332 repository revision. | |
333 | |
334 :type metadata_id: str | |
335 :param metadata_id: Encoded repository metadata ID | |
336 | |
337 :rtype: dict | |
338 :return: Returns a dictionary that includes information about a | |
339 specified repository revision. | |
340 For example:: | |
341 | |
342 {'changeset_revision': '7602de1e7f32', | |
343 'do_not_test': False, | |
344 'downloadable': True, | |
345 'has_repository_dependencies': False, | |
346 'id': '504be8aaa652c154', | |
347 'includes_datatypes': False, | |
348 'includes_tool_dependencies': False, | |
349 'includes_tools': True, | |
350 'includes_tools_for_display_in_tool_panel': True, | |
351 'includes_workflows': False, | |
352 'malicious': False, | |
353 'missing_test_components': True, | |
354 'repository_id': '491b7a3fddf9366f', | |
355 'test_install_error': False, | |
356 'time_last_tested': None, | |
357 'tool_test_results': {'missing_test_components': []}, | |
358 'tools_functionally_correct': False, | |
359 'url': '/api/repository_revisions/504be8aaa652c154'} | |
360 ''' | |
361 # Not using '_make_url' or '_get' to create url since the module id used | |
362 # to create url is not the same as needed for this method | |
363 # since metadata_id has to be defined, easy to create the url here | |
364 url = '/'.join((self.gi.url, 'repository_revisions', metadata_id)) | |
365 return self._get(url=url) | |
366 | |
367 def update_repository(self, id, tar_ball_path, commit_message=None): | |
368 """ | |
369 Update the contents of a Tool Shed repository with specified tar ball. | |
370 | |
371 :type id: str | |
372 :param id: Encoded repository ID | |
373 | |
374 :type tar_ball_path: str | |
375 :param tar_ball_path: Path to file containing tar ball to upload. | |
376 | |
377 :type commit_message: str | |
378 :param commit_message: Commit message used for the underlying Mercurial | |
379 repository backing Tool Shed repository. | |
380 | |
381 :rtype: dict | |
382 :return: Returns a dictionary that includes repository content warnings. | |
383 Most valid uploads will result in no such warning and an exception | |
384 will be raised generally if there are problems. | |
385 For example a successful upload will look like:: | |
386 | |
387 {'content_alert': '', | |
388 'message': ''} | |
389 | |
390 .. versionadded:: 0.5.2 | |
391 """ | |
392 url = self._make_url(id) + '/changeset_revision' | |
393 payload = { | |
394 'file': attach_file(tar_ball_path) | |
395 } | |
396 if commit_message is not None: | |
397 payload['commit_message'] = commit_message | |
398 try: | |
399 return self._post(payload=payload, files_attached=True, url=url) | |
400 finally: | |
401 payload['file'].close() | |
402 | |
403 def create_repository(self, name, synopsis, description=None, | |
404 type='unrestricted', remote_repository_url=None, | |
405 homepage_url=None, category_ids=None): | |
406 """ | |
407 Create a new repository in a Tool Shed. | |
408 | |
409 :type name: str | |
410 :param name: Name of the repository | |
411 | |
412 :type synopsis: str | |
413 :param synopsis: Synopsis of the repository | |
414 | |
415 :type description: str | |
416 :param description: Optional description of the repository | |
417 | |
418 :type type: str | |
419 :param type: type of the repository. One of "unrestricted", | |
420 "repository_suite_definition", or "tool_dependency_definition" | |
421 | |
422 :type remote_repository_url: str | |
423 :param remote_repository_url: Remote URL (e.g. GitHub/Bitbucket | |
424 repository) | |
425 | |
426 :type homepage_url: str | |
427 :param homepage_url: Upstream's homepage for the project | |
428 | |
429 :type category_ids: list | |
430 :param category_ids: List of encoded category IDs | |
431 | |
432 :rtype: dict | |
433 :return: a dictionary containing information about the new repository. | |
434 For example:: | |
435 | |
436 {"deleted": false, | |
437 "deprecated": false, | |
438 "description": "new_synopsis", | |
439 "homepage_url": "https://github.com/galaxyproject/", | |
440 "id": "8cf91205f2f737f4", | |
441 "long_description": "this is some repository", | |
442 "model_class": "Repository", | |
443 "name": "new_repo_17", | |
444 "owner": "qqqqqq", | |
445 "private": false, | |
446 "remote_repository_url": "https://github.com/galaxyproject/tools-devteam", | |
447 "times_downloaded": 0, | |
448 "type": "unrestricted", | |
449 "user_id": "adb5f5c93f827949"} | |
450 """ | |
451 payload = { | |
452 'name': name, | |
453 'synopsis': synopsis, | |
454 } | |
455 if description is not None: | |
456 payload['description'] = description | |
457 if description is not None: | |
458 payload['description'] = description | |
459 if type is not None: | |
460 payload['type'] = type | |
461 if remote_repository_url is not None: | |
462 payload['remote_repository_url'] = remote_repository_url | |
463 if homepage_url is not None: | |
464 payload['homepage_url'] = homepage_url | |
465 if category_ids is not None: | |
466 payload['category_ids[]'] = category_ids | |
467 return self._post(payload) |