From 4be853d0dc4a89f01d1816a294ffb0ec2e4fe021 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 18 Aug 2010 11:20:24 +0000 Subject: [PATCH] read_fasta now reads zipped fasta fails again git-svn-id: http://biopieces.googlecode.com/svn/trunk@1065 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/fasta.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/code_ruby/Maasha/lib/fasta.rb b/code_ruby/Maasha/lib/fasta.rb index 23bad26..b0db2c8 100644 --- a/code_ruby/Maasha/lib/fasta.rb +++ b/code_ruby/Maasha/lib/fasta.rb @@ -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? -- 2.39.5