pybcf 1.0.2__tar.gz → 1.2.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 (105) hide show
  1. {pybcf-1.0.2 → pybcf-1.2.0}/MANIFEST.in +4 -2
  2. pybcf-1.2.0/PKG-INFO +49 -0
  3. pybcf-1.2.0/README.md +33 -0
  4. {pybcf-1.0.2 → pybcf-1.2.0}/setup.py +43 -15
  5. {pybcf-1.0.2 → pybcf-1.2.0}/src/gzstream/gzstream.h +1 -1
  6. {pybcf-1.0.2 → pybcf-1.2.0}/src/header.cpp +65 -0
  7. {pybcf-1.0.2 → pybcf-1.2.0}/src/header.h +4 -0
  8. {pybcf-1.0.2 → pybcf-1.2.0}/src/info.cpp +12 -0
  9. {pybcf-1.0.2 → pybcf-1.2.0}/src/info.h +1 -0
  10. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf/reader.cpp +9225 -4434
  11. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf/reader.pyx +125 -22
  12. pybcf-1.2.0/src/pybcf.egg-info/PKG-INFO +49 -0
  13. pybcf-1.2.0/src/pybcf.egg-info/SOURCES.txt +81 -0
  14. pybcf-1.2.0/src/sample_data.cpp +247 -0
  15. {pybcf-1.0.2 → pybcf-1.2.0}/src/sample_data.h +2 -0
  16. {pybcf-1.0.2 → pybcf-1.2.0}/src/types.h +15 -2
  17. pybcf-1.2.0/src/zlib-ng/adler32.c +69 -0
  18. pybcf-1.2.0/src/zlib-ng/adler32_p.h +70 -0
  19. pybcf-1.2.0/src/zlib-ng/arch_functions.h +29 -0
  20. pybcf-1.2.0/src/zlib-ng/chunkset_tpl.h +200 -0
  21. pybcf-1.2.0/src/zlib-ng/compare256_rle.h +134 -0
  22. pybcf-1.2.0/src/zlib-ng/compress.c +98 -0
  23. pybcf-1.2.0/src/zlib-ng/cpu_features.c +23 -0
  24. pybcf-1.2.0/src/zlib-ng/cpu_features.h +43 -0
  25. pybcf-1.2.0/src/zlib-ng/crc32.c +42 -0
  26. pybcf-1.2.0/src/zlib-ng/crc32.h +16 -0
  27. pybcf-1.2.0/src/zlib-ng/crc32_braid_comb.c +56 -0
  28. pybcf-1.2.0/src/zlib-ng/crc32_braid_comb_p.h +42 -0
  29. pybcf-1.2.0/src/zlib-ng/crc32_braid_p.h +64 -0
  30. pybcf-1.0.2/src/zlib/crc32.h → pybcf-1.2.0/src/zlib-ng/crc32_braid_tbl.h +49 -49
  31. pybcf-1.2.0/src/zlib-ng/deflate.c +1513 -0
  32. pybcf-1.2.0/src/zlib-ng/deflate.h +448 -0
  33. pybcf-1.2.0/src/zlib-ng/deflate_fast.c +102 -0
  34. pybcf-1.2.0/src/zlib-ng/deflate_huff.c +45 -0
  35. pybcf-1.2.0/src/zlib-ng/deflate_medium.c +278 -0
  36. pybcf-1.2.0/src/zlib-ng/deflate_p.h +126 -0
  37. pybcf-1.2.0/src/zlib-ng/deflate_quick.c +129 -0
  38. pybcf-1.2.0/src/zlib-ng/deflate_rle.c +85 -0
  39. pybcf-1.2.0/src/zlib-ng/deflate_slow.c +143 -0
  40. pybcf-1.2.0/src/zlib-ng/deflate_stored.c +186 -0
  41. pybcf-1.2.0/src/zlib-ng/fallback_builtins.h +47 -0
  42. pybcf-1.2.0/src/zlib-ng/functable.c +354 -0
  43. pybcf-1.2.0/src/zlib-ng/functable.h +55 -0
  44. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/gzguts.h +41 -110
  45. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/gzlib.c +108 -162
  46. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/gzwrite.c +88 -193
  47. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/infback.c +144 -254
  48. pybcf-1.2.0/src/zlib-ng/inffast_tpl.h +326 -0
  49. pybcf-1.2.0/src/zlib-ng/inffixed_tbl.h +94 -0
  50. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/inflate.c +611 -684
  51. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/inflate.h +53 -22
  52. pybcf-1.2.0/src/zlib-ng/inflate_p.h +231 -0
  53. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/inftrees.c +38 -42
  54. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/inftrees.h +17 -13
  55. pybcf-1.2.0/src/zlib-ng/insert_string.c +21 -0
  56. pybcf-1.2.0/src/zlib-ng/insert_string_roll.c +24 -0
  57. pybcf-1.2.0/src/zlib-ng/insert_string_tpl.h +107 -0
  58. pybcf-1.2.0/src/zlib-ng/match_tpl.h +284 -0
  59. pybcf-1.2.0/src/zlib-ng/trees.c +818 -0
  60. pybcf-1.2.0/src/zlib-ng/trees.h +40 -0
  61. pybcf-1.2.0/src/zlib-ng/trees_emit.h +227 -0
  62. pybcf-1.2.0/src/zlib-ng/trees_tbl.h +132 -0
  63. {pybcf-1.0.2/src/zlib → pybcf-1.2.0/src/zlib-ng}/uncompr.c +21 -26
  64. pybcf-1.2.0/src/zlib-ng/zbuild.h +327 -0
  65. pybcf-1.2.0/src/zlib-ng/zendian.h +60 -0
  66. pybcf-1.2.0/src/zlib-ng/zutil.c +111 -0
  67. pybcf-1.2.0/src/zlib-ng/zutil.h +140 -0
  68. pybcf-1.2.0/src/zlib-ng/zutil_p.h +75 -0
  69. pybcf-1.2.0/test/test_pybcf.py +170 -0
  70. pybcf-1.0.2/PKG-INFO +0 -38
  71. pybcf-1.0.2/README.md +0 -22
  72. pybcf-1.0.2/src/pybcf.egg-info/PKG-INFO +0 -38
  73. pybcf-1.0.2/src/pybcf.egg-info/SOURCES.txt +0 -55
  74. pybcf-1.0.2/src/sample_data.cpp +0 -104
  75. pybcf-1.0.2/src/zlib/adler32.c +0 -164
  76. pybcf-1.0.2/src/zlib/compress.c +0 -75
  77. pybcf-1.0.2/src/zlib/crc32.c +0 -1049
  78. pybcf-1.0.2/src/zlib/deflate.c +0 -2140
  79. pybcf-1.0.2/src/zlib/deflate.h +0 -377
  80. pybcf-1.0.2/src/zlib/gzclose.c +0 -23
  81. pybcf-1.0.2/src/zlib/gzread.c +0 -603
  82. pybcf-1.0.2/src/zlib/inffast.c +0 -320
  83. pybcf-1.0.2/src/zlib/inffast.h +0 -11
  84. pybcf-1.0.2/src/zlib/inffixed.h +0 -94
  85. pybcf-1.0.2/src/zlib/trees.c +0 -1117
  86. pybcf-1.0.2/src/zlib/trees.h +0 -128
  87. pybcf-1.0.2/src/zlib/zconf.h +0 -541
  88. pybcf-1.0.2/src/zlib/zlib.h +0 -1941
  89. pybcf-1.0.2/src/zlib/zutil.c +0 -299
  90. pybcf-1.0.2/src/zlib/zutil.h +0 -253
  91. pybcf-1.0.2/test/test_pybcf.py +0 -98
  92. {pybcf-1.0.2 → pybcf-1.2.0}/LICENSE.txt +0 -0
  93. {pybcf-1.0.2 → pybcf-1.2.0}/pyproject.toml +0 -0
  94. {pybcf-1.0.2 → pybcf-1.2.0}/setup.cfg +0 -0
  95. {pybcf-1.0.2 → pybcf-1.2.0}/src/bcf.cpp +0 -0
  96. {pybcf-1.0.2 → pybcf-1.2.0}/src/bcf.h +0 -0
  97. {pybcf-1.0.2 → pybcf-1.2.0}/src/gzstream/gzstream.C +0 -0
  98. {pybcf-1.0.2 → pybcf-1.2.0}/src/index.cpp +0 -0
  99. {pybcf-1.0.2 → pybcf-1.2.0}/src/index.h +0 -0
  100. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf/__init__.py +0 -0
  101. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf.egg-info/dependency_links.txt +0 -0
  102. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf.egg-info/requires.txt +0 -0
  103. {pybcf-1.0.2 → pybcf-1.2.0}/src/pybcf.egg-info/top_level.txt +0 -0
  104. {pybcf-1.0.2 → pybcf-1.2.0}/src/variant.cpp +0 -0
  105. {pybcf-1.0.2 → pybcf-1.2.0}/src/variant.h +0 -0
