Class: FastqFile

Inherits:
File
  • Object
show all
Defined in:
lib/parse_fasta/fastq_file.rb

Overview

Provides simple interface for parsing four-line-per-record fastq format files.

Instance Method Summary collapse

Instance Method Details

#each_record {|header, sequence, description, quality_string| ... } ⇒ Object

Analagous to File#each_line, #each_record is used to go through a fastq file record by record.

Examples:

Parsing a fastq file

FastqFile.open('reads.fq', 'r').each_record do |head, seq, desc, qual|
  # do some fun stuff here!
end

Yields:

  • The header, sequence, description and quality string for each record in the fastq file to the block

Yield Parameters:

  • header (String)

    The header of the fastq record without the leading '@'

  • sequence (Sequence)

    The sequence of the fastq record

  • description (String)

    The description line of the fastq record without the leading '+'

  • quality_string (Quality)

    The quality string of the fastq record



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/parse_fasta/fastq_file.rb', line 40

def each_record
  count = 0
  header = ''
  sequence = ''
  description = ''
  quality = ''
  
  self.each_line do |line|
    line.chomp!

    case count % 4
    when 0
      header = line.sub(/^@/, '')
    when 1
      sequence = Sequence.new(line)
    when 2
      description = line.sub(/^\+/, '')
    when 3
      quality = Quality.new(line)
      yield(header, sequence, description, quality)
    end
    
    count += 1
  end
end