diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26baa88..7b25fa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,9 +56,9 @@ jobs: - name: Install pybigtools run: | - pip install maturin pytest + pip install maturin cd pybigtools - pip install -e . + pip install -e .[test] - name: Install run: | diff --git a/pybigtools/pyproject.toml b/pybigtools/pyproject.toml index 562e4be..cd8225b 100644 --- a/pybigtools/pyproject.toml +++ b/pybigtools/pyproject.toml @@ -6,10 +6,34 @@ build-backend = "maturin" name = "pybigtools" description = "Python bindings to the Bigtools Rust library for high-performance BigWig and BigBed I/O" license = { text = "MIT" } +keywords = [ + "bigwig", + "bigbed", + "bbi", + "bioinformatics", + "genomics", + "kent", + "ucsc", + "rust", +] +classifiers = [ + "Development Status :: 4 - Beta", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering :: Bio-Informatics", + "Programming Language :: Rust", + "Programming Language :: Python", + "Programming Language :: Python :: 3", +] dependencies = [ "numpy" ] +[project.optional-dependencies] +test = [ + "pytest", + "smart_open[http]" +] + [project.urls] homepage = "https://github.com/jackh726/bigtools" documentation = "https://bigtools.readthedocs.io" diff --git a/pybigtools/tests/test_api.py b/pybigtools/tests/test_api.py index 76184d1..28d1715 100644 --- a/pybigtools/tests/test_api.py +++ b/pybigtools/tests/test_api.py @@ -4,6 +4,7 @@ import numpy as np import pytest +import smart_open import pybigtools @@ -17,12 +18,6 @@ def test_open_close(): b.close() assert pytest.raises(pybigtools.BBIFileClosed, b.chroms) - # Works with pathlib.Path - path = REPO_ROOT / "bigtools/resources/test/valid.bigWig" - b = pybigtools.open(path, "r") - b.close() - assert pytest.raises(pybigtools.BBIFileClosed, b.chroms) - # Files are closed when exiting a context manager with pybigtools.open(path, "r") as b: pass @@ -33,6 +28,39 @@ def test_open_close(): assert pytest.raises(pybigtools.BBIReadError, pybigtools.open, s, "r") +def test_open_pathlib_path(): + path = REPO_ROOT / "bigtools/resources/test/valid.bigWig" + with pybigtools.open(path, "r") as b: + assert b.chroms() == {"chr17": 83_257_441} + + +def test_open_raw_url(): + url = "http://genome.ucsc.edu/goldenPath/help/examples/bigLollyExample2.bb" + with pybigtools.open(url, "r") as b: + assert b.chroms() == {'chr21': 46_709_983} + + +def test_open_filelike(): + # Regular file + with open(REPO_ROOT / "bigtools/resources/test/valid.bigWig", "rb") as f: + with pybigtools.open(f, "r") as b: + assert b.chroms() == {"chr17": 83_257_441} + + # BytesIO + with open(REPO_ROOT / "bigtools/resources/test/valid.bigWig", "rb") as f: + bw_bytes = f.read() + + with BytesIO(bw_bytes) as f: + with pybigtools.open(f, "r") as b: + assert b.chroms() == {"chr17": 83_257_441} + + # Other file-like objects + url = "http://genome.ucsc.edu/goldenPath/help/examples/bigWigExample.bw" + with smart_open.open(url, "rb") as f: + with pybigtools.open(f, "r") as b: + assert b.chroms() == {'chr21': 48_129_895} + + @pytest.fixture def bw(): path = str(REPO_ROOT / "bigtools/resources/test/valid.bigWig") @@ -77,8 +105,8 @@ def test_chroms(bw, bb): assert bb.chroms() == {"chr21": 48_129_895} # Arg with chrom name => length - assert bw.chroms("chr17") == 83257441 - assert bb.chroms("chr21") == 48129895 + assert bw.chroms("chr17") == 83_257_441 + assert bb.chroms("chr21") == 48_129_895 # Missing chrom => KeyError pytest.raises(KeyError, bw.chroms, "chr11")