htslib 0.2.6 → 0.2.9

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.
@@ -570,5 +570,18 @@ module HTS
570
570
  :external, 4,
571
571
  :core, 5
572
572
  )
573
+
574
+ CramBlockMethod = enum(
575
+ :unknown, -1,
576
+ :raw, 0,
577
+ :gzip, 1,
578
+ :bzip2, 2,
579
+ :lzma, 3,
580
+ :rans4x8, 4,
581
+ :ransnx16, 5,
582
+ :arith, 6,
583
+ :fqz, 7,
584
+ :tok3, 8
585
+ )
573
586
  end
574
587
  end
@@ -79,12 +79,27 @@ module HTS
79
79
  %i[cram_container int32 pointer],
80
80
  :void
81
81
 
82
+ attach_function \
83
+ :cram_container_get_num_records,
84
+ [:cram_container],
85
+ :int32
86
+
87
+ attach_function \
88
+ :cram_container_get_num_bases,
89
+ [:cram_container],
90
+ :int32
91
+
92
+ # Returns true if the container is empty (EOF marker)
82
93
  attach_function \
83
94
  :cram_container_is_empty,
84
95
  [:cram_fd],
85
96
  :int
86
97
 
87
- # cram_block
98
+ # Returns chromosome and start/span from container struct
99
+ attach_function \
100
+ :cram_container_get_coords,
101
+ %i[cram_container pointer pointer],
102
+ :void
88
103
 
89
104
  attach_function \
90
105
  :cram_block_get_content_id,
@@ -116,6 +131,16 @@ module HTS
116
131
  [:cram_block],
117
132
  CramContentType
118
133
 
134
+ attach_function \
135
+ :cram_block_get_method,
136
+ [:cram_block],
137
+ CramBlockMethod
138
+
139
+ attach_function \
140
+ :cram_expand_method,
141
+ [:pointer, :int32, CramBlockMethod],
142
+ :pointer
143
+
119
144
  attach_function \
120
145
  :cram_block_set_content_id,
121
146
  %i[cram_block int32],
@@ -167,6 +192,18 @@ module HTS
167
192
  [:cram_block],
168
193
  :uint32
169
194
 
195
+ # Returns the Block Content ID values referred to by a cram_codec in ids[2].
196
+ attach_function \
197
+ :cram_codec_get_content_ids,
198
+ %i[pointer pointer],
199
+ :void
200
+
201
+ # Produces a human readable description of the codec parameters.
202
+ attach_function \
203
+ :cram_codec_describe,
204
+ [:pointer, KString.ptr],
205
+ :int
206
+
170
207
  # Renumbers RG numbers in a cram compression header.
171
208
  attach_function \
172
209
  :cram_transcode_rg,
@@ -180,6 +217,51 @@ module HTS
180
217
  %i[cram_fd cram_fd int32],
181
218
  :int
182
219
 
220
+ # Copies a container, but filtering it down to a specific region (as
221
+ # already specified in 'in'
222
+ attach_function \
223
+ :cram_filter_container,
224
+ %i[cram_fd cram_fd cram_container pointer],
225
+ :int
226
+
227
+ # Decodes a CRAM block compression header.
228
+ attach_function \
229
+ :cram_decode_compression_header,
230
+ %i[cram_fd cram_block],
231
+ :pointer # cram_block_compression_hdr
232
+
233
+ # Frees a cram_block_compression_hdr structure.
234
+ attach_function \
235
+ :cram_free_compression_header,
236
+ [:pointer],
237
+ :void
238
+
239
+ # Map cram block numbers to data-series.
240
+ attach_function \
241
+ :cram_update_cid2ds_map,
242
+ %i[pointer pointer],
243
+ :pointer
244
+
245
+ # Return a list of data series observed as belonging to a block with
246
+ # the specified content_id.
247
+ attach_function \
248
+ :cram_cid2ds_query,
249
+ %i[pointer int pointer],
250
+ :int
251
+
252
+ # Frees a cram_cid2ds_t allocated by cram_update_cid2ds_map
253
+ attach_function \
254
+ :cram_cid2ds_free,
255
+ [:pointer],
256
+ :void
257
+
258
+ # Produces a description of the record and tag encodings held within
259
+ # a compression header and appends to 'ks'.
260
+ attach_function \
261
+ :cram_describe_encodings,
262
+ [:pointer, KString.ptr],
263
+ :int
264
+
183
265
  # Returns the number of cram blocks within this slice.
