Class: HTS::Bam::Aux

Inherits:
Object
  • Object
show all
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.



20
21
22
# File 'lib/hts/bam/auxi.rb', line 20

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



18
19
20
# File 'lib/hts/bam/auxi.rb', line 18

def record
  @record
end

Instance Method Details

#[](key) ⇒ Object



67
68
69
# File 'lib/hts/bam/auxi.rb', line 67

def [](key)
  get(key)
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`.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/hts/bam/auxi.rb', line 28

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

  type = type ? type.to_s : 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

#get_float(key) ⇒ Object

For compatibility with HTS.cr.



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

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

#get_int(key) ⇒ Object

For compatibility with HTS.cr.



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

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

#get_string(key) ⇒ Object

For compatibility with HTS.cr.



63
64
65
# File 'lib/hts/bam/auxi.rb', line 63

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