From: martinahansen Date: Fri, 3 Jul 2009 15:08:59 +0000 (+0000) Subject: last cleanups X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e446cc78c79404a09c5109e8f046567d9c9657ee;p=biopieces.git last cleanups git-svn-id: http://biopieces.googlecode.com/svn/trunk@553 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/Maasha/lib/seq.rb b/code_ruby/Maasha/lib/seq.rb index f80d397..8146ab4 100644 --- a/code_ruby/Maasha/lib/seq.rb +++ b/code_ruby/Maasha/lib/seq.rb @@ -121,6 +121,12 @@ class Seq < String class NA < Seq # Class containing methods specific for DNA sequences. class DNA < NA + # Method to initialize a new DNA sequence. + def initialize( seq = "" ) + @seq = seq + @seq_type = :DNA + end + # Method that complements DNA sequence including ambiguity codes. def complement @seq.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'TCGAAYRWSKMDHBVNtcgaayrwskmdhbvn' ) @@ -129,6 +135,12 @@ class Seq < String # Class containing methods specific for RNA sequences. class RNA < NA + # Method to initialize a new RNA sequence. + def initialize( seq = "" ) + @seq = seq + @seq_type = :RNA + end + # Method that complements RNA sequence including ambiguity codes. def complement @seq.tr!( 'AGCUTRYWSMKHDVBNagcutrywsmkhdvbn', 'UCGAAYRWSKMDHBVNucgaayrwskmdhbvn' ) diff --git a/code_ruby/Maasha/test/test_seq.rb b/code_ruby/Maasha/test/test_seq.rb index 4297720..e6e28a2 100755 --- a/code_ruby/Maasha/test/test_seq.rb +++ b/code_ruby/Maasha/test/test_seq.rb @@ -263,5 +263,63 @@ class TestSeq < Test::Unit::TestCase assert_equal( "SEQ", s.to_s ) assert_equal( :AA, s.seq_type ) end + + # Testing Seq::AA#mol_weight + + def test_Seq_aa_mol_wight_bad_residue + s = Seq::AA.new( "7" ) + assert_raise( RuntimeError ) { s.mol_weight } + end + + def test_Seq_aa_mol_wight_return_correct + s = Seq::AA.new( "SEQ" ) + assert_equal( 398.0, s.mol_weight ) + end + + # Testing Seq::NA::DNA#initialize + + # test marked for deletion - too simple and not informative + def test_Seq_NA_DNA_inialize_with_0_args + s = Seq::NA::DNA.new + assert_equal( "", s.to_s ) + assert_equal( :DNA, s.seq_type ) + end + + # test marked for deletion - too simple and not informative + def test_Seq_NA_DNA_inialize_with_1_args + s = Seq::NA::DNA.new( "ATCG" ) + assert_equal( "ATCG", s.to_s ) + assert_equal( :DNA, s.seq_type ) + end + + # Testing Seq::NA::DNA#complement + + def test_Seq_NA_DNA_complement_correct + s = Seq::NA::DNA.new( "ATCG" ) + assert_equal( "TAGC", s.complement.to_s ) + end + + # Testing Seq::NA::RNA#initialize + + # test marked for deletion - too simple and not informative + def test_Seq_NA_RNA_inialize_with_0_args + s = Seq::NA::RNA.new + assert_equal( "", s.to_s ) + assert_equal( :RNA, s.seq_type ) + end + + # test marked for deletion - too simple and not informative + def test_Seq_NA_RNA_inialize_with_1_args + s = Seq::NA::RNA.new( "AUCG" ) + assert_equal( "AUCG", s.to_s ) + assert_equal( :RNA, s.seq_type ) + end + + # Testing Seq::NA::RNA#complement + + def test_Seq_NA_DNA_complement_correct + s = Seq::NA::RNA.new( "AUCG" ) + assert_equal( "UAGC", s.complement.to_s ) + end end