]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/seq.rb
added Seq.type_guess to ruby code
[biopieces.git] / code_ruby / lib / maasha / seq.rb
index 21e6e079f0c60a031aa2fb97ef2621c95fff7fb9..a3fe78905159ab4edeee58fcd0067ee4aca2988c 100644 (file)
@@ -86,6 +86,24 @@ class Seq
     @qual     = qual
   end
 
+  # Method that guesses and returns the sequence type
+  # by inspecting the first 100 residues.
+  def type_guess
+    raise SeqError, "Guess failed: sequence is nil" if self.seq.nil?
+
+    case self.seq[0 ... 100].downcase
+    when /[flpqie]/ then return "protein"
+    when /[u]/      then return "rna"
+    else                 return "dna"
+    end
+  end
+
+  # Method that guesses and sets the sequence type
+  # by inspecting the first 100 residues.
+  def type_guess!
+    self.type = self.type_guess
+  end
+
   # Returns the length of a sequence.
   def length
     self.seq.nil? ? 0 : self.seq.length