Class: FastqFile
- Inherits:
-
File
- Object
- File
- FastqFile
- Defined in:
- lib/parse_fasta/fastq_file.rb
Overview
Provides simple interface for parsing four-line-per-record fastq format files. Gzipped files are no problem.
Instance Method Summary collapse
-
#each_record {|header, sequence, description, quality_string| ... } ⇒ Object
Analagous to IO#each_line, #each_record is used to go through a fastq file record by record.
Instance Method Details
#each_record {|header, sequence, description, quality_string| ... } ⇒ Object
Analagous to IO#each_line, #each_record is used to go through a fastq file record by record. It will accept gzipped files as well.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/parse_fasta/fastq_file.rb', line 46 def each_record count = 0 header = '' sequence = '' description = '' quality = '' begin f = Zlib::GzipReader.open(self) rescue Zlib::GzipFile::Error => e f = self end f.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 f.close if f.instance_of?(Zlib::GzipReader) return f end |