Class: HTS::Bam::Cigar

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

Overview

CIGAR string

Instance Method Summary collapse

Constructor Details

#initialize(pointer, n_cigar) ⇒ Cigar

Returns a new instance of Cigar.



9
10
11
12
13
14
# File 'lib/hts/bam/cigar.rb', line 9

def initialize(pointer, n_cigar)
  @n_cigar = n_cigar
  # Read the pointer before the memory is changed.
  # Especially when called from a block of `each` iterator.
  @c = pointer.read_array_of_uint32(n_cigar)
end

Instance Method Details

#eachObject



20
21
22
23
24
25
26
27
28
# File 'lib/hts/bam/cigar.rb', line 20

def each
  return to_enum(__method__) unless block_given?

  @c.each do |c|
    op =  LibHTS.bam_cigar_opchr(c)
    len = LibHTS.bam_cigar_oplen(c)
    yield [op, len]
  end
end

#to_sObject



16
17
18
# File 'lib/hts/bam/cigar.rb', line 16

def to_s
  map { |op, len| "#{len}#{op}" }.join
end