From 124ad80bd42309d1e6ea7d10dcffb86938c29069 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 28 Feb 2013 10:21:22 +0000 Subject: [PATCH] added Seq.shuffle method and tests git-svn-id: http://biopieces.googlecode.com/svn/trunk@2105 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/lib/maasha/seq.rb | 7 ++++++- code_ruby/test/maasha/test_seq.rb | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index 577d51a..e72250d 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -390,7 +390,12 @@ class Seq seq_new end - # Method to shuffle a sequence readomly inline. + # Method to return a new Seq object with shuffled sequence. + def shuffle + Seq.new(self.seq_name, self.seq.split('').shuffle!.join, self.type, self.qual) + end + + # Method to shuffle a sequence randomly inline. def shuffle! self.seq = self.seq.split('').shuffle!.join self diff --git a/code_ruby/test/maasha/test_seq.rb b/code_ruby/test/maasha/test_seq.rb index a7145ef..f966a5f 100755 --- a/code_ruby/test/maasha/test_seq.rb +++ b/code_ruby/test/maasha/test_seq.rb @@ -9,7 +9,8 @@ class TestSeq < Test::Unit::TestCase @entry = Seq.new end - # def test_Seq# autoremoves whitespace, newlines, and carriage returns + # # autoremoves whitespace, newlines, and carriage returns + # def test_Seq_strip # dna = Seq.new # dna.seq = "A\tT\r\tC\nG " # assert_equal(dna.seq, "ATCG") @@ -277,6 +278,19 @@ class TestSeq < Test::Unit::TestCase end end + def test_Seq_shuffle_returns_correctly + orig = "actgactgactgatcgatcgatcgatcgtactg" + @entry.seq = "actgactgactgatcgatcgatcgatcgtactg" + entry_shuf = @entry.shuffle + assert_equal(orig, @entry.seq) + assert_not_equal(@entry.seq, entry_shuf.seq) + end + + def test_Seq_shuffle_bang_returns_correctly + @entry.seq = "actgactgactgatcgatcgatcgatcgtactg" + assert_not_equal(@entry.seq, @entry.shuffle!.seq) + end + def test_Seq_subseq_with_start_lt_0_raises @entry.seq = "ATCG" assert_raise(SeqError) { @entry.subseq(-1, 1) } -- 2.39.2