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.



52
53
54
55
56
57
# 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

Instance Attribute Details

#nameObject (readonly)

Format name



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

def name
  @name
end

#offsetObject (readonly)

Offset when converting a score to a character



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

def offset
  @offset
end

#quality_score_typeObject (readonly)

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



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

def quality_score_type
  @quality_score_type
end

#score_rangeObject (readonly)

Allowed range of a score value



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

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.



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

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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

#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



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

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