]> git.donarmstrong.com Git - biopieces.git/commitdiff
read_fasta now reads zipped fasta fails again
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Aug 2010 11:20:24 +0000 (11:20 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 18 Aug 2010 11:20:24 +0000 (11:20 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1065 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/Maasha/lib/fasta.rb

index 23bad26241dd3bd40a9423d7adc43d1d2e24bc8f..b0db2c8dd9bedf417f47860e782ce3001c3f6744 100644 (file)
@@ -21,6 +21,8 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'seq'
+require 'zlib'
+require 'pp'
 
 # Error class for all exceptions to do with FASTA.
 class FastaError < StandardError; end
@@ -28,10 +30,17 @@ class FastaError < StandardError; end
 class Fasta
   include Enumerable
 
-  # Class method allowing open to be used on files.
-  # See File.open.
+  # Class method allowing open to be used on (zipped) files.
+  # See File.open and Zlib::GzipReader.
   def self.open(*args)
-    ios   = File.open(*args)
+    ios = File.open(*args)
+
+    begin
+      ios = Zlib::GzipReader.new(ios)
+    rescue
+      ios.rewind
+    end
+
     fasta = self.new(ios)
 
     if block_given?