pybcf 1.3.7__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. {pybcf-1.3.7 → pybcf-1.4.0}/MANIFEST.in +8 -3
  2. {pybcf-1.3.7/src/pybcf.egg-info → pybcf-1.4.0}/PKG-INFO +16 -22
  3. {pybcf-1.3.7 → pybcf-1.4.0}/README.md +11 -7
  4. pybcf-1.4.0/pyproject.toml +43 -0
  5. pybcf-1.4.0/setup.py +81 -0
  6. pybcf-1.4.0/src/bcf.cpp +91 -0
  7. pybcf-1.4.0/src/bcf.h +30 -0
  8. pybcf-1.4.0/src/bgzf.cpp +176 -0
  9. pybcf-1.4.0/src/bgzf.h +65 -0
  10. pybcf-1.4.0/src/gzreader.cpp +161 -0
  11. pybcf-1.4.0/src/gzreader.h +55 -0
  12. pybcf-1.4.0/src/header.cpp +232 -0
  13. pybcf-1.4.0/src/header.h +42 -0
  14. pybcf-1.4.0/src/index.cpp +159 -0
  15. pybcf-1.4.0/src/index.h +42 -0
  16. pybcf-1.4.0/src/info.cpp +136 -0
  17. pybcf-1.4.0/src/info.h +77 -0
  18. {pybcf-1.3.7 → pybcf-1.4.0}/src/pybcf/__init__.py +3 -2
  19. pybcf-1.4.0/src/pybcf/libbcf.pxd +105 -0
  20. pybcf-1.4.0/src/pybcf/py.typed +0 -0
  21. pybcf-1.4.0/src/pybcf/reader.pyi +118 -0
  22. pybcf-1.4.0/src/pybcf/reader.pyx +450 -0
  23. {pybcf-1.3.7 → pybcf-1.4.0/src/pybcf.egg-info}/PKG-INFO +16 -22
  24. {pybcf-1.3.7 → pybcf-1.4.0}/src/pybcf.egg-info/SOURCES.txt +9 -6
  25. pybcf-1.4.0/src/sample_data.cpp +218 -0
  26. pybcf-1.4.0/src/sample_data.h +62 -0
  27. pybcf-1.4.0/src/simd.h +287 -0
  28. pybcf-1.4.0/src/types.h +201 -0
  29. pybcf-1.4.0/src/variant.cpp +154 -0
  30. pybcf-1.4.0/src/variant.h +43 -0
  31. pybcf-1.3.7/pyproject.toml +0 -2
  32. pybcf-1.3.7/setup.py +0 -110
  33. pybcf-1.3.7/src/bcf.cpp +0 -81
  34. pybcf-1.3.7/src/bcf.h +0 -31
  35. pybcf-1.3.7/src/gzstream.cpp +0 -181
  36. pybcf-1.3.7/src/gzstream.h +0 -117
  37. pybcf-1.3.7/src/header.cpp +0 -205
  38. pybcf-1.3.7/src/header.h +0 -57
  39. pybcf-1.3.7/src/index.cpp +0 -206
  40. pybcf-1.3.7/src/index.h +0 -47
  41. pybcf-1.3.7/src/info.cpp +0 -139
  42. pybcf-1.3.7/src/info.h +0 -59
  43. pybcf-1.3.7/src/pybcf/reader.cpp +0 -41080
  44. pybcf-1.3.7/src/pybcf/reader.pyx +0 -419
  45. pybcf-1.3.7/src/sample_data.cpp +0 -568
  46. pybcf-1.3.7/src/sample_data.h +0 -56
  47. pybcf-1.3.7/src/types.h +0 -129
  48. pybcf-1.3.7/src/variant.cpp +0 -85
  49. pybcf-1.3.7/src/variant.h +0 -45
  50. pybcf-1.3.7/test/test_indexed.py +0 -212
  51. pybcf-1.3.7/test/test_pybcf.py +0 -222
  52. {pybcf-1.3.7 → pybcf-1.4.0}/LICENSE.txt +0 -0
  53. {pybcf-1.3.7 → pybcf-1.4.0}/setup.cfg +0 -0
  54. {pybcf-1.3.7 → pybcf-1.4.0}/src/pybcf.egg-info/dependency_links.txt +0 -0
  55. {pybcf-1.3.7 → pybcf-1.4.0}/src/pybcf.egg-info/requires.txt +0 -0
  56. {pybcf-1.3.7 → pybcf-1.4.0}/src/pybcf.egg-info/top_level.txt +0 -0
  57. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/CMakeLists.txt +0 -0
  58. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/Makefile.in +0 -0
  59. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/adler32.c +0 -0
  60. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/adler32_p.h +0 -0
  61. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/Makefile.in +0 -0
  62. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/acle_intrins.h +0 -0
  63. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/adler32_neon.c +0 -0
  64. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/arm_features.c +0 -0
  65. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/arm_features.h +0 -0
  66. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/arm_functions.h +0 -0
  67. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/chunkset_neon.c +0 -0
  68. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/compare256_neon.c +0 -0
  69. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/crc32_acle.c +0 -0
  70. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/neon_intrins.h +0 -0
  71. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/slide_hash_armv6.c +0 -0
  72. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/arm/slide_hash_neon.c +0 -0
  73. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/Makefile.in +0 -0
  74. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/adler32_c.c +0 -0
  75. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/adler32_fold_c.c +0 -0
  76. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/chunk_permute_table.h +0 -0
  77. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/chunkset_c.c +0 -0
  78. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/compare256_c.c +0 -0
  79. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/crc32_braid_c.c +0 -0
  80. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/crc32_fold_c.c +0 -0
  81. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/generic_functions.h +0 -0
  82. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/generic/slide_hash_c.c +0 -0
  83. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/Makefile.in +0 -0
  84. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/adler32_power8.c +0 -0
  85. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/adler32_vmx.c +0 -0
  86. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/chunkset_power8.c +0 -0
  87. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/compare256_power9.c +0 -0
  88. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/crc32_constants.h +0 -0
  89. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/crc32_power8.c +0 -0
  90. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/fallback_builtins.h +0 -0
  91. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/power_features.c +0 -0
  92. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/power_features.h +0 -0
  93. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/power_functions.h +0 -0
  94. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/slide_hash_power8.c +0 -0
  95. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/slide_hash_vmx.c +0 -0
  96. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/power/slide_ppc_tpl.h +0 -0
  97. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/adler32_rvv.c +0 -0
  98. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/chunkset_rvv.c +0 -0
  99. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/compare256_rvv.c +0 -0
  100. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/riscv_features.c +0 -0
  101. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/riscv_features.h +0 -0
  102. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/riscv_functions.h +0 -0
  103. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/riscv/slide_hash_rvv.c +0 -0
  104. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/Makefile.in +0 -0
  105. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/crc32-vx.c +0 -0
  106. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_common.h +0 -0
  107. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_deflate.c +0 -0
  108. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_deflate.h +0 -0
  109. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_detail.h +0 -0
  110. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_inflate.c +0 -0
  111. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/dfltcc_inflate.h +0 -0
  112. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/s390_features.c +0 -0
  113. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/s390_features.h +0 -0
  114. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/s390/s390_functions.h +0 -0
  115. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/Makefile.in +0 -0
  116. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_avx2.c +0 -0
  117. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_avx2_p.h +0 -0
  118. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_avx512.c +0 -0
  119. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_avx512_p.h +0 -0
  120. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_avx512_vnni.c +0 -0
  121. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_sse42.c +0 -0
  122. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_ssse3.c +0 -0
  123. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/adler32_ssse3_p.h +0 -0
  124. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/chunkset_avx2.c +0 -0
  125. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/chunkset_sse2.c +0 -0
  126. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/chunkset_ssse3.c +0 -0
  127. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/compare256_avx2.c +0 -0
  128. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/compare256_sse2.c +0 -0
  129. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/crc32_fold_pclmulqdq_tpl.h +0 -0
  130. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/crc32_fold_vpclmulqdq_tpl.h +0 -0
  131. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/crc32_pclmulqdq.c +0 -0
  132. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/crc32_pclmulqdq_tpl.h +0 -0
  133. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/crc32_vpclmulqdq.c +0 -0
  134. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/slide_hash_avx2.c +0 -0
  135. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/slide_hash_sse2.c +0 -0
  136. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/x86_features.c +0 -0
  137. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/x86_features.h +0 -0
  138. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/x86_functions.h +0 -0
  139. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch/x86/x86_intrins.h +0 -0
  140. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/arch_functions.h +0 -0
  141. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/chunkset_tpl.h +0 -0
  142. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-arch.c +0 -0
  143. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-arch.cmake +0 -0
  144. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-coverage.cmake +0 -0
  145. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-install-dirs.cmake +0 -0
  146. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-intrinsics.cmake +0 -0
  147. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/detect-sanitizer.cmake +0 -0
  148. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/fallback-macros.cmake +0 -0
  149. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-aarch64.cmake +0 -0
  150. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-arm.cmake +0 -0
  151. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-armhf.cmake +0 -0
  152. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-llvm-mingw-aarch64.cmake +0 -0
  153. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-llvm-mingw-armv7.cmake +0 -0
  154. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-llvm-mingw-i686.cmake +0 -0
  155. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-llvm-mingw-x86_64.cmake +0 -0
  156. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-mingw-i686.cmake +0 -0
  157. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-mingw-x86_64.cmake +0 -0
  158. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-mips.cmake +0 -0
  159. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-mips64.cmake +0 -0
  160. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc.cmake +0 -0
  161. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64-clang.cmake +0 -0
  162. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64-power9.cmake +0 -0
  163. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64.cmake +0 -0
  164. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64le-clang.cmake +0 -0
  165. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64le-power9.cmake +0 -0
  166. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-powerpc64le.cmake +0 -0
  167. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-riscv.cmake +0 -0
  168. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-s390x.cmake +0 -0
  169. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cmake/toolchain-sparc64.cmake +0 -0
  170. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/compare256_rle.h +0 -0
  171. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/compress.c +0 -0
  172. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cpu_features.c +0 -0
  173. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/cpu_features.h +0 -0
  174. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32.c +0 -0
  175. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32.h +0 -0
  176. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32_braid_comb.c +0 -0
  177. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32_braid_comb_p.h +0 -0
  178. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32_braid_p.h +0 -0
  179. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/crc32_braid_tbl.h +0 -0
  180. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate.c +0 -0
  181. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate.h +0 -0
  182. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_fast.c +0 -0
  183. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_huff.c +0 -0
  184. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_medium.c +0 -0
  185. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_p.h +0 -0
  186. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_quick.c +0 -0
  187. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_rle.c +0 -0
  188. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_slow.c +0 -0
  189. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/deflate_stored.c +0 -0
  190. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/fallback_builtins.h +0 -0
  191. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/functable.c +0 -0
  192. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/functable.h +0 -0
  193. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/gzguts.h +0 -0
  194. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/gzlib.c +0 -0
  195. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/gzread.c.in +0 -0
  196. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/gzwrite.c +0 -0
  197. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/infback.c +0 -0
  198. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inffast_tpl.h +0 -0
  199. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inffixed_tbl.h +0 -0
  200. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inflate.c +0 -0
  201. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inflate.h +0 -0
  202. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inflate_p.h +0 -0
  203. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inftrees.c +0 -0
  204. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/inftrees.h +0 -0
  205. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/insert_string.c +0 -0
  206. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/insert_string_roll.c +0 -0
  207. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/insert_string_tpl.h +0 -0
  208. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/match_tpl.h +0 -0
  209. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/trees.c +0 -0
  210. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/trees.h +0 -0
  211. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/trees_emit.h +0 -0
  212. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/trees_tbl.h +0 -0
  213. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/uncompr.c +0 -0
  214. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zbuild.h +0 -0
  215. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zconf-ng.h.in +0 -0
  216. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zconf.h.in +0 -0
  217. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zendian.h +0 -0
  218. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib-config.cmake.in +0 -0
  219. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib-ng-config.cmake.in +0 -0
  220. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib-ng.h.in +0 -0
  221. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib.h.in +0 -0
  222. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib.pc.cmakein +0 -0
  223. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib.pc.in +0 -0
  224. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib_name_mangling-ng.h.in +0 -0
  225. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib_name_mangling.h.empty +0 -0
  226. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zlib_name_mangling.h.in +0 -0
  227. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zutil.c +0 -0
  228. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zutil.h +0 -0
  229. {pybcf-1.3.7 → pybcf-1.4.0}/src/zlib-ng/zutil_p.h +0 -0
