module SequenceServer::Sequence::Retriever::IO
Provides IO
for Retriever
similar to BLAST::Formatter
. We dynamically extend Retriever
object with this module if file download has been requested (here it must be remembered that Retriever
is used by sequence viewer and FASTA download links).
Public Instance Methods
file()
click to toggle source
Returns handle to a temporary file to which data should be written to or read from.
# File lib/sequenceserver/sequence.rb, line 132 def file @file ||= Tempfile.new filename end
filename()
click to toggle source
Returns a file name to use for the temporary file.
# File lib/sequenceserver/sequence.rb, line 137 def filename return @filename if @filename name = sequence_ids.first if sequence_ids.length == 1 name = "#{sequence_ids.length}_hits" if sequence_ids.length >= 2 @filename = "sequenceserver-#{name}.fa" end
mime()
click to toggle source
Returns mime type to use if this file were to be transferred over Internet.
# File lib/sequenceserver/sequence.rb, line 147 def mime :fasta end
Private Instance Methods
write()
click to toggle source
# File lib/sequenceserver/sequence.rb, line 153 def write file.open write_error_msgs write_sequences file.close end
write_error_msgs()
click to toggle source
Write error messages to file. Expects file to be open.
# File lib/sequenceserver/sequence.rb, line 161 def write_error_msgs error_msgs.each do |heading, message| file.puts "# #{heading}" message.each_line do |line| file.puts "# #{line}" end end end
write_sequences()
click to toggle source
Write sequence data to file. Expects file to be open.
# File lib/sequenceserver/sequence.rb, line 171 def write_sequences sequences.each do |sequence| file.puts sequence.fasta end end