htslib 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d26f2d2af0e353b349235ec153e4127288ecd602362254dafd91e015f61dc0a2
4
- data.tar.gz: 567d03329907f3f53424511f74a4c9fd6f745ef7c2b0c6c14e8dff6da957dbdb
3
+ metadata.gz: 93ee916dafed0ba04e486a59c81d2bd9befbceda3d679ef820e32d8817597afe
4
+ data.tar.gz: 7dda13879d0c3707354ab69fe9967f60f0300c1971011218a5cf79e5e211ee25
5
5
  SHA512:
6
- metadata.gz: 4c51ee0ed3c259da9e5e7353ae92bcbc7faad622453c8875ff749e8bb0a861c6c28fa09df7dac79ca37d15a0e6f83afb200d4065028e7da63910eab8f9c6e7a4
7
- data.tar.gz: c62b5c7e95ba91a9f465b6822170c0faa05cf9626af8c63c486ecb55edb1af7f3d841cfa8b2d5adcd9cd1ac6df75088b85ea3145ae78a645eb2b7e3390ca11bd
6
+ metadata.gz: 8cf68e9276f353bdea4389f5584066870a4887f07891387cf143408cf215c43232f2c390c08b80c57225a8d8b3722a9dcc5ba5cc3cc716079cf004bd34df0da0
7
+ data.tar.gz: f30abf9c0d0dd07201e150dea5ec6976e7d968bc2f6bf2c347c1dec18cdfaaa5c141793208587f1629fa3cefeaaadd268083a105ab42dd450ce2ac8cfa0e2d7e
data/lib/hts/bam.rb CHANGED
@@ -13,7 +13,7 @@ module HTS
13
13
  class Bam
14
14
  include Enumerable
15
15
 
16
- attr_reader :file_name, :index_name, :mode, :header
16
+ attr_reader :file_name, :index_name, :mode, :header, :nthreads
17
17
 
18
18
  def self.open(*args, **kw)
19
19
  file = new(*args, **kw) # do not yield
@@ -28,7 +28,7 @@ module HTS
28
28
  end
29
29
 
30
30
  def initialize(file_name, mode = "r", index: nil, fai: nil, threads: nil,
31
- create_index: false)
31
+ build_index: false)
32
32
  if block_given?
33
33
  message = "HTS::Bam.new() dose not take block; Please use HTS::Bam.open() instead"
34
34
  raise message
@@ -39,6 +39,7 @@ module HTS
39
39
  @file_name = file_name
40
40
  @index_name = index
41
41
  @mode = mode
42
+ @nthreads = threads
42
43
  @hts_file = LibHTS.hts_open(@file_name, mode)
43
44
 
44
45
  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
@@ -53,21 +54,24 @@ module HTS
53
54
  return if @mode[0] == "w"
54
55
 
55
56
  @header = Bam::Header.new(@hts_file)
56
- create_index(index) if create_index
57
+ build_index(index) if build_index
57
58
  @idx = load_index(index)
58
59
  @start_position = tell
59
60
  super # do nothing
60
61
  end
61
62
 
62
- def create_index(index_name = nil)
63
+ def build_index(index_name = nil, min_shift: 0)
63
64
  check_closed
64
65
 
65
- warn "Create index for #{@file_name} to #{index_name}"
66
- if index
67
- LibHTS.sam_index_build2(@file_name, index_name, -1)
66
+ if index_name
67
+ warn "Create index for #{@file_name} to #{index_name}"
68
68
  else
69
- LibHTS.sam_index_build(@file_name, -1)
69
+ warn "Create index for #{@file_name}"
70
70
  end
71
+ r = LibHTS.sam_index_build3(@file_name, index_name, min_shift, @nthreads)
72
+ raise "Failed to build index for #{@file_name}" if r < 0
73
+
74
+ self
71
75
  end
72
76
 
73
77
  def load_index(index_name = nil)
@@ -137,7 +137,7 @@ module HTS
137
137
 
138
138
  private
139
139
 
140
- def initialize_copy(orig)\
140
+ def initialize_copy(orig)
141
141
  @header = orig.header
142
142
  @bcf1 = LibHTS.bcf_dup(orig.struct)
143
143
  end
data/lib/hts/bcf.rb CHANGED
@@ -13,7 +13,7 @@ module HTS
13
13
  class Bcf < Hts
14
14
  include Enumerable
15
15
 
16
- attr_reader :file_name, :index_name, :mode, :header
16
+ attr_reader :file_name, :index_name, :mode, :header, :nthreads
17
17
 
18
18
  def self.open(*args, **kw)
19
19
  file = new(*args, **kw) # do not yield
