class Bio::Fastq::FormatData

Bio::Fastq::FormatData is a data class to store Fastq format parameters and quality calculation methods. Bio::Fastq internal use only.



Format name. Should be redefined in subclass.


Offset. Should be redefined in subclass.


Range of score. Should be redefined in subclass. The range must not exclude end value, i.e. it must be X..Y, and must not be X…Y.



Format name


Offset when converting a score to a character


Type of quality scores. Maybe one of :phred or :solexa.


Allowed range of a score value


Format name symbol. Note that “-” in the format name is substituted to “_” because “-” in a symbol is relatively difficult to handle.

Public Class Methods

new() click to toggle source
   # File lib/bio/db/fastq.rb
52 def initialize
53   @name = self.class::NAME
54   @symbol = @name.gsub(/\-/, '_').to_sym
55   @offset = self.class::OFFSET
56   @score_range = self.class::SCORE_RANGE
57 end

Public Instance Methods

scores2str(a) { |i| ... } click to toggle source

Converts scores to a string. Overflow/underflow checks will be performed. If a block is given, when overflow/underflow detected, the score value is passed to the block, and uses returned value as the score. If no blocks, silently truncated.


  • (required) a: (Array containing Integer) score values


(String) quality string

    # File lib/bio/db/fastq.rb
 98 def scores2str(a)
 99   if block_given? then
100     tmp = a.collect do |i|
101       i = yield(i) unless @score_range.include?(i)
102       i + @offset
103     end
104   else
105     min = @score_range.begin
106     max = @score_range.end
107     tmp = a.collect do |i|
108       if i < min then
109         i = min
110       elsif i > max then
111         i = max
112       end
113       i + @offset
114     end
115   end
116   tmp.pack('C*')
117 end
str2scores(str) click to toggle source

Converts quality string to scores. No overflow/underflow checks will be performed.


  • (required) c: (String) quality string


(Array containing Integer) score values

   # File lib/bio/db/fastq.rb
82 def str2scores(str)
83   a = str.unpack('C*')
84   a.collect! { |i| i - @offset }
85   a
86 end