Skip to content

Commit 3b900d6

Browse files
committed
fix: Convert path objects to string
1 parent fe90034 commit 3b900d6

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/dask_ngs/__init__.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ def read_bam(
6161
"""
6262
path = Path(path)
6363
if index is None:
64-
bai_index = path.with_suffix(".bai")
65-
csi_index = path.with_suffix(".csi")
64+
bai_index = path.with_suffix(path.suffix + ".bai")
65+
csi_index = path.with_suffix(path.suffix + ".csi")
6666
if bai_index.exists():
67-
index = bai_index
67+
index = str(bai_index)
6868
elif csi_index.exists():
69-
index = csi_index
69+
index = str(csi_index)
7070
else:
7171
msg = "Index .bai or .csi file not found."
7272
raise FileNotFoundError(msg)
7373

7474
vpos = ox.partition_from_index_file(index, chunksize)
7575
chunks = [
76-
dask.delayed(_read_bam_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
76+
dask.delayed(_read_bam_vpos_from_path)(
77+
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
78+
)
7779
for i in range(len(vpos) - 1)
7880
]
7981

@@ -103,19 +105,21 @@ def read_vcf(
103105
"""
104106
path = Path(path)
105107
if index is None:
106-
tbi_index = path.with_suffix(".tbi")
107-
csi_index = path.with_suffix(".csi")
108+
tbi_index = path.with_suffix(path.suffix + ".tbi")
109+
csi_index = path.with_suffix(path.suffix + ".csi")
108110
if tbi_index.exists():
109-
index = tbi_index
111+
index = str(tbi_index)
110112
elif csi_index.exists():
111-
index = csi_index
113+
index = str(csi_index)
112114
else:
113115
msg = "Index .tbi or .csi file not found."
114116
raise FileNotFoundError(msg)
115117

116118
vpos = ox.partition_from_index_file(index, chunksize)
117119
chunks = [
118-
dask.delayed(_read_vcf_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
120+
dask.delayed(_read_vcf_vpos_from_path)(
121+
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
122+
)
119123
for i in range(len(vpos) - 1)
120124
]
121125

@@ -145,16 +149,18 @@ def read_bcf(
145149
"""
146150
path = Path(path)
147151
if index is None:
148-
csi_index = path.with_suffix(".csi")
152+
csi_index = path.with_suffix(path.suffix + ".csi")
149153
if csi_index.exists():
150-
index = csi_index
154+
index = str(csi_index)
151155
else:
152156
msg = "Index .csi file not found."
153157
raise FileNotFoundError(msg)
154158

155159
vpos = ox.partition_from_index_file(index, chunksize)
156160
chunks = [
157-
dask.delayed(_read_bcf_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
161+
dask.delayed(_read_bcf_vpos_from_path)(
162+
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
163+
)
158164
for i in range(len(vpos) - 1)
159165
]
160166

tests/test_readers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def example_bam():
1717
def test_read_bam_pnext_value(example_bam):
1818
# Verifies that the pnext value was read correctly from the BAM file
1919
few_pnext_values = example_bam["pnext"].head()
20-
assert few_pnext_values[2] == 82982
20+
pnext_val = 82982
21+
assert few_pnext_values[2] == pnext_val
2122

2223

2324
def test_read_correct_data_types_from_bam(example_bam):

0 commit comments

Comments
 (0)