pyxetabase 3.1.0.dev0__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.

Files changed (63) hide show
  1. pyopencga/__init__.py +0 -0
  2. pyopencga/commons.py +347 -0
  3. pyopencga/exceptions.py +8 -0
  4. pyopencga/opencga_client.py +334 -0
  5. pyopencga/opencga_config.py +160 -0
  6. pyopencga/rest_clients/__init__.py +0 -0
  7. pyopencga/rest_clients/_parent_rest_clients.py +110 -0
  8. pyopencga/rest_clients/admin_client.py +173 -0
  9. pyopencga/rest_clients/alignment_client.py +373 -0
  10. pyopencga/rest_clients/clinical_analysis_client.py +1279 -0
  11. pyopencga/rest_clients/cohort_client.py +338 -0
  12. pyopencga/rest_clients/disease_panel_client.py +352 -0
  13. pyopencga/rest_clients/family_client.py +355 -0
  14. pyopencga/rest_clients/file_client.py +698 -0
  15. pyopencga/rest_clients/ga4gh_client.py +86 -0
  16. pyopencga/rest_clients/individual_client.py +435 -0
  17. pyopencga/rest_clients/job_client.py +415 -0
  18. pyopencga/rest_clients/meta_client.py +83 -0
  19. pyopencga/rest_clients/organization_client.py +206 -0
  20. pyopencga/rest_clients/project_client.py +128 -0
  21. pyopencga/rest_clients/sample_client.py +446 -0
  22. pyopencga/rest_clients/study_client.py +433 -0
  23. pyopencga/rest_clients/user_client.py +192 -0
  24. pyopencga/rest_clients/variant_client.py +1378 -0
  25. pyopencga/rest_clients/variant_operation_client.py +719 -0
  26. pyopencga/rest_clients/workflow_client.py +263 -0
  27. pyopencga/rest_response.py +220 -0
  28. pyopencga/retry.py +57 -0
  29. pyxetabase/__init__.py +0 -0
  30. pyxetabase/commons.py +347 -0
  31. pyxetabase/exceptions.py +8 -0
  32. pyxetabase/opencga_client.py +344 -0
  33. pyxetabase/opencga_config.py +160 -0
  34. pyxetabase/rest_clients/__init__.py +0 -0
  35. pyxetabase/rest_clients/_parent_rest_clients.py +110 -0
  36. pyxetabase/rest_clients/admin_client.py +173 -0
  37. pyxetabase/rest_clients/alignment_client.py +373 -0
  38. pyxetabase/rest_clients/clinical_analysis_client.py +1273 -0
  39. pyxetabase/rest_clients/cohort_client.py +338 -0
  40. pyxetabase/rest_clients/cvdb_client.py +2258 -0
  41. pyxetabase/rest_clients/disease_panel_client.py +352 -0
  42. pyxetabase/rest_clients/family_client.py +355 -0
  43. pyxetabase/rest_clients/federation_client.py +133 -0
  44. pyxetabase/rest_clients/file_client.py +698 -0
  45. pyxetabase/rest_clients/ga4gh_client.py +86 -0
  46. pyxetabase/rest_clients/individual_client.py +435 -0
  47. pyxetabase/rest_clients/job_client.py +415 -0
  48. pyxetabase/rest_clients/meta_client.py +83 -0
  49. pyxetabase/rest_clients/organization_client.py +206 -0
  50. pyxetabase/rest_clients/project_client.py +128 -0
  51. pyxetabase/rest_clients/sample_client.py +446 -0
  52. pyxetabase/rest_clients/study_client.py +433 -0
  53. pyxetabase/rest_clients/user_client.py +212 -0
  54. pyxetabase/rest_clients/variant_client.py +1378 -0
  55. pyxetabase/rest_clients/variant_operation_client.py +719 -0
  56. pyxetabase/rest_clients/workflow_client.py +263 -0
  57. pyxetabase/rest_response.py +220 -0
  58. pyxetabase/retry.py +57 -0
  59. pyxetabase-3.1.0.dev0.dist-info/METADATA +159 -0
  60. pyxetabase-3.1.0.dev0.dist-info/RECORD +63 -0
  61. pyxetabase-3.1.0.dev0.dist-info/WHEEL +5 -0
  62. pyxetabase-3.1.0.dev0.dist-info/licenses/LICENSE +202 -0
  63. pyxetabase-3.1.0.dev0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,160 @@
