Class: HTS::Bam::Aux

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hts/bam/auxi.rb

Overview

Auxiliary record data

The result of the alignment is assigned to the bam1 structure. Ruby’s Aux class references a part of it. There is no one-to-one correspondence between C structures and Ruby’s Aux class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Aux

Returns a new instance of Aux.



24
25
26
# File 'lib/hts/bam/auxi.rb', line 24

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



22
23
24
# File 'lib/hts/bam/auxi.rb', line 22

def record
  @record
end

Instance Method Details

#[](key) ⇒ Object



54
55
56
# File 'lib/hts/bam/auxi.rb', line 54

def [](key)
  get(key)
end

#eachObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hts/bam/auxi.rb', line 65

def each
  return enum_for(__method__) unless block_given?

  aux_ptr = first_pointer
  return nil if aux_ptr.null?

  loop do
    yield get_ruby_aux(aux_ptr)
    aux_ptr = LibHTS.bam_aux_next(@record.struct, aux_ptr)
    break if aux_ptr.null?
  end
end

#firstObject



58
59
60
61
62
63
# File 'lib/hts/bam/auxi.rb', line 58

def first
  aux_ptr = first_pointer
  return nil if aux_ptr.null?

  get_ruby_aux(aux_ptr)
end

#get(key, type = nil) ⇒ Object

Note:

Why is this method named “get” instead of “fetch”?

This is for compatibility with the Crystal language which provides methods like ‘get_int`, `get_float`, etc. I think they are better than `fetch_int“ and `fetch_float`.



32
33
34
35
36
37
# File 'lib/hts/bam/auxi.rb', line 32

def get(key, type = nil)
  aux_ptr = LibHTS.bam_aux_get(@record.struct, key)
  return nil if aux_ptr.null?

  get_ruby_aux(aux_ptr, type)
end

#get_float(key) ⇒ Object

For compatibility with HTS.cr.



45
46
47
# File 'lib/hts/bam/auxi.rb', line 45

def get_float(key)
  get(key, "f")
end

#get_int(key) ⇒ Object

For compatibility with HTS.cr.



40
41
42
# File 'lib/hts/bam/auxi.rb', line 40

def get_int(key)
  get(key, "i")
end

#get_string(key) ⇒ Object

For compatibility with HTS.cr.



50
51
52
# File 'lib/hts/bam/auxi.rb', line 50

def get_string(key)
  get(key, "Z")
end

#to_hObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/hts/bam/auxi.rb', line 78

def to_h
  h = {}
  aux_ptr = first_pointer
  return h if aux_ptr.null?

  loop do
    key = FFI::Pointer.new(aux_ptr.address - 2).read_string(2)
    h[key] = get_ruby_aux(aux_ptr)
    aux_ptr = LibHTS.bam_aux_next(@record.struct, aux_ptr)
    break if aux_ptr.null?
  end
  h
end