@@ -8,5 +8,7 @@ include src/*.h
8
8
  include src/*.cpp
9
9
  include src/gzstream/gzstream.h
10
10
  include src/gzstream/gzstream.C
11
- include src/zlib/*.h
12
- include src/zlib/*.c
11
+ include src/zlib-ng/*.h
12
+ include src/zlib-ng/*.c
13
+ recursive-include src/zlib-ng/arch/*.h
14
+ recursive-include src/zlib-ng/arch/*.c
pybcf-1.2.0/PKG-INFO ADDED
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.1
2
+ Name: pybcf
3
+ Version: 1.2.0
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
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Requires-Dist: numpy
14
+ Provides-Extra: test
15
+ Requires-Dist: pysam; extra == "test"
16
+
17
+
18
+ ### pybcf
19
+
20
+ This is a package for reading BCF files (binary call format). Similar to pysam/cyvcf2,
21
+ but limited to reading from BCF files only, and oriented around getting genotype
22
+ data into numpy arrays quickly.
23
+
24
+ This performs relatively better at larger sample sizes e.g. it's 7X faster than
25
+ pysam with 2k samples, but improves to 50X faster than pysam with 30k samples.
26
+ Currently it's slower than pysam for BCFs without samples, but on the other hand,
27
+ BCFs without variants aren't generally the limiting factor e.g. it still parses
28
+ 300k variants/second under those conditions.
29
+
30
+ ```py
31
+ from pybcf import BcfReader
32
+
33
+ bcf = BcfReader(bcf_path)
34
+
35
+ sample_ids = bcf.samples
36
+ contigs = bcf.header.contigs
37
+
38
+ for var in bcf:
39
+ # the usual attributes are available e.g.
40
+ # var.chrom, var.pos, var.ref, var.alts, var.info['AF']
41
+
42
+ # sample data is accessed as numpy arrays via the format keys
43
+ keys = list(var.samples)
44
+ genotypes = var.samples['GT'] # as n x 2 numpy array, missing=-1
45
+ ```
46
+
47
+ ### Limitations
48
+ - can't fetch variants from random regions yet
49
+ - extracting info fields is a little slow
pybcf-1.2.0/README.md ADDED
@@ -0,0 +1,33 @@
1
+
2
+ ### pybcf
3
+
4
+ This is a package for reading BCF files (binary call format). Similar to pysam/cyvcf2,
5
+ but limited to reading from BCF files only, and oriented around getting genotype
6
+ data into numpy arrays quickly.
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 samples, but on the other hand,
11
+ BCFs without variants aren't generally the limiting factor e.g. it still parses
12
+ 300k variants/second under those conditions.
13
+
14
+ ```py
15
+ from pybcf import BcfReader
16
+
17
+ bcf = BcfReader(bcf_path)
18
+
19
+ sample_ids = bcf.samples
20
+ contigs = bcf.header.contigs
21
+
22
+ for var in bcf:
23
+ # the usual attributes are available e.g.
24
+ # var.chrom, var.pos, var.ref, var.alts, var.info['AF']
25
+
26
+ # sample data is accessed as numpy arrays via the format keys
27
+ keys = list(var.samples)
28
+ genotypes = var.samples['GT'] # as n x 2 numpy array, missing=-1
29
+ ```
30
+
31
+ ### Limitations
32
+ - can't fetch variants from random regions yet
33
+ - extracting info fields is a little slow
@@ -1,9 +1,12 @@
1
1
 
2
2
  import glob
3
3
  import io
4
+ from pathlib import Path
4
5
  from setuptools import setup
6
+ import subprocess
5
7
  import sys
6
8
  import os
9
+ import platform
7
10
 
8
11
  from distutils.core import Extension
9
12
  from distutils.ccompiler import new_compiler
@@ -21,22 +24,38 @@ if sys.platform == "darwin":
21
24
  "-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib",
22
25
  ]
23
26
 
27
+ if platform.machine() == 'x86_64':
28
+ EXTRA_COMPILE_ARGS += ['-mavx', '-mavx2']
29
+
24
30
  def flatten(*lists):
25
31
  return [str(x) for sublist in lists for x in sublist]
26
32
 
27
33
  def build_zlib():
28
- ''' compile zlib code to object files for linking with bgen on windows
34
+ ''' compile zlib code to object files for linking
29
35
 
30
36
  Returns:
31
37
  list of paths to compiled object code
32
38
  '''
33
- include_dirs = ['src/zlib/']
34
- sources = list(glob.glob('src/zlib/*.c'))
35
- extra_compile_args = ['/O2']
39
+ cur_dir = Path.cwd()
40
+ source_dir = cur_dir / 'src' / 'zlib-ng'
41
+ build_dir = cur_dir / 'zlib_build'
42
+ build_dir.mkdir(exist_ok=True)
43
+ os.chdir(build_dir)
44
+
45
+ cmd = ['cmake', '-S', source_dir, '-B', build_dir,
46
+ '-DZLIB_COMPAT=ON',
47
+ '-DZLIB_ENABLE_TESTS=OFF',
48
+ f'-DCMAKE_C_FLAGS="-fPIC"',
49
+ ]
50
+ subprocess.run(cmd)
51
+ subprocess.run(['cmake', '--build', build_dir, '--config', 'Release'])
52
+ os.chdir(cur_dir)
53
+
54
+ objs = [str(build_dir / 'libz.a')]
55
+ if sys.platform == 'win32':
56
+ objs = [str(build_dir / 'Release' / 'zlib.lib')]
36
57
 
37
- cc = new_compiler()
38
- return cc.compile(sources, include_dirs=include_dirs,
39
- extra_preargs=extra_compile_args)
58
+ return str(build_dir), objs
40
59
 
41
60
  def get_gzstream_path():
42
61
  ''' workaround for building gzstream on windows
@@ -63,6 +82,9 @@ def scrub_gzstream():
63
82
  directory from the include dirs, then clang complains about the missing
64
83
  gzstream.h. This is because gzstream.C identifies it's header file with
65
84
  angle brackets. Replacing the angle brackets in that line seems to work.
85
+
86
+ We also need to do the same for the "#include <zlib.h>" in the gzstream
87
+ header, since this now uses zlib-ng for better performance.
66
88
  '''
67
89
  with open(get_gzstream_path(), 'rt') as handle:
68
90
  lines = handle.readlines()
@@ -72,12 +94,19 @@ def scrub_gzstream():
72
94
  if line == '#include <gzstream.h>\n':
73
95
  line = '#include "gzstream.h"\n'
74
96
  handle.write(line)
97
+
98
+ # rejig the header file
99
+ gzstream_header_path = get_gzstream_path().rsplit('.')[0] + '.h'
100
+ with open(gzstream_header_path, 'rt') as handle:
101
+ lines = handle.readlines()
102
+
103
+ with open(gzstream_header_path, 'wt') as handle:
104
+ for line in lines:
105
+ if line == '#include <zlib.h>\n':
106
+ line = '#include "zlib.h"\n'
107
+ handle.write(line)
75
108
 
76
- if sys.platform == 'win32':
77
- zlib, libs = build_zlib(), []
78
- else:
79
- zlib, libs = [], ['z']
80
-
109
+ include_dir, zlib = build_zlib()
81
110
  scrub_gzstream()
82
111
 
83
112
  ext = cythonize([
@@ -92,8 +121,7 @@ ext = cythonize([
92
121
  'src/sample_data.cpp',
93
122
  'src/variant.cpp'],
94
123
  extra_objects=zlib,
95
- include_dirs=['src', 'src/zlib'],
96
- libraries=libs,
124
+ include_dirs=['src', include_dir],
97
125
  language='c++'),
98
126
  ])
99
127
 
@@ -101,7 +129,7 @@ setup(name='pybcf',
101
129
  description='Package for loading data from bcf files',
102
130
  long_description=io.open('README.md', encoding='utf-8').read(),
103
131
  long_description_content_type='text/markdown',
104
- version='1.0.2',
132
+ version='1.2.0',
105
133
  author='Jeremy McRae',
106
134
  author_email='jmcrae@illumina.com',
107
135
  license="MIT",
@@ -32,7 +32,7 @@
32
32
  // standard C++ with new header file names and std:: namespace
33
33
  #include <iostream>
34
34
  #include <fstream>
35
- #include <zlib.h>
35
+ #include "zlib.h"
36
36
 
37
37
  #ifdef GZSTREAM_NAMESPACE
38
38
  namespace GZSTREAM_NAMESPACE {
@@ -1,6 +1,7 @@
1
1
 
2
2
 
3
3
  #include <sstream>
4
+ #include <algorithm>
4
5
 
5
6
  #include "header.h"
6
7
 
@@ -116,4 +117,68 @@ Header::Header(std::string & text) {
116
117
 
117
118
  }
118
119
 
120
+ std::vector<std::string> Header::get_contigs() {
121
+ std::vector<std::uint32_t> keys;
122
+ keys.reserve(contigs.size());
123
+ for (auto& it : contigs) {
124
+ keys.push_back(it.first);
125
+ }
126
+ std::sort(keys.begin(), keys.end());
127
+
128
+ std::vector<std::string> vals;
129
+ vals.reserve(contigs.size());
130
+ for (auto & k : keys) {
131
+ vals.push_back(contigs[k].id);
132
+ }
133
+ return vals;
134
+ }
135
+
136
+ std::vector<std::string> Header::get_info() {
137
+ std::vector<std::uint32_t> keys;
138
+ keys.reserve(info.size());
139
+ for (auto& it : info) {
140
+ keys.push_back(it.first);
141
+ }
142
+ std::sort(keys.begin(), keys.end());
143
+
144
+ std::vector<std::string> vals;
145
+ vals.reserve(info.size());
146
+ for (auto & k : keys) {
147
+ vals.push_back(info[k].id);
148
+ }
149
+ return vals;
150
+ }
151
+
152
+ std::vector<std::string> Header::get_filters() {
153
+ std::vector<std::uint32_t> keys;
154
+ keys.reserve(filters.size());
155
+ for (auto& it : filters) {
156
+ keys.push_back(it.first);
157
+ }
158
+ std::sort(keys.begin(), keys.end());
159
+
160
+ std::vector<std::string> vals;
161
+ vals.reserve(filters.size());
162
+ for (auto & k : keys) {
163
+ vals.push_back(filters[k].id);
164
+ }
165
+ return vals;
166
+ }
167
+
168
+ std::vector<std::string> Header::get_formats() {
169
+ std::vector<std::uint32_t> keys;
170
+ keys.reserve(format.size());
171
+ for (auto& it : format) {
172
+ keys.push_back(it.first);
173
+ }
174
+ std::sort(keys.begin(), keys.end());
175
+
176
+ std::vector<std::string> vals;
177
+ vals.reserve(format.size());
178
+ for (auto & k : keys) {
179
+ vals.push_back(format[k].id);
180
+ }
181
+ return vals;
182
+ }
183
+
119
184
  }
@@ -44,6 +44,10 @@ public:
44
44
  std::unordered_map<std::uint32_t, FilterField> filters;
45
45
  std::unordered_map<std::uint32_t, FormatField> format;
46
46
  std::vector<std::string> samples={};
47
+ std::vector<std::string> get_contigs();
48
+ std::vector<std::string> get_info();
49
+ std::vector<std::string> get_filters();
50
+ std::vector<std::string> get_formats();
47
51
  };
48
52
 
49
53
  }
@@ -14,6 +14,18 @@ Info::Info(char * _buf, Header * _header, std::uint32_t _offset, std::uint32_t _
14
14
  n_info = _n_info;
15
15
  }
16
16
 
17
+ std::vector<std::string> Info::get_keys() {
18
+ if (!is_parsed) {
19
+ parse();
20
+ is_parsed = true;
21
+ }
22
+ std::vector<std::string> key_vals;
23
+ for (auto & x : keys) {
24
+ key_vals.push_back(x.first);
25
+ }
26
+ return key_vals;
27
+ }
28
+
17
29
  void Info::parse() {
18
30
  std::uint32_t buf_idx = offset;
19
31
  Typed type_val;
@@ -39,6 +39,7 @@ class Info {
39
39
  public:
40
40
  Info(char * _buf, Header * _header, std::uint32_t _offset, std::uint32_t _n_info);
41
41
  Info() {};
42
+ std::vector<std::string> get_keys();
42
43
  InfoType get_type(std::string &key);
43
44
 
44
45
  std::int32_t get_int(uint32_t offset) {return scalar_ints[offset];};