Class: HTS::Hts

Inherits:
Object
  • Object
show all
Defined in:
lib/hts/hts.rb

Overview

A base class for hts files.

Direct Known Subclasses

Bam, Bcf, Tbx

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Hts

Returns a new instance of Hts.



34
35
36
# File 'lib/hts/hts.rb', line 34

def initialize(*args)
  # do nothing
end

Instance Method Details

#closeObject



61
62
63
64
65
66
# File 'lib/hts/hts.rb', line 61

def close
  return if closed?

  LibHTS.hts_close(@hts_file)
  @hts_file = nil
end

#closed?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/hts/hts.rb', line 68

def closed?
  @hts_file.nil? || @hts_file.null?
end

#file_formatObject



46
47
48
# File 'lib/hts/hts.rb', line 46

def file_format
  LibHTS.hts_get_format(@hts_file)[:format].to_s
end

#file_format_versionObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/hts/hts.rb', line 50

def file_format_version
  v = LibHTS.hts_get_format(@hts_file)[:version]
  major = v[:major]
  minor = v[:minor]
  if minor == -1
    major.to_s
  else
    "#{major}.#{minor}"
  end
end

#rewindObject



104
105
106
107
108
109
110
111
112
113
# File 'lib/hts/hts.rb', line 104

def rewind
  if @start_position
    r = seek(@start_position)
    raise "Failed to rewind: #{r}" if r < 0

    tell
  else
    raise "Cannot rewind: no start position"
  end
end

#seek(offset) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/hts/hts.rb', line 82

def seek(offset)
  if @hts_file[:is_cram] == 1
    LibHTS.cram_seek(@hts_file[:fp][:cram], offset, IO::SEEK_SET)
  elsif @hts_file[:is_bgzf] == 1
    LibHTS.bgzf_seek(@hts_file[:fp][:bgzf], offset, IO::SEEK_SET)
  else
    LibHTS.hseek(@hts_file[:fp][:hfile], offset, IO::SEEK_SET)
  end
end

#set_threads(n) ⇒ Object

Raises:

  • (TypeError)


72
73
74
75
76
77
78
79
80
# File 'lib/hts/hts.rb', line 72

def set_threads(n)
  raise TypeError unless n.is_a(Integer)

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

#structObject



38
39
40
# File 'lib/hts/hts.rb', line 38

def struct
  @hts_file
end

#tellObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/hts/hts.rb', line 92

def tell
  if @hts_file[:is_cram] == 1
    # LibHTS.cram_tell(@hts_file[:fp][:cram])
    # warn 'cram_tell is not implemented in c htslib'
    nil
  elsif @hts_file[:is_bgzf] == 1
    LibHTS.bgzf_tell(@hts_file[:fp][:bgzf])
  else
    LibHTS.htell(@hts_file[:fp][:hfile])
  end
end

#to_ptrObject



42
43
44
# File 'lib/hts/hts.rb', line 42

def to_ptr
  @hts_file.to_ptr
end