pybcf 1.3.4__tar.gz → 1.3.6__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 (84) hide show
  1. {pybcf-1.3.4 → pybcf-1.3.6}/MANIFEST.in +2 -2
  2. {pybcf-1.3.4/src/pybcf.egg-info → pybcf-1.3.6}/PKG-INFO +1 -1
  3. {pybcf-1.3.4 → pybcf-1.3.6}/setup.py +15 -8
  4. {pybcf-1.3.4 → pybcf-1.3.6}/src/bcf.cpp +9 -1
  5. {pybcf-1.3.4 → pybcf-1.3.6}/src/bcf.h +3 -3
  6. {pybcf-1.3.4 → pybcf-1.3.6}/src/gzstream.cpp +26 -18
  7. {pybcf-1.3.4 → pybcf-1.3.6}/src/gzstream.h +4 -1
  8. {pybcf-1.3.4 → pybcf-1.3.6}/src/header.cpp +8 -0
  9. {pybcf-1.3.4 → pybcf-1.3.6}/src/header.h +1 -0
  10. {pybcf-1.3.4 → pybcf-1.3.6}/src/index.cpp +11 -33
  11. {pybcf-1.3.4 → pybcf-1.3.6}/src/index.h +1 -3
  12. {pybcf-1.3.4 → pybcf-1.3.6}/src/info.cpp +6 -10
  13. {pybcf-1.3.4 → pybcf-1.3.6}/src/info.h +6 -2
  14. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf/reader.cpp +84 -354
  15. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf/reader.pyx +2 -2
  16. {pybcf-1.3.4 → pybcf-1.3.6/src/pybcf.egg-info}/PKG-INFO +1 -1
  17. {pybcf-1.3.4 → pybcf-1.3.6}/src/sample_data.cpp +92 -18
  18. {pybcf-1.3.4 → pybcf-1.3.6}/src/sample_data.h +10 -4
  19. {pybcf-1.3.4 → pybcf-1.3.6}/src/variant.cpp +4 -1
  20. {pybcf-1.3.4 → pybcf-1.3.6}/test/test_indexed.py +14 -0
  21. {pybcf-1.3.4 → pybcf-1.3.6}/LICENSE.txt +0 -0
  22. {pybcf-1.3.4 → pybcf-1.3.6}/README.md +0 -0
  23. {pybcf-1.3.4 → pybcf-1.3.6}/pyproject.toml +0 -0
  24. {pybcf-1.3.4 → pybcf-1.3.6}/setup.cfg +0 -0
  25. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf/__init__.py +0 -0
  26. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf.egg-info/SOURCES.txt +0 -0
  27. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf.egg-info/dependency_links.txt +0 -0
  28. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf.egg-info/requires.txt +0 -0
  29. {pybcf-1.3.4 → pybcf-1.3.6}/src/pybcf.egg-info/top_level.txt +0 -0
  30. {pybcf-1.3.4 → pybcf-1.3.6}/src/types.h +0 -0
  31. {pybcf-1.3.4 → pybcf-1.3.6}/src/variant.h +0 -0
  32. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/adler32.c +0 -0
  33. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/adler32_p.h +0 -0
  34. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/arch_functions.h +0 -0
  35. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/chunkset_tpl.h +0 -0
  36. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/compare256_rle.h +0 -0
  37. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/compress.c +0 -0
  38. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/cpu_features.c +0 -0
  39. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/cpu_features.h +0 -0
  40. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32.c +0 -0
  41. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32.h +0 -0
  42. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32_braid_comb.c +0 -0
  43. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32_braid_comb_p.h +0 -0
  44. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32_braid_p.h +0 -0
  45. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/crc32_braid_tbl.h +0 -0
  46. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate.c +0 -0
  47. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate.h +0 -0
  48. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_fast.c +0 -0
  49. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_huff.c +0 -0
  50. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_medium.c +0 -0
  51. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_p.h +0 -0
  52. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_quick.c +0 -0
  53. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_rle.c +0 -0
  54. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_slow.c +0 -0
  55. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/deflate_stored.c +0 -0
  56. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/fallback_builtins.h +0 -0
  57. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/functable.c +0 -0
  58. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/functable.h +0 -0
  59. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/gzguts.h +0 -0
  60. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/gzlib.c +0 -0
  61. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/gzwrite.c +0 -0
  62. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/infback.c +0 -0
  63. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inffast_tpl.h +0 -0
  64. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inffixed_tbl.h +0 -0
  65. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inflate.c +0 -0
  66. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inflate.h +0 -0
  67. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inflate_p.h +0 -0
  68. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inftrees.c +0 -0
  69. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/inftrees.h +0 -0
  70. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/insert_string.c +0 -0
  71. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/insert_string_roll.c +0 -0
  72. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/insert_string_tpl.h +0 -0
  73. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/match_tpl.h +0 -0
  74. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/trees.c +0 -0
  75. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/trees.h +0 -0
  76. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/trees_emit.h +0 -0
  77. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/trees_tbl.h +0 -0
  78. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/uncompr.c +0 -0
  79. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/zbuild.h +0 -0
  80. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/zendian.h +0 -0
  81. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/zutil.c +0 -0
  82. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/zutil.h +0 -0
  83. {pybcf-1.3.4 → pybcf-1.3.6}/src/zlib-ng/zutil_p.h +0 -0
  84. {pybcf-1.3.4 → pybcf-1.3.6}/test/test_pybcf.py +0 -0
