diff --git a/.travis.yml b/.travis.yml index e611ae8..7e1991d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,7 @@ install: - isort --check-only . - python3 setup.py test - python3 -m pip install cibuildwheel + - git clean -xdfq script: - python3 -m cibuildwheel --output-dir wheelhouse after_success: diff --git a/MANIFEST.in b/MANIFEST.in index f0f56d7..128126d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,8 @@ include README.md include bgen_reader/athr.dll include bgen_reader/bgen.dll include bgen_reader/interface.h +include bgen_reader/genotype.c +include bgen_reader/genotype.h include bgen_reader/partition.c include bgen_reader/partition.h include bgen_reader/samples.c diff --git a/bgen_reader/__init__.py b/bgen_reader/__init__.py index 6037cab..dca2a0d 100644 --- a/bgen_reader/__init__.py +++ b/bgen_reader/__init__.py @@ -39,7 +39,7 @@ raise RuntimeError(str(e) + _ffi_err) -__version__ = "4.1.0" +__version__ = "4.0.5" __all__ = [ "__version__", diff --git a/bgen_reader/_bgen_file.py b/bgen_reader/_bgen_file.py index 941f9af..c947b09 100644 --- a/bgen_reader/_bgen_file.py +++ b/bgen_reader/_bgen_file.py @@ -1,7 +1,7 @@ from math import floor, sqrt from pathlib import Path -from numpy import asarray, float64, full, nan, zeros +from numpy import float64, full, nan, uint8, zeros from pandas import Series from ._ffi import ffi, lib @@ -71,13 +71,15 @@ def read_genotype(self, offset: int): lib.bgen_genotype_read(genotype, ffi.cast("double *", probs.ctypes.data)) phased = lib.bgen_genotype_phased(genotype) - ploidy = asarray( - [lib.bgen_genotype_ploidy(genotype, i) for i in range(nsamples)], int - ) - missing = asarray( - [lib.bgen_genotype_missing(genotype, i) for i in range(nsamples)], bool - ) + + ploidy = full(nsamples, 0, dtype=uint8) + lib.read_ploidy(genotype, ffi.cast("uint8_t *", ploidy.ctypes.data), nsamples) + + missing = full(nsamples, 0, dtype=bool) + lib.read_missing(genotype, ffi.cast("bool *", missing.ctypes.data), nsamples) + lib.bgen_genotype_close(genotype) + return {"probs": probs, "phased": phased, "ploidy": ploidy, "missing": missing} def close(self): diff --git a/bgen_reader/genotype.c b/bgen_reader/genotype.c new file mode 100644 index 0000000..6ff2659 --- /dev/null +++ b/bgen_reader/genotype.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +static void read_ploidy(struct bgen_genotype const* genotype, uint8_t* ploidy, + uint32_t nsamples) +{ + for (uint32_t i = 0; i < nsamples; ++i) + ploidy[i] = bgen_genotype_ploidy(genotype, i); +} + +static void read_missing(struct bgen_genotype const* genotype, bool* missing, + uint32_t nsamples) +{ + for (uint32_t i = 0; i < nsamples; ++i) + missing[i] = bgen_genotype_missing(genotype, i); +} diff --git a/bgen_reader/genotype.h b/bgen_reader/genotype.h new file mode 100644 index 0000000..1c8968d --- /dev/null +++ b/bgen_reader/genotype.h @@ -0,0 +1,4 @@ +static void read_ploidy(struct bgen_genotype const* genotype, uint8_t* ploidy, + uint32_t nsamples); +static void read_missing(struct bgen_genotype const* genotype, bool* missing, + uint32_t nsamples); diff --git a/build_ext.py b/build_ext.py index 8392dd4..7ec4abc 100644 --- a/build_ext.py +++ b/build_ext.py @@ -18,6 +18,12 @@ with open(join(folder, "bgen_reader", "interface.h"), "r") as f: ffibuilder.cdef(f.read()) +with open(join(folder, "bgen_reader", "genotype.h"), "r") as f: + ffibuilder.cdef(f.read()) + +with open(join(folder, "bgen_reader", "genotype.c"), "r") as f: + genotype_c = f.read() + with open(join(folder, "bgen_reader", "partition.h"), "r") as f: ffibuilder.cdef(f.read()) @@ -38,6 +44,7 @@ "bgen_reader._ffi", fr""" #include "bgen/bgen.h" + {genotype_c} {partition_c} {samples_c} """, diff --git a/ci/linux-deps b/ci/linux-deps index 207422a..6291d0d 100755 --- a/ci/linux-deps +++ b/ci/linux-deps @@ -3,6 +3,7 @@ yum install -y libffi libffi-devel zlib-devel yum remove -y cmake +python -m pip install pip --upgrade python -m pip install cmake numpy pandas curl https://raw.githubusercontent.com/horta/zstd.install/master/install --output install-zstd diff --git a/ci/test b/ci/test index e26f804..b18a78f 100755 --- a/ci/test +++ b/ci/test @@ -1,3 +1,4 @@ #!/bin/bash +ldd $(find / -type f -name "_ffi.abi3.so") (cd ~/ && python -c "import bgen_reader; import sys; sys.exit(bgen_reader.test())") diff --git a/pyproject.toml b/pyproject.toml index 364bf2a..0c968a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools >= 49.3.0", "wheel >= 0.34.2"] +requires = ["setuptools>=49.3.0", "wheel>=0.34.2", "cffi>=1.14.1"] build-backend = "setuptools.build_meta" [tool.isort] diff --git a/setup.cfg b/setup.cfg index b5b74ca..59dd1b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,12 +25,12 @@ zip_safe = False include_package_data = True packages = find: setup_requires = - cffi>=1.14.0 + cffi>=1.14.1 pytest-runner>=5.2 install_requires = appdirs>=1.4.3 cachetools>=3.1.1 - cffi>=1.14.0 + cffi>=1.14.1 dask[bag,array,dataframe,delayed]>=2.12.0 numpy>=1.17.4 pandas>=0.24.0