Module: Bio::Ngs::Illumina::FastqGz

Defined in:
lib/bio/ngs/illumina/fastq.rb

Overview

TODO this module can be move in another namespace more generic

Class Method Summary collapse

Class Method Details

.gets_compressed(file, &block) ⇒ Object



44
45
46
47
48
49
# File 'lib/bio/ngs/illumina/fastq.rb', line 44

def gets_compressed(file, &block)
   Zlib::GzipWriter.open(file) do |gz|
    yield gz
    gz.close
  end
end

.gets_filtered(file, &block) ⇒ Object

Return the number of reads processed



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bio/ngs/illumina/fastq.rb', line 52

def gets_filtered(file, &block)
  n_reads = 0
  gets_uncompressed(file) do |header, seq, splitter, qual|
   if header=~/^@.* [^:]*:N:[^:]*:/ 
    n_reads+=1
        #pass to the block header, fasta, quality splitter, quality
        yield header, seq, splitter, qual
      end
  end #GzipReader
  n_reads
end

.gets_uncompressed(file, &block) ⇒ Object

Return the number of reads processed



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bio/ngs/illumina/fastq.rb', line 29

def gets_uncompressed(file, &block)
  n_reads = 0
  Zlib::GzipReader.open(file) do |gz|
    while  header=gz.gets
      #seq, splitter, qual = gz.gets, gz.gets, gz.gets
      n_reads+=1
      #yield header, seq, splitter, qual
      yield header, gz.gets, gz.gets, gz.gets
    end #while
    gz.close
  end #GzipReader
  n_reads
end