From af545a8962b7fd47682a11852bb752e4b9bad50f Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sat, 19 Mar 2011 08:20:17 +0000 Subject: [PATCH] cleanup of Filsys in ruby code git-svn-id: http://biopieces.googlecode.com/svn/trunk@1296 74ccb610-7750-0410-82ae-013aeee3265d --- code_python/Cjung/Args.pyc | Bin 5601 -> 5375 bytes code_ruby/Maasha/lib/biopieces.rb | 2 +- code_ruby/Maasha/lib/fasta.rb | 55 ++---------------------------- code_ruby/Maasha/lib/fastq.rb | 8 ++--- code_ruby/Maasha/lib/filesys.rb | 2 +- code_ruby/Maasha/lib/genbank.rb | 41 ++-------------------- 6 files changed, 10 insertions(+), 98 deletions(-) diff --git a/code_python/Cjung/Args.pyc b/code_python/Cjung/Args.pyc index 66b245e94a16f34c4cd693215c8322410309cd50..c22941cdaa6b72f2e8e900a946250984191f6325 100644 GIT binary patch delta 612 zcmaE;{a=&g;wN6NDKhT98#yxA1PvJ&81zGnQ;UlAa}yJbGZH5!@~TeW$!5w}JNZ4E zql_g3V+lJ$CI>?%Cqpv>Lp~P+V+u2ayGIHuL-1sO_Ln#eXyj0~VP)iGn7@Nd zo{@F(4K7W_xXDc1nldsBEI`wMW@K?Oy){=3e0w*ez9^JWtda004lG2LJ#7 delta 809 zcmeyb`B0l<^Cw=e8#j}EHgaUJskksOFz6STx$&GALj180TusO=xFff*|Gh}iwWO6bzGce@yGBBnvGq`)CurdVaF)~cHWPeGl zkvfy(Ib;|)Cf9IC@>~SEqGA(63DCq>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'seq' -require 'zlib' +require 'filesys' # Error class for all exceptions to do with FASTA. class FastaError < StandardError; end -class Fasta - 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 FASTA enries. - def each - while entry = get_entry do - yield entry - end - end - +class Fasta < Filesys # 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. def get_entry @@ -94,22 +59,6 @@ class Fasta @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 diff --git a/code_ruby/Maasha/lib/fastq.rb b/code_ruby/Maasha/lib/fastq.rb index 82c242e..a1eb86c 100644 --- a/code_ruby/Maasha/lib/fastq.rb +++ b/code_ruby/Maasha/lib/fastq.rb @@ -33,10 +33,10 @@ class Fastq < Filesys # 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 diff --git a/code_ruby/Maasha/lib/filesys.rb b/code_ruby/Maasha/lib/filesys.rb index 6f6d8cc..7e0deaa 100644 --- a/code_ruby/Maasha/lib/filesys.rb +++ b/code_ruby/Maasha/lib/filesys.rb @@ -65,7 +65,7 @@ class Filesys @io.close end - # Iterator method for parsing FASTQ enries. + # Iterator method for parsing entries. def each while entry = get_entry do yield entry diff --git a/code_ruby/Maasha/lib/genbank.rb b/code_ruby/Maasha/lib/genbank.rb index 7abed69..beff0ed 100644 --- a/code_ruby/Maasha/lib/genbank.rb +++ b/code_ruby/Maasha/lib/genbank.rb @@ -23,40 +23,17 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< require 'seq' -require 'zlib' +require 'filesys' # Error class for all exceptions to do with Genbank. class GenbankError < StandardError; end -class Genbank - 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 - +class Genbank < Filesys def initialize(io) @io = io @entry = [] end - # Method to close ios. - def close - @io.close - end - # Iterator method for parsing Genbank entries. def each(hash_keys, hash_feats, hash_quals) while @entry = get_entry do @@ -82,20 +59,6 @@ class Genbank 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 - # Method to get the next Genbank entry form an ios and return this. def get_entry block = @io.gets("//" + $/) -- 2.39.2