File: __init__.py

package info (click to toggle)
python-bioblend 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: python: 7,596; sh: 219; makefile: 158
file content (196 lines) | stat: -rw-r--r-- 7,929 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"""
Interaction with a Galaxy Tool Shed.
"""

from typing import (
    Any,
    Dict,
    List,
    Optional,
    TYPE_CHECKING,
)

from bioblend.galaxy.client import Client

if TYPE_CHECKING:
    from bioblend.galaxy import GalaxyInstance


class ToolShedClient(Client):
    module = "tool_shed_repositories"

    def __init__(self, galaxy_instance: "GalaxyInstance") -> None:
        super().__init__(galaxy_instance)

    def get_repositories(self) -> List[Dict[str, Any]]:
        """
        Get the list of all installed Tool Shed repositories on this Galaxy instance.

        :rtype: list
        :return: a list of dictionaries containing information about
          repositories present in the Tool Shed.
          For example::

            [{'changeset_revision': '4afe13ac23b6',
              'deleted': False,
              'dist_to_shed': False,
              'error_message': '',
              'name': 'velvet_toolsuite',
              'owner': 'edward-kirton',
              'status': 'Installed'}]

        .. versionchanged:: 0.4.1
            Changed method name from ``get_tools`` to ``get_repositories`` to
            better align with the Tool Shed concepts

        .. seealso:: bioblend.galaxy.tools.get_tool_panel()
        """
        return self._get()

    def show_repository(self, toolShed_id: str) -> Dict[str, Any]:
        """
        Get details of a given Tool Shed repository as it is installed on this
        Galaxy instance.

        :type toolShed_id: str
        :param toolShed_id: Encoded Tool Shed ID

        :rtype: dict
        :return: Information about the tool
          For example::

            {'changeset_revision': 'b17455fb6222',
             'ctx_rev': '8',
             'owner': 'aaron',
             'status': 'Installed',
             'url': '/api/tool_shed_repositories/82de4a4c7135b20a'}

        .. versionchanged:: 0.4.1
            Changed method name from ``show_tool`` to ``show_repository`` to
            better align with the Tool Shed concepts
        """
        return self._get(id=toolShed_id)

    def install_repository_revision(
        self,
        tool_shed_url: str,
        name: str,
        owner: str,
        changeset_revision: str,
        install_tool_dependencies: bool = False,
        install_repository_dependencies: bool = False,
        install_resolver_dependencies: bool = False,
        tool_panel_section_id: Optional[str] = None,
        new_tool_panel_section_label: Optional[str] = None,
    ) -> Dict[str, Any]:
        """
        Install a specified repository revision from a specified Tool Shed into
        this Galaxy instance. This example demonstrates installation of a repository
        that contains valid tools, loading them into a section of the Galaxy tool
        panel or creating a new tool panel section.
        You can choose if tool dependencies or repository dependencies should be
        installed through the Tool Shed,
        (use ``install_tool_dependencies`` or ``install_repository_dependencies``)
        or through a resolver that supports installing dependencies
        (use ``install_resolver_dependencies``). Note that any combination of
        the three dependency resolving variables is valid.

        Installing the repository into an existing tool panel section requires
        the tool panel config file (e.g., tool_conf.xml, shed_tool_conf.xml, etc)
        to contain the given tool panel section:

            <section id="from_test_tool_shed" name="From Test Tool Shed" version="">
            </section>

        :type tool_shed_url: str
        :param tool_shed_url: URL of the Tool Shed from which the repository should
                              be installed from (e.g., ``https://testtoolshed.g2.bx.psu.edu``)

        :type name: str
        :param name: The name of the repository that should be installed

        :type owner: str
        :param owner: The name of the repository owner

        :type changeset_revision: str
        :param changeset_revision: The revision of the repository to be installed

        :type install_tool_dependencies: bool
        :param install_tool_dependencies: Whether or not to automatically handle
                                          tool dependencies (see
                                          https://galaxyproject.org/toolshed/tool-dependency-recipes/
                                          for more details)

        :type install_repository_dependencies: bool
        :param install_repository_dependencies: Whether or not to automatically
                                                handle repository dependencies
                                                (see https://galaxyproject.org/toolshed/defining-repository-dependencies/
                                                for more details)

        :type install_resolver_dependencies: bool
        :param install_resolver_dependencies: Whether or not to automatically
                                                install resolver dependencies (e.g. conda).

        :type tool_panel_section_id: str
        :param tool_panel_section_id: The ID of the Galaxy tool panel section
                                      where the tool should be insterted under.
                                      Note that you should specify either this
                                      parameter or the ``new_tool_panel_section_label``.
                                      If both are specified, this one will take
                                      precedence.

        :type new_tool_panel_section_label: str
        :param new_tool_panel_section_label: The name of a Galaxy tool panel section
                                             that should be created and the repository
                                             installed into.
        """
        payload: Dict[str, Any] = {}
        payload["tool_shed_url"] = tool_shed_url
        payload["name"] = name
        payload["owner"] = owner
        payload["changeset_revision"] = changeset_revision
        payload["install_tool_dependencies"] = install_tool_dependencies
        payload["install_repository_dependencies"] = install_repository_dependencies
        payload["install_resolver_dependencies"] = install_resolver_dependencies
        if tool_panel_section_id:
            payload["tool_panel_section_id"] = tool_panel_section_id
        elif new_tool_panel_section_label:
            payload["new_tool_panel_section_label"] = new_tool_panel_section_label

        url = self._make_url() + "/new/install_repository_revision"
        return self._post(url=url, payload=payload)

    def uninstall_repository_revision(
        self, name: str, owner: str, changeset_revision: str, tool_shed_url: str, remove_from_disk: bool = True
    ) -> Dict[str, Any]:
        """
        Uninstalls a specified repository revision from this Galaxy instance.

        :type name: str
        :param name: The name of the repository

        :type owner: str
        :param owner: The owner of the repository

        :type changeset_revision: str
        :param changeset_revision: The revision of the repository to uninstall

        :type tool_shed_url: str
        :param tool_shed_url: URL of the Tool Shed from which the repository was
          installed from (e.g., ``https://testtoolshed.g2.bx.psu.edu``)

        :type remove_from_disk: bool
        :param remove_from_disk: whether to also remove the repository from disk
          (the default) or only deactivate it

        :rtype: dict
        :return: If successful, a dictionary with a message noting the removal
        """
        payload: Dict[str, Any] = {
            "tool_shed_url": tool_shed_url,
            "name": name,
            "owner": owner,
            "changeset_revision": changeset_revision,
            "remove_from_disk": remove_from_disk,
        }
        return self._delete(params=payload)