htslib 0.2.5 → 0.2.8

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.
@@ -158,7 +158,7 @@ module HTS
158
158
  :specific, :pointer
159
159
  end
160
160
 
161
- class HtsIdx < FFI::Struct
161
+ class HtsIdx < FFI::Struct # FIXME: ManagedStruct
162
162
  layout \
163
163
  :fmt, :int,
164
164
  :min_shift, :int,
@@ -205,7 +205,7 @@ module HTS
205
205
  end
206
206
 
207
207
  # HtsFile
208
- class SamHdr < FFI::Struct
208
+ class SamHdr < FFI::ManagedStruct
209
209
  layout \
210
210
  :n_targets, :int32,
211
211
  :ignore_sam_err, :int32,
@@ -255,7 +255,7 @@ module HTS
255
255
 
256
256
  SamFile = HtsFile
257
257
 
258
- class HtsTpool < FFI::Struct
258
+ class HtsTpool < FFI::ManagedStruct
259
259
  layout \
260
260
  :pool, :pointer,
261
261
  :qsize, :int
@@ -277,7 +277,7 @@ module HTS
277
277
  :next, HtsOpt.ptr
278
278
  end
279
279
 
280
- class HtsItr < FFI::BitStruct
280
+ class HtsItr < FFI::BitStruct # FIXME: ManagedBitStruct
281
281
  layout \
282
282
  :_flags, :uint32, # bit_fields
283
283
  :tid, :int,
@@ -358,14 +358,14 @@ module HTS
358
358
  class BamPileupCd < FFI::Union
359
359
  layout \
360
360
  :p, :pointer,
361
- :i, :int64_t,
361
+ :i, :int64,
362
362
  :f, :double
363
363
  end
364
364
 
365
365
  class BamPileup1 < FFI::BitStruct
366
366
  layout \
367
367
  :b, Bam1.ptr,
368
- :qpos, :int32_t,
368
+ :qpos, :int32,
369
369
  :indel, :int,
370
370
  :level, :int,
371
371
  :_flags, :uint32, # bit_fields
@@ -391,9 +391,9 @@ module HTS
391
391
  :line_skip, :int32
392
392
  end
393
393
 
394
- class Tbx < FFI::Struct
394
+ class Tbx < FFI::ManagedStruct
395
395
  layout \
396
- :conf, TbxConf.ptr,
396
+ :conf, TbxConf,
397
397
  :idx, HtsIdx.ptr,
398
398
  :dict, :pointer
399
399
 
@@ -406,8 +406,8 @@ module HTS
406
406
 
407
407
  FaiFormatOptions = enum(:FAI_NONE, :FAI_FASTA, :FAI_FASTQ)
408
408
 
409
- class Faidx < FFI::Struct
410
- layout :bgzf, BGZF,
409
+ class Faidx < FFI::Struct # FIXME: ManagedStruct
410
+ layout :bgzf, BGZF.ptr,
411
411
  :n, :int,
412
412
  :m, :int,
413
413
  :name, :pointer,
@@ -428,7 +428,7 @@ module HTS
428
428
  end
429
429
 
430
430
  # Complete textual representation of a header line
431
- class BcfHrec < FFI::Struct
431
+ class BcfHrec < FFI::ManagedStruct
432
432
  layout \
433
433
  :type, :int,
434
434
  :key, :string,
@@ -463,7 +463,7 @@ module HTS
463
463
 
464
464
  class BcfIdinfo < FFI::Struct
465
465
  layout \
466
- :info, [:uint64_t, 3],
466
+ :info, [:uint64, 3],
467
467
  :hrec, [BcfHrec.ptr, 3],
468
468
  :id, :int
469
469
  end
@@ -474,7 +474,7 @@ module HTS
474
474
  :val, BcfIdinfo.ptr
475
475
  end
476
476
 
477
- class BcfHdr < FFI::Struct
477
+ class BcfHdr < FFI::ManagedStruct
478
478
  layout \
