From: martinahansen Date: Fri, 21 Sep 2012 09:27:34 +0000 (+0000) Subject: added parser for phred qual to fasta.rb X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=354e8c6706ede00940b714bd8f6878b1376dedba;p=biopieces.git added parser for phred qual to fasta.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@1937 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/fasta.rb b/code_ruby/lib/maasha/fasta.rb index d4c443b..c9ce43d 100644 --- a/code_ruby/lib/maasha/fasta.rb +++ b/code_ruby/lib/maasha/fasta.rb @@ -51,6 +51,31 @@ class Fasta < Filesys entry end + + # Method to get the next pseudo FASTA entry consisting of a sequence name and + # space seperated quality scores in decimals instead of sequence. This is + # the quality format used by Sanger and 454. + def get_decimal_qual + block = @io.gets($/ + '>') + return nil if block.nil? + + block.chomp!($/ + '>') + + (seq_name, qual) = block.split($/, 2) + + raise FastaError, "Bad FASTA qual format" if seq_name.nil? or qual.nil? + + entry = Seq.new + entry.seq_name = seq_name.sub(/^>/, '').rstrip + entry.seq = nil + entry.type = nil + entry.qual = qual.tr("\n", " ").strip.split(" ").collect { |q| (q.to_i + SCORE_BASE).chr }.join("") + + raise FastaError, "Bad FASTA format" if entry.seq_name.empty? + raise FastaError, "Bad FASTA format" if entry.qual.empty? + + entry + end end