# 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
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
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
@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
# 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
@io.close
end
- # Iterator method for parsing FASTQ enries.
+ # Iterator method for parsing entries.
def each
while entry = get_entry do
yield entry
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
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
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("//" + $/)