184
266
  attach_function \
185
267
  :cram_slice_hdr_get_num_blocks,
@@ -360,5 +442,35 @@ module HTS
360
442
  :cram_get_refs,
361
443
  [HtsFile.by_ref],
362
444
  :pointer # refs_t
445
+
446
+ # Returns the file offsets of CRAM slices covering a specific region query.
447
+ attach_function \
448
+ :cram_index_extents,
449
+ %i[cram_fd int hts_pos_t hts_pos_t pointer pointer],
450
+ :int
451
+
452
+ # Returns the total number of containers in the CRAM index.
453
+ attach_function \
454
+ :cram_num_containers,
455
+ [:cram_fd],
456
+ :int64
457
+
458
+ # Returns the number of containers in the CRAM index within given offsets.
459
+ attach_function \
460
+ :cram_num_containers_between,
461
+ %i[cram_fd off_t off_t pointer pointer],
462
+ :int64
463
+
464
+ # Returns the byte offset for the start of the n^th container.
465
+ attach_function \
466
+ :cram_container_num2offset,
467
+ %i[cram_fd int64],
468
+ :off_t
469
+
470
+ # Returns the container number for the first container at offset >= pos.
471
+ attach_function \
472
+ :cram_container_offset2num,
473
+ %i[cram_fd off_t],
474
+ :int64
363
475
  end
364
476
  end
@@ -447,7 +447,7 @@ module HTS
447
447
  # Computes the final 128-bit MD5 hash from the given context
448
448
  attach_function \
449
449
  :hts_md5_final,
450
- %i[pointer pointer], # unsinged char
450
+ %i[pointer pointer], # unsigned char
451
451
  :void
452
452
 
453
453
  # Resets an md5_context to the initial state, as returned by hts_md5_init().
@@ -247,7 +247,7 @@ module HTS
247
247
  :hts_pos_t,
248
248
  :uint8,
249
249
  :size_t,
250
- :string,
250
+ :pointer,
251
251
  :int32,
252
252
  :hts_pos_t,
253
253
  :hts_pos_t,
@@ -440,10 +440,22 @@ module HTS
440
440
  [SamHdr, Bam1, :pointer], # hts_filter_t
441
441
  :int
442
442
 
443
+ # Return a pointer to a BAM record's first aux field
444
+ attach_function \
445
+ :bam_aux_first,
446
+ [Bam1],
447
+ :pointer
448
+
449
+ # Return a pointer to a BAM record's next aux field
450
+ attach_function \
451
+ :bam_aux_next,
452
+ [Bam1, :pointer],
453
+ :pointer
454
+
443
455
  # Return a pointer to an aux record
444
456
  attach_function \
445
457
  :bam_aux_get,
446
- [Bam1, :string], # FIXME
458
+ [Bam1, :string], # const char tag[2]
447
459
  :pointer
448
460
 
449
461
  # Get an integer aux value
@@ -500,6 +512,12 @@ module HTS
500
512
  [Bam1, :pointer],
501
513
  :int
502
514
 
515
+ # Delete an aux field from a BAM record. Identical to @c bam_aux_del() apart from the return value
516
+ attach_function \
517
+ :bam_aux_remove,
518
+ [Bam1, :pointer],
519
+ :pointer
520
+
503
521
  # Update or add a string-type tag
504
522
  attach_function \
505
523
  :bam_aux_update_str,
@@ -570,17 +588,17 @@ module HTS
570
588
  [:bam_plp],
571
589
  :void
572
590
 
573
- callback :bam_plp_callback_funcion, [:pointer, Bam1, BamPileupCd], :int
591
+ callback :bam_plp_callback_function, [:pointer, Bam1, BamPileupCd], :int
574
592
 
