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.
Constants
- NAME
Format name. Should be redefined in subclass.
- OFFSET
Offset. Should be redefined in subclass.
- SCORE_RANGE
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.
Attributes
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
# File lib/bio/db/fastq.rb, line 52 def initialize @name = self.class::NAME @symbol = @name.gsub(/\-/, '_').to_sym @offset = self.class::OFFSET @score_range = self.class::SCORE_RANGE end
Public Instance Methods
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.
Arguments:
-
(required) a: (Array containing Integer) score values
- Returns
-
(String) quality string
# File lib/bio/db/fastq.rb, line 98 def scores2str(a) if block_given? then tmp = a.collect do |i| i = yield(i) unless @score_range.include?(i) i + @offset end else min = @score_range.begin max = @score_range.end tmp = a.collect do |i| if i < min then i = min elsif i > max then i = max end i + @offset end end tmp.pack('C*') end
Converts quality string to scores. No overflow/underflow checks will be performed.
Arguments:
-
(required) c: (String) quality string
- Returns
-
(Array containing Integer) score values
# File lib/bio/db/fastq.rb, line 82 def str2scores(str) a = str.unpack('C*') a.collect! { |i| i - @offset } a end