From c85f041b9eb75126e3c6768beca1e547e23df51e Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 18 Aug 2010 19:48:50 +0000 Subject: [PATCH] added zip reading to read_fasta git-svn-id: http://biopieces.googlecode.com/svn/trunk@1066 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/Maasha/lib/doc/classes/Fasta.html | 75 ++++++++++------ code_ruby/Maasha/lib/doc/created.rid | 2 +- code_ruby/Maasha/lib/doc/files/fasta_rb.html | 6 +- code_ruby/Maasha/lib/doc/fr_class_index.html | 16 ---- code_ruby/Maasha/lib/doc/fr_file_index.html | 4 - code_ruby/Maasha/lib/doc/fr_method_index.html | 88 ++----------------- code_ruby/Maasha/lib/doc/index.html | 2 +- code_ruby/Maasha/lib/fasta.rb | 40 +++++---- 8 files changed, 86 insertions(+), 147 deletions(-) diff --git a/code_ruby/Maasha/lib/doc/classes/Fasta.html b/code_ruby/Maasha/lib/doc/classes/Fasta.html index 8a9c706..ab36f56 100644 --- a/code_ruby/Maasha/lib/doc/classes/Fasta.html +++ b/code_ruby/Maasha/lib/doc/classes/Fasta.html @@ -91,13 +91,15 @@
- each   + close   - get_entry   + each   - new   + get_entry   - open   + new   + + open  
@@ -128,13 +130,13 @@

Public Class methods

-
- +
+ -
- +
+
- + - open(*args) {|fasta| ...} + open(*args) {|ios| ...} @@ -165,7 +167,7 @@

-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.

@@ -175,13 +177,37 @@ Class method allowing open to be used on files. See File.open.

Public Instance methods

-
- +
+ + + + +
+ +

+Method to close ios. +

+ +
+
+ + +
+ -
- +
+
- + get_entry() @@ -216,9 +242,8 @@ Iterator method for parsing FASTA enries.

-Method to get the next FASTA entry form an ios and return this as a Seq object. If no entry is found or eof then nil is -returned. +Method to get the next FASTA entry form an ios and return this as a Seq +object. If no entry is found or eof then nil is returned.

diff --git a/code_ruby/Maasha/lib/doc/created.rid b/code_ruby/Maasha/lib/doc/created.rid index 90dc268..120565f 100644 --- a/code_ruby/Maasha/lib/doc/created.rid +++ b/code_ruby/Maasha/lib/doc/created.rid @@ -1 +1 @@ -Tue, 17 Aug 2010 15:43:49 +0200 +Wed, 18 Aug 2010 21:48:07 +0200 diff --git a/code_ruby/Maasha/lib/doc/files/fasta_rb.html b/code_ruby/Maasha/lib/doc/files/fasta_rb.html index 6f2167f..21a9b00 100644 --- a/code_ruby/Maasha/lib/doc/files/fasta_rb.html +++ b/code_ruby/Maasha/lib/doc/files/fasta_rb.html @@ -53,7 +53,7 @@ Last Update: - 2010-08-17 15:43:01 +0200 + 2010-08-18 21:33:24 +0200
@@ -78,7 +78,9 @@ any later version.
- seq   + seq   + + zlib  
diff --git a/code_ruby/Maasha/lib/doc/fr_class_index.html b/code_ruby/Maasha/lib/doc/fr_class_index.html index 7fc7d71..2557682 100644 --- a/code_ruby/Maasha/lib/doc/fr_class_index.html +++ b/code_ruby/Maasha/lib/doc/fr_class_index.html @@ -17,26 +17,10 @@

Classes

diff --git a/code_ruby/Maasha/lib/doc/fr_file_index.html b/code_ruby/Maasha/lib/doc/fr_file_index.html index fd47302..83e8a04 100644 --- a/code_ruby/Maasha/lib/doc/fr_file_index.html +++ b/code_ruby/Maasha/lib/doc/fr_file_index.html @@ -17,12 +17,8 @@

Files

diff --git a/code_ruby/Maasha/lib/doc/fr_method_index.html b/code_ruby/Maasha/lib/doc/fr_method_index.html index 5a0e1e9..007edaa 100644 --- a/code_ruby/Maasha/lib/doc/fr_method_index.html +++ b/code_ruby/Maasha/lib/doc/fr_method_index.html @@ -17,93 +17,15 @@

Methods

diff --git a/code_ruby/Maasha/lib/doc/index.html b/code_ruby/Maasha/lib/doc/index.html index b40cde7..b25b07d 100644 --- a/code_ruby/Maasha/lib/doc/index.html +++ b/code_ruby/Maasha/lib/doc/index.html @@ -16,6 +16,6 @@ - + diff --git a/code_ruby/Maasha/lib/fasta.rb b/code_ruby/Maasha/lib/fasta.rb index b0db2c8..31c7529 100644 --- a/code_ruby/Maasha/lib/fasta.rb +++ b/code_ruby/Maasha/lib/fasta.rb @@ -22,7 +22,6 @@ require 'seq' require 'zlib' -require 'pp' # Error class for all exceptions to do with FASTA. class FastaError < StandardError; end @@ -31,28 +30,18 @@ class Fasta include Enumerable # Class method allowing open to be used on (zipped) files. - # See File.open and Zlib::GzipReader. + # See File.open. def self.open(*args) - ios = File.open(*args) - - begin - ios = Zlib::GzipReader.new(ios) - rescue - ios.rewind - end - - fasta = self.new(ios) + ios = self.zopen(*args) if block_given? begin - yield fasta + yield ios ensure ios.close end - - return true else - return fasta + return ios end end @@ -61,6 +50,11 @@ class Fasta @type = type end + # Method to close ios. + def close + @io.close + end + # Iterator method for parsing FASTA enries. def each while entry = get_entry do @@ -90,6 +84,22 @@ class Fasta entry 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 -- 2.39.5