ebi-eva-common-pyutils 0.6.8__py3-none-any.whl → 0.6.9__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.
@@ -22,6 +22,9 @@ class InternalServerError(Exception):
22
22
  pass
23
23
 
24
24
 
25
+ CONTING_ALIAS_URL = 'https://www.ebi.ac.uk/eva/webservices/contig-alias'
26
+
27
+
25
28
  # TODO add the get methods
26
29
  class ContigAliasClient(AppLogger):
27
30
  """
@@ -29,8 +32,13 @@ class ContigAliasClient(AppLogger):
29
32
  Authentication is required if using admin endpoints.
30
33
  """
31
34
 
32
- def __init__(self, base_url, username=None, password=None):
33
- self.base_url = base_url
35
+ def __init__(self, base_url=None, username=None, password=None, default_page_size=1000):
36
+ if base_url:
37
+ self.base_url = base_url
38
+ else:
39
+ self.base_url = os.environ.get('CONTING_ALIAS_URL') or CONTING_ALIAS_URL
40
+ # Used for get method
41
+ self.default_page_size=default_page_size
34
42
  # Only required for admin endpoints
35
43
  self.username = username
36
44
  self.password = password
@@ -69,3 +77,39 @@ class ContigAliasClient(AppLogger):
69
77
  raise InternalServerError
70
78
  else:
71
79
  self.error(f'Assembly accession {assembly} could not be deleted. Response: {response.text}')
80
+
81
+ @retry(tries=3, delay=2, backoff=1.2, jitter=(1, 3))
82
+ def _get_page_for_contig_alias_url(self, sub_url, page=0):
83
+ """queries the contig alias to retrieve the page of the provided url"""
84
+ url = f'{self.base_url}/{sub_url}?page={page}&size={self.default_page_size}'
85
+ response = requests.get(url, headers={'accept': 'application/json'})
86
+ response.raise_for_status()
87
+ response_json = response.json()
88
+ return response_json
89
+
90
+ def _depaginate_iter(self, sub_url, entity_to_retrieve):
91
+ """Generator that provides the contigs in the assembly requested."""
92
+ page = 0
93
+ response_json = self._get_page_for_contig_alias_url(sub_url, page=page)
94
+ for entity in response_json.get('_embedded', {}).get(entity_to_retrieve, []):
95
+ yield entity
96
+ while 'next' in response_json['_links']:
97
+ page += 1
98
+ response_json = self._get_page_for_contig_alias_url(sub_url, page=page)
99
+ for entity in response_json.get('_embedded', {}).get(entity_to_retrieve, []):
100
+ yield entity
101
+
102
+ def assembly_contig_iter(self, assembly_accession):
103
+ """Generator that provides the contigs in the assembly requested."""
104
+ sub_url = f'v1/assemblies/{assembly_accession}/chromosomes'
105
+ return self._depaginate_iter(sub_url, 'chromosomeEntities')
106
+
107
+ def assembly(self, assembly_accession):
108
+ """provides the description of the requested assembly."""
109
+ sub_url = f'v1/assemblies/{assembly_accession}'
110
+ response_json = self._get_page_for_contig_alias_url(sub_url)
111
+ return response_json.get('_embedded', {}).get('assemblyEntities', [])[0]
112
+
113
+ def contig_iter(self, insdc_accession):
114
+ sub_url = f'v1/chromosomes/genbank/{insdc_accession}'
115
+ return self._depaginate_iter(sub_url, 'chromosomeEntities')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: ebi_eva_common_pyutils
3
- Version: 0.6.8
2
+ Name: ebi-eva-common-pyutils
3
+ Version: 0.6.9
4
4
  Summary: EBI EVA - Common Python Utilities
5
5
  Home-page: https://github.com/EBIVariation/eva-common-pyutils
6
6
  License: Apache
@@ -19,5 +19,5 @@ Requires-Dist: retry
19
19
  Provides-Extra: eva-internal
20
20
  Requires-Dist: psycopg2-binary ; extra == 'eva-internal'
21
21
  Requires-Dist: pymongo ; extra == 'eva-internal'
22
- Requires-Dist: networkx <=2.5 ; extra == 'eva-internal'
22
+ Requires-Dist: networkx (<=2.5) ; extra == 'eva-internal'
23
23
 
@@ -12,7 +12,7 @@ ebi_eva_common_pyutils/network_utils.py,sha256=iJjs5PPzT1V4CceZnCHOTs711AmpwlDo5
12
12
  ebi_eva_common_pyutils/assembly/__init__.py,sha256=KSWPwBY5nZj00odxWFntk8Sqg_rw273xH8S5D6Jo-T4,67
