Class: Bio::Fastq::FormatData
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
Defined Under Namespace
Classes: FASTQ_ILLUMINA, FASTQ_SANGER, FASTQ_SOLEXA
Constant Summary
- 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)
-
- (Object) name
readonly
Format name.
-
- (Object) offset
readonly
Offset when converting a score to a character.
-
- (Object) quality_score_type
readonly
Returns the value of attribute quality_score_type.
-
- (Object) score_range
readonly
Allowed range of a score value.
-
- (Object) symbol
readonly
Format name symbol.
Instance Method Summary (collapse)
-
- (FormatData) initialize
constructor
A new instance of FormatData.
-
- (Object) scores2str(a)
Converts scores to a string.
-
- (Object) str2scores(str)
Converts quality string to scores.
Constructor Details
- (FormatData) initialize
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
- (Object) name (readonly)
Format name
60 61 62 |
# File 'lib/bio/db/fastq.rb', line 60 def name @name end |
- (Object) offset (readonly)
Offset when converting a score to a character
68 69 70 |
# File 'lib/bio/db/fastq.rb', line 68 def offset @offset end |
- (Object) quality_score_type (readonly)
Returns the value of attribute quality_score_type
74 75 76 |
# File 'lib/bio/db/fastq.rb', line 74 def quality_score_type @quality_score_type end |
- (Object) score_range (readonly)
Allowed range of a score value
71 72 73 |
# File 'lib/bio/db/fastq.rb', line 71 def score_range @score_range end |
- (Object) symbol (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
- (Object) scores2str(a)
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 |
- (Object) str2scores(str)
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 |