Class: BioDSL::Fastq

Inherits:
Filesys show all
Defined in:
lib/BioDSL/fastq.rb

Overview

Class for parsing FASTQ entries from an ios and return as Seq objects.

Defined Under Namespace

Classes: IO

Instance Attribute Summary

Attributes inherited from Filesys

#io

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filesys

#close, #eof?, #gets, #puts, #read, tmpfile, which, #write

Constructor Details

#initialize(io) ⇒ Fastq

Returns a new instance of Fastq.



49
50
51
# File 'lib/BioDSL/fastq.rb', line 49

def initialize(io)
  @io = io
end

Class Method Details

.open(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/BioDSL/fastq.rb', line 35

def self.open(*args)
  ios = IO.open(*args)

  if block_given?
    begin
      yield new(ios)
    ensure
      ios.close
    end
  else
    return new(ios)
  end
end

Instance Method Details

#eachObject



53
54
55
56
57
# File 'lib/BioDSL/fastq.rb', line 53

def each
  while (entry = next_entry)
    yield entry
  end
end

#next_entryObject

Method to get the next FASTQ entry from an ios and return this as a Seq object. If no entry is found or eof then nil is returned.



61
62
63
64
65
66
67
68
69
# File 'lib/BioDSL/fastq.rb', line 61

def next_entry
  return nil if @io.eof?
  seq_name = @io.gets[1..-2]
  seq      = @io.gets.chomp
  @io.gets
  qual = @io.gets.chomp

  Seq.new(seq_name: seq_name, seq: seq, qual: qual)
end