|
18 | 18 | from curies.preprocessing import BlocklistError |
19 | 19 | from curies.vocabulary import SynonymScope |
20 | 20 | from more_itertools import pairwise |
21 | | -from pystow.utils import safe_open |
| 21 | +from pystow.utils import open_zipfile, safe_open |
22 | 22 | from tqdm.auto import tqdm |
23 | 23 |
|
24 | 24 | from .reader_utils import ( |
@@ -78,16 +78,9 @@ def from_obo_path( |
78 | 78 | """Get the OBO graph from a path.""" |
79 | 79 | path = Path(path).expanduser().resolve() |
80 | 80 | if path.suffix.endswith(".zip"): |
81 | | - import io |
82 | | - import zipfile |
83 | | - |
84 | 81 | logger.info("[%s] parsing zipped OBO with obonet from %s", prefix or "<unknown>", path) |
85 | | - with zipfile.ZipFile(path) as zf: |
86 | | - with zf.open(path.name.removesuffix(".zip"), "r") as file: |
87 | | - content = file.read().decode("utf-8") |
88 | | - graph = _read_obo( |
89 | | - io.StringIO(content), prefix, ignore_obsolete=ignore_obsolete, use_tqdm=use_tqdm |
90 | | - ) |
| 82 | + with open_zipfile(path, path.name.removesuffix(".zip")) as file: |
| 83 | + graph = _read_obo(file, prefix, ignore_obsolete=ignore_obsolete, use_tqdm=use_tqdm) |
91 | 84 | else: |
92 | 85 | logger.info("[%s] parsing OBO with obonet from %s", prefix or "<unknown>", path) |
93 | 86 | with safe_open(path, operation="read") as file: |
|
0 commit comments