Class: Bio::Fastq::FormatData

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/db/fastq.rb

Overview

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

Direct Known Subclasses

FASTQ_ILLUMINA, FASTQ_SANGER, FASTQ_SOLEXA

Defined Under Namespace

Classes: FASTQ_ILLUMINA, FASTQ_SANGER, FASTQ_SOLEXA

Constant Summary collapse

NAME =

Format name. Should be redefined in subclass.

nil
OFFSET =

Offset. Should be redefined in subclass.

nil
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.

nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormatData

Returns a new instance of FormatData.



53
54
55
56
57
58
# File 'lib/bio/db/fastq.rb', line 53

def initialize
  @name = self.class::NAME
  @symbol = @name.gsub(/\-/, '_').to_sym
  @offset = self.class::OFFSET
  @score_range = self.class::SCORE_RANGE
end

Instance Attribute Details

#nameObject (readonly)

Format name



61
62
63
# File 'lib/bio/db/fastq.rb', line 61

def name
  @name
end

#offsetObject (readonly)

Offset when converting a score to a character



69
70
71
# File 'lib/bio/db/fastq.rb', line 69

def offset
  @offset
end

#quality_score_typeObject (readonly)

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



75
76
77
# File 'lib/bio/db/fastq.rb', line 75

def quality_score_type
  @quality_score_type
end

#score_rangeObject (readonly)

Allowed range of a score value



72
73
74
# File 'lib/bio/db/fastq.rb', line 72

def score_range
  @score_range
end

#symbolObject (readonly)

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



66
67
68
# File 'lib/bio/db/fastq.rb', line 66

def symbol
  @symbol
end

Instance Method Details

#scores2str(a) ⇒ Object

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/bio/db/fastq.rb', line 99

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

#str2scores(str) ⇒ Object

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


Arguments:

  • (required) c: (String) quality string

Returns

(Array containing Integer) score values



83
84
85
86
87
# File 'lib/bio/db/fastq.rb', line 83

def str2scores(str)
  a = str.unpack('C*')
  a.collect! { |i| i - @offset }
  a
end