Class: HTS::Tabix
- Inherits:
-
Hts
show all
- Includes:
- Enumerable
- Defined in:
- lib/hts/tabix.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Hts
#fai=, #file_format, #file_format_version, #rewind, #seek, #set_threads, #struct, #tell, #to_ptr
Constructor Details
#initialize(file_name, index: nil, threads: nil, build_index: false) ⇒ Tabix
Returns a new instance of Tabix.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/hts/tabix.rb', line 25
def initialize(file_name, index: nil, threads: nil, build_index: false)
if block_given?
message = "HTS::Tabix.new() does not take block; Please use HTS::Tabix.open() instead"
raise message
end
@file_name = file_name
@index_name = index
@mode = "r"
@nthreads = threads
@hts_file = LibHTS.hts_open(@file_name, @mode)
raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
set_threads(threads) if threads
@idx = load_index(index)
end
|
Instance Attribute Details
#file_name ⇒ Object
Returns the value of attribute file_name.
11
12
13
|
# File 'lib/hts/tabix.rb', line 11
def file_name
@file_name
end
|
#index_name ⇒ Object
Returns the value of attribute index_name.
11
12
13
|
# File 'lib/hts/tabix.rb', line 11
def index_name
@index_name
end
|
#mode ⇒ Object
Returns the value of attribute mode.
11
12
13
|
# File 'lib/hts/tabix.rb', line 11
def mode
@mode
end
|
#nthreads ⇒ Object
Returns the value of attribute nthreads.
11
12
13
|
# File 'lib/hts/tabix.rb', line 11
def nthreads
@nthreads
end
|
Class Method Details
.open(*args, **kw) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/hts/tabix.rb', line 13
def self.open(*args, **kw)
file = new(*args, **kw) return file unless block_given?
begin
yield file
ensure
file.close
end
file
end
|
Instance Method Details
#build_index(index_name = nil, min_shift: 0) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/hts/tabix.rb', line 47
def build_index(index_name = nil, min_shift: 0)
check_closed
if index_name
warn "Create index for #{@file_name} to #{index_name}"
case LibHTS.tbx_index_build2(@file_name, index_name, min_shift, LibHTS.tbx_conf_vcf)
when 0 when -1 then raise "general failure"
when -2 then raise "compression not BGZF"
else raise "unknown error"
end
else
warn "Create index for #{@file_name}"
case LibHTS.tbx_index_build(@file_name, min_shift, LibHTS.tbx_conf_vcf)
when 0 when -1 then raise "general failure"
when -2 then raise "compression not BGZF"
else raise "unknown error"
end
end
self end
|
#close ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/hts/tabix.rb', line 108
def close
return if closed?
@idx = nil
super
end
|
#closed? ⇒ Boolean
118
119
120
|
# File 'lib/hts/tabix.rb', line 118
def closed?
@hts_file.nil? || @hts_file.null?
end
|
#index_loaded? ⇒ Boolean
79
80
81
82
|
# File 'lib/hts/tabix.rb', line 79
def index_loaded?
check_closed
!@idx.null?
end
|
#load_index(index_name = nil) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/hts/tabix.rb', line 70
def load_index(index_name = nil)
check_closed
if index_name
LibHTS.tbx_index_load2(@file_name, index_name)
else
LibHTS.tbx_index_load3(@file_name, nil, 2)
end
end
|
#name2id(name) ⇒ Object
84
85
86
87
|
# File 'lib/hts/tabix.rb', line 84
def name2id(name)
check_closed
LibHTS.tbx_name2id(@idx, name)
end
|
#query(region, start = nil, end_ = nil, &block) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/hts/tabix.rb', line 97
def query(region, start = nil, end_ = nil, &block)
check_closed
raise "Index file is required to call the query method." unless index_loaded?
if start && end_
queryi(name2id(region), start, end_, &block)
else
querys(region, &block)
end
end
|
#seqnames ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/hts/tabix.rb', line 89
def seqnames
check_closed
nseq = FFI::MemoryPointer.new(:int)
LibHTS.tbx_seqnames(@idx, nseq).then do |pts|
pts.read_array_of_pointer(nseq.read_int).map(&:read_string)
end
end
|