Class: Bio::Sequence::Format::Formatter::Fasta_numeric

Inherits:
Bio::Sequence::Format::FormatterBase show all
Defined in:
lib/bio/db/fasta/format_qual.rb

Overview

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

Direct Known Subclasses

Qual

Instance Method Summary collapse

Methods inherited from Bio::Sequence::Format::FormatterBase

output

Constructor Details

#initializeFasta_numeric

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD.

Creates a new FastaNumericFormat generater object from the sequence.

It does not care whether the content of the quality score is consistent with the sequence or not, e.g. it does not check length of the quality score.


Arguments:

  • sequence: Bio::Sequence object

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

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



28
# File 'lib/bio/db/fasta/format_qual.rb', line 28

def initialize; end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bio::Sequence::Format::FormatterBase

Instance Method Details

#outputObject

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')
s.quality_scores = [ 70, 80, 90, 100 ]
puts s.output(:fasta_numeric)

Returns

String object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bio/db/fasta/format_qual.rb', line 41

def output
  header = @options[:header]
  width = @options.has_key?(:width) ? @options[:width] : 70
  seq = @sequence.seq.to_s
  entry_id = @sequence.entry_id || 
    "#{@sequence.primary_accession}.#{@sequence.sequence_version}"
  definition = @sequence.definition
  header ||= "#{entry_id} #{definition}"

  sc = fastanumeric_quality_scores(seq)
  if width then
    if width <= 0 then
      main = sc.join("\n")
    else
      len = 0
      main = sc.collect do |x|
        str = (len == 0) ? "#{x}" : " #{x}"
        len += str.size
        if len > width then
          len = "#{x}".size
          str = "\n#{x}"
        end
        str
      end.join('')
    end
  else
    main = sc.join(' ')
  end

  ">#{header}\n#{main}\n"
end