Class: HTS::Hts
- Inherits:
-
Object
- Object
- HTS::Hts
- Defined in:
- lib/hts/hts.rb
Overview
A base class for hts files.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #fai=(fai) ⇒ Object
- #file_format ⇒ Object
- #file_format_version ⇒ Object
-
#initialize(*_args) ⇒ Hts
constructor
A new instance of Hts.
- #rewind ⇒ Object
- #seek(offset) ⇒ Object
- #set_threads(n = nil) ⇒ Object
- #struct ⇒ Object
- #tell ⇒ Object
- #to_ptr ⇒ Object
Constructor Details
#initialize(*_args) ⇒ Hts
Returns a new instance of Hts.
34 35 36 |
# File 'lib/hts/hts.rb', line 34 def initialize(*_args) raise TypeError, "Can't make instance of HTS abstract class" end |
Instance Method Details
#close ⇒ Object
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
68 69 70 |
# File 'lib/hts/hts.rb', line 68 def closed? @hts_file.nil? || @hts_file.null? end |
#fai=(fai) ⇒ Object
72 73 74 75 |
# File 'lib/hts/hts.rb', line 72 def fai=(fai) check_closed LibHTS.hts_set_fai_filename(@hts_file, fai) > 0 || raise end |
#file_format ⇒ Object
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_version ⇒ Object
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 |
#rewind ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/hts/hts.rb', line 114 def rewind raise "Cannot rewind: no start position" unless @start_position r = seek(@start_position) raise "Failed to rewind: #{r}" if r < 0 tell end |
#seek(offset) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/hts/hts.rb', line 92 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 = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hts/hts.rb', line 77 def set_threads(n = nil) if n.nil? require "etc" n = [Etc.nprocessors - 1, 1].max end raise TypeError unless n.is_a?(Integer) raise ArgumentError, "Number of threads must be positive" if n < 1 r = LibHTS.hts_set_threads(@hts_file, n) raise "Failed to set number of threads: #{threads}" if r < 0 @nthreads = n self end |
#struct ⇒ Object
38 39 40 |
# File 'lib/hts/hts.rb', line 38 def struct @hts_file end |
#tell ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hts/hts.rb', line 102 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_ptr ⇒ Object
42 43 44 |
# File 'lib/hts/hts.rb', line 42 def to_ptr @hts_file.to_ptr end |