From: martinahansen Date: Sat, 19 Mar 2011 08:20:17 +0000 (+0000) Subject: cleanup of Filsys in ruby code X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=af545a8962b7fd47682a11852bb752e4b9bad50f;p=biopieces.git cleanup of Filsys in ruby code git-svn-id: http://biopieces.googlecode.com/svn/trunk@1296 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_python/Cjung/Args.pyc b/code_python/Cjung/Args.pyc index 66b245e..c22941c 100644 Binary files a/code_python/Cjung/Args.pyc and b/code_python/Cjung/Args.pyc differ diff --git a/code_ruby/Maasha/lib/biopieces.rb b/code_ruby/Maasha/lib/biopieces.rb index 05658e4..2f98fe9 100644 --- a/code_ruby/Maasha/lib/biopieces.rb +++ b/code_ruby/Maasha/lib/biopieces.rb @@ -571,7 +571,7 @@ class Stream < IO # specified in options[:stream_out] or options[:data_out]. def self.open(options, mode, stdio) if mode == "r" - if options[:data_in].first == "-" + if options[:data_in] and options[:data_in].first == "-" self.nread(["-"]) else $stdin.tty? ? read(options[:stream_in]) : stdio diff --git a/code_ruby/Maasha/lib/fasta.rb b/code_ruby/Maasha/lib/fasta.rb index 26e6d73..e972751 100644 --- a/code_ruby/Maasha/lib/fasta.rb +++ b/code_ruby/Maasha/lib/fasta.rb @@ -23,47 +23,12 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 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("//" + $/)