]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/Maasha/lib/fasta.rb
add dist option to find_adaptor
[biopieces.git] / code_ruby / Maasha / lib / fasta.rb
index 23bad26241dd3bd40a9423d7adc43d1d2e24bc8f..e972751320e137df58f413258b87901a16f052ba 100644 (file)
@@ -1,3 +1,5 @@
+# Copyright (C) 2007-2011 Martin A. Hansen.
+
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'seq'
+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 files.
-  # See File.open.
-  def self.open(*args)
-    ios   = File.open(*args)
-    fasta = self.new(ios)
-
-    if block_given?
-      begin
-        yield fasta
-      ensure
-        ios.close
-      end
-
-      return true
-    else
-      return fasta
-    end
-  end
-
-  def initialize(io, type=nil)
-    @io   = io
-    @type = type
-  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
@@ -81,6 +51,14 @@ class Fasta
 
     entry
   end
+
+  # TODO - this should be some custom to_s method instead.
+  def puts(record)
+    if record.has_key? :SEQ_NAME and record.has_key? :SEQ
+      @io.print ">#{record[:SEQ_NAME]}\n"
+      @io.print "#{record[:SEQ]}\n"
+    end
+  end
 end