Skip to content

Commit

Permalink
fix: Convert path objects to string
Browse files Browse the repository at this point in the history
  • Loading branch information
nvictus committed Jul 30, 2023
1 parent fe90034 commit 3b900d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/dask_ngs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,21 @@ def read_bam(
"""
path = Path(path)
if index is None:
bai_index = path.with_suffix(".bai")
csi_index = path.with_suffix(".csi")
bai_index = path.with_suffix(path.suffix + ".bai")
csi_index = path.with_suffix(path.suffix + ".csi")
if bai_index.exists():
index = bai_index
index = str(bai_index)
elif csi_index.exists():
index = csi_index
index = str(csi_index)
else:
msg = "Index .bai or .csi file not found."
raise FileNotFoundError(msg)

vpos = ox.partition_from_index_file(index, chunksize)
chunks = [
dask.delayed(_read_bam_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
dask.delayed(_read_bam_vpos_from_path)(
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
)
for i in range(len(vpos) - 1)
]

Expand Down Expand Up @@ -103,19 +105,21 @@ def read_vcf(
"""
path = Path(path)
if index is None:
tbi_index = path.with_suffix(".tbi")
csi_index = path.with_suffix(".csi")
tbi_index = path.with_suffix(path.suffix + ".tbi")
csi_index = path.with_suffix(path.suffix + ".csi")
if tbi_index.exists():
index = tbi_index
index = str(tbi_index)
elif csi_index.exists():
index = csi_index
index = str(csi_index)
else:
msg = "Index .tbi or .csi file not found."
raise FileNotFoundError(msg)

vpos = ox.partition_from_index_file(index, chunksize)
chunks = [
dask.delayed(_read_vcf_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
dask.delayed(_read_vcf_vpos_from_path)(
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
)
for i in range(len(vpos) - 1)
]

Expand Down Expand Up @@ -145,16 +149,18 @@ def read_bcf(
"""
path = Path(path)
if index is None:
csi_index = path.with_suffix(".csi")
csi_index = path.with_suffix(path.suffix + ".csi")
if csi_index.exists():
index = csi_index
index = str(csi_index)
else:
msg = "Index .csi file not found."
raise FileNotFoundError(msg)

vpos = ox.partition_from_index_file(index, chunksize)
chunks = [
dask.delayed(_read_bcf_vpos_from_path)(path, tuple(vpos[i]), tuple(vpos[i + 1]))
dask.delayed(_read_bcf_vpos_from_path)(
str(path), tuple(vpos[i]), tuple(vpos[i + 1])
)
for i in range(len(vpos) - 1)
]

Expand Down
3 changes: 2 additions & 1 deletion tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def example_bam():
def test_read_bam_pnext_value(example_bam):
# Verifies that the pnext value was read correctly from the BAM file
few_pnext_values = example_bam["pnext"].head()
assert few_pnext_values[2] == 82982
pnext_val = 82982
assert few_pnext_values[2] == pnext_val


def test_read_correct_data_types_from_bam(example_bam):
Expand Down

0 comments on commit 3b900d6

Please sign in to comment.