@@ -28,7 +28,7 @@ module HTS
28
28
  end
29
29
 
30
30
  def initialize(file_name, mode = "r", index: nil, threads: nil,
31
- create_index: false)
31
+ build_index: false)
32
32
  if block_given?
33
33
  message = "HTS::Bcf.new() dose not take block; Please use HTS::Bcf.open() instead"
34
34
  raise message
@@ -39,6 +39,7 @@ module HTS
39
39
  @file_name = file_name
40
40
  @index_name = index
41
41
  @mode = mode
42
+ @nthreads = threads
42
43
  @hts_file = LibHTS.hts_open(@file_name, mode)
43
44
 
44
45
  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
@@ -48,21 +49,24 @@ module HTS
48
49
  return if @mode[0] == "w"
49
50
 
50
51
  @header = Bcf::Header.new(@hts_file)
51
- create_index(index) if create_index
52
+ build_index(index) if build_index
52
53
  @idx = load_index(index)
53
54
  @start_position = tell
54
55
  super # do nothing
55
56
  end
56
57
 
57
- def create_index(index_name = nil)
58
+ def build_index(index_name = nil, min_shift: 14)
58
59
  check_closed
59
60
 
60
- warn "Create index for #{@file_name} to #{index_name}"
61
61
  if index_name
62
- LibHTS.bcf_index_build2(@file_name, index_name, -1)
62
+ warn "Create index for #{@file_name} to #{index_name}"
63
63
  else
64
- LibHTS.bcf_index_build(@file_name, -1)
64
+ warn "Create index for #{@file_name}"
65
65
  end
66
+ r = LibHTS.bcf_index_build3(@file_name, index_name, min_shift, @nthreads)
67
+ raise "Failed to build index for #{@file_name}" if r < 0
68
+
69
+ self
66
70
  end
67
71
 
68
72
  def load_index(index_name = nil)
data/lib/hts/hts.rb CHANGED
@@ -69,13 +69,18 @@ module HTS
69
69
  @hts_file.nil? || @hts_file.null?
70
70
  end
71
71
 
72
- def set_threads(n)
73
- raise TypeError unless n.is_a(Integer)
74
-
75
- if n > 0
76
- r = LibHTS.hts_set_threads(@hts_file, n)
77
- raise "Failed to set number of threads: #{threads}" if r < 0
72
+ def set_threads(n = nil)
73
+ if n.nil?
74
+ require "etc"
75
+ n = [Etc.nprocessors - 1, 1].max
78
76
  end
77
+ raise TypeError unless n.is_a?(Integer)
78
+ raise ArgumentError, "Number of threads must be positive" if n < 1
79
+
80
+ r = LibHTS.hts_set_threads(@hts_file, n)
81
+ raise "Failed to set number of threads: #{threads}" if r < 0
82
+
83
+ @nthreads = n
79
84
  self
80
85
  end
81
86
 
@@ -172,6 +172,31 @@ module HTS
172
172
  %i[cram_fd cram_fd int32],
173
173
  :int
174
174
 
175
+ attach_function \
176
+ :cram_slice_hdr_get_num_blocks,
177
+ [:pointer],
178
+ :int32
179
+
180
+ attach_function \
181
+ :cram_slice_hdr_get_embed_ref_id,
182
+ [:pointer],
183
+ :int
184
+
185
+ attach_function \
186
+ :cram_slice_hdr_get_coords,
187
+ %i[pointer pointer pointer pointer],
188
+ :void
189
+
190
+ attach_function \
191
+ :cram_decode_slice_header,
192
+ %i[pointer pointer],
193
+ :pointer
194
+
195
+ attach_function \
196
+ :cram_free_slice_header,
197
+ [:pointer],
198
+ :void
199
+
175
200
  attach_function \
176
201
  :cram_new_block,
177
202
  [CramContentType, :int],
@@ -685,6 +685,18 @@ module HTS
685
685
  :bam_mods_at_qpos,
686
686
  [Bam1, :int, :pointer, :pointer, :int],
687
687
  :int
688
+
689
+ # Returns data about a specific modification type for the alignment record.
690
+ attach_function \
691
+ :bam_mods_query_type,
692
+ %i[pointer int pointer pointer string],
693
+ :int
694
+
695
+ # Returns the list of base modification codes provided for this
696
+ attach_function \
697
+ :bam_mods_recorded,
698
+ %i[pointer pointer],
699
+ :int
688
700
  end
689
701
  end
690
702
 
@@ -34,11 +34,11 @@ module HTS
34
34
  end
35
35
 
36
36
  def bam_cigar_gen(l, o)