479
479
  :n, [:int, 3],
480
480
  :id, [:pointer, 3], # BcfIdpair.ptr
@@ -536,7 +536,7 @@ module HTS
536
536
  layout \
537
537
  :pos, :hts_pos_t,
538
538
  :rlen, :hts_pos_t,
539
- :rid, :int32_t,
539
+ :rid, :int32,
540
540
  :qual, :float,
541
541
  :_n_info_allele, :uint32,
542
542
  :_n_fmt_sample, :uint32,
@@ -352,7 +352,7 @@ module HTS
352
352
  # As int32_decoded/encode, but from/to blocks instead of cram_fd
353
353
  attach_function \
354
354
  :int32_put_blk,
355
- %i[cram_block int32_t],
355
+ %i[cram_block int32],
356
356
  :int
357
357
 
358
358
  # Returns the refs_t structure used by a cram file handle.
@@ -242,13 +242,13 @@ module HTS
242
242
  [Bam1,
243
243
  :size_t,
244
244
  :string,
245
- :uint16_t,
246
- :int32_t,
245
+ :uint16,
246
+ :int32,
247
247
  :hts_pos_t,
248
- :uint8_t,
248
+ :uint8,
249
249
  :size_t,
250
250
  :string,
251
- :int32_t,
251
+ :int32,
252
252
  :hts_pos_t,
253
253
  :hts_pos_t,
254
254
  :size_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
@@ -570,17 +582,17 @@ module HTS
570
582
  [:bam_plp],
571
583
  :void
572
584
 
573
- callback :bam_plp_callback_funcion, [:pointer, Bam1, BamPileupCd], :int
585
+ callback :bam_plp_callback_function, [:pointer, Bam1, BamPileupCd], :int
574
586
 
575
587
  # sets a callback to initialise any per-pileup1_t fields.
576
588
  attach_function \
577
589
  :bam_plp_constructor,
578
- %i[bam_plp bam_plp_callback_funcion],
590
+ %i[bam_plp bam_plp_callback_function],
579
591
  :void
580
592
 
581
593
  attach_function \
582
594
  :bam_plp_destructor,
583
- %i[bam_plp bam_plp_callback_funcion],
595
+ %i[bam_plp bam_plp_callback_function],
584
596
  :void
585
597
 
586
598
  # Get pileup padded insertion sequence
@@ -632,12 +644,12 @@ module HTS
632
644
 
633
645
  attach_function \
634
646
  :bam_mplp_constructor,
635
- %i[bam_mplp bam_plp_callback_funcion],
647
+ %i[bam_mplp bam_plp_callback_function],
636
648
  :void
637
649
 
638
650
  attach_function \
639
651
  :bam_mplp_destructor,
640
- %i[bam_mplp bam_plp_callback_funcion],
652
+ %i[bam_mplp bam_plp_callback_function],
641
653
  :void
642
654
 
643
655
  attach_function \
@@ -68,3 +68,5 @@ module HTS
68
68
  :void
69
69
  end
70
70
  end
71
+
72
+ require_relative "tbx_funcs"
@@ -8,7 +8,7 @@ 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_, @@tbx_readrec)
12
12
  end
13
13
 
14
14
  def tbx_itr_querys(tbx, s)
@@ -469,7 +469,7 @@ module HTS
469
469
  attach_function \
470
470
  :bcf_fmt_sized_array,
471
471
  [KString, :pointer],
472
- :uint8_t
472
+ :uint8
473
473
 
474
474
  # Encode a variable-length char array in BCF format
