Class: HTS::Bam::Pileup
- Inherits:
-
Object
- Object
- HTS::Bam::Pileup
- Includes:
- Enumerable
- Defined in:
- lib/hts/bam/pileup.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(bam) ⇒ Pileup
constructor
A new instance of Pileup.
Constructor Details
#initialize(bam) ⇒ Pileup
Returns a new instance of Pileup.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/hts/bam/pileup.rb', line 6 def initialize(bam) @bam = bam # typedef int (*bam_plp_auto_f)(void *data, bam1_t *b); f = FFI::Function.new(:int, %i[pointer pointer], blocking: true) do |_data, _b| 0 end pt = FFI::MemoryPointer.new(:pointer) @iterator = LibHTS.bam_plp_init(f, pt) raise "Failed to initialize pileup" if @iterator.null? end |
Instance Method Details
#each(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hts/bam/pileup.rb', line 17 def each(&block) return enum_for(:each) unless block_given? @bam.each do |record| raise "Failed to push BAM record" if LibHTS.bam_plp_push(@iterator, record.struct) < 0 while (entries = fetch_next_pileup) entries.each(&block) end end # Signal the end of the BAM stream by pushing a NULL record LibHTS.bam_plp_push(@iterator, nil) end |