class Bio::MAF::ParseContext

A MAF parsing context, used for random-access parsing.

Attributes

at_end[RW]
chunk_start[RW]
cr[RW]
f[RW]
last_block_pos[RW]
opts[RW]
parser[RW]
s[RW]

Public Class Methods

new(fd, chunk_size, parser) click to toggle source
# File lib/bio/maf/parser.rb, line 434
def initialize(fd, chunk_size, parser)
  @f = fd
  @parser = parser
  @opts = parser.opts
  @cr = parser.base_reader.new(@f, chunk_size)
  @last_block_pos = -1
end

Public Instance Methods

append_chunks_to(len) click to toggle source
# File lib/bio/maf/parser.rb, line 503
def append_chunks_to(len)
  while s.string.size < len
    s.string << cr.read_chunk()
  end
end
fetch_blocks(offset, len, block_offsets) { |block| ... } click to toggle source

Fetch and parse blocks at given ‘offset` and `len` @param [Integer] offset Offset to start parsing at. @param [Integer] len Number of bytes to read. @param [Array] block_offsets Offsets of blocks to parse. @return [Array<Block>]

# File lib/bio/maf/parser.rb, line 463
def fetch_blocks(offset, len, block_offsets)
  if block_given?
    LOG.debug { "fetching blocks from #{offset} (length #{len}): #{block_offsets.inspect}" }
    start_chunk_read_if_needed(offset, len)
    # read chunks until we have the entire merged set of
    # blocks ready to parse
    # to avoid fragment joining
    append_chunks_to(len)
    # parse the blocks
    block_offsets.each do |expected_offset|
      # skip ahead, in case there is a gap resulting from a
      # block that is not being parsed
      rel_offset = expected_offset - offset
      if s.pos < rel_offset
        s.pos = rel_offset
      end
      # now actually parse the block data
      block = _parse_block
      parse_error("expected a block at offset #{expected_offset} but could not parse one!") unless block
      parse_error("got block with offset #{block.offset}, expected #{expected_offset}!") unless block.offset == expected_offset
      yield block
    end
  else
    enum_for(:fetch_blocks, offset, len, block_offsets)
  end
end
parse_empty() click to toggle source
# File lib/bio/maf/parser.rb, line 446
def parse_empty
  parser.parse_empty
end
parse_extended() click to toggle source
# File lib/bio/maf/parser.rb, line 450
def parse_extended
  parser.parse_extended
end
sequence_filter() click to toggle source
# File lib/bio/maf/parser.rb, line 442
def sequence_filter
  parser.sequence_filter
end
set_last_block_pos!() click to toggle source
# File lib/bio/maf/parser.rb, line 454
def set_last_block_pos!
  @last_block_pos = s.string.rindex(BLOCK_START)
end
start_chunk_read_if_needed(offset, len) click to toggle source
# File lib/bio/maf/parser.rb, line 490
def start_chunk_read_if_needed(offset, len)
  if chunk_start \
    && (chunk_start <= offset) \
    && (offset < (chunk_start + s.string.size))
    ## the selected offset is in the current chunk
    s.pos = offset - chunk_start
  else
    chunk = cr.read_chunk_at(offset, len)
    @chunk_start = offset
    @s = StringScanner.new(chunk)
  end
end