475
475
  attach_function \
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"
data/lib/hts/tabix.rb ADDED
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../htslib"
4
+
5
+ require_relative "hts"
6
+
7
+ module HTS
8
+ class Tabix < Hts
9
+ include Enumerable
10
+
11
+ attr_reader :file_name, :index_name, :mode, :nthreads
12
+
13
+ def self.open(*args, **kw)
14
+ file = new(*args, **kw) # do not yield
15
+ return file unless block_given?
16
+
17
+ begin
18
+ yield file
19
+ ensure
20
+ file.close
21
+ end
22
+ file
23
+ end
24
+
25
+ def initialize(file_name, index: nil, threads: nil, build_index: false)
26
+ if block_given?
27
+ message = "HTS::Tabix.new() dose not take block; Please use HTS::Tabix.open() instead"
28
+ raise message
29
+ end
30
+
31
+ # NOTE: Do not check for the existence of local files, since file_names may be remote URIs.
32
+
33
+ @file_name = file_name
34
+ @index_name = index
35
+ @mode = "r"
36
+ @nthreads = threads
37
+ @hts_file = LibHTS.hts_open(@file_name, @mode)
38
+
39
+ raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
40
+
41
+ set_threads(threads) if threads
42
+
43
+ # build_index(index) if build_index
44
+ @idx = load_index(index)
45
+ end
46
+
47
+ def build_index
48
+ raise "Not implemented yet"
49
+ end
50
+
51
+ def load_index(index_name = nil)
52
+ if index_name
53
+ LibHTS.tbx_index_load2(@file_name, index_name)
54
+ else
55
+ LibHTS.tbx_index_load3(@file_name, nil, 2)
56
+ end
57
+ end
58
+
59
+ def index_loaded?
60
+ !@idx.null?
61
+ end
62
+
63
+ def name2id(name)
64
+ LibHTS.tbx_name2id(@idx, name)
65
+ end
66
+
67
+ def seqnames
68
+ nseq = FFI::MemoryPointer.new(:int)
69
+ LibHTS.tbx_seqnames(@idx, nseq).then do |pts|
70
+ pts.read_array_of_pointer(nseq.read_int).map(&:read_string)
71
+ end
72
+ end
73
+
74
+ def query(region, start = nil, end_ = nil, &block)
75
+ check_closed
76
+ raise "Index file is required to call the query method." unless index_loaded?
77
+
78
+ if start && end_
79
+ queryi(name2id(region), start, end_, &block)
80
+ else
81
+ querys(region, &block)
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def queryi(id, start, end_, &block)
88
+ return to_enum(__method__, id, start, end_) unless block_given?
89
+
90
+ qiter = LibHTS.tbx_itr_queryi(@idx, id, start, end_)
91
+ raise "Failed to query region: #{id}:#{start}-#{end_}" if qiter.null?
92
+
93
+ query_yield(qiter, &block)
94
+ self
95
+ end
96
+
97
+ def querys(region, &block)
98
+ return to_enum(__method__, region) unless block_given?
99
+
100
+ qiter = LibHTS.tbx_itr_querys(@idx, region)
101
+ raise "Failed to query region: #{region}" if qiter.null?
102
+
103
+ query_yield(qiter, &block)
104
+ self
105
+ end
106
+
107
+ def query_yield(qiter)
108
+ r = LibHTS::KString.new
109
+ begin
110
+ yield r[:s].split("\t") while LibHTS.tbx_itr_next(@hts_file, @idx, qiter, r) > 0
111
+ ensure
112
+ LibHTS.hts_itr_destroy(qiter)
113
+ end
114
+ end
115
+ end
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.5"
4
+ VERSION = "0.2.8"
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.5
4
+ version: 0.2.8
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-10-27 00:00:00.000000000 Z
11
+ date: 2023-05-17 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: []
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - LICENSE.txt
133
133
  - README.md
134
+ - TUTORIAL.md
134
135
  - lib/hts/bam.rb
135
136
  - lib/hts/bam/auxi.rb
136
137
  - lib/hts/bam/cigar.rb
@@ -145,6 +146,7 @@ files:
145
146
  - lib/hts/bcf/info.rb
146
147
  - lib/hts/bcf/record.rb
