Class: HTS::Tbx

Inherits:
Hts
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hts/tbx.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hts

#close, #closed?, #format, #format_version, #rewind, #seek, #struct, #tell, #to_ptr

Constructor Details

#initialize(file_name, threads: nil) ⇒ Tbx

Returns a new instance of Tbx.

Raises:

  • (Errno::ENOENT)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hts/tbx.rb', line 25

def initialize(file_name, threads: nil)
  if block_given?
    message = "HTS::Tbx.new() dose not take block; Please use HTS::Tbx.open() instead"
    raise message
  end

  @file_name = file_name

  # NOTE: Do not check for the existence of local files, since file_names may be remote URIs.

  @mode     = "r"
  @hts_file = LibHTS.hts_open(@file_name, @mode)

  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?

  if threads&.> 0
    r = LibHTS.hts_set_threads(@hts_file, threads)
    raise "Failed to set number of threads: #{threads}" if r < 0
  end
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



11
12
13
# File 'lib/hts/tbx.rb', line 11

def file_name
  @file_name
end

Class Method Details

.open(*args, **kw) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hts/tbx.rb', line 13

def self.open(*args, **kw)
  file = new(*args, **kw) # do not yield
  return file unless block_given?

  begin
    yield file
  ensure
    file.close
  end
  file
end