]> git.donarmstrong.com Git - biopieces.git/commitdiff
cleanup of Filsys in ruby code
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 19 Mar 2011 08:20:17 +0000 (08:20 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sat, 19 Mar 2011 08:20:17 +0000 (08:20 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1296 74ccb610-7750-0410-82ae-013aeee3265d

code_python/Cjung/Args.pyc
code_ruby/Maasha/lib/biopieces.rb
code_ruby/Maasha/lib/fasta.rb
code_ruby/Maasha/lib/fastq.rb
code_ruby/Maasha/lib/filesys.rb
code_ruby/Maasha/lib/genbank.rb

index 66b245e94a16f34c4cd693215c8322410309cd50..c22941cdaa6b72f2e8e900a946250984191f6325 100644 (file)
Binary files a/code_python/Cjung/Args.pyc and b/code_python/Cjung/Args.pyc differ
index 05658e4d11a4c564915f0620f69640ed83a4d1d8..2f98fe9f9812b815fb4c3dc33001390e64f3a0f0 100644 (file)
@@ -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
index 26e6d735e4a74cc47be9074ea30c06ac5e96823c..e972751320e137df58f413258b87901a16f052ba 100644 (file)
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 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
 
 
index 82c242e62fe34d664faba1e81f53a74e271976b0..a1eb86ccd7009163594fc5540464ff60cd10d6b3 100644 (file)
@@ -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
index 6f6d8cc210d1d64d52c18d4645f6dcddc7fa4197..7e0deaa4f465b6828e945fed8a6ff57662dbed14 100644 (file)
@@ -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
index 7abed69913645dca36c91b31836e3319a84c779e..beff0eda7fd1c6093c3c69b04a44418b608d2d1a 100644 (file)
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 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("//" + $/)