From 14e51cd98e6f898e4b37d9d102922fee25c40ac5 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 13 Oct 2011 09:56:15 +0000 Subject: [PATCH] beautifying fasta.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1560 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/write_fasta_files | 4 +++- code_ruby/lib/maasha/biopieces.rb | 10 +++++----- code_ruby/lib/maasha/fasta.rb | 8 -------- code_ruby/lib/maasha/filesys.rb | 7 +++++++ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/bp_bin/write_fasta_files b/bp_bin/write_fasta_files index da4a1c6..debea31 100755 --- a/bp_bin/write_fasta_files +++ b/bp_bin/write_fasta_files @@ -46,6 +46,8 @@ fh_hash = {} Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| input.each_record do |record| if record[:SEQ_NAME] and record[:SEQ] and record[key] + seq = Seq.new_bp(record) + if fh_hash.has_key? record[key].to_sym fasta_io = fh_hash[record[key].to_sym] else @@ -54,7 +56,7 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| fh_hash[record[key].to_sym] = fasta_io end - fasta_io.puts record + fasta_io.puts seq.to_fasta end output.puts record unless options[:no_stream] diff --git a/code_ruby/lib/maasha/biopieces.rb b/code_ruby/lib/maasha/biopieces.rb index 5fd6edf..1d1deb5 100644 --- a/code_ruby/lib/maasha/biopieces.rb +++ b/code_ruby/lib/maasha/biopieces.rb @@ -171,7 +171,7 @@ class Biopieces end # Class method for opening data stream for writing Biopiece records. - # Records are written to STDOU (default) or file. + # Records are written to STDOUT (default) or file. def self.open_output(output) if output.nil? output = self.new(STDOUT, stdio = true) @@ -209,10 +209,10 @@ class Casts < Array # Add ubiquitous options casts. def ubiquitous - @cast_list << {:long=>'help', :short=>'?', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} - @cast_list << {:long=>'stream_in', :short=>'I', :type=>'file!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} - @cast_list << {:long=>'stream_out', :short=>'O', :type=>'file', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} - @cast_list << {:long=>'verbose', :short=>'v', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} + @cast_list << {:long=>'help', :short=>'?', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} + @cast_list << {:long=>'stream_in', :short=>'I', :type=>'file!', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} + @cast_list << {:long=>'stream_out', :short=>'O', :type=>'file', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} + @cast_list << {:long=>'verbose', :short=>'v', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} end # Check integrity of the casts. diff --git a/code_ruby/lib/maasha/fasta.rb b/code_ruby/lib/maasha/fasta.rb index f57a622..05655f6 100644 --- a/code_ruby/lib/maasha/fasta.rb +++ b/code_ruby/lib/maasha/fasta.rb @@ -51,14 +51,6 @@ class Fasta < Filesys 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 diff --git a/code_ruby/lib/maasha/filesys.rb b/code_ruby/lib/maasha/filesys.rb index 9024a58..b3b450a 100644 --- a/code_ruby/lib/maasha/filesys.rb +++ b/code_ruby/lib/maasha/filesys.rb @@ -65,6 +65,7 @@ class Filesys end end + # TODO figure out what type is for. def initialize(io, type=nil) @io = io @type = type @@ -82,6 +83,11 @@ class Filesys end end + # Method to puts directoy on Filesys objects. + def puts *args + @io.puts *args + end + private # Helper method to return an ios to a file that may be zipped in which case @@ -98,3 +104,4 @@ class Filesys self.new(ios) end end + -- 2.39.2