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.

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


27
28
29
30
31
# File 'lib/bio/maf/parser.rb', line 27

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)

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

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)

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

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)

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

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.


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

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:


53
54
55
56
57
# File 'lib/bio/maf/parser.rb', line 53

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.

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.


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

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