Class: Bio::BGZF::Reader
- Inherits:
-
Object
- Object
- Bio::BGZF::Reader
- Includes:
- Bio::BGZF
- Defined in:
- lib/bio-bgzf/reader.rb
Constant Summary
Constants included from Bio::BGZF
CM, FLG, ID1, ID2, MAX_BYTES, MTIME, OS, SI1, SI2, SLEN, XFL, XLEN
Instance Attribute Summary collapse
-
#f ⇒ Object
readonly
Returns the value of attribute f.
Instance Method Summary collapse
-
#each_block ⇒ Object
Iterates over the blocks in a BGZF file, yielding [block, vo] pairs where.
-
#initialize(f) ⇒ Reader
constructor
A new instance of Reader.
-
#read_block ⇒ String
Reads the BGZF block at the current position.
-
#read_block_at(vo) ⇒ String
Reads a portion of a BGZF block, starting from the given virtual offset.
-
#tell ⇒ Integer
Returns the reader’s current virtual offset.
Methods included from Bio::BGZF
decompress_block, pack, read_bgzf_block, unpack, vo_block_offset, vo_data_offset
Constructor Details
#initialize(f) ⇒ Reader
Returns a new instance of Reader.
8 9 10 11 |
# File 'lib/bio-bgzf/reader.rb', line 8 def initialize(f) @f = f @cur_block = nil end |
Instance Attribute Details
#f ⇒ Object (readonly)
Returns the value of attribute f.
6 7 8 |
# File 'lib/bio-bgzf/reader.rb', line 6 def f @f end |
Instance Method Details
#each_block ⇒ Object
Iterates over the blocks in a BGZF file, yielding [block, vo] pairs where
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bio-bgzf/reader.rb', line 52 def each_block if block_given? while true pos = tell b = read_block break unless b yield b, pos end else enum_for(:each_block) end end |
#read_block ⇒ String
Reads the BGZF block at the current position. Returns its decompressed data.
27 28 29 |
# File 'lib/bio-bgzf/reader.rb', line 27 def read_block decompress_block(f) end |
#read_block_at(vo) ⇒ String
Reads a portion of a BGZF block, starting from the given virtual offset. If the offset is the start of a block (low 16 bits are zero) the entire block’s data will be returned. Otherwise, the subset of the data starting at the given offset will be returned.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bio-bgzf/reader.rb', line 39 def read_block_at(vo) block_offset = vo_block_offset(vo) data_offset = vo_data_offset(vo) f.seek(block_offset) block_data = decompress_block(f) if data_offset == 0 return block_data else return block_data.slice(data_offset...block_data.size) end end |
#tell ⇒ Integer
Returns the reader’s current virtual offset. Between #read_block calls, the file position will always be at the start of a block or at EOF, so the low 16 bits of the virtual offset will always be zero.
19 20 21 |
# File 'lib/bio-bgzf/reader.rb', line 19 def tell f.tell << 16 end |