class Bio::Sequence::Format::Formatter::Qual

INTERNAL USE ONLY, YOU SHOULD NOT USE THIS CLASS. Simple Qual format (sequence quality) output class for Bio::Sequence.

Public Class Methods

new() click to toggle source

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD.

Creates a new Qual format generater object from the sequence.

The only difference from Fastanumeric is that Qual outputs Phred score by default, and data conversion will be performed if needed. Output score type can be changed by the “:quality_score_type” option.

If the sequence have no quality score type information and no error probabilities, but the score exists, the score is regarded as :phred (Phred score).


Arguments:

  • sequence: Bio::Sequence object

  • (optional) :header => header: (String) (default nil)

  • (optional) :width => width: (Fixnum) (default 70)

  • (optional) :quality_score_type => type: (Symbol) (default nil)

  • (optional) :default_score => score: (Integer) default score for bases that have no valid quality scores or error probabilities (default 0)

    # File lib/bio/db/fasta/format_qual.rb
105 def initialize; end

Private Instance Methods

fastanumeric_quality_scores(seq) click to toggle source
    # File lib/bio/db/fasta/format_qual.rb
109 def fastanumeric_quality_scores(seq)
110   qsc = qual_quality_scores(seq)
111   if qsc.size > seq.length then
112     qsc = qsc[0, seq.length]
113   elsif qsc.size < seq.length then
114     padding = @options[:default_score] || 0
115     psize = seq.length - qsc.size
116     qsc += Array.new(psize, padding)
117   end
118   qsc
119 end
qual_quality_scores(seq) click to toggle source
    # File lib/bio/db/fasta/format_qual.rb
121 def qual_quality_scores(seq)
122   return [] if seq.length <= 0
123 
124   # get output quality score type
125   fmt = @options[:quality_score_type]
126 
127   qsc = @sequence.quality_scores
128   qsc_type = @sequence.quality_score_type
129 
130   # checks if no need to convert
131   if qsc and qsc_type == fmt and
132       qsc.size >= seq.length then
133     return qsc
134   end
135 
136   # default output quality score type is :phred
137   fmt ||= :phred
138   # If quality score type of the sequence is nil, implicitly
139   # regarded as :phred.
140   qsc_type ||= :phred
141 
142   # checks error_probabilities
143   ep = @sequence.error_probabilities
144   if ep and ep.size >= seq.length then
145     case fmt
146     when :phred
147       return Bio::Sequence::QualityScore::Phred.p2q(ep[0, seq.length])
148     when :solexa
149       return Bio::Sequence::QualityScore::Solexa.p2q(ep[0, seq.length])
150     end
151   end
152 
153   # Checks if scores can be converted.
154   if qsc and qsc.size >= seq.length then
155     case [ qsc_type, fmt ]
156     when [ :phred, :solexa ]
157       return Bio::Sequence::QualityScore::Phred.convert_scores_to_solexa(qsc[0, seq.length])
158     when [ :solexa, :phred ]
159       return Bio::Sequence::QualityScore::Solexa.convert_scores_to_phred(qsc[0, seq.length])
160     end
161   end
162 
163   # checks quality scores type
164   case qsc_type
165   when :phred, :solexa
166     #does nothing
167   else
168     qsc_type = nil
169     qsc = nil
170   end
171 
172   # collects piece of information
173   qsc_cov = qsc ? qsc.size.quo(seq.length) : 0
174   ep_cov = ep ? ep.size.quo(seq.length) : 0
175   if qsc_cov > ep_cov then
176     case [ qsc_type, fmt ]
177     when [ :phred, :phred ], [ :solexa, :solexa ]
178       return qsc
179     when [ :phred, :solexa ]
180       return Bio::Sequence::QualityScore::Phred.convert_scores_to_solexa(qsc)
181     when [ :solexa, :phred ]
182       return Bio::Sequence::QualityScore::Solexa.convert_scores_to_phred(qsc)
183     end
184   elsif ep_cov > qsc_cov then
185     case fmt
186     when :phred
187       return Bio::Sequence::QualityScore::Phred.p2q(ep)
188     when :solexa
189       return Bio::Sequence::QualityScore::Solexa.p2q(ep)
190     end
191   end
192 
193   # if no information, returns empty array
194   return []
195 end