]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/Maasha/lib/fastq.rb
add dist option to find_adaptor
[biopieces.git] / code_ruby / Maasha / lib / fastq.rb
index b8ce35eb69c285350d94a717969bac72ab4c1198..a1eb86ccd7009163594fc5540464ff60cd10d6b3 100644 (file)
@@ -1,3 +1,5 @@
+# Copyright (C) 2007-2011 Martin A. Hansen.
+
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'seq'
-require 'zlib'
+require 'filesys'
 
 # Error class for all exceptions to do with FASTQ.
 class FastqError < StandardError; end
 
-class Fastq
-  include Enumerable
-
-  # Class method allowing open to be used on (zipped) files.
-  # See File.open.
-  def self.open(*args)
-    ios = self.zopen(*args)
-
-    if block_given?
-      begin
-        yield ios
-      ensure
-        ios.close
-      end
-    else
-      return ios
-    end
-  end
-
-  def initialize(io, type=nil)
-    @io   = io
-    @type = type
-  end
-
-  # Method to close ios.
-  def close
-    @io.close
-  end
-
-  # Iterator method for parsing FASTQ enries.
-  def each
-    while entry = get_entry do
-      yield entry
-    end
-  end
-
+class Fastq < Filesys
   # Method to get the next FASTQ entry form an ios and return this
   # as a Seq object. If no entry is found or eof then nil is returned.
   def get_entry
     begin
-      seq_name  = @io.gets.chomp!
-      seq       = @io.gets.chomp!
-      qual_name = @io.gets.chomp!
-      qual      = @io.gets.chomp!
+      seq_name       = @io.gets.chomp!
+      seq            = @io.gets.chomp!
+      qual_name      = @io.gets.chomp!
+      qual           = @io.gets.chomp!
 
       entry          = Seq.new
       entry.type     = @type.nil? ? nil : @type.downcase
@@ -90,22 +57,6 @@ class Fastq
       @io.print "#{record[:SEQ]}\n"
     end
   end
-
-  private
-
-  # Helper method to return an ios to a file that may be zipped in which case
-  # the ios is unzipped on the fly. See File.open.
-  def self.zopen(*args)
-    ios = File.open(*args)
-
-    begin
-      ios = Zlib::GzipReader.new(ios)
-    rescue
-      ios.rewind
-    end
-
-    self.new(ios)
-  end
 end