575
593
  # sets a callback to initialise any per-pileup1_t fields.
576
594
  attach_function \
577
595
  :bam_plp_constructor,
578
- %i[bam_plp bam_plp_callback_funcion],
596
+ %i[bam_plp bam_plp_callback_function],
579
597
  :void
580
598
 
581
599
  attach_function \
582
600
  :bam_plp_destructor,
583
- %i[bam_plp bam_plp_callback_funcion],
601
+ %i[bam_plp bam_plp_callback_function],
584
602
  :void
585
603
 
586
604
  # Get pileup padded insertion sequence
@@ -632,12 +650,12 @@ module HTS
632
650
 
633
651
  attach_function \
634
652
  :bam_mplp_constructor,
635
- %i[bam_mplp bam_plp_callback_funcion],
653
+ %i[bam_mplp bam_plp_callback_function],
636
654
  :void
637
655
 
638
656
  attach_function \
639
657
  :bam_mplp_destructor,
640
- %i[bam_mplp bam_plp_callback_funcion],
658
+ %i[bam_mplp bam_plp_callback_function],
641
659
  :void
642
660
 
643
661
  attach_function \
@@ -662,12 +680,18 @@ module HTS
662
680
  [:pointer], # hts_base_mod_state
663
681
  :void
664
682
 
665
- # Parses the Mm and Ml tags out of a bam record.
683
+ # Parses the MM and ML tags out of a bam record.
666
684
  attach_function \
667
685
  :bam_parse_basemod,
668
686
  [Bam1, :pointer],
669
687
  :int
670
688
 
689
+ # Parses the MM and ML tags out of a bam record.
690
+ attach_function \
691
+ :bam_parse_basemod2,
692
+ [Bam1, :pointer, :uint32],
693
+ :int
694
+
671
695
  # Returns modification status for the next base position in the query seq.
672
696
  attach_function \
673
697
  :bam_mods_at_next_pos,
@@ -692,6 +716,12 @@ module HTS
692
716
  %i[pointer int pointer pointer string],
693
717
  :int
694
718
 
719
+ # Returns data about the i^th modification type for the alignment record.
720
+ attach_function \
721
+ :bam_mods_queryi,
722
+ %i[pointer int pointer pointer string],
723
+ :int
724
+
695
725
  # Returns the list of base modification codes provided for this
696
726
  attach_function \
697
727
  :bam_mods_recorded,
@@ -2,6 +2,13 @@
2
2
 
3
3
  module HTS
4
4
  module LibHTS
5
+ attach_variable :tbx_conf_gff, TbxConf
6
+ attach_variable :tbx_conf_bed, TbxConf
7
+ attach_variable :tbx_conf_psltbl, TbxConf
8
+ attach_variable :tbx_conf_sam, TbxConf
9
+ attach_variable :tbx_conf_vcf, TbxConf
10
+ attach_variable :tbx_conf_gaf, TbxConf
11
+
5
12
  attach_function \
6
13
  :tbx_name2id,
7
14
  [Tbx, :string],
@@ -8,11 +8,16 @@ module HTS
8
8
  end
9
9
 
10
10
  def tbx_itr_queryi(tbx, tid, beg, end_)
11
- hts_itr_query(tbx[:idx], tid, beg, end_, @@tbx_readrec)
11
+ hts_itr_query(tbx[:idx], tid, beg, end_, @ffi_functions[:tbx_readrec])
12
+ end
13
+
14
+ @@tbx_name2id = proc do |tbx, ss|
15
+ LibHTS.tbx_name2id(tbx, ss)
12
16
  end
13
17
 
14
18
  def tbx_itr_querys(tbx, s)
15
- hts_itr_querys(tbx[:idx], s, @@tbx_name2id, tbx, @@hts_itr_query, @@tbx_readrec)
19
+ hts_itr_querys(tbx[:idx], s, @@tbx_name2id, tbx, @ffi_functions[:hts_itr_query],
20
+ @ffi_functions[:tbx_readrec])
16
21
  end
17
22
 