1
+ import os
2
+ import json
3
+ import requests
4
+ import yaml
5
+
6
+
7
+ class ClientConfiguration(object):
8
+ """PyOpenCGA configuration"""
9
+
10
+ def __init__(self, config_input):
11
+ """
12
+ :param dict or str config_input: a dict, or a yaml/json file containing an OpenCGA valid client configuration.
13
+ """
14
+
15
+ if isinstance(config_input, dict):
16
+ self._config = config_input
17
+ else:
18
+ self._config = self._get_dictionary_from_file(config_input)
19
+
20
+ self.get_sso_login_info()
21
+
22
+ self._validate_configuration()
23
+
24
+ @staticmethod
25
+ def _get_dictionary_from_file(config_fpath):
26
+ config_fhand = open(config_fpath, 'r')
27
+
28
+ if config_fpath.endswith('.yml') or config_fpath.endswith('.yaml'):
29
+ config_dict = yaml.safe_load(config_fhand)
30
+ elif config_fpath.endswith('.json'):
31
+ config_dict = json.loads(config_fhand.read())
32
+ else:
33
+ raise NotImplementedError('Input must be a dictionary, a yaml file (.yml or .yaml) or a json file (.json)')
34
+
35
+ config_fhand.close()
36
+
37
+ return config_dict
38
+
39
+ def get_sso_login_info(self):
40
+ if (('sso_login' in self._config and self._config['sso_login']) or
41
+ ('cookies' in self._config and self._config['cookies'])):
42
+ python_session_fhand = open(os.path.expanduser("~/.opencga/session.json"), 'r')
43
+ session_info = json.loads(python_session_fhand.read())
44
+ self._config['sso_login'] = True
45
+ self._config['cookies'] = session_info['cookies']
46
+ self._config['token'] = session_info['token']
47
+
48
+ def _validate_configuration(self):
49
+ if self._config is None:
50
+ raise ValueError('Missing configuration dictionary.')
51
+
52
+ if 'rest' not in self._config:
53
+ raise ValueError('Missing configuration field "rest".')
54
+
55
+ if 'host' not in self._config['rest'] or not self._config['rest']['host']:
56
+ raise ValueError('Missing configuration field "host".')
57
+
58
+ self._validate_host(self._config['rest']['host'])
59
+
60
+ @staticmethod
61
+ def _validate_host(host):
62
+ try:
63
+ r = requests.head(host, timeout=2)
64
+ if r.status_code == 302:
65
+ return
66
+ except requests.ConnectionError:
67
+ raise Exception('Unreachable host "{}"'.format(host))
68
+
69
+ @property
70
+ def configuration(self):
71
+ return self._config
72
+
73
+ @property
74
+ def host(self):
75
+ return self._config['rest']['host']
76
+
77
+ @host.setter
78
+ def host(self, host):
79
+ self._config['rest']['host'] = host
80
+ self._validate_host(host)
81
+
82
+ @property
83
+ def version(self):
84
+ return self._config['version'] if 'version' in self._config else 'v2'
85
+
86
+ @version.setter
87
+ def version(self, version):
88
+ self._config['version'] = version
89
+
90
+ @property
91
+ def sso_login(self):
92
+ if 'sso_login' in self._config and self._config['sso_login']:
93
+ return self._config['sso_login']
94
+ else:
95
+ return False
96
+
97
+ @sso_login.setter
98
+ def sso_login(self, sso_login):
99
+ if isinstance(str, sso_login):
100
+ self._config['sso_login'] = sso_login.lower() == 'true'
101
+ if isinstance(bool, sso_login):
102
+ self._config['sso_login'] = sso_login
103
+
104
+ @property
105
+ def cookies(self):
106
+ if 'cookies' in self._config and self._config['cookies']:
107
+ return self._config['cookies']
108
+ else:
109
+ return None
110
+
111
+ @cookies.setter
112
+ def cookies(self, cookies):
113
+ self._config['cookies'] = cookies
114
+
115
+ @property
116
+ def token(self):
117
+ if 'token' in self._config and self._config['token']:
118
+ return self._config['token']
119
+ else:
120
+ return None
121
+
122
+ @token.setter
123
+ def token(self, token):
124
+ self._config['token'] = token
125
+
126
+ @property
127
+ def max_attempts(self):
128
+ """Returns configured max_attempts or 1 if not configured"""
129
+ if 'max_attempts' in self._config and self._config['max_attempts']:
130
+ return self._config['max_attempts']
131
+ else:
132
+ return 1
133
+
134
+ @max_attempts.setter
135
+ def max_attempts(self, max_attempts):
136
+ self._config['max_attempts'] = max_attempts
137
+
138
+ @property
139
+ def min_retry_secs(self):
140
+ """Returns configured min_retry_seconds or 0 if not configured"""
141
+ if 'min_retry_secs' in self._config and self._config['min_retry_secs']:
142
+ return self._config['min_retry_secs']
143
+ else:
144
+ return 0
145
+
146
+ @min_retry_secs.setter
147
+ def min_retry_secs(self, min_retry_secs):
148
+ self._config['min_retry_secs'] = min_retry_secs
149
+
150
+ @property
151
+ def max_retry_secs(self):
152
+ """Returns configured max_retry_seconds or 0 if not configured"""
153
+ if 'max_retry_secs' in self._config and self._config['max_retry_secs']:
154
+ return self._config['max_retry_secs']
155
+ else:
156
+ return 0
157
+
158
+ @max_retry_secs.setter
159
+ def max_retry_secs(self, max_retry_secs):
160
+ self._config['max_retry_secs'] = max_retry_secs
File without changes
@@ -0,0 +1,110 @@
1
+ import json
2
+
3
+ from pyopencga.commons import execute
4
+ from pyopencga.rest_response import RestResponse
5
+ from pyopencga.retry import retry
6
+
7
+
8
+ class _ParentRestClient(object):
9
+ """Queries the REST service given the different query params"""
10
+
11
+ def __init__(self, configuration, token=None, login_handler=None,
12
+ auto_refresh=True):
13
+ self.auto_refresh = auto_refresh
14
+ self._cfg = configuration
15
+ self.token = token
16
+ self.refresh_token = None
17
+ self.login_handler = login_handler
18
+ self.on_retry = None
19
+
20
+ def _client_login_handler(self):
21
+ if self.login_handler:
22
+ self.token, self.refresh_token = self.login_handler()
23
+
24
+ def _refresh_token_client(self):
25
+ if self.login_handler:
26
+ self.token, self.refresh_token = self.login_handler(refresh=True)
27
+
28
+ @staticmethod
29
+ def _get_query_id_str(query_ids):
30
+ if query_ids is None:
31
+ return None
32
+ elif isinstance(query_ids, list):
33
+ return ','.join(map(str, query_ids))
34
+ else:
35
+ return str(query_ids)
36
+
37
+ def _rest_retry(self, method, category, resource, query_id=None, subcategory=None,
38
+ second_query_id=None, data=None, dont_retry=None,
39
+ **options):
40
+
41
+ query_ids_str = self._get_query_id_str(query_id)
42
+
43
+ def exec_retry():
44
+ return execute(config=self._cfg,
45
+ sid=self.token,
46
+ category=category,
47
+ subcategory=subcategory,
48
+ method=method,
49
+ query_id=query_ids_str,
50
+ second_query_id=second_query_id,
51
+ resource=resource,
52
+ data=data,
53
+ options=options)
54
+
55
+ def notify_retry(exc_type, exc_val, exc_tb):
56
+ if self.on_retry is not None:
57
+ self.on_retry(self, exc_type, exc_val, exc_tb, dict(
58
+ method=method, resource=resource, query_id=query_id,
59
+ category=category, subcategory=subcategory,
60
+ second_query_id=second_query_id, data=data,
61
+ options=options
62
+ ))
63
+
64
+ response = retry(
65
+ exec_retry, self._cfg.max_attempts, self._cfg.min_retry_secs,
66
+ self._cfg.max_retry_secs, login_handler=self.login_handler,
67
+ on_retry=notify_retry, dont_retry=dont_retry
68
+ )
69
+
70
+ if self.auto_refresh:
71
+ self._refresh_token_client()
72
+
73
+ if isinstance(response, dict):
74
+ return RestResponse(response)
75
+ else: # Not a JSON (e.g. /{apiVersion}/files/{file}/download)
76
+ return response
77
+
78
+ def _get(self, category, resource, query_id=None, subcategory=None,
79
+ second_query_id=None, **options):
80
+ """Queries the REST service and returns the result"""
81
+ return self._rest_retry(
82
+ method='get', category=category, resource=resource, query_id=query_id,
83
+ subcategory=subcategory, second_query_id=second_query_id,
84
+ **options
85
+ )
86
+
87
+ def _post(self, category, resource, data=None, query_id=None, subcategory=None,
88
+ second_query_id=None, **options):
89
+ """Queries the REST service and returns the result"""
90
+ if data is not None:
91
+ return self._rest_retry(
92
+ method='post', category=category, resource=resource, query_id=query_id,
93
+ subcategory=subcategory, second_query_id=second_query_id,
94
+ data=data, **options
95
+ )
96
+ else:
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
+ **options
101
+ )
102
+
103
+ def _delete(self, category, resource, query_id=None, subcategory=None,
104
+ second_query_id=None, **options):
105
+ """Queries the REST service and returns the result"""
106
+ return self._rest_retry(
107
+ method='delete', category=category, resource=resource, query_id=query_id,
108
+ subcategory=subcategory, second_query_id=second_query_id,
109
+ **options
110
+ )
@@ -0,0 +1,173 @@
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 pyopencga.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 WORKFLOW
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 jwt_catalog(self, data=None, **options):
58
+ """
59
+ Change JWT secret key.
60
+ PATH: /{apiVersion}/admin/catalog/jwt
61
+
62
+ :param dict data: JSON containing the parameters. (REQUIRED)
63
+ :param str organization: Organization id.
64
+ """
65
+
66
+ return self._post(category='admin', resource='jwt', subcategory='catalog', data=data, **options)
67
+
68
+ def fetch_resource(self, data=None, **options):
69
+ """
70
+ Fetch resources from the public server and save them into the OpenCGA
71
+ local installation.
72
+ PATH: /{apiVersion}/admin/resource/fetch
73
+
74
+ :param dict data: Download-resources tool parameters. (REQUIRED)
75
+ :param str job_id: Job ID. It must be a unique string within the
76
+ study. An ID will be autogenerated automatically if not provided.
77
+ :param str job_description: Job description.
78
+ :param str job_depends_on: Comma separated list of existing job IDs
79
+ the job will depend on.
80
+ :param str job_tags: Job tags.
81
+ :param str job_scheduled_start_time: Time when the job is scheduled to
82
+ start.
83
+ :param str job_priority: Priority of the job.
84
+ :param bool job_dry_run: Flag indicating that the job will be executed
85
+ in dry-run mode. In this mode, OpenCGA will validate that all
86
+ parameters and prerequisites are correctly set for successful
87
+ execution, but the job will not actually run.
88
+ """
89
+
90
+ return self._post(category='admin', resource='fetch', subcategory='resource', data=data, **options)
91
+
92
+ def create_users(self, data=None, **options):
93
+ """
94
+ Create a new user.
95
+ PATH: /{apiVersion}/admin/users/create
96
+
97
+ :param dict data: JSON containing the parameters. (REQUIRED)
98
+ """
99
+
100
+ return self._post(category='admin', resource='create', subcategory='users', data=data, **options)
101
+
102
+ def import_users(self, data=None, **options):
103
+ """
104
+ Import users or a group of users from LDAP or AAD.
105
+ PATH: /{apiVersion}/admin/users/import
106
+
107
+ :param dict data: JSON containing the parameters. (REQUIRED)
108
+ :param str organization: Organization id.
109
+ """
110
+
111
+ return self._post(category='admin', resource='import', subcategory='users', data=data, **options)
112
+
113
+ def permissions_users(self, **options):
114
+ """
115
+ User permissions.
116
+ PATH: /{apiVersion}/admin/users/permissions
117
+
118
+ :param str study: Study [[organization@]project:]study where study and
119
+ project can be either the ID or UUID.
120
+ :param str entry_ids: Comma separated list of entry ids.
121
+ :param str permissions: Comma separated list of permissions to be
122
+ retrieved.
123
+ :param str category: Category corresponding to the id's provided.
124
+ """
125
+
126
+ return self._get(category='admin', resource='permissions', subcategory='users', **options)
127
+
128
+ def search_users(self, **options):
129
+ """
130
+ User search method.
131
+ PATH: /{apiVersion}/admin/users/search
132
+
133
+ :param str include: Fields included in the response, whole JSON path
134
+ must be provided.
135
+ :param str exclude: Fields excluded in the response, whole JSON path
136
+ must be provided.
137
+ :param int limit: Number of results to be returned.
138
+ :param int skip: Number of results to skip.
139
+ :param bool count: Get the total number of results matching the query.
140
+ Deactivated by default.
141
+ :param str organization: Organization id.
142
+ :param str user: User ID.
143
+ :param str authentication_id: Authentication origin ID.
144
+ """
145
+
146
+ return self._get(category='admin', resource='search', subcategory='users', **options)
147
+
148
+ def sync_users(self, data=None, **options):
149
+ """
150
+ Synchronise a group of users from an authentication origin with a
151
+ group in a study from catalog.
152
+ PATH: /{apiVersion}/admin/users/sync
153
+
154
+ :param dict data: JSON containing the parameters. (REQUIRED)
155
+ :param str organization: Organization id.
156
+ """
157
+
158
+ return self._post(category='admin', resource='sync', subcategory='users', data=data, **options)
159
+
160
+ def users_update_groups(self, user, data=None, **options):
161
+ """
162
+ Add or remove users from existing groups.
163
+ PATH: /{apiVersion}/admin/users/{user}/groups/update
164
+
165
+ :param dict data: JSON containing the parameters. (REQUIRED)
166
+ :param str user: User ID. (REQUIRED)
167
+ :param str organization: Organization id.
168
+ :param str action: Action to be performed: ADD or REMOVE user to/from
169
+ groups. Allowed values: ['ADD REMOVE']
170
+ """
171
+
172
+ return self._post(category='admin/users', resource='update', query_id=user, subcategory='groups', data=data, **options)
173
+