From 7593a3bbda4ca8a388bfc51fc5da15c5b56d175d Mon Sep 17 00:00:00 2001 From: Arya Massarat <23412689+aryarm@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:33:17 -0800 Subject: [PATCH 1/3] ensure version setting is outside try/except --- haptools/__init__.py | 8 ++++---- haptools/data/haplotypes.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/haptools/__init__.py b/haptools/__init__.py index e4cfabeb..5d14e362 100644 --- a/haptools/__init__.py +++ b/haptools/__init__.py @@ -4,7 +4,7 @@ # handles py3.7, since importlib.metadata was introduced in py3.8 from importlib_metadata import version, PackageNotFoundError - try: - __version__ = version(__name__) - except PackageNotFoundError: - __version__ = "unknown" +try: + __version__ = version(__name__) +except PackageNotFoundError: + __version__ = "unknown" diff --git a/haptools/data/haplotypes.py b/haptools/data/haplotypes.py index 14f0cb15..228d1019 100644 --- a/haptools/data/haplotypes.py +++ b/haptools/data/haplotypes.py @@ -101,7 +101,7 @@ def fmt_str(self) -> str: class classproperty(object): """ - A daad-simple read-only decorator that combines the functionality of + A dead-simple read-only decorator that combines the functionality of @classmethod and @property Stolen from https://stackoverflow.com/a/13624858/16815703 From 726cd9021b14493495c2dbefb7ba17f2a3399df3 Mon Sep 17 00:00:00 2001 From: Arya Massarat <23412689+aryarm@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:37:56 -0800 Subject: [PATCH 2/3] reproduce no-header issue encountered by Ximei --- tests/test_data.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_data.py b/tests/test_data.py index 835b3867..28dfa7bf 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1184,6 +1184,20 @@ def test_load(self): haps = Haplotypes.load(DATADIR / "basic.hap.gz") assert expected == haps.data + def test_load_no_header(self): + expected = self._basic_haps() + + # what if we remove the header line, can we still load it? + # let's try to make a version without the header + no_header_file = DATADIR / "basic_no_header.hap" + with open(DATADIR / "basic.hap", "r") as fr, open(no_header_file, "w") as fw: + fw.writelines([ln for ln in fr.readlines() if not ln.startswith("#\t")]) + + haps = Haplotypes.load(no_header_file) + assert expected == haps.data + + no_header_file.unlink() + def test_iterate(self): exp_full = self._basic_haps() From 6fd1d0a6a3ff7145ee9b4dda14edade2dca13b42 Mon Sep 17 00:00:00 2001 From: Arya Massarat <23412689+aryarm@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:49:21 -0800 Subject: [PATCH 3/3] fix err occuring when hap file has no header --- haptools/data/haplotypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haptools/data/haplotypes.py b/haptools/data/haplotypes.py index 228d1019..23021bda 100644 --- a/haptools/data/haplotypes.py +++ b/haptools/data/haplotypes.py @@ -1231,7 +1231,7 @@ def __iter__( # These are usually just comment lines, so we can ignore it pass else: - if header_lines: + if header_lines is not None: metas, extras = self.check_header(header_lines) types = self._get_field_types(extras, metas.get("order")) header_lines = None