aiondata
Advanced tools
+22
-20
| import io | ||
| from typing import Optional, Generator, Union | ||
| from typing import Optional, Generator, Union, Tuple | ||
| import urllib.request | ||
@@ -41,7 +41,7 @@ from rdkit import Chem | ||
| if cached_sdf.exists(): | ||
| self.fd = self.from_compressed_file(cached_sdf) | ||
| self.outer_fd, self.fd = self.from_compressed_file(cached_sdf) | ||
| else: | ||
| self.fd = self.from_url(self.SOURCE) | ||
| self.outer_fd, self.fd = self.from_url(self.SOURCE) | ||
| else: | ||
| self.fd = fd | ||
| self.outer_fd, self.fd = fd | ||
@@ -77,3 +77,3 @@ def _convert_to_numeric( | ||
| @staticmethod | ||
| def from_url(url: str) -> io.BufferedReader: | ||
| def from_url(url: str) -> Tuple[zipfile.ZipFile, io.BufferedReader]: | ||
| """ | ||
@@ -86,13 +86,11 @@ Creates a BindingDB instance from a URL containing a compressed SDF file, using streaming. | ||
| Returns: | ||
| A BufferedReader instance containing the content of the SDF file. | ||
| A tuple containing the ZipFile instance and a BufferedReader instance containing the content of the SDF file. | ||
| """ | ||
| with urllib.request.urlopen(url) as response: | ||
| with zipfile.ZipFile(io.BytesIO(response.read())) as z: | ||
| sdf_name = z.namelist()[0] | ||
| with z.open(sdf_name) as sdf_file: | ||
| sdf_content = io.BufferedReader(sdf_file) | ||
| return sdf_content | ||
| response = urllib.request.urlopen(url) | ||
| return BindingDB.from_compressed_file(io.BytesIO(response.read())) | ||
| @staticmethod | ||
| def from_compressed_file(file_path: str) -> io.BufferedReader: | ||
| def from_compressed_file( | ||
| file_path: str, | ||
| ) -> Tuple[zipfile.ZipFile, io.BufferedReader]: | ||
| """ | ||
@@ -105,9 +103,9 @@ Creates a BindingDB instance from a compressed SDF file. | ||
| Returns: | ||
| A BufferedReader instance containing the content of the SDF file. | ||
| A tuple containing the ZipFile instance and a BufferedReader instance containing the content of the SDF file. | ||
| """ | ||
| with zipfile.ZipFile(file_path) as z: | ||
| sdf_name = z.namelist()[0] | ||
| with z.open(sdf_name) as sdf_file: | ||
| sdf_content = io.BufferedReader(sdf_file) | ||
| return sdf_content | ||
| zip_file = zipfile.ZipFile(file_path) | ||
| sdf_name = zip_file.namelist()[0] | ||
| sdf_file = zip_file.open(sdf_name) | ||
| sdf_content = io.BufferedReader(sdf_file) | ||
| return zip_file, sdf_content | ||
@@ -125,3 +123,3 @@ @staticmethod | ||
| """ | ||
| return open(file_path, "rb") | ||
| return None, open(file_path, "rb") | ||
@@ -165,4 +163,8 @@ def to_generator(self, progress_bar: bool = True) -> Generator[dict, None, None]: | ||
| self.fd.close() | ||
| if self.outer_fd is not None: | ||
| self.outer_fd.close() | ||
| # Re-enable logging | ||
| RDLogger.EnableLog("rdApp.error") | ||
| RDLogger.EnableLog("rdApp.warning") |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: aiondata | ||
| Version: 0.4.4 | ||
| Version: 0.4.5 | ||
| Summary: A common data access layer for AI-driven drug discovery. | ||
@@ -5,0 +5,0 @@ Home-page: https://www.github.com/aion-labs/aiondata |
+1
-1
| [tool.poetry] | ||
| name = "aiondata" | ||
| version = "0.4.4" | ||
| version = "0.4.5" | ||
| description = "A common data access layer for AI-driven drug discovery." | ||
@@ -5,0 +5,0 @@ authors = ["JJ Ben-Joseph <jj@tensorspace.ai>"] |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
50622
0.25%580
0.17%