Class: HTS::Bam::Cigar

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

Constant Summary collapse

OP_CHARS =
"MIDNSHP=XB"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil) ⇒ Cigar

Returns a new instance of Cigar.



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

def initialize(record = nil)
  @array = record ? record.__send__(:native_handle).cigar_values : []
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



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

def array
  @array
end

Class Method Details

.parse(str) ⇒ Object



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

def self.parse(str)
  new.tap { |cigar| cigar.array = Native.cigar_parse(str.to_s) }
end

Instance Method Details

#==(other) ⇒ Object



29
# File 'lib/hts/bam/cigar.rb', line 29

def ==(other) = other.is_a?(Cigar) && @array == other.array

#eachObject



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

def each
  return to_enum(__method__) unless block_given?

  @array.each { |encoded| yield OP_CHARS[encoded & 15], encoded >> 4 }
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
# File 'lib/hts/bam/cigar.rb', line 30

def eql?(other) = other.is_a?(Cigar) && @array.eql?(other.array)

#qlenObject



27
# File 'lib/hts/bam/cigar.rb', line 27

def qlen = Native.cigar_qlen(@array)

#rlenObject



28
# File 'lib/hts/bam/cigar.rb', line 28

def rlen = Native.cigar_rlen(@array)

#to_sObject



19
# File 'lib/hts/bam/cigar.rb', line 19

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