@@ -6,8 +6,8 @@ include src/pybcf/*.py
6
6
  include src/pybcf/*.pyx
7
7
  include src/*.h
8
8
  include src/*.cpp
9
- include src/gzstream/gzstream.h
10
- include src/gzstream/gzstream.C
9
+ include src/gzstream.h
10
+ include src/gzstream.C
11
11
  include src/zlib-ng/*.h
12
12
  include src/zlib-ng/*.c
13
13
  recursive-include src/zlib-ng/arch/*.h
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pybcf
3
- Version: 1.3.4
3
+ Version: 1.3.6
4
4
  Summary: Package for loading data from bcf files
5
5
  Home-page: https://github.com/jeremymcrae/pybcf
6
6
  Author: Jeremy McRae
@@ -10,19 +10,24 @@ import platform
10
10
  from distutils.core import Extension
11
11
  from Cython.Build import cythonize
12
12
 
13
- EXTRA_COMPILE_ARGS = ['-std=c++11', '-I/usr/include']
14
13
  EXTRA_LINK_ARGS = []
15
- if sys.platform == "darwin":
14
+ EXTRA_COMPILE_ARGS = []
15
+ if sys.platform == 'linux':
16
+ EXTRA_COMPILE_ARGS = ['-std=c++11', '-I/usr/include']
17
+ elif sys.platform == "darwin":
16
18
  EXTRA_COMPILE_ARGS += [
17
19
  "-stdlib=libc++",
20
+ "-std=c++11",
21
+ '-mavx', # required for macosx testing on github actions
22
+ '-mavx2', # required for macosx testing on github actions
18
23
  "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
19
24
  "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
20
- '-mavx',
21
- '-mavx2',
22
25
  ]
23
26
  EXTRA_LINK_ARGS += [
24
27
  "-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib",
25
28
  ]
29
+ elif sys.platform == "win32":
30
+ EXTRA_COMPILE_ARGS += ['/std:c++14', '/O2']
26
31
 
27
32
  if platform.machine() == 'x86_64':
28
33
  EXTRA_COMPILE_ARGS += ['-mavx', '-mavx2']
@@ -42,15 +47,17 @@ def build_zlib():
42
47
  cmd = ['cmake', '-S', source_dir, '-B', build_dir,
43
48
  '-DZLIB_COMPAT=ON',
44
49
  '-DZLIB_ENABLE_TESTS=OFF',
45
- f'-DCMAKE_C_FLAGS="-fPIC"',
50
+ '-DBUILD_SHARED_LIBS=OFF',
51
+ '-DCMAKE_C_FLAGS="-fPIC"',
46
52
  ]
47
53
  subprocess.run(cmd)
48
- subprocess.run(['cmake', '--build', build_dir, '--config', 'Release'])
54
+ subprocess.run(['cmake', '--build', build_dir, '-v', '--config', 'Release'])
49
55
  os.chdir(cur_dir)
50
56
 
51
57
  objs = [str(build_dir / 'libz.a')]
52
58
  if sys.platform == 'win32':
53
- objs = [str(build_dir / 'Release' / 'zlib.lib')]
59
+ objs = [str(build_dir / 'Release' / 'zlibstatic.lib'),
60
+ ]
54
61
 
55
62
  return str(build_dir), objs
56
63
 
@@ -77,7 +84,7 @@ setup(name='pybcf',
77
84
  description='Package for loading data from bcf files',
78
85
  long_description=io.open('README.md', encoding='utf-8').read(),
79
86
  long_description_content_type='text/markdown',
80
- version='1.3.4',
87
+ version='1.3.6',
81
88
  author='Jeremy McRae',
82
89
  author_email='jmcrae@illumina.com',
83
90
  license="MIT",
@@ -8,6 +8,9 @@
8
8
  namespace bcf {
9
9
 
10
10
 
11
+ /// @brief open BCF file
12
+ /// @param path path to bcf file
13
+ /// @param index_path path to index file (if exists)
11
14
  BCF::BCF(std::string path, std::string index_path) {
12
15
  infile.open(path.c_str());
13
16
  if (infile.fail()) {
@@ -37,6 +40,7 @@ BCF::BCF(std::string path, std::string index_path) {
37
40
 
38
41
  }
39
42
 
43
+ // extract the next variant from the BCF
40
44
  Variant BCF::nextvar() {
41
45
  Variant var = Variant(infile, header);
42
46
  if ((query_chrom.size() != 0) && (var.chrom != query_chrom)) {
@@ -55,7 +59,11 @@ Variant BCF::nextvar() {
55
59
  return var;
56
60
  }
57
61
 
58
- void BCF::set_region(std::string chrom, std::uint32_t start, std::uint32_t end) {
62
+ /// @brief define genome region to extract variants from
63
+ /// @param chrom chromosome/contig name
64
+ /// @param start start position (in base pairs)
65
+ /// @param end end position (in base-pairs)
66
+ void BCF::set_region(std::string chrom, std::int32_t start, std::int32_t end) {
59
67
  if (!idxfile.has_index) {
60
68
  throw std::invalid_argument("cannot fetch without an index file");
61
69
  }
@@ -17,12 +17,12 @@ class BCF {
17
17
  igzstream infile;
18
18
  IndexFile idxfile;
19
19
  std::string query_chrom="";
20
- std::uint32_t query_start=0;
21
- std::uint32_t query_end=1 << 31;
20
+ std::int32_t query_start=0;
21
+ std::int32_t query_end=1 << 30;
22
22
  public:
23
23
  BCF(std::string path, std::string index_path="");
24
24
  Variant nextvar();
25
- void set_region(std::string chrom, std::uint32_t start=0, std::uint32_t end=1 << 31);
25
+ void set_region(std::string chrom, std::int32_t start=0, std::int32_t end=1 << 30);
26
26
  Header header;
27
27
  };
28
28
 
@@ -30,8 +30,8 @@
30
30
  #include <iostream>
31
31
  #include <string.h> // for memcpy
32
32
  #include <stdexcept>
33
- #include <fcntl.h>
34
- #include <unistd.h>
33
+
34
+ #include <iostream>
35
35
 
36
36
  #ifdef GZSTREAM_NAMESPACE
37
37
  namespace GZSTREAM_NAMESPACE {
@@ -54,6 +54,11 @@ void get_fmode( char* fmode, int open_mode) {
54
54
  }
55
55
 
56
56
  gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
57
+ filename = std::string(name);
58
+ // const size_t n = strlen(name); // excludes null terminator
59
+ // filename = new char[n + 1]{}; // {} zero initializes array
60
+ // std::copy_n(name, n, filename);
61
+
57
62
  if ( is_open())
58
63
  return (gzstreambuf*)0;
59
64
  mode = open_mode;
@@ -61,10 +66,13 @@ gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
61
66
  if ((mode & std::ios::ate) || (mode & std::ios::app)
62
67
  || ((mode & std::ios::in) && (mode & std::ios::out)))
63
68
  return (gzstreambuf*)0;
64
- char fmode[10];
65
69
  get_fmode(fmode, mode);
66
- fd = ::open(name, open_mode);
67
- file = gzdopen( fd, fmode);
70
+ handle = fopen(filename.c_str(), fmode);
71
+ if (!handle) {
72
+ return 0;
73
+ }
74
+
75
+ file = gzdopen(fileno(handle), fmode);
68
76
  if (file == 0)
69
77
  return (gzstreambuf*)0;
70
78
  opened = 1;
@@ -81,6 +89,8 @@ gzstreambuf * gzstreambuf::close() {
81
89
  return (gzstreambuf*)0;
82
90
  }
83
91
 
92
+ /// @brief seek the bgzip file to a new offset
93
+ /// @param offset file offset of new bgzip block to seek to
84
94
  void gzstreambuf::seek(bcf::Offsets offset) {
85
95
  // reset the input buffer
86
96
  setp( buffer, buffer + (bufferSize-1));
@@ -88,20 +98,18 @@ void gzstreambuf::seek(bcf::Offsets offset) {
88
98
  buffer + 4, // read position
89
99
  buffer + 4); // end position
90
100
 
91
- // We must close the previous gzFile, otherwise we leak memory on each seek.
92
- // But when we close the gzFile, this also closes the file descriptor, so we
93
- // duplicate the file descriptor first.
94
- int new_fd = dup(fd);
95
-
96
- // seek using the file descriptor to an offset in the compressed file
97
- ::lseek(new_fd, offset.c_offset, SEEK_SET);
98
-
99
- // open a new gzfile object using the file descriptor (at new offset)
100
- char fmode[10];
101
- get_fmode(fmode, mode);
102
- file = gzdopen(new_fd, fmode);
103
- fd = new_fd;
101
+ // close old gzfile object and associated file handle
102
+ fclose(handle);
103
+ gzclose(file);
104
+
105
+ // open new file handle, and seek to an offset in the compressed file
106
+ handle = fopen(filename.c_str(), fmode);
107
+ fseek(handle, offset.c_offset, SEEK_SET);
108
+ ftell(handle);
104
109
 
110
+ // open new gzfile object using the file descriptor (at new offset);
111
+ file = gzdopen(fileno(handle), fmode);
112
+
105
113
  if (file == 0) {
106
114
  throw std::invalid_argument("cannot seek within this gzfile");
107
115
  }
@@ -33,6 +33,7 @@
33
33
  #include <iostream>
34
34
  #include <string>
35
35
  #include <fstream>
36
+ #include <cstdio>
36
37
  #include "zlib.h"
37
38
 
38
39
  #include "index.h"
@@ -54,7 +55,9 @@ private:
54
55
  char buffer[bufferSize]; // data buffer
55
56
  char opened; // open/close state of stream
56
57
  int mode; // I/O mode
57
- int fd=-1;
58
+ char fmode[10];
59
+ FILE * handle;
60
+ std::string filename;
58
61
  public:
59
62
  gzstreambuf() : opened(0) {
60
63
  setp( buffer, buffer + (bufferSize-1));
@@ -117,6 +117,8 @@ Header::Header(std::string & text) {
117
117
 
118
118
  }
119
119
 
120
+ /// @brief get contigs/chromosomes defined in BCF header
121
+ /// @return vector of chromosome/contig names
120
122
  std::vector<std::string> Header::get_contigs() {
121
123
  std::vector<std::uint32_t> keys;
122
124
  keys.reserve(contigs.size());
@@ -133,6 +135,8 @@ std::vector<std::string> Header::get_contigs() {
133
135
  return vals;
134
136
  }
135
137
 
138
+ /// @brief get info fields used in the BCF header
139
+ /// @return vector of info keys (as strings) used in the BCF
136
140
  std::vector<std::string> Header::get_info() {
137
141
  std::vector<std::uint32_t> keys;
138
142
  keys.reserve(info.size());
@@ -149,6 +153,8 @@ std::vector<std::string> Header::get_info() {
149
153
  return vals;
150
154
  }
151
155
 
156
+ /// @brief get filters used in the BCF
157
+ /// @return vector of unqiue filter values used in the BCF
152
158
  std::vector<std::string> Header::get_filters() {
153
159
  std::vector<std::uint32_t> keys;
154
160
  keys.reserve(filters.size());
@@ -165,6 +171,8 @@ std::vector<std::string> Header::get_filters() {
165
171
  return vals;
166
172
  }
167
173
 
174
+ /// @brief get format fields used in the BCF header
175
+ /// @return vector of format keys (as strings) used in the BCF
168
176
  std::vector<std::string> Header::get_formats() {
169
177
  std::vector<std::uint32_t> keys;
170
178
  keys.reserve(format.size());
@@ -1,6 +1,7 @@
1
1
  #ifndef BCF_HEADER_H
2
2
  #define BCF_HEADER_H
3
3
 
4
+ #include <cstdint>
4
5
  #include <string>
5
6
  #include <vector>
6
7
  #include <unordered_set>
@@ -10,7 +10,12 @@
10
10
 
11
11
  namespace bcf {
12
12
 
13
-
13
+ /// @brief parse the uncompressed and compressed parts of a virtual offset
14
+ /// @param v_offset virtual offset (contains compressed offset in highest 48 bits,
15
+ /// and uncompressed offset in lowest 16 bits). The uncompressed
16
+ /// offset can be 65536 at max (2^16), since that is the max size
17
+ /// of an uncompressed bgzip block
18
+ /// @return struct containing u_offset and c_offset fields
14
19
  Offsets parse_virtual_offset(std::uint64_t v_offset) {
15
20
  std::uint64_t u_offset = v_offset & 0x000000000000ffff;
16
21
  std::uint64_t c_offset = v_offset >> 16;
@@ -42,7 +47,7 @@ IndexFile::IndexFile(std::string path) {
42
47
  std::uint64_t v_offset;
43
48
  std::int32_t n_chunks;
44
49
  Offsets bin_offsets, chunk_begin, chunk_end;
45
- for (std::uint32_t i=0; i< n_ref; i++) {
50
+ for (std::int32_t i=0; i < n_ref; i++) {
46
51
  std::unordered_map<std::uint32_t, Bin> bins;
47
52
  infile.read(reinterpret_cast<char *>(&n_bins), sizeof(n_bins));
48
53
 
@@ -53,7 +58,7 @@ IndexFile::IndexFile(std::string path) {
53
58
 
54
59
  bin_offsets = parse_virtual_offset(v_offset);
55
60
  std::vector<Chunk> chunks;
56
- for (std::uint32_t k=0; k<n_chunks; k++) {
61
+ for (std::int32_t k=0; k<n_chunks; k++) {
57
62
  infile.read(reinterpret_cast<char *>(&v_offset), sizeof(v_offset));
58
63
  chunk_begin = parse_virtual_offset(v_offset);
59
64
  infile.read(reinterpret_cast<char *>(&v_offset), sizeof(v_offset));
@@ -67,17 +72,6 @@ IndexFile::IndexFile(std::string path) {
67
72
  has_index = true;
68
73
  }
69
74
 
70
- /// calculate bin given an alignment covering [beg,end) (zero-based, half-close-half-open)
71
- int IndexFile::reg2bin(std::int64_t beg, std::int64_t end) {
72
- int l, s = min_shift, t = ((1 << depth * 3) - 1) / 7;
73
- for (--end, l = depth; l > 0; --l, s += 3, t -= 1 << l * 3) {
74
- if (beg >> s == end >> s) {
75
- return t + (beg >> s);
76
- }
77
- }
78
- return 0;
79
- }
80
-
81
75
  /// @brief calculate the list of bins that may overlap with region [beg,end) (zero-based).
82
76
  ///
83
77
  /// This code is from https://samtools.github.io/hts-specs/CSIv1.pdf, but adapted
@@ -86,9 +80,7 @@ int IndexFile::reg2bin(std::int64_t beg, std::int64_t end) {
86
80
  /// @param beg start position of region
87
81
  /// @param end end position of region
88
82
  /// @return currently integer, but this should be an iterator instead
89
- std::vector<std::uint32_t> IndexFile::reg2bins(std::int64_t beg, std::int64_t end) {
90
- int max_bins = bin_limit();
91
-
83
+ std::vector<std::uint32_t> IndexFile::region_to_bins(std::int64_t beg, std::int64_t end) {
92
84
  std::vector<std::uint32_t> bins;
93
85
  int l, t, n, s = min_shift + depth * 3;
94
86
  for (--end, l = n = t = 0; l <= depth; s -= 3, t += 1 << l * 3, ++l) {
@@ -102,11 +94,6 @@ std::vector<std::uint32_t> IndexFile::reg2bins(std::int64_t beg, std::int64_t en
102
94
  return bins;
103
95
  }
104
96
 
105
- /* calculate maximum bin number -- valid bin numbers range within [0,bin_limit) */
106
- int IndexFile::bin_limit() {
107
- return ((1 << (depth + 1) * 3) - 1) / 7;
108
- }
109
-
110
97
  /// @brief find the depth for a bin