37
- l << BAM_CIGAR_SHIFT | o
37
+ (l << BAM_CIGAR_SHIFT) | o
38
38
  end
39
39
 
40
40
  def bam_cigar_type(o)
41
- BAM_CIGAR_TYPE >> (o << 1) & 3
41
+ (BAM_CIGAR_TYPE >> (o << 1)) & 3
42
42
  end
43
43
  end
44
44
 
@@ -91,7 +91,7 @@ module HTS
91
91
  end
92
92
 
93
93
  def bam_seqi(s, i)
94
- s[i >> 1].read_uint8 >> ((~i & 1) << 2) & 0xf
94
+ (s[i >> 1].read_uint8 >> ((~i & 1) << 2)) & 0xf
95
95
  end
96
96
 
97
97
  def bam_set_seqi(s, i, b)
@@ -59,7 +59,7 @@ module HTS
59
59
 
60
60
  attach_function \
61
61
  :tbx_seqnames,
62
- [Tbx, :int],
62
+ [Tbx, :pointer],
63
63
  :pointer
64
64
 
65
65
  attach_function \
@@ -0,0 +1,25 @@
1
+ module HTS
2
+ module LibHTS
3
+ class << self
4
+ def tbx_itr_destroy(iter)
5
+ hts_itr_destroy(iter)
6
+ end
7
+
8
+ def tbx_itr_queryi(tbx, tid, beg, end_)
9
+ hts_itr_query(tbx[:idx], tid, beg, end_, tbx_readrec)
10
+ end
11
+
12
+ def tbx_itr_querys(tbx, s)
13
+ hts_itr_querys(tbx[:idx], s, @@tbx_name2id, tbx, @@hts_itr_query, @@tbx_readrec)
14
+ end
15
+
16
+ def tbx_itr_next(htsfp, tbx, itr, r)
17
+ hts_itr_next(hts_get_bgzfp(htsfp), itr, r, tbx)
18
+ end
19
+
20
+ def tbx_bgzf_itr_next(bgzfp, tbx, itr, r)
21
+ hts_itr_next(bgzfp, itr, r, tbx)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -154,10 +154,12 @@ module HTS
154
154
  [BcfHdr, :int, KString],
155
155
  :int
156
156
 
157
- attach_function \
158
- :bcf_hdr_fmt_text,
159
- [BcfHdr, :int, :pointer],
160
- :string
157
+ # DEPRECATED
158
+ #
159
+ # attach_function \
160
+ # :bcf_hdr_fmt_text,
161
+ # [BcfHdr, :int, :pointer],
162
+ # :string
161
163
 
162
164
  attach_function \
163
165
  :bcf_hdr_append,
@@ -274,6 +276,21 @@ module HTS
274
276
  [Bcf1, :int],
275
277
  :int
276
278
 
279
+ attach_function \
280
+ :bcf_has_variant_types,
281
+ [Bcf1, :uint32, :int],
282
+ :int
283
+
284
+ attach_function \
285
+ :bcf_has_variant_type,
286
+ [Bcf1, :int, :uint32],
287
+ :int
288
+
289
+ attach_function \
290
+ :bcf_variant_length,
291
+ [Bcf1, :int],
292
+ :int
293
+
277
294
  attach_function \
278
295
  :bcf_is_snp,
279
296
  [Bcf1],
@@ -433,6 +450,16 @@ module HTS
433
450
  :bcf_idx_save,
434
451
  [HtsFile],
435
452
  :int
453
+
454
+ attach_function \
455
+ :bcf_float_vector_end,
456
+ [],
457
+ :uint32
458
+
459
+ attach_function \
460
+ :bcf_float_missing,
461
+ [],
462
+ :uint32
436
463
  end
437
464
  end
438
465
 
@@ -259,6 +259,25 @@ module HTS
259
259
  def bcf_index_seqnames(idx, hdr, nptr)
260
260
  hts_idx_seqnames(idx, nptr, @@bcf_hdr_id2name, hdr)
261
261
  end
262
+
263
+ # Typed value I/O
264
+ def bcf_int8_vector_end = -127 # INT8_MIN + 1
265
+ def bcf_int16_vector_end = -32_767 # INT16_MIN + 1
266
+ def bcf_int32_vector_end = -2_147_483_647 # INT32_MIN + 1
267
+ def bcf_int64_vector_end = -9_223_372_036_854_775_807 # INT64_MIN + 1
268
+ def bcf_str_vector_end = 0
269
+ def bcf_int8_missing = -128 # INT8_MIN
270
+ def bcf_int16_missing = (-32_767 - 1) # INT16_MIN
271
+ def bcf_int32_missing = (-2_147_483_647 - 1) # INT32_MIN
272
+ def bcf_int64_missing = (-9_223_372_036_854_775_807 - 1) # INT64_MIN
273
+ def bcf_str_missing = 0x07
274
+
275
+ BCF_MAX_BT_INT8 = 0x7f # INT8_MAX */
276
+ BCF_MAX_BT_INT16 = 0x7fff # INT16_MAX */
277
+ BCF_MAX_BT_INT32 = 0x7fffffff # INT32_MAX */
278
+ BCF_MIN_BT_INT8 = -120 # INT8_MIN + 8 */
279
+ BCF_MIN_BT_INT16 = -32_760 # INT16_MIN + 8 */
280
+ BCF_MIN_BT_INT32 = -2_147_483_640 # INT32_MIN + 8 */
262
281
  end
263
282
  end
264
283
  end
data/lib/hts/tbx.rb CHANGED
@@ -8,7 +8,7 @@ module HTS
8
8
  class Tbx < Hts
9
9
  include Enumerable
10
10
 
11
- attr_reader :file_name
11
+ attr_reader :file_name, :index_name, :mode, :nthreads
12
12
 
13
13
  def self.open(*args, **kw)
14
14
  file = new(*args, **kw) # do not yield
@@ -22,24 +22,56 @@ module HTS
22
22
  file
23
23
  end
24
24
 
25
- def initialize(file_name, threads: nil)
25
+ def initialize(file_name, mode = "r", index: nil, threads: nil, build_index: false)
26
26
  if block_given?
27
27
  message = "HTS::Tbx.new() dose not take block; Please use HTS::Tbx.open() instead"
28
28
  raise message
29
29
  end
30
30
 
31
- @file_name = file_name
32
-
33
31
  # NOTE: Do not check for the existence of local files, since file_names may be remote URIs.
34
32
 
35
- @mode = "r"
33
+ @file_name = file_name
34
+ @index_name = index
35
+ @mode = mode
36
+ @nthreads = threads
36
37
  @hts_file = LibHTS.hts_open(@file_name, @mode)
37
38
 
38
39
  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
39
40
 
40
41
  set_threads(threads) if threads
41
42
 
43
+ # return if @mode[0] == "w"
44
+ raise "Not implemented" if @mode[0] == "w"
45
+
46
+ # build_index(index) if build_index
47
+ @idx = load_index(index)
48
+
42
49
  super # do nothing
43
50
  end
51
+
52
+ def build_index
53
+ raise "Not implemented yet"
54
+ end
55
+
56
+ def load_index(index_name = nil)
57
+ if index_name
58
+ LibHTS.tbx_index_load2(@file_name, index_name)
59
+ else
60
+ LibHTS.tbx_index_load3(@file_name, nil, 2)
61
+ end
62
+ end
63
+
64
+ def tid(name)
65
+ LibHTS.tbx_name2id(@idx, name)
66
+ end
67
+
68
+ def seqnames
69
+ nseq = FFI::MemoryPointer.new(:int)
70
+ LibHTS.tbx_seqnames(@idx, nseq).then do |pts|
71
+ pts.read_array_of_pointer(nseq.read_int).map do |pt|
72
+ pt.read_string
73
+ end
74
+ end
75
+ end
44
76
  end
45
77
  end
data/lib/hts/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htslib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - 2xijok@gmail.com
128
128
  executables: []
@@ -159,18 +159,18 @@ files:
159
159
  - lib/hts/libhts/sam.rb
160
160
  - lib/hts/libhts/sam_funcs.rb
161
161
  - lib/hts/libhts/tbx.rb
162
+ - lib/hts/libhts/tbx_funcs.rb
162
163
  - lib/hts/libhts/thread_pool.rb
163
164
  - lib/hts/libhts/vcf.rb
164
165
  - lib/hts/libhts/vcf_funcs.rb
165
166
  - lib/hts/tbx.rb
166
167
  - lib/hts/version.rb
167
168
  - lib/htslib.rb
168
- - vendor/libhts.dylib
169
169
  homepage: https://github.com/kojix2/ruby-htslib
170
170
  licenses:
171
171
  - MIT
172
172
  metadata: {}
173
- post_install_message:
173
+ post_install_message:
174
174
  rdoc_options: []
175
175
  require_paths:
176
176
  - lib
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubygems_version: 3.3.7
189
- signing_key:
189
+ signing_key:
190
190
  specification_version: 4
191
191
  summary: HTSlib bindings for Ruby
192
192
  test_files: []
data/vendor/libhts.dylib DELETED
Binary file