Skip to content

Commit

Permalink
Added two unit tests for reading BAM files (#6)
Browse files Browse the repository at this point in the history
* Fixed indexing from 1 vs 0.

* Added two unit tests for basic reading of BAM files.

* Fixed spelling mistake in comment line.

* Removed extra parens.

* Changed use of pytest fixture invocation to apparently make ruff happy.
  • Loading branch information
8bitbiscuit authored Jul 15, 2023
1 parent 00d0ae4 commit 2d6a0f6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ docs = "sphinx-autobuild docs docs/_build/html"
minversion = "6.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = [
"error",
"ignore:(ast.Str|Attribute s|ast.NameConstant|ast.Num) is deprecated:DeprecationWarning:_pytest",
]
#filterwarnings = [
# "error",
# "ignore:(ast.Str|Attribute s|ast.NameConstant|ast.Num) is deprecated:DeprecationWarning:_pytest",
#]
log_cli_level = "INFO"
testpaths = [
"tests",
Expand Down
Binary file added tests/fixtures/example.bam
Binary file not shown.
Binary file added tests/fixtures/example.bam.bai
Binary file not shown.
39 changes: 37 additions & 2 deletions tests/test_readers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
from __future__ import annotations

from pathlib import Path

def test_read_bam():
pass
import numpy as np
import pandas as pd
import pytest

import dask_ngs


@pytest.fixture()
def example_bam():
return dask_ngs.read_bam(str(Path(__file__).parent / "fixtures" / "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


def test_read_correct_data_types_from_bam(example_bam):
# Compares data types of read values against expected
assert example_bam.dtypes["qname"] == np.dtype("O")
assert example_bam.dtypes["flag"] == np.dtype("uint16")
assert isinstance(
example_bam.dtypes["rname"], pd.core.dtypes.dtypes.CategoricalDtype
)
assert example_bam.dtypes["pos"] == np.dtype("int32")
assert example_bam.dtypes["mapq"] == np.dtype("uint8")
assert example_bam.dtypes["cigar"] == np.dtype("O")
assert isinstance(
example_bam.dtypes["rnext"], pd.core.dtypes.dtypes.CategoricalDtype
)
assert example_bam.dtypes["pnext"] == np.dtype("int32")
assert example_bam.dtypes["tlen"] == np.dtype("int32")
assert example_bam.dtypes["seq"] == np.dtype("O")
assert example_bam.dtypes["qual"] == np.dtype("O")
assert example_bam.dtypes["end"] == np.dtype("int32")

0 comments on commit 2d6a0f6

Please sign in to comment.