18
23
  def tbx_itr_next(htsfp, tbx, itr, r)
@@ -2,6 +2,12 @@
2
2
 
3
3
  module HTS
4
4
  module LibHTS
5
+ # Get error description for bcf error code
6
+ attach_function \
7
+ :bcf_strerror,
8
+ %i[int pointer size_t],
9
+ :string
10
+
5
11
  # Create an empty BCF header.
6
12
  attach_function \
7
13
  :bcf_hdr_init,
@@ -272,7 +272,7 @@ module HTS
272
272
  alias bcf_itr_destroy hts_itr_destroy
273
273
 
274
274
  def bcf_itr_queryi(idx, tid, beg, _end)
275
- hts_itr_query(idx, tid, beg, _end, @@bcf_readrec)
275
+ hts_itr_query(idx, tid, beg, _end, @ffi_functions[:bcf_readrec])
276
276
  end
277
277
 
278
278
  @@bcf_hdr_name2id = proc do |hdr, id|
@@ -280,7 +280,7 @@ module HTS
280
280
  end
281
281
 
282
282
  def bcf_itr_querys(idx, hdr, s)
283
- hts_itr_querys(idx, s, @@bcf_hdr_name2id, hdr, @@hts_itr_query, @@bcf_readrec)
283
+ hts_itr_querys(idx, s, @@bcf_hdr_name2id, hdr, @ffi_functions[:hts_itr_query], @ffi_functions[:bcf_readrec])
284
284
  end
285
285
 
286
286
  # Load a BCF index
data/lib/hts/libhts.rb CHANGED
@@ -37,5 +37,5 @@ require_relative "libhts/sam"
37
37
  require_relative "libhts/cram"
38
38
  require_relative "libhts/vcf"
39
39
  require_relative "libhts/tbx"
40
- require_relative "libhts/faidx"
40
+ require_relative "libhts/fai"
41
41
  require_relative "libhts/thread_pool"
@@ -5,7 +5,7 @@ require_relative "../htslib"
5
5
  require_relative "hts"
6
6
 
7
7
  module HTS
8
- class Tbx < Hts
8
+ class Tabix < Hts
9
9
  include Enumerable
10
10
 
11
11
  attr_reader :file_name, :index_name, :mode, :nthreads
@@ -22,9 +22,9 @@ module HTS
22
22
  file
23
23
  end
24
24
 
25
- def initialize(file_name, mode = "r", index: nil, threads: nil, build_index: false)
25
+ def initialize(file_name, index: nil, threads: nil, build_index: false)
26
26
  if block_given?
27
- message = "HTS::Tbx.new() dose not take block; Please use HTS::Tbx.open() instead"
27
+ message = "HTS::Tabix.new() dose not take block; Please use HTS::Tabix.open() instead"
28
28
  raise message
29
29
  end
30
30
 
@@ -32,17 +32,14 @@ module HTS
32
32
 
33
33
  @file_name = file_name
34
34
  @index_name = index
35
- @mode = mode
35
+ @mode = "r"
36
36
  @nthreads = threads
37
- @hts_file = LibHTS.hts_open(@file_name, @mode)
37
+ @hts_file = LibHTS.hts_open(@file_name, @mode)
38
38
 
39
39
  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
40
40
 
41
41
  set_threads(threads) if threads
42
42
 
43
- # return if @mode[0] == "w"
44
- raise "Not implemented" if @mode[0] == "w"
45
-
46
43
  # build_index(index) if build_index
47
44
  @idx = load_index(index)
48
45
  end
@@ -63,7 +60,7 @@ module HTS
63
60
  !@idx.null?
64
61
  end
65
62
 
66
- def tid(name)
63
+ def name2id(name)
67
64
  LibHTS.tbx_name2id(@idx, name)
68
65
  end
69
66
 
@@ -79,7 +76,7 @@ module HTS
79
76
  raise "Index file is required to call the query method." unless index_loaded?
80
77
 
81
78
  if start && end_
82
- queryi(tid(region), start, end_, &block)
79
+ queryi(name2id(region), start, end_, &block)
83
80
  else
