pyxetabase 4.0.0.dev56__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyxetabase might be problematic. Click here for more details.
- pyxetabase/__init__.py +0 -0
- pyxetabase/commons.py +347 -0
- pyxetabase/exceptions.py +8 -0
- pyxetabase/opencga_client.py +344 -0
- pyxetabase/opencga_config.py +211 -0
- pyxetabase/rest_clients/__init__.py +0 -0
- pyxetabase/rest_clients/_parent_rest_clients.py +144 -0
- pyxetabase/rest_clients/admin_client.py +179 -0
- pyxetabase/rest_clients/alignment_client.py +373 -0
- pyxetabase/rest_clients/clinical_analysis_client.py +1216 -0
- pyxetabase/rest_clients/cohort_client.py +349 -0
- pyxetabase/rest_clients/cvdb_client.py +2285 -0
- pyxetabase/rest_clients/disease_panel_client.py +345 -0
- pyxetabase/rest_clients/family_client.py +355 -0
- pyxetabase/rest_clients/federation_client.py +133 -0
- pyxetabase/rest_clients/file_client.py +710 -0
- pyxetabase/rest_clients/ga4gh_client.py +86 -0
- pyxetabase/rest_clients/individual_client.py +435 -0
- pyxetabase/rest_clients/job_client.py +416 -0
- pyxetabase/rest_clients/meta_client.py +85 -0
- pyxetabase/rest_clients/organization_client.py +216 -0
- pyxetabase/rest_clients/project_client.py +128 -0
- pyxetabase/rest_clients/sample_client.py +446 -0
- pyxetabase/rest_clients/study_client.py +462 -0
- pyxetabase/rest_clients/user_client.py +212 -0
- pyxetabase/rest_clients/user_tool_client.py +471 -0
- pyxetabase/rest_clients/variant_client.py +1378 -0
- pyxetabase/rest_clients/variant_operation_client.py +718 -0
- pyxetabase/rest_clients/workflow_client.py +263 -0
- pyxetabase/rest_response.py +220 -0
- pyxetabase/retry.py +57 -0
- pyxetabase-4.0.0.dev56.dist-info/METADATA +159 -0
- pyxetabase-4.0.0.dev56.dist-info/RECORD +36 -0
- pyxetabase-4.0.0.dev56.dist-info/WHEEL +5 -0
- pyxetabase-4.0.0.dev56.dist-info/licenses/LICENSE +202 -0
- pyxetabase-4.0.0.dev56.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from pyxetabase.commons import execute, _create_rest_url, snake_to_camel_case
|
|
5
|
+
from pyxetabase.rest_response import RestResponse
|
|
6
|
+
from pyxetabase.retry import retry
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class _ParentRestClient(object):
|
|
10
|
+
"""Queries the REST service given the different query params"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, configuration, token=None, login_handler=None,
|
|
13
|
+
auto_refresh=True):
|
|
14
|
+
self.auto_refresh = auto_refresh
|
|
15
|
+
self._cfg = configuration
|
|
16
|
+
self.token = token
|
|
17
|
+
self.refresh_token = None
|
|
18
|
+
self.login_handler = login_handler
|
|
19
|
+
self.on_retry = None
|
|
20
|
+
|
|
21
|
+
def _client_login_handler(self):
|
|
22
|
+
if self.login_handler:
|
|
23
|
+
self.token, self.refresh_token = self.login_handler()
|
|
24
|
+
|
|
25
|
+
def _refresh_token_client(self):
|
|
26
|
+
if self.login_handler:
|
|
27
|
+
self.token, self.refresh_token = self.login_handler(refresh=True)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def _get_query_id_str(query_ids):
|
|
31
|
+
if query_ids is None:
|
|
32
|
+
return None
|
|
33
|
+
elif isinstance(query_ids, list):
|
|
34
|
+
return ','.join(map(str, query_ids))
|
|
35
|
+
else:
|
|
36
|
+
return str(query_ids)
|
|
37
|
+
|
|
38
|
+
def _rest_retry(self, method, category, resource, query_id=None, subcategory=None,
|
|
39
|
+
second_query_id=None, data=None, dont_retry=None,
|
|
40
|
+
**options):
|
|
41
|
+
|
|
42
|
+
query_ids_str = self._get_query_id_str(query_id)
|
|
43
|
+
|
|
44
|
+
def exec_retry():
|
|
45
|
+
return execute(config=self._cfg,
|
|
46
|
+
sid=self.token,
|
|
47
|
+
category=category,
|
|
48
|
+
subcategory=subcategory,
|
|
49
|
+
method=method,
|
|
50
|
+
query_id=query_ids_str,
|
|
51
|
+
second_query_id=second_query_id,
|
|
52
|
+
resource=resource,
|
|
53
|
+
data=data,
|
|
54
|
+
options=options)
|
|
55
|
+
|
|
56
|
+
def notify_retry(exc_type, exc_val, exc_tb):
|
|
57
|
+
if self.on_retry is not None:
|
|
58
|
+
self.on_retry(self, exc_type, exc_val, exc_tb, dict(
|
|
59
|
+
method=method, resource=resource, query_id=query_id,
|
|
60
|
+
category=category, subcategory=subcategory,
|
|
61
|
+
second_query_id=second_query_id, data=data,
|
|
62
|
+
options=options
|
|
63
|
+
))
|
|
64
|
+
|
|
65
|
+
response = retry(
|
|
66
|
+
exec_retry, self._cfg.max_attempts, self._cfg.min_retry_secs,
|
|
67
|
+
self._cfg.max_retry_secs, login_handler=self.login_handler,
|
|
68
|
+
on_retry=notify_retry, dont_retry=dont_retry
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if self.auto_refresh:
|
|
72
|
+
self._refresh_token_client()
|
|
73
|
+
|
|
74
|
+
if isinstance(response, dict):
|
|
75
|
+
return RestResponse(response)
|
|
76
|
+
else: # Not a JSON (e.g. /{apiVersion}/files/{file}/download)
|
|
77
|
+
return response
|
|
78
|
+
|
|
79
|
+
def _get(self, category, resource, query_id=None, subcategory=None,
|
|
80
|
+
second_query_id=None, **options):
|
|
81
|
+
"""Queries the REST service and returns the result"""
|
|
82
|
+
return self._rest_retry(
|
|
83
|
+
method='get', category=category, resource=resource, query_id=query_id,
|
|
84
|
+
subcategory=subcategory, second_query_id=second_query_id,
|
|
85
|
+
**options
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def _post(self, category, resource, data=None, query_id=None, subcategory=None,
|
|
89
|
+
second_query_id=None, **options):
|
|
90
|
+
"""Queries the REST service and returns the result"""
|
|
91
|
+
# Special treatment for the "/{apiVersion}/files/upload" endpoint
|
|
92
|
+
if category == 'files' and resource == 'upload':
|
|
93
|
+
response = self._upload(category=category, resource=resource, **options)
|
|
94
|
+
return RestResponse(response)
|
|
95
|
+
else:
|
|
96
|
+
if data is not None:
|
|
97
|
+
return self._rest_retry(
|
|
98
|
+
method='post', category=category, resource=resource, query_id=query_id,
|
|
99
|
+
subcategory=subcategory, second_query_id=second_query_id,
|
|
100
|
+
data=data, **options
|
|
101
|
+
)
|
|
102
|
+
else:
|
|
103
|
+
return self._rest_retry(
|
|
104
|
+
method='post', category=category, resource=resource, query_id=query_id,
|
|
105
|
+
subcategory=subcategory, second_query_id=second_query_id,
|
|
106
|
+
**options
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def _delete(self, category, resource, query_id=None, subcategory=None,
|
|
110
|
+
second_query_id=None, **options):
|
|
111
|
+
"""Queries the REST service and returns the result"""
|
|
112
|
+
return self._rest_retry(
|
|
113
|
+
method='delete', category=category, resource=resource, query_id=query_id,
|
|
114
|
+
subcategory=subcategory, second_query_id=second_query_id,
|
|
115
|
+
**options
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
def _upload(self, category, resource, **options):
|
|
119
|
+
"""Upload files"""
|
|
120
|
+
|
|
121
|
+
# Checking that the parameter file contains the file path to upload
|
|
122
|
+
if 'file' not in options or not isinstance(options['file'], str):
|
|
123
|
+
raise ValueError('To upload a file, please specify the file path as the "file" parameter.')
|
|
124
|
+
|
|
125
|
+
# Creating URL and headers
|
|
126
|
+
url, header = _create_rest_url(host=self._cfg.host, version=self._cfg.version, sid=self.token,
|
|
127
|
+
category=category, resource=resource, options=options)
|
|
128
|
+
|
|
129
|
+
# Creating data
|
|
130
|
+
data = {}
|
|
131
|
+
for k, v in options.items():
|
|
132
|
+
if k == 'file': # Param "file" is not included in data
|
|
133
|
+
continue
|
|
134
|
+
data[snake_to_camel_case(k)] = v
|
|
135
|
+
|
|
136
|
+
# Uploading
|
|
137
|
+
fpath = os.path.realpath(os.path.expanduser(options['file']))
|
|
138
|
+
with open(fpath, "rb") as f:
|
|
139
|
+
fhand = {"file": (fpath, f, "application/octet-stream")}
|
|
140
|
+
response = requests.post(url, headers=header, files=fhand, data=data or None)
|
|
141
|
+
if response.status_code != 200:
|
|
142
|
+
raise Exception(response.content)
|
|
143
|
+
|
|
144
|
+
return response.json()
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WARNING: AUTOGENERATED CODE
|
|
3
|
+
|
|
4
|
+
This code was generated by a tool.
|
|
5
|
+
|
|
6
|
+
Manual changes to this file may cause unexpected behavior in your application.
|
|
7
|
+
Manual changes to this file will be overwritten if the code is regenerated.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pyxetabase.rest_clients._parent_rest_clients import _ParentRestClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Admin(_ParentRestClient):
|
|
14
|
+
"""
|
|
15
|
+
This class contains methods for the 'Admin' webservices
|
|
16
|
+
PATH: /{apiVersion}/admin
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, configuration, token=None, login_handler=None, *args, **kwargs):
|
|
20
|
+
super(Admin, self).__init__(configuration, token, login_handler, *args, **kwargs)
|
|
21
|
+
|
|
22
|
+
def group_by_audit(self, fields, entity, **options):
|
|
23
|
+
"""
|
|
24
|
+
Group by operation.
|
|
25
|
+
PATH: /{apiVersion}/admin/audit/groupBy
|
|
26
|
+
|
|
27
|
+
:param str entity: Entity to be grouped by. Allowed values: ['AUDIT
|
|
28
|
+
NOTE ORGANIZATION USER PROJECT STUDY FILE SAMPLE JOB INDIVIDUAL
|
|
29
|
+
COHORT DISEASE_PANEL FAMILY CLINICAL_ANALYSIS INTERPRETATION
|
|
30
|
+
VARIANT ALIGNMENT CLINICAL EXPRESSION RGA FUNCTIONAL EXTERNAL_TOOL
|
|
31
|
+
RESOURCE'] (REQUIRED)
|
|
32
|
+
:param str fields: Comma separated list of fields by which to group
|
|
33
|
+
by. (REQUIRED)
|
|
34
|
+
:param bool count: Count the number of elements matching the group.
|
|
35
|
+
:param int limit: Maximum number of documents (groups) to be returned.
|
|
36
|
+
:param str action: Action performed.
|
|
37
|
+
:param str before: Object before update.
|
|
38
|
+
:param str after: Object after update.
|
|
39
|
+
:param str date: Date <,<=,>,>=(Format: yyyyMMddHHmmss) and
|
|
40
|
+
yyyyMMddHHmmss-yyyyMMddHHmmss.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
options['fields'] = fields
|
|
44
|
+
options['entity'] = entity
|
|
45
|
+
return self._get(category='admin', resource='groupBy', subcategory='audit', **options)
|
|
46
|
+
|
|
47
|
+
def install_catalog(self, data=None, **options):
|
|
48
|
+
"""
|
|
49
|
+
Install OpenCGA database.
|
|
50
|
+
PATH: /{apiVersion}/admin/catalog/install
|
|
51
|
+
|
|
52
|
+
:param dict data: JSON containing the mandatory parameters. (REQUIRED)
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
return self._post(category='admin', resource='install', subcategory='catalog', data=data, **options)
|
|
56
|
+
|
|
57
|
+
def update_catalog_workspace(self, data=None, **options):
|
|
58
|
+
"""
|
|
59
|
+
Update the OpenCGA Catalog workspace.
|
|
60
|
+
PATH: /{apiVersion}/admin/catalog/workspace/update
|
|
61
|
+
|
|
62
|
+
:param dict data: JSON containing the workspace parameters. (REQUIRED)
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
return self._post(category='admin', resource='update', subcategory='catalog/workspace', data=data, **options)
|
|
66
|
+
|
|
67
|
+
def list_organizations(self, **options):
|
|
68
|
+
"""
|
|
69
|
+
List current Organizations.
|
|
70
|
+
PATH: /{apiVersion}/admin/organizations/list
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
return self._get(category='admin', resource='list', subcategory='organizations', **options)
|
|
74
|
+
|
|
75
|
+
def fetch_resource(self, data=None, **options):
|
|
76
|
+
"""
|
|
77
|
+
Fetch resources from the public server and save them into the OpenCGA
|
|
78
|
+
local installation.
|
|
79
|
+
PATH: /{apiVersion}/admin/resource/fetch
|
|
80
|
+
|
|
81
|
+
:param dict data: Download-resources tool parameters. (REQUIRED)
|
|
82
|
+
:param str job_id: Job ID. It must be a unique string within the
|
|
83
|
+
study. An ID will be autogenerated automatically if not provided.
|
|
84
|
+
:param str job_description: Job description.
|
|
85
|
+
:param str job_depends_on: Comma separated list of existing job IDs
|
|
86
|
+
the job will depend on.
|
|
87
|
+
:param str job_tags: Job tags.
|
|
88
|
+
:param str job_scheduled_start_time: Time when the job is scheduled to
|
|
89
|
+
start.
|
|
90
|
+
:param str job_priority: Priority of the job.
|
|
91
|
+
:param bool job_dry_run: Flag indicating that the job will be executed
|
|
92
|
+
in dry-run mode. In this mode, OpenCGA will validate that all
|
|
93
|
+
parameters and prerequisites are correctly set for successful
|
|
94
|
+
execution, but the job will not actually run.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
return self._post(category='admin', resource='fetch', subcategory='resource', data=data, **options)
|
|
98
|
+
|
|
99
|
+
def create_users(self, data=None, **options):
|
|
100
|
+
"""
|
|
101
|
+
Create a new user.
|
|
102
|
+
PATH: /{apiVersion}/admin/users/create
|
|
103
|
+
|
|
104
|
+
:param dict data: JSON containing the parameters. (REQUIRED)
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
return self._post(category='admin', resource='create', subcategory='users', data=data, **options)
|
|
108
|
+
|
|
109
|
+
def import_users(self, data=None, **options):
|
|
110
|
+
"""
|
|
111
|
+
Import users or a group of users from LDAP or AAD.
|
|
112
|
+
PATH: /{apiVersion}/admin/users/import
|
|
113
|
+
|
|
114
|
+
:param dict data: JSON containing the parameters. (REQUIRED)
|
|
115
|
+
:param str organization: Organization id.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
return self._post(category='admin', resource='import', subcategory='users', data=data, **options)
|
|
119
|
+
|
|
120
|
+
def permissions_users(self, **options):
|
|
121
|
+
"""
|
|
122
|
+
User permissions.
|
|
123
|
+
PATH: /{apiVersion}/admin/users/permissions
|
|
124
|
+
|
|
125
|
+
:param str study: Study [[organization@]project:]study where study and
|
|
126
|
+
project can be either the ID or UUID.
|
|
127
|
+
:param str entry_ids: Comma separated list of entry ids.
|
|
128
|
+
:param str permissions: Comma separated list of permissions to be
|
|
129
|
+
retrieved.
|
|
130
|
+
:param str category: Category corresponding to the id's provided.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
return self._get(category='admin', resource='permissions', subcategory='users', **options)
|
|
134
|
+
|
|
135
|
+
def search_users(self, **options):
|
|
136
|
+
"""
|
|
137
|
+
User search method.
|
|
138
|
+
PATH: /{apiVersion}/admin/users/search
|
|
139
|
+
|
|
140
|
+
:param str include: Fields included in the response, whole JSON path
|
|
141
|
+
must be provided.
|
|
142
|
+
:param str exclude: Fields excluded in the response, whole JSON path
|
|
143
|
+
must be provided.
|
|
144
|
+
:param int limit: Number of results to be returned.
|
|
145
|
+
:param int skip: Number of results to skip.
|
|
146
|
+
:param bool count: Get the total number of results matching the query.
|
|
147
|
+
Deactivated by default.
|
|
148
|
+
:param str organization: Organization id.
|
|
149
|
+
:param str user: User ID.
|
|
150
|
+
:param str authentication_id: Authentication origin ID.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
return self._get(category='admin', resource='search', subcategory='users', **options)
|
|
154
|
+
|
|
155
|
+
def sync_users(self, data=None, **options):
|
|
156
|
+
"""
|
|
157
|
+
[DEPRECATED] Moved to /users/sync.
|
|
158
|
+
PATH: /{apiVersion}/admin/users/sync
|
|
159
|
+
|
|
160
|
+
:param dict data: JSON containing the parameters. (REQUIRED)
|
|
161
|
+
:param str organization: Organization id.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
return self._post(category='admin', resource='sync', subcategory='users', data=data, **options)
|
|
165
|
+
|
|
166
|
+
def users_update_groups(self, user, data=None, **options):
|
|
167
|
+
"""
|
|
168
|
+
Add or remove users from existing groups.
|
|
169
|
+
PATH: /{apiVersion}/admin/users/{user}/groups/update
|
|
170
|
+
|
|
171
|
+
:param dict data: JSON containing the parameters. (REQUIRED)
|
|
172
|
+
:param str user: User ID. (REQUIRED)
|
|
173
|
+
:param str organization: Organization id.
|
|
174
|
+
:param str action: Action to be performed: ADD or REMOVE user to/from
|
|
175
|
+
groups. Allowed values: ['ADD REMOVE']
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
return self._post(category='admin/users', resource='update', query_id=user, subcategory='groups', data=data, **options)
|
|
179
|
+
|