147
148
  - lib/hts/faidx.rb
149
+ - lib/hts/faidx/sequence.rb
148
150
  - lib/hts/ffi_ext/README.md
149
151
  - lib/hts/ffi_ext/pointer.rb
150
152
  - lib/hts/ffi_ext/struct.rb
@@ -153,7 +155,7 @@ files:
153
155
  - lib/hts/libhts/bgzf.rb
154
156
  - lib/hts/libhts/constants.rb
155
157
  - lib/hts/libhts/cram.rb
156
- - lib/hts/libhts/faidx.rb
158
+ - lib/hts/libhts/fai.rb
157
159
  - lib/hts/libhts/hfile.rb
158
160
  - lib/hts/libhts/hts.rb
159
161
  - lib/hts/libhts/kfunc.rb
@@ -164,7 +166,7 @@ files:
164
166
  - lib/hts/libhts/thread_pool.rb
165
167
  - lib/hts/libhts/vcf.rb
166
168
  - lib/hts/libhts/vcf_funcs.rb
167
- - lib/hts/tbx.rb
169
+ - lib/hts/tabix.rb
168
170
  - lib/hts/version.rb
169
171
  - lib/htslib.rb
170
172
  homepage: https://github.com/kojix2/ruby-htslib
@@ -172,7 +174,7 @@ licenses:
172
174
  - MIT
173
175
  metadata:
174
176
  msys2_mingw_dependencies: htslib
175
- post_install_message:
177
+ post_install_message:
176
178
  rdoc_options: []
177
179
  require_paths:
178
180
  - lib
@@ -187,8 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
189
  - !ruby/object:Gem::Version
188
190
  version: '0'
189
191
  requirements: []
190
- rubygems_version: 3.3.7
191
- signing_key:
192
+ rubygems_version: 3.4.10
193
+ signing_key:
192
194
  specification_version: 4
193
195
  summary: HTSlib bindings for Ruby
194
196
  test_files: []
data/lib/hts/tbx.rb DELETED
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../htslib"
4
-
5
- require_relative "hts"
6
-
7
- module HTS
8
- class Tbx < Hts
9
- include Enumerable
10
-
11
- attr_reader :file_name, :index_name, :mode, :nthreads
12
-
13
- def self.open(*args, **kw)
14
- file = new(*args, **kw) # do not yield
15
- return file unless block_given?
16
-
17
- begin
18
- yield file
19
- ensure
20
- file.close
21
- end
22
- file
23
- end
24
-
25
- def initialize(file_name, mode = "r", index: nil, threads: nil, build_index: false)
26
- if block_given?
27
- message = "HTS::Tbx.new() dose not take block; Please use HTS::Tbx.open() instead"
28
- raise message
29
- end
30
-
31
- # NOTE: Do not check for the existence of local files, since file_names may be remote URIs.
32
-
33
- @file_name = file_name
34
- @index_name = index
35
- @mode = mode
36
- @nthreads = threads
37
- @hts_file = LibHTS.hts_open(@file_name, @mode)
38
-
39
- raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
40
-
41
- set_threads(threads) if threads
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
- end
49
-
50
- def build_index
51
- raise "Not implemented yet"
52
- end
53
-
54
- def load_index(index_name = nil)
55
- if index_name
56
- LibHTS.tbx_index_load2(@file_name, index_name)
57
- else
58
- LibHTS.tbx_index_load3(@file_name, nil, 2)
59
- end
60
- end
61
-
62
- def tid(name)
63
- LibHTS.tbx_name2id(@idx, name)
64
- end
65
-
66
- def seqnames
67
- nseq = FFI::MemoryPointer.new(:int)
68
- LibHTS.tbx_seqnames(@idx, nseq).then do |pts|
69
- pts.read_array_of_pointer(nseq.read_int).map(&:read_string)
70
- end
71
- end
72
- end
73
- end
File without changes