Class: Quality

Inherits:
String
  • Object
show all
Defined in:
lib/parse_fasta/quality.rb

Overview

Provide some methods for dealing with common tasks regarding quality strings.

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Quality

Strips whitespace from the str argument before calling super

Examples:

Removes whitespace

Quality.new "I I 2 ! " #=> "II2!"


29
30
31
# File 'lib/parse_fasta/quality.rb', line 29

def initialize(str)
  super(str.gsub(/ +/, ""))
end

Instance Method Details

#mean_qualFloat

Returns the mean quality for the record. This will be a good deal faster than getting the average with ‘qual_scores` and reduce.

Examples:

Get mean quality score for a record

Quality.new("!+5?I").mean_qual #=> 20.0

Returns:

  • (Float)

    Mean quality score for record



40
41
42
# File 'lib/parse_fasta/quality.rb', line 40

def mean_qual
  (self.sum - (self.length * 33)) / self.length.to_f
end

#qual_scoresArray<Fixnum>

Returns an array of illumina style quality scores. The quality scores generated will be Phred+33 (i.e., new Illumina).

Examples:

Get quality score array of a Quality

Quality.new("!+5?I").qual_scores #=> [0, 10, 20, 30, 40]

Returns:

  • (Array<Fixnum>)

    the quality scores



51
52
53
# File 'lib/parse_fasta/quality.rb', line 51

def qual_scores
  self.each_byte.map { |b| b - 33 }
end