Class: HTS::Bam::Cigar
- Inherits:
-
Object
- Object
- HTS::Bam::Cigar
- Includes:
- Enumerable
- Defined in:
- lib/hts/bam/cigar.rb
Overview
CIGAR string
Instance Attribute Summary collapse
-
#array ⇒ Object
a uint32_t array (with 32 bits for every CIGAR op: length<<4|operation).
Class Method Summary collapse
-
.parse(str) ⇒ Object
Create a new Cigar object from a string.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(record = nil) ⇒ Cigar
constructor
A new instance of Cigar.
- #qlen ⇒ Object
- #rlen ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(record = nil) ⇒ Cigar
Returns a new instance of Cigar.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hts/bam/cigar.rb', line 25 def initialize(record = nil) if record # The record is used at initialization and is not retained after that. bam1 = record.struct n_cigar = bam1[:core][:n_cigar] @array = LibHTS.bam_get_cigar(bam1).read_array_of_uint32(n_cigar) else @array = [] end end |
Instance Attribute Details
#array ⇒ Object
a uint32_t array (with 32 bits for every CIGAR op: length<<4|operation)
10 11 12 |
# File 'lib/hts/bam/cigar.rb', line 10 def array @array end |
Class Method Details
.parse(str) ⇒ Object
Create a new Cigar object from a string. The CIGAR string is converted to a uint32_t array in htslib.
15 16 17 18 19 20 21 22 23 |
# File 'lib/hts/bam/cigar.rb', line 15 def self.parse(str) c = FFI::MemoryPointer.new(:pointer) m = FFI::MemoryPointer.new(:size_t) LibHTS.sam_parse_cigar(str, FFI::Pointer::NULL, c, m) cigar_array = c.read_pointer.read_array_of_uint32(m.read(:size_t)) obj = new obj.array = cigar_array obj end |
Instance Method Details
#==(other) ⇒ Object
62 63 64 |
# File 'lib/hts/bam/cigar.rb', line 62 def ==(other) other.is_a?(Cigar) && (@array == other.array) end |
#each ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/hts/bam/cigar.rb', line 40 def each return to_enum(__method__) unless block_given? @array.each do |c| op = LibHTS.bam_cigar_opchr(c) len = LibHTS.bam_cigar_oplen(c) yield [op, len] end end |
#eql?(other) ⇒ Boolean
66 67 68 |
# File 'lib/hts/bam/cigar.rb', line 66 def eql?(other) other.is_a?(Cigar) && @array.eql?(other.array) end |
#qlen ⇒ Object
50 51 52 53 54 |
# File 'lib/hts/bam/cigar.rb', line 50 def qlen a = FFI::MemoryPointer.new(:uint32, @array.size) a.write_array_of_uint32(@array) LibHTS.bam_cigar2qlen(@array.size, a) end |
#rlen ⇒ Object
56 57 58 59 60 |
# File 'lib/hts/bam/cigar.rb', line 56 def rlen a = FFI::MemoryPointer.new(:uint32, @array.size) a.write_array_of_uint32(@array) LibHTS.bam_cigar2rlen(@array.size, a) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/hts/bam/cigar.rb', line 36 def to_s map { |op, len| "#{len}#{op}" }.join end |