111
98
  ///
112
99
  /// We need to know the depth of a bin in order to figure out how wide the bin
@@ -171,8 +158,8 @@ Offsets IndexFile::query(std::uint32_t contig_id, std::int64_t beg, std::int64_t
171
158
  }
172
159
 
173
160
  // find the bins which could overlap a position
174
- auto bins = reg2bins(beg, end);
175
-
161
+ auto bins = region_to_bins(beg, end);
162
+
176
163
  // cull bins which do not exist in the indexfile, and find the bin with the
177
164
  // closest start to the position, preferrably immediately upstream of the begin
178
165
  // position, but allow using the first downstream, if upstream bins do not exist
@@ -217,12 +204,3 @@ Offsets IndexFile::query(std::uint32_t contig_id, std::int64_t beg, std::int64_t
217
204
  }
218
205
 
219
206
  }
220
-
221
- // int main() {
222
- // bcf::IndexFile indexfile = bcf::IndexFile("/users/jmcrae/apps/pybcf/chr5.110000001-115000000.bcf.csi");
223
- // std::cout << "bin: " << indexfile.reg2bin(111000000, 112000000) << std::endl;
224
- // indexfile.query(4, 111000000);
225
- // return 0;
226
- // }
227
-
228
- // g++ -stdlib=libc++ -std=c++11 -lz index.cpp gzstream.cpp; ./a.out
@@ -35,9 +35,7 @@ class IndexFile {
35
35
  public:
36
36
  IndexFile(std::string path);
37
37
  IndexFile() {};
38
- int reg2bin(std::int64_t beg, std::int64_t end);
39
- std::vector<std::uint32_t> reg2bins(std::int64_t beg, std::int64_t end);
40
- int bin_limit();
38
+ std::vector<std::uint32_t> region_to_bins(std::int64_t beg, std::int64_t end);
41
39
  std::uint32_t get_bin_depth(std::uint32_t bin_idx);
42
40
  std::uint32_t get_bin_offset(std::uint32_t bin_idx);
43
41
  Offsets query(std::uint32_t contig_id, std::int64_t beg, std::int64_t end);
@@ -1,19 +1,13 @@
1
1
 
2
2
  #include <iostream>
3
3
  #include <bitset>
4
+ #include <vector>
4
5
 
5
6
  #include "info.h"
6
7
  #include "types.h"
7
8
 
8
9
  namespace bcf {
9
10
 
10
- Info::Info(char * _buf, Header * _header, std::uint32_t _offset, std::uint32_t _n_info) {
11
- buf = _buf;
12
- header = _header;
13
- offset = _offset;
14
- n_info = _n_info;
15
- }
16
-
17
11
  std::vector<std::string> Info::get_keys() {
18
12
  if (!is_parsed) {
19
13
  parse();
@@ -26,8 +20,9 @@ std::vector<std::string> Info::get_keys() {
26
20
  return key_vals;
27
21
  }
28
22
 
23
+ /// @brief parse the info data for keys and values
29
24
  void Info::parse() {
30
- std::uint32_t buf_idx = offset;
25
+ std::uint32_t buf_idx = 0;
31
26
  Typed type_val;
32
27
 
33
28
  // read the info fields. TODO - find out a way to skip this if not required
@@ -45,8 +40,9 @@ void Info::parse() {
45
40
  for (std::uint32_t i = 0; i < n_info; i++) {
46
41
  type_val = {buf, buf_idx};
47
42
  id_idx = parse_int(&buf[0], buf_idx, type_val.type_size);
48
- key = header->info[id_idx].id;
49
- number = header->info[id_idx].number;
43
+ InfoField & field = header->info[id_idx];
44
+ key = field.id;
45
+ number = field.number;
50
46
  has_multiple = number == "A" || number == "R" || number == "G";
51
47
  if ((number.find_first_not_of("0123456789") == std::string::npos)) {
52
48
  has_multiple |= std::stol(number) > 1;
@@ -22,7 +22,6 @@ class Info {
22
22
 
23
23
  Header * header;
24
24
  bool is_parsed=false;
25
- std::uint32_t offset=0;
26
25
  std::uint32_t n_info=0;
27
26
  char * buf;
28
27
 
@@ -37,7 +36,12 @@ class Info {
37
36
  std::vector<std::vector<float>> vector_floats; // type 3
38
37
  std::vector<std::vector<std::int32_t>> vector_ints; // type 4
39
38
  public:
40
- Info(char * _buf, Header * _header, std::uint32_t _offset, std::uint32_t _n_info);
39
+ /// @brief start Info object for a variant. Doesn't parse data until required
40
+ /// @param _buf data to parse for info fields and values. The pointer points to
41
+ /// the data of the info data
42
+ /// @param _header pointer to bcf header data, so we can interpret info fields
43
+ /// @param _n_info number of info fields
44
+ Info(char * buf, Header * header, std::uint32_t n_info) : header(header), n_info(n_info), buf(buf) {};
41
45
  Info() {};
42
46
  std::vector<std::string> get_keys();
43
47
  InfoType get_type(std::string &key);