13
13
  ebi_eva_common_pyutils/assembly/assembly.py,sha256=IEmleROX4ZchPyhINKCuMmET_Ih1Jg4ok-opAKY6Z9A,3142
14
14
  ebi_eva_common_pyutils/contig_alias/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- ebi_eva_common_pyutils/contig_alias/contig_alias.py,sha256=8mxcIbOhivqedgDjpzsHEY3UbYwHvk9DGoEiyHLLOBk,3056
15
+ ebi_eva_common_pyutils/contig_alias/contig_alias.py,sha256=7tQXljEJtRCMs_JPrglYvTEZ-fJvzl8txwnCvqRB3Ck,5214
16
16
  ebi_eva_common_pyutils/reference/__init__.py,sha256=NsDjGCu2H2CZLOPaEL6GCoZo5ND_EA9RFmbzGfpSXRQ,134
17
17
  ebi_eva_common_pyutils/reference/assembly.py,sha256=FK4zsvg4_GDeKd9z2z5ZeM9R84TsusgQYdMOGuggQU0,12162
18
18
  ebi_eva_common_pyutils/reference/sequence.py,sha256=bg96QcuB-oytQYpaUkV10OzM_RIFhxsy6t3PQOg2Gy0,3911
@@ -20,7 +20,7 @@ ebi_eva_common_pyutils/taxonomy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
20
20
  ebi_eva_common_pyutils/taxonomy/taxonomy.py,sha256=p3XV4g3y0hEjyeZ4PwgN7Q3Et9G515ctQkSIo1kdDbU,2259
21
21
  ebi_eva_common_pyutils/variation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  ebi_eva_common_pyutils/variation/contig_utils.py,sha256=kMNEW_P2yPnd8Xx1tep19hy5ee7ojxz6ZOO1grTQsRQ,5230
23
- ebi_eva_common_pyutils-0.6.8.data/scripts/archive_directory.py,sha256=0lWJ0ju_AB2ni7lMnJXPFx6U2OdTGbe-WoQs-4BfKOM,4976
23
+ ebi_eva_common_pyutils-0.6.9.data/scripts/archive_directory.py,sha256=0lWJ0ju_AB2ni7lMnJXPFx6U2OdTGbe-WoQs-4BfKOM,4976
24
24
  ebi_eva_internal_pyutils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  ebi_eva_internal_pyutils/archive_directory.py,sha256=IxVEfh_gaCiT652k0Q_-58fonRusy1yzXu7BCO8yVLo,4989
26
26
  ebi_eva_internal_pyutils/config_utils.py,sha256=EGRC5rsmU_ug7OY9-t1UW1XZXRsauSyZB9xPcBux8ts,7909
@@ -32,8 +32,8 @@ ebi_eva_internal_pyutils/mongodb/__init__.py,sha256=0oyTlkYZCV7udlPl09Zl-sDyE3c9
32
32
  ebi_eva_internal_pyutils/mongodb/mongo_database.py,sha256=kesaJaaxYFeF_uYZBgL8tbufGKUXll7bXb4WlOS9vKM,9596
33
33
  ebi_eva_internal_pyutils/nextflow/__init__.py,sha256=OOiJS8jZOz98q0t77NNog7aI_fFrVxi4kGmiSskuAqM,122
34
34
  ebi_eva_internal_pyutils/nextflow/nextflow_pipeline.py,sha256=ew623hhK8jmFLQjJwLZbgBmW9RTiJBEULVqHfIUv_dc,10114
35
- ebi_eva_common_pyutils-0.6.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
36
- ebi_eva_common_pyutils-0.6.8.dist-info/METADATA,sha256=xL-ZPU8JZ9arUWs_6aAraTEq2Xmi4DPBKCz9mWgL6YU,822
37
- ebi_eva_common_pyutils-0.6.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
38
- ebi_eva_common_pyutils-0.6.8.dist-info/top_level.txt,sha256=sXoiqiGU8vlMQpFWDlKrekxhlusk06AhkOH3kSvDT6c,48
39
- ebi_eva_common_pyutils-0.6.8.dist-info/RECORD,,
35
+ ebi_eva_common_pyutils-0.6.9.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
36
+ ebi_eva_common_pyutils-0.6.9.dist-info/METADATA,sha256=iEw5N92Ad8rSkru7KNyzfpSgUD0NCpuF4Eu1dPSVp1I,824
37
+ ebi_eva_common_pyutils-0.6.9.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
38
+ ebi_eva_common_pyutils-0.6.9.dist-info/top_level.txt,sha256=sXoiqiGU8vlMQpFWDlKrekxhlusk06AhkOH3kSvDT6c,48
39
+ ebi_eva_common_pyutils-0.6.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: bdist_wheel (0.38.4)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5