class Bio::Sequence::Format::Formatter::Fasta

INTERNAL USE ONLY, YOU SHOULD NOT USE THIS CLASS. Simple Fasta format output class for Bio::Sequence.

Public Class Methods

new() click to toggle source

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD.

Creates a new Fasta format generater object from the sequence.


Arguments:

  • sequence: Bio::Sequence object

  • (optional) :header => header: String (default nil)

  • (optional) :width => width: Fixnum (default 70)

   # File lib/bio/db/fasta/format_fasta.rb
26 def initialize; end

Public Instance Methods

output() click to toggle source

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD.

Output the FASTA format string of the sequence.

Currently, this method is used in Bio::Sequence#output like so,

s = Bio::Sequence.new('atgc')
puts s.output(:fasta)                   #=> "> \natgc\n"

Returns

String object

   # File lib/bio/db/fasta/format_fasta.rb
38 def output
39   header = @options[:header]
40   width = @options.has_key?(:width) ? @options[:width] : 70
41   seq = @sequence.seq
42   entry_id = @sequence.entry_id || 
43     "#{@sequence.primary_accession}.#{@sequence.sequence_version}"
44   definition = @sequence.definition
45   header ||= "#{entry_id} #{definition}"
46 
47   ">#{header}\n" +
48     if width
49       seq.to_s.gsub(Regexp.new(".{1,#{width}}"), "\\0\n")
50     else
51       seq.to_s + "\n"
52     end
53 end