htslib 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hts/tbx.rb CHANGED
@@ -59,6 +59,10 @@ module HTS
59
59
  end
60
60
  end
61
61
 
62
+ def index_loaded?
63
+ !@idx.null?
64
+ end
65
+
62
66
  def tid(name)
63
67
  LibHTS.tbx_name2id(@idx, name)
64
68
  end
@@ -69,5 +73,50 @@ module HTS
69
73
  pts.read_array_of_pointer(nseq.read_int).map(&:read_string)
70
74
  end
71
75
  end
76
+
77
+ def query(region, start = nil, end_ = nil, &block)
78
+ check_closed
79
+ raise "Index file is required to call the query method." unless index_loaded?
80
+
81
+ if start && end_
82
+ queryi(tid(region), start, end_, &block)
83
+ else
84
+ querys(region, &block)
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def queryi(id, start, end_)
91
+ return to_enum(__method__, id, start, end_) unless block_given?
92
+
93
+ qiter = LibHTS.tbx_itr_queryi(@idx, id, start, end_)
94
+
95
+ raise "Failed to query region: #{id}:#{start}-#{end_}" if qiter.null?
96
+
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
103
+ self
104
+ end
105
+
106
+ def querys(region)
107
+ return to_enum(__method__, region) unless block_given?
108
+
109
+ qiter = LibHTS.tbx_itr_querys(@idx, region)
110
+
111
+ raise "Failed to query region: #{region}" if qiter.null?
112
+
113
+ r = LibHTS::KString.new
114
+ begin
115
+ yield r[:s].split("\t") while LibHTS.tbx_itr_next(@hts_file, @idx, qiter, r) > 0
116
+ ensure
117
+ LibHTS.hts_itr_destroy(qiter)
118
+ end
119
+ self
120
+ end
72
121
  end
73
122
  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.6"
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.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -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
@@ -187,7 +189,7 @@ 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
192
+ rubygems_version: 3.4.1
191
193
  signing_key:
192
194
  specification_version: 4
193
195
  summary: HTSlib bindings for Ruby