Class: Bio::MAF::ChunkReader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/maf/parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Reads MAF files in chunks.

Direct Known Subclasses

ThreadedChunkReader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f, chunk_size) ⇒ ChunkReader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ChunkReader.



25
26
27
28
29
# File 'lib/bio/maf/parser.rb', line 25

def initialize(f, chunk_size)
  @f = f
  self.chunk_size = chunk_size
  @pos = 0
end

Instance Attribute Details

#chunk_sizeInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Size, in bytes, of the chunks to read. Must be a power of 2.

Returns:

  • (Integer)


18
19
20
# File 'lib/bio/maf/parser.rb', line 18

def chunk_size
  @chunk_size
end

#fFile (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

File from which chunks are read.

Returns:

  • (File)


24
25
26
# File 'lib/bio/maf/parser.rb', line 24

def f
  @f
end

#posInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Current position in the file.

Returns:

  • (Integer)


21
22
23
# File 'lib/bio/maf/parser.rb', line 21

def pos
  @pos
end

Instance Method Details

#check_chunk_size(size) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
41
42
43
44
45
46
47
# File 'lib/bio/maf/parser.rb', line 38

def check_chunk_size(size)
  if size < 1
    raise "Invalid chunk size: #{size}"
  end
  ## test whether it is a power of 2
  ## cf. http://bit.ly/JExNc4
  if size & (size - 1) != 0
    raise "Invalid chunk size (not a power of 2): #{size}}"
  end
end

#read_chunkString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads the next chunk of the file.

Returns:



51
52
53
54
55
# File 'lib/bio/maf/parser.rb', line 51

def read_chunk
  chunk = f.read(@chunk_size)
  @pos += chunk.bytesize if chunk
  return chunk
end

#read_chunk_at(offset, size_hint = @chunk_size) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a chunk of the file.

Currently always reads size_hint bytes but this may change with BGZF support.

Parameters:

  • offset (Integer)

    file offset to read from.

  • size_hint (Integer) (defaults to: @chunk_size)

    desired size of chunk.

Returns:

  • (String)

    Chunk of MAF data.



65
66
67
68
69
70
# File 'lib/bio/maf/parser.rb', line 65

def read_chunk_at(offset, size_hint=@chunk_size)
  f.seek(offset)
  chunk = f.read(size_hint)
  @pos = offset + chunk.bytesize
  return chunk
end