@@ -1,20 +1,25 @@
1
1
  # pybcf code
2
2
  include MANIFEST.in
3
3
  include pyproject.toml
4
- include src/pybcf/*.cpp
5
4
  include src/pybcf/*.py
5
+ include src/pybcf/*.pyi
6
+ include src/pybcf/py.typed
6
7
  include src/pybcf/*.pyx
8
+ include src/pybcf/*.pxd
9
+ # cython generates these while building, so a copy here could be stale
10
+ exclude src/pybcf/*.cpp
7
11
  include src/*.h
8
12
  include src/*.cpp
9
- include src/gzstream.h
10
- include src/gzstream.C
11
13
  include src/zlib-ng/*.h
12
14
  include src/zlib-ng/*.c
13
15
  include src/zlib-ng/CMakeLists.txt
14
16
  include src/zlib-ng/*.in
15
17
  include src/zlib-ng/*.cmakein
16
18
  include src/zlib-ng/*.empty
19
+ exclude src/zlib-ng/zlib.h src/zlib-ng/zconf.h src/zlib-ng/zlib-ng.h src/zlib-ng/zconf-ng.h
20
+ exclude src/zlib-ng/zlib_name_mangling.h src/zlib-ng/zlib_name_mangling-ng.h
17
21
  recursive-include src/zlib-ng/cmake/ *
18
22
  recursive-include src/zlib-ng/arch/ *.c
19
23
  recursive-include src/zlib-ng/arch/ *.h
20
24
  recursive-include src/zlib-ng/arch/ *.in
25
+ prune test
@@ -1,29 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybcf
3
- Version: 1.3.7
3
+ Version: 1.4.0
4
4
  Summary: Package for loading data from bcf files
5
- Home-page: https://github.com/jeremymcrae/pybcf
6
- Author: Jeremy McRae
7
- Author-email: jmcrae@illumina.com
8
- License: MIT
5
+ Author-email: Jeremy McRae <jmcrae@illumina.com>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/jeremymcrae/pybcf
9
8
  Classifier: Development Status :: 4 - Beta
10
9
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
10
+ Requires-Python: >=3.9
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE.txt
13
13
  Requires-Dist: numpy
14
14
  Provides-Extra: test
15
15
  Requires-Dist: pysam; extra == "test"
16
- Dynamic: author
17
- Dynamic: author-email
18
- Dynamic: classifier
19
- Dynamic: description
20
- Dynamic: description-content-type
21
- Dynamic: home-page
22
- Dynamic: license
23
16
  Dynamic: license-file
24
- Dynamic: provides-extra
25
- Dynamic: requires-dist
26
- Dynamic: summary
27
17
 
28
18
 
29
19
  ### pybcf
@@ -32,11 +22,8 @@ This is a package for reading BCF files (binary call format). Similar to pysam/c
32
22
  but limited to reading from BCF files only, and oriented around getting genotype
33
23
  data into numpy arrays quickly.
34
24
 
35
- This performs relatively better at larger sample sizes e.g. it's 7X faster than
36
- pysam with 2k samples, but improves to 50X faster than pysam with 30k samples.
37
- Currently it's slower than pysam for BCFs without sample level data, but BCFs
38
- without genotypes aren't generally a limiting factor e.g. it still parses
39
- 300k variants/second under those conditions.
25
+ This performs relatively better at larger sample sizes e.g. it's ~15X faster than
26
+ pysam with 100 samples, but improves to ~200X faster than pysam with 100k samples.
40
27
 
41
28
  ```py
42
29
  from pybcf import BcfReader
@@ -54,11 +41,18 @@ for var in bcf:
54
41
  keys = list(var.samples)
55
42
  genotypes = var.samples['GT'] # as n x 2 numpy array, missing=nan
56
43
 
57
- # or fetch from random regions if bcf is indexed
44
+ # or fetch from random regions if bcf is indexed. Positions are 1-based and
45
+ # include both ends (pysam's fetch is 0-based and excludes the end)
58
46
  for var in bcf.fetch('chr1', 10000, 200000):
59
47
  print(var.chrom, var.pos)
48
+
49
+ # you can read from stdin, but that doesn't allow fetching random regions
50
+ import sys
51
+ bcf = BcfReader(sys.stdin)
60
52
  ```
61
53
 
62
54
  ### Limitations
63
- - doesn't work with uncompressed BCFs
55
+ - `fetch()` needs a bgzip-compressed BCF with a `.csi` index
56
+ - a reader has one position in the file, so `fetch()` inside a loop over the
57
+ same reader ends that loop. Open a second `BcfReader` to do both at once
64
58
  - extracting info fields is a little slow
@@ -5,11 +5,8 @@ This is a package for reading BCF files (binary call format). Similar to pysam/c
5
5
  but limited to reading from BCF files only, and oriented around getting genotype
6
6
  data into numpy arrays quickly.
7
7
 
8
- This performs relatively better at larger sample sizes e.g. it's 7X faster than
9
- pysam with 2k samples, but improves to 50X faster than pysam with 30k samples.
10
- Currently it's slower than pysam for BCFs without sample level data, but BCFs
11
- without genotypes aren't generally a limiting factor e.g. it still parses
12
- 300k variants/second under those conditions.
8
+ This performs relatively better at larger sample sizes e.g. it's ~15X faster than
9
+ pysam with 100 samples, but improves to ~200X faster than pysam with 100k samples.
13
10
 
14
11
  ```py
15
12
  from pybcf import BcfReader
@@ -27,11 +24,18 @@ for var in bcf:
27
24
  keys = list(var.samples)
28
25
  genotypes = var.samples['GT'] # as n x 2 numpy array, missing=nan
29
26
 
30
- # or fetch from random regions if bcf is indexed
27
+ # or fetch from random regions if bcf is indexed. Positions are 1-based and
28
+ # include both ends (pysam's fetch is 0-based and excludes the end)
31
29
  for var in bcf.fetch('chr1', 10000, 200000):
32
30
  print(var.chrom, var.pos)
31
+
32
+ # you can read from stdin, but that doesn't allow fetching random regions
33
+ import sys
34
+ bcf = BcfReader(sys.stdin)
33
35
  ```
34
36
 
35
37
  ### Limitations
36
- - doesn't work with uncompressed BCFs
38
+ - `fetch()` needs a bgzip-compressed BCF with a `.csi` index
39
+ - a reader has one position in the file, so `fetch()` inside a loop over the
40
+ same reader ends that loop. Open a second `BcfReader` to do both at once
37
41
  - extracting info fields is a little slow
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["cython", "setuptools>=77.0.3"]
3
+ build-backend = 'setuptools.build_meta'
4
+
5
+ [project]
6
+ name = 'pybcf'
7
+ version = '1.4.0'
8
+ description = 'Package for loading data from bcf files'
9
+ readme = 'README.md'
10
+ license = 'MIT'
11
+ requires-python = '>=3.9'
12
+ authors = [
13
+ {name = "Jeremy McRae", email = 'jmcrae@illumina.com'},
14
+ ]
15
+
16
+ dependencies = [
17
+ 'numpy',
18
+ ]
19
+
20
+ classifiers = [
21
+ 'Development Status :: 4 - Beta',
22
+ 'Topic :: Scientific/Engineering :: Bio-Informatics',
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ test = [
27
+ 'pysam',
28
+ ]
29
+
30
+ [tool.setuptools]
31
+ include-package-data = false
32
+ packages = [
33
+ 'pybcf',
34
+ ]
35
+
36
+ [tool.setuptools.package-data]
37
+ pybcf = [
38
+ 'py.typed',
39
+ '*.pyi',
40
+ ]
41
+
42
+ [project.urls]
43
+ homepage = 'https://github.com/jeremymcrae/pybcf'
pybcf-1.4.0/setup.py ADDED
@@ -0,0 +1,81 @@
1
+
2
+ from pathlib import Path
3
+ from setuptools import setup, Extension
4
+ from setuptools.command.build_ext import build_ext
5
+ import subprocess
6
+ import sys
7
+
8
+ from Cython.Build import cythonize
9
+
10
+ ROOT = Path(__file__).resolve().parent
11
+
12
+ EXTRA_COMPILE_ARGS = []
13
+ if sys.platform == 'linux':
14
+ EXTRA_COMPILE_ARGS += ['-std=c++11', '-O2']
15
+ elif sys.platform == "darwin":
16
+ EXTRA_COMPILE_ARGS += ["-stdlib=libc++", "-std=c++11", "-O2"]
17
+ elif sys.platform == "win32":
18
+ EXTRA_COMPILE_ARGS += ['/std:c++14', '/O2']
19
+
20
+ def build_zlib(build_dir):
21
+ ''' compile zlib-ng into a static library to link with
22
+
23
+ Args:
24
+ build_dir: folder to build in, which also gets the generated zlib.h
25
+
26
+ Returns:
27
+ list holding the path to the static library
28
+ '''
29
+ source_dir = ROOT / 'src' / 'zlib-ng'
30
+ cmd = ['cmake', '-S', source_dir, '-B', build_dir,
31
+ '-DZLIB_COMPAT=ON',
32
+ '-DZLIB_ENABLE_TESTS=OFF',
33
+ '-DBUILD_SHARED_LIBS=OFF',
34
+ '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
35
+ ]
36
+ subprocess.run(cmd, check=True)
37
+ subprocess.run(['cmake', '--build', build_dir, '-v', '--config', 'Release'],
38
+ check=True)
39
+
40
+ if sys.platform == 'win32':
41
+ return [str(build_dir / 'Release' / 'zlibstatic.lib')]
42
+ return [str(build_dir / 'libz.a')]
43
+
44
+ class build_ext_subclass(build_ext):
45
+ ''' link the vendored zlib-ng into the extension module
46
+
47
+ zlib-ng is only needed to link the extension module, so compiling it here
48
+ (rather than at import) keeps metadata-only commands such as egg_info and
49
+ sdist from invoking cmake.
50
+ '''
51
+ def build_extensions(self):
52
+ # built alongside the other temporary files, rather than in the source tree
53
+ zlib_dir = Path(self.build_temp) / 'zlib-ng'
54
+ zlib = build_zlib(zlib_dir)
55
+ for ext in self.extensions:
56
+ ext.include_dirs.append(str(zlib_dir))
57
+ ext.extra_objects = zlib
58
+ super().build_extensions()
59
+
60
+ extensions = [
61
+ Extension('pybcf.reader',
62
+ extra_compile_args=EXTRA_COMPILE_ARGS,
63
+ sources=['src/pybcf/reader.pyx',
64
+ 'src/bgzf.cpp',
65
+ 'src/gzreader.cpp',
66
+ 'src/bcf.cpp',
67
+ 'src/index.cpp',
68
+ 'src/header.cpp',
69
+ 'src/info.cpp',
70
+ 'src/sample_data.cpp',
71
+ 'src/variant.cpp'],
72
+ depends=[p.relative_to(ROOT).as_posix() for p in sorted((ROOT / 'src').glob('*.h'))],
73
+ include_dirs=['src'],
74
+ language='c++'),
75
+ ]
76
+
77
+ setup(
78
+ package_dir={'': 'src'},
79
+ ext_modules=cythonize(extensions),
80
+ cmdclass={'build_ext': build_ext_subclass},
81
+ )
@@ -0,0 +1,91 @@
1
+ #include <algorithm>
2
+ #include <stdexcept>
3
+
4
+ #include "bcf.h"
5
+
6
+ namespace bcf {
7
+
8
+ /// @brief open a BGZF-compressed BCF2.2 file and load its header and optional CSI index
9
+ /// @param path path to bcf file
10
+ /// @param index_path explicit CSI index path, or empty to probe `<path>.csi`
11
+ BCF::BCF(const std::string & path, const std::string & index_path) {
12
+ infile.open(path);
13
+ if (!infile.is_open()) {
14
+ throw std::invalid_argument("cannot open file at " + path);
15
+ }
16
+
17
+ // Verify the 5-byte BCF2.2 magic header ("BCF\x02\x02").
18
+ char magic[5];
19
+ infile.read_exact(magic, 5, "doesn't look like a BCF2.2 file");
20
+ if (magic[0] != 'B' || magic[1] != 'C' || magic[2] != 'F' || magic[3] != 2 || magic[4] != 2) {
21
+ throw std::invalid_argument("doesn't look like a BCF2.2 file");
22
+ }
23
+
24
+ // Read the uint32 length of the NUL-terminated ASCII VCF header text, then parse it.
25
+ // The length is untrusted, so grow the text in 1 MB chunks rather than allocating it upfront.
26
+ std::uint32_t len = 0;
27
+ infile.read_exact(&len, sizeof(len), "truncated BCF header length");
28
+ std::string text;
29
+ while (text.size() < len) {
30
+ std::size_t start = text.size();
31
+ text.resize(start + std::min<std::size_t>(len - start, 1 << 20));
32
+ infile.read_exact(&text[start], text.size() - start, "truncated BCF header text");
33
+ }
34
+ header = Header(text);
35
+
36
+ // Load `<path>.csi` opportunistically if present, but fail immediately if a
37
+ // user-supplied `index_path` is missing.
38
+ bool explicit_index = !index_path.empty();
39
+ std::string csi_path = explicit_index ? index_path : (path + ".csi");
40
+ idxfile.open(csi_path, explicit_index);
41
+ }
42
+
43
+ // Read the next variant matching the current stream/region state, returning false at EOF or end of region.
44
+ bool BCF::nextvar(Variant & var) {
45
+ if (exhausted) {
46
+ return false;
47
+ }
48
+ // A read that throws leaves the stream part-way through a record, where the following
49
+ // bytes could pass for a record of their own. So only carry on after a successful read.
50
+ exhausted = true;
51
+ exhausted = !var.read(infile, header, region);
52
+ return !exhausted;
53
+ }
54
+
55
+ /// @brief seek to a 1-based inclusive genomic region `[start, end]` using the CSI index
56
+ /// @param chrom chromosome/contig name
57
+ /// @param start 1-based start position in base pairs (0 includes telomeric POS = 0 records)
58
+ /// @param end 1-based inclusive end position in base pairs
59
+ void BCF::set_region(const std::string & chrom, std::int32_t start, std::int32_t end) {
60
+ if (!idxfile.has_index) {
61
+ throw std::invalid_argument("cannot fetch without an index file");
62
+ }
63
+ if (start < 0) {
64
+ throw std::invalid_argument("start position must be non-negative: " + std::to_string(start));
65
+ }
66
+ if (end < start) {
67
+ throw std::invalid_argument("start is after end: " + std::to_string(start) + " > " + std::to_string(end));
68
+ }
69
+
70
+ std::uint32_t contig_id = header.get_contig_id(chrom);
71
+
72
+ region.contig_id = static_cast<std::int32_t>(contig_id);
73
+ region.start = start;
74
+ region.end = end;
75
+
76
+ // CSI bins use 0-based half-open `[beg, end)` coordinates, so convert 1-based `start`
77
+ // to `max(0, start - 1)`. There is nothing to read if the index has no chunk for the
78
+ // region, or if the seek throws.
79
+ exhausted = true;
80
+ std::uint64_t offset = 0;
81
+ if (idxfile.query(contig_id, std::max<std::int64_t>(0, start - 1), end, offset)) {
82
+ infile.seek(offset);
83
+ exhausted = false;
84
+ }
85
+ }
86
+
87
+ void BCF::close() {
88
+ infile.close();
89
+ }
90
+
91
+ } // namespace bcf
pybcf-1.4.0/src/bcf.h ADDED
@@ -0,0 +1,30 @@
1
+ #ifndef BCF_BCF_H
2
+ #define BCF_BCF_H
3
+
4
+ #include <cstdint>
5
+ #include <string>
6
+
7
+ #include "gzreader.h"
8
+ #include "header.h"
9
+ #include "index.h"
10
+ #include "variant.h"
11
+
12
+ namespace bcf {
13
+
14
+ // Top-level BCF2.2 reader supporting sequential iteration and `.csi`-indexed region queries.
15
+ class BCF {
16
+ GzReader infile;
17
+ IndexFile idxfile;
18
+ Region region; // which records to read: all of them, until `set_region` is called
19
+ bool exhausted = false; // true once EOF or end of the active region is reached
20
+ public:
21
+ BCF(const std::string & path, const std::string & index_path = "");
22
+ bool nextvar(Variant & var);
23
+ void set_region(const std::string & chrom, std::int32_t start = 0, std::int32_t end = INT32_MAX);
24
+ void close();
25
+ Header header;
26
+ };
27
+
28
+ } // namespace bcf
29
+
30
+ #endif
@@ -0,0 +1,176 @@
1
+ #include "bgzf.h"
2
+
3
+ #include <cstdio>
4
+ #include <cstring>
5
+ #include <stdexcept>
6
+
7
+ #include <fcntl.h>
8
+ #ifdef _WIN32
9
+ #include <io.h>
10
+ #else
11
+ #include <unistd.h>
12
+ #endif
13
+
14
+ namespace bcf {
15
+
16
+ namespace {
17
+
18
+ // Every BGZF block starts with an 18-byte gzip header and ends with its CRC32 and
19
+ // uncompressed size (4 bytes each).
20
+ const std::size_t HEADER_SIZE = 18;
21
+ const std::size_t FOOTER_SIZE = 8;
22
+
23
+ // Read up to `count` bytes starting `pos` bytes into the file, without moving the file's
24
+ // own position. Returns how many bytes were read, or -1 on failure, as for a pipe.
25
+ long long read_at(int fd, unsigned char * dst, std::size_t count, std::uint64_t pos) {
26
+ #ifdef _WIN32
27
+ // Windows has no `pread`, so move to `pos`, read, then move back.
28
+ __int64 start = _lseeki64(fd, 0, SEEK_CUR);
29
+ if (start < 0 || _lseeki64(fd, static_cast<__int64>(pos), SEEK_SET) < 0) {
30
+ return -1;
31
+ }
32
+ int got = _read(fd, dst, static_cast<unsigned int>(count));
33
+ _lseeki64(fd, start, SEEK_SET);
34
+ return got;
35
+ #else
36
+ return pread(fd, dst, count, static_cast<off_t>(pos));
37
+ #endif
38
+ }
39
+
40
+ // A BGZF block is a gzip member whose header has a 'BC' extra field holding the block's size.
41
+ bool is_bgzf_header(const unsigned char * h) {
42
+ return h[0] == 0x1f && h[1] == 0x8b && h[2] == 8 && (h[3] & 4) && h[10] == 6 && h[11] == 0 &&
43
+ h[12] == 'B' && h[13] == 'C' && h[14] == 2 && h[15] == 0;
44
+ }
45
+
46
+ } // namespace
47
+
48
+ int open_file(const std::string & path) {
49
+ // "-" means standard input. It is duplicated, so closing the file leaves stdin open.
50
+ #ifdef _WIN32
51
+ if (path == "-") {
52
+ int fd = _dup(0);
53
+ if (fd >= 0) {
54
+ _setmode(fd, _O_BINARY);
55
+ }
56
+ return fd;
57
+ }
58
+ return _open(path.c_str(), _O_RDONLY | _O_BINARY);
59
+ #else
60
+ if (path == "-") {
61
+ return ::dup(STDIN_FILENO);
62
+ }
63
+ return ::open(path.c_str(), O_RDONLY);
64
+ #endif
65
+ }
66
+
67
+ void close_file(int fd) {
68
+ #ifdef _WIN32
69
+ _close(fd);
70
+ #else
71
+ ::close(fd);
72
+ #endif
73
+ }
74
+
75
+ bool BgzfFile::open(int open_fd, const std::string & filepath) {
76
+ close();
77
+ // Checking the first bytes reads them at an offset, which leaves the file's position at
78
+ // the start. A pipe always fails the check, since a pipe can't be read at an offset.
79
+ unsigned char head[HEADER_SIZE];
80
+ if (read_at(open_fd, head, sizeof(head), 0) != static_cast<long long>(sizeof(head)) ||
81
+ !is_bgzf_header(head)) {
82
+ return false;
83
+ }
84
+ // A window of 15 + 16 makes inflate expect a gzip header, and check each block's CRC32 and size.
85
+ if (inflateInit2(&strm, 15 + 16) != Z_OK) {
86
+ return false;
87
+ }
88
+ fd = open_fd;
89
+ path = filepath;
90
+ raw.resize(BGZF_MAX_BLOCK_SIZE);
91
+ return true;
92
+ }
93
+
94
+ void BgzfFile::close() {
95
+ if (fd >= 0) {
96
+ inflateEnd(&strm);
97
+ close_file(fd);
98
+ fd = -1;
99
+ }
100
+ std::vector<unsigned char>().swap(raw);
101
+ raw_pos = 0;
102
+ raw_len = 0;
103
+ file_pos = 0;
104
+ }
105
+
106
+ // Read more of the file, until `raw` holds `count` compressed bytes from `raw_pos` on.
107
+ // Returns false if the file ends first. `raw` has room for the largest BGZF block.
108
+ bool BgzfFile::load(std::size_t count) {
109
+ if (raw_len - raw_pos >= count) {
110
+ return true;
111
+ }
112
+ // Move the bytes not yet used to the front, to make room to read more after them.
113
+ raw_len -= raw_pos;
114
+ std::memmove(raw.data(), raw.data() + raw_pos, raw_len);
115
+ raw_pos = 0;
116
+ while (raw_len < count) {
117
+ long long got = read_at(fd, raw.data() + raw_len, raw.size() - raw_len, file_pos);
118
+ if (got < 0) {
119
+ throw std::invalid_argument("cannot read " + path);
120
+ }
121
+ if (got == 0) {
122
+ return false;
123
+ }
124
+ raw_len += static_cast<std::size_t>(got);
125
+ file_pos += static_cast<std::uint64_t>(got);
126
+ }
127
+ return true;
128
+ }
129
+
130
+ bool BgzfFile::next_block() {
131
+ bool has_header = load(HEADER_SIZE);
132
+ if (!has_header && raw_pos == raw_len) {
133
+ return false;
134
+ }
135
+ if (!has_header || !is_bgzf_header(&raw[raw_pos])) {
136
+ throw std::invalid_argument("invalid BGZF block header in " + path);
137
+ }
138
+ // The header's 'BC' field holds the block's total size minus 1, and the footer ends
139
+ // with the uncompressed size.
140
+ compressed_size = (raw[raw_pos + 16] | (raw[raw_pos + 17] << 8)) + 1;
141
+ if (compressed_size < HEADER_SIZE + FOOTER_SIZE) {
142
+ throw std::invalid_argument("invalid BGZF block size in " + path);
143
+ }
144
+ if (!load(compressed_size)) {
145
+ throw std::invalid_argument("truncated BGZF block in " + path);
146
+ }
147
+ std::uint32_t isize = 0;
148
+ std::memcpy(&isize, &raw[raw_pos + compressed_size - 4], sizeof(isize));
149
+ if (isize > BGZF_MAX_BLOCK_SIZE) {
150
+ throw std::invalid_argument("invalid BGZF block size in " + path);
151
+ }
152
+ uncompressed_size = isize;
153
+ return true;
154
+ }
155
+
156
+ // The whole block is decompressed in a single `inflate` call.
157
+ void BgzfFile::inflate_block(char * dst) {
158
+ inflateReset(&strm);
159
+ strm.next_in = &raw[raw_pos];
160
+ strm.avail_in = static_cast<unsigned int>(compressed_size);
161
+ strm.next_out = reinterpret_cast<unsigned char *>(dst);
162
+ strm.avail_out = static_cast<unsigned int>(uncompressed_size);
163
+ raw_pos += compressed_size;
164
+ if (inflate(&strm, Z_FINISH) != Z_STREAM_END || strm.avail_in != 0) {
165
+ throw std::invalid_argument(std::string(strm.msg ? strm.msg : "corrupt BGZF block") + " in " + path);
166
+ }
167
+ }
168
+
169
+ // Drop the bytes read ahead, so the next read starts at `offset`.
170
+ void BgzfFile::seek(std::uint64_t offset) {
171
+ raw_pos = 0;
172
+ raw_len = 0;
173
+ file_pos = offset;
174
+ }
175
+
176
+ } // namespace bcf
pybcf-1.4.0/src/bgzf.h ADDED
@@ -0,0 +1,65 @@
1
+ #ifndef BCF_BGZF_H
2
+ #define BCF_BGZF_H
3
+
4
+ #include <cstddef>
5
+ #include <cstdint>
6
+ #include <string>
7
+ #include <vector>
8
+ #include "zlib.h"
9
+
10
+ namespace bcf {
11
+
12
+ // The most bytes a BGZF block can hold, both compressed and uncompressed.
13
+ const std::size_t BGZF_MAX_BLOCK_SIZE = 65536;
14
+
15
+ // Open a file for reading, or standard input if `path` is "-", returning its file
16
+ // descriptor, or -1 on failure.
17
+ int open_file(const std::string & path);
18
+ void close_file(int fd);
19
+
20
+ // Reads a BGZF file one block at a time. BGZF is gzip written as a series of small
21
+ // blocks, each of which can be decompressed on its own, so reading can start at any block.
22
+ //
23
+ // The file is read at offsets this class tracks itself, rather than at the file's own
24
+ // position. Copies of a reader in forked processes share that position, and so would
25
+ // otherwise move it under each other.
26
+ class BgzfFile {
27
+ std::string path; // for error messages
28
+ int fd = -1;
29
+ std::uint64_t file_pos = 0; // offset in the file of the next bytes to read
30
+ std::vector<unsigned char> raw; // compressed bytes read from the file
31
+ std::size_t raw_len = 0;
32
+ std::size_t raw_pos = 0; // start of the next block in `raw`
33
+ std::size_t compressed_size = 0; // size of the next block in `raw`
34
+ std::size_t uncompressed_size = 0; // size of the next block once decompressed
35
+ z_stream strm{}; // inflate state, reset for each block
36
+
37
+ bool load(std::size_t count);
38
+ public:
39
+ BgzfFile() = default;
40
+ BgzfFile(const BgzfFile &) = delete;
41
+ BgzfFile & operator=(const BgzfFile &) = delete;
42
+ ~BgzfFile() { close(); }
43
+
44
+ // Take over an open file, if it starts with a BGZF block. Otherwise return false,
45
+ // leaving the file open and at its start. A pipe is never taken over.
46
+ bool open(int open_fd, const std::string & filepath);
47
+ void close();
48
+ bool is_open() const { return fd >= 0; }
49
+
50
+ // Find the next block, returning false at the end of the file.
51
+ bool next_block();
52
+
53
+ // Size of the block found by `next_block`, once decompressed.
54
+ std::size_t block_size() const { return uncompressed_size; }
55
+
56
+ // Decompress the block found by `next_block` into `dst`, which must hold `block_size()` bytes.
57
+ void inflate_block(char * dst);
58
+
59
+ // Carry on from the block that starts `offset` bytes into the file.
60
+ void seek(std::uint64_t offset);
61
+ };
62
+
63
+ } // namespace bcf
64
+
65
+ #endif