X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fscores_to_dec;h=b69f37c950fecc3afa0c24a494dd17283b100fd8;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=b93587f3db97f5af3557e853b2472aaa549063d8;hpb=5a9b7c80e4e4428e404575ed3c0290cde15a7402;p=biopieces.git diff --git a/bp_bin/scores_to_dec b/bp_bin/scores_to_dec index b93587f..b69f37c 100755 --- a/bp_bin/scores_to_dec +++ b/bp_bin/scores_to_dec @@ -30,29 +30,19 @@ require 'maasha/biopieces' require 'maasha/seq' - -# Expading class Hash with possibly evil monkey patch. -class Hash - # Method to convert scores from ASCII encode string to - # a semi-colon seperated string of decimal values. - def scores2dec! - if self[:SCORES] - self[:SCORES].gsub! /./ do |score| - score = (score.ord - Seq::SCORE_BASE).to_s + ";" - end - - self[:SCORES].chomp! ";" - end - - self - end -end +require 'narray' options = Biopieces.options_parse(ARGV) Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| input.each_record do |record| - output.puts record.scores2dec! + if record[:SCORES] + na = NArray.to_na(record[:SCORES], "byte") + na -= Seq::SCORE_BASE + record[:SCORES] = na.to_a.join("; ") + end + + output.puts record end end