]> git.donarmstrong.com Git - biopieces.git/commitdiff
added Seq.type_guess to ruby code
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 13 Jun 2011 20:43:28 +0000 (20:43 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 13 Jun 2011 20:43:28 +0000 (20:43 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1468 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq.rb
code_ruby/test/maasha/test_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
index 5e79a0ff4b5a048e1da3c300b45a317743093207..93737d44280dbf02d8c029048ada0d2a51816998 100755 (executable)
@@ -39,7 +39,48 @@ class TestSeq < Test::Unit::TestCase
 
   def test_Seq_is_protein_with_protein_sequence_type_returns_true
     @entry.type = 'protein'
-    assert(@entry.is_protein? == true)
+    assert_equal(true, @entry.is_protein?)
+  end
+
+  def test_Seq_type_guess_without_sequence_raises
+    assert_raise(SeqError) { @entry.type_guess }
+  end
+
+  def test_Seq_type_guess_with_protein_returns_protein
+    @entry.seq = 'atcatcrFgatcg'
+    assert_equal('protein', @entry.type_guess)
+  end
+
+  def test_Seq_type_guess_with_rna_returns_rna
+    @entry.seq = 'atcatcrUgatcg'
+    assert_equal('rna', @entry.type_guess)
+  end
+
+  def test_Seq_type_guess_with_dna_returns_dna
+    @entry.seq = 'atcatcgatcg'
+    assert_equal('dna', @entry.type_guess)
+  end
+
+  def test_Seq_type_guess_EM_without_sequence_raises
+    assert_raise(SeqError) { @entry.type_guess! }
+  end
+
+  def test_Seq_type_guess_EM_with_protein_returns_protein
+    @entry.seq = 'atcatcrFgatcg'
+    @entry.type_guess!
+    assert_equal('protein', @entry.type)
+  end
+
+  def test_Seq_type_guess_EM_with_rna_returns_rna
+    @entry.seq = 'atcatcrUgatcg'
+    @entry.type_guess!
+    assert_equal('rna', @entry.type)
+  end
+
+  def test_Seq_type_guess_EM_with_dna_returns_dna
+    @entry.seq = 'atcatcgatcg'
+    @entry.type_guess!
+    assert_equal('dna', @entry.type)
   end
 
   def test_Seq_length_is_correct