Class: HTS::Bam::Aux

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

Overview

Auxiliary record data

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Aux

Returns a new instance of Aux.



7
8
9
# File 'lib/hts/bam/aux.rb', line 7

def initialize(record)
  @record = record
end

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/hts/bam/aux.rb', line 35

def [](key)
  get(key)
end

#get(key, type = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hts/bam/aux.rb', line 11

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

  type ||= aux.read_string(1)

  # A (character), B (general array),
  # f (real number), H (hexadecimal array),
  # i (integer), or Z (string).

  case type
  when "i", "I", "c", "C", "s", "S"
    LibHTS.bam_aux2i(aux)
  when "f", "d"
    LibHTS.bam_aux2f(aux)
  when "Z", "H"
    LibHTS.bam_aux2Z(aux)
  when "A" # char
    LibHTS.bam_aux2A(aux).chr
  else
    raise NotImplementedError, "type: #{t}"
  end
end