Class: Bio::MAF::ParseContext
- Inherits:
-
Object
- Object
- Bio::MAF::ParseContext
show all
- Includes:
- MAFParsing
- Defined in:
- lib/bio/maf/parser.rb
Overview
A MAF parsing context, used for random-access parsing.
Constant Summary
Constants included
from MAFParsing
MAFParsing::BLOCK_START, MAFParsing::BLOCK_START_OR_EOS, MAFParsing::COMMENT, MAFParsing::E, MAFParsing::EOL_OR_EOF, MAFParsing::I, MAFParsing::Q, MAFParsing::S, MAFParsing::STRAND_SYM
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from MAFParsing
#_parse_block, #gather_leading_fragment, #parse_block_data, #parse_empty_line, #parse_error, #parse_maf_vars, #parse_seq_line, #parse_trailing_fragment, #seq_filter_ok?, #trailing_nl?
Constructor Details
#initialize(fd, chunk_size, parser) ⇒ ParseContext
Returns a new instance of ParseContext.
423
424
425
426
427
428
429
|
# File 'lib/bio/maf/parser.rb', line 423
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
|
Instance Attribute Details
#at_end ⇒ Object
421
422
423
|
# File 'lib/bio/maf/parser.rb', line 421
def at_end
@at_end
end
|
#chunk_start ⇒ Object
421
422
423
|
# File 'lib/bio/maf/parser.rb', line 421
def chunk_start
@chunk_start
end
|
#cr ⇒ Object
420
421
422
|
# File 'lib/bio/maf/parser.rb', line 420
def cr
@cr
end
|
#f ⇒ Object
420
421
422
|
# File 'lib/bio/maf/parser.rb', line 420
def f
@f
end
|
#last_block_pos ⇒ Object
421
422
423
|
# File 'lib/bio/maf/parser.rb', line 421
def last_block_pos
@last_block_pos
end
|
#opts ⇒ Object
420
421
422
|
# File 'lib/bio/maf/parser.rb', line 420
def opts
@opts
end
|
#parser ⇒ Object
420
421
422
|
# File 'lib/bio/maf/parser.rb', line 420
def parser
@parser
end
|
#s ⇒ Object
420
421
422
|
# File 'lib/bio/maf/parser.rb', line 420
def s
@s
end
|
Instance Method Details
#append_chunks_to(len) ⇒ Object
492
493
494
495
496
|
# File 'lib/bio/maf/parser.rb', line 492
def append_chunks_to(len)
while s.string.size < len
s.string << cr.read_chunk()
end
end
|
#fetch_blocks(offset, len, block_offsets) ⇒ Array<Block>
Fetch and parse blocks at given offset
and len
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
# File 'lib/bio/maf/parser.rb', line 452
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)
append_chunks_to(len)
block_offsets.each do |expected_offset|
rel_offset = expected_offset - offset
if s.pos < rel_offset
s.pos = rel_offset
end
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 ⇒ Object
435
436
437
|
# File 'lib/bio/maf/parser.rb', line 435
def parse_empty
parser.parse_empty
end
|
#parse_extended ⇒ Object
439
440
441
|
# File 'lib/bio/maf/parser.rb', line 439
def parse_extended
parser.parse_extended
end
|
#sequence_filter ⇒ Object
431
432
433
|
# File 'lib/bio/maf/parser.rb', line 431
def sequence_filter
parser.sequence_filter
end
|
#set_last_block_pos! ⇒ Object
443
444
445
|
# File 'lib/bio/maf/parser.rb', line 443
def set_last_block_pos!
@last_block_pos = s.string.rindex(BLOCK_START)
end
|
#start_chunk_read_if_needed(offset, len) ⇒ Object
479
480
481
482
483
484
485
486
487
488
489
490
|
# File 'lib/bio/maf/parser.rb', line 479
def start_chunk_read_if_needed(offset, len)
if chunk_start \
&& (chunk_start <= offset) \
&& (offset < (chunk_start + s.string.size))
s.pos = offset - chunk_start
else
chunk = cr.read_chunk_at(offset, len)
@chunk_start = offset
@s = StringScanner.new(chunk)
end
end
|