84
81
  querys(region, &block)
85
82
  end
@@ -87,36 +84,33 @@ module HTS
87
84
 
88
85
  private
89
86
 
90
- def queryi(id, start, end_)
87
+ def queryi(id, start, end_, &block)
91
88
  return to_enum(__method__, id, start, end_) unless block_given?
92
89
 
93
90
  qiter = LibHTS.tbx_itr_queryi(@idx, id, start, end_)
94
-
95
91
  raise "Failed to query region: #{id}:#{start}-#{end_}" if qiter.null?
96
92
 
97
- r = LibHTS::KString.new
98
- begin
99
- yield r[:s] while LibHTS.tbx_itr_next(@hts_file, @idx, qiter, r) > 0
100
- ensure
101
- LibHTS.hts_itr_destroy(qiter)
102
- end
93
+ query_yield(qiter, &block)
103
94
  self
104
95
  end
105
96
 
106
- def querys(region)
97
+ def querys(region, &block)
107
98
  return to_enum(__method__, region) unless block_given?
108
99
 
109
100
  qiter = LibHTS.tbx_itr_querys(@idx, region)
110
-
111
101
  raise "Failed to query region: #{region}" if qiter.null?
112
102
 
103
+ query_yield(qiter, &block)
104
+ self
105
+ end
106
+
107
+ def query_yield(qiter)
113
108
  r = LibHTS::KString.new
114
109
  begin
115
110
  yield r[:s].split("\t") while LibHTS.tbx_itr_next(@hts_file, @idx, qiter, r) > 0
116
111
  ensure
117
112
  LibHTS.hts_itr_destroy(qiter)
118
113
  end
119
- self
120
114
  end
121
115
  end
122
116
  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.6"
4
+ VERSION = "0.2.9"
5
5
  end
data/lib/htslib.rb CHANGED
@@ -55,6 +55,6 @@ module HTS
55
55
  autoload :Hts, "hts/hts"
56
56
  autoload :Bam, "hts/bam"
57
57
  autoload :Bcf, "hts/bcf"
58
- autoload :Tbx, "hts/tbx"
59
58
  autoload :Faidx, "hts/faidx"
59
+ autoload :Tabix, "hts/tabix"
60
60
  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.6
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -52,77 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: irb
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: simplecov
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- description:
55
+ description:
126
56
  email:
127
57
  - 2xijok@gmail.com
128
58
  executables: []
@@ -155,7 +85,7 @@ files:
155
85
  - lib/hts/libhts/bgzf.rb
156
86
  - lib/hts/libhts/constants.rb
157
87
  - lib/hts/libhts/cram.rb
158
- - lib/hts/libhts/faidx.rb
88
+ - lib/hts/libhts/fai.rb
159
89
  - lib/hts/libhts/hfile.rb
160
90
  - lib/hts/libhts/hts.rb
161
91
  - lib/hts/libhts/kfunc.rb
@@ -166,7 +96,7 @@ files:
166
96
  - lib/hts/libhts/thread_pool.rb
167
97
  - lib/hts/libhts/vcf.rb
168
98
  - lib/hts/libhts/vcf_funcs.rb
169
- - lib/hts/tbx.rb
99
+ - lib/hts/tabix.rb
170
100
  - lib/hts/version.rb
171
101
  - lib/htslib.rb
172
102
  homepage: https://github.com/kojix2/ruby-htslib
@@ -174,7 +104,7 @@ licenses:
174
104
  - MIT
175
105
  metadata:
176
106
  msys2_mingw_dependencies: htslib
177
- post_install_message:
107
+ post_install_message:
178
108
  rdoc_options: []
179
109
  require_paths:
180
110
  - lib
@@ -189,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
119
  - !ruby/object:Gem::Version
190
120
  version: '0'
191
121
  requirements: []
192
- rubygems_version: 3.4.1
193
- signing_key:
122
+ rubygems_version: 3.5.11
123
+ signing_key:
194
124
  specification_version: 4
195
125
  summary: HTSlib bindings for Ruby
196
126
  test_files: []
File without changes