7 class TestSeq < Test::Unit::TestCase
12 # def test_Seq# autoremoves whitespace, newlines, and carriage returns
14 # dna.seq = "A\tT\r\tC\nG "
15 # assert_equal(dna.seq, "ATCG")
18 def test_Seq_is_dna_with_no_sequence_type_returns_false
19 assert(@entry.is_dna? == false)
22 def test_Seq_is_dna_with_dna_sequence_type_returns_true
24 assert(@entry.is_dna? == true)
27 def test_Seq_is_rna_with_no_sequence_type_returns_false
28 assert(@entry.is_rna? == false)
31 def test_Seq_is_rna_with_rna_sequence_type_returns_true
33 assert(@entry.is_rna? == true)
36 def test_Seq_is_protein_with_no_sequence_type_returns_false
37 assert(@entry.is_protein? == false)
40 def test_Seq_is_protein_with_protein_sequence_type_returns_true
41 @entry.type = 'protein'
42 assert(@entry.is_protein? == true)
45 def test_Sequence_length_is_correct
47 assert_equal(4, @entry.length)
50 def test_Seq_to_rna_raises_if_no_sequence
52 assert_raise(SeqError) { @entry.to_rna }
55 def test_Seq_to_rna_raises_on_bad_type
58 assert_raise(SeqError) { @entry.to_rna }
61 def test_Seq_to_rna_transcribes_correctly
62 @entry.seq = 'ATCGatcg'
64 assert_equal("AUCGaucg", @entry.to_rna)
67 def test_Seq_to_rna_changes_entry_type_to_rna
68 @entry.seq = 'ATCGatcg'
71 assert_equal("rna", @entry.type)
74 def test_Seq_to_dna_raises_if_no_sequence
76 assert_raise(SeqError) { @entry.to_dna }
79 def test_Seq_to_dna_raises_on_bad_type
82 assert_raise(SeqError) { @entry.to_dna }
85 def test_Seq_to_dna_transcribes_correctly
86 @entry.seq = 'AUCGaucg'
88 assert_equal("ATCGatcg", @entry.to_dna)
91 def test_Seq_to_dna_changes_entry_type_to_dna
92 @entry.seq = 'AUCGaucg'
95 assert_equal("dna", @entry.type)
98 def test_Seq_to_bp_returns_correct_record
99 @entry.seq_name = 'test'
101 assert_equal({:SEQ_NAME=>"test", :SEQ=>"ATCG", :SEQ_LEN=>4}, @entry.to_bp)
104 def test_Seq_to_bp_raises_on_missing_seq_name
106 assert_raise(SeqError) { @entry.to_bp }
109 def test_Seq_to_bp_raises_on_missing_sequence
110 @entry.seq_name = 'test'
111 assert_raise(SeqError) { @entry.to_bp }
114 def test_Seq_to_fasta_returns_correct_entry
115 @entry.seq_name = 'test'
117 assert_equal(">test\nATCG\n", @entry.to_fasta)
120 def test_Seq_to_fasta_wraps_correctly
121 entry = Seq.new("test", "ATCG")
122 assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
125 def test_Seq_reverse_returns_correctly
127 assert_equal("GCTA", @entry.reverse)
130 def test_Seq_complement_raises_if_no_sequence
132 assert_raise(SeqError) { @entry.complement }
135 def test_Seq_complement_raises_on_bad_type
137 @entry.type = 'protein'
138 assert_raise(SeqError) { @entry.complement }
141 def test_Seq_complement_for_DNA_is_correct
142 @entry.seq = 'ATCGatcg'
144 assert_equal("TAGCtagc", @entry.complement)
147 def test_Seq_complement_for_RNA_is_correct
148 @entry.seq = 'AUCGaucg'
150 assert_equal("UAGCuagc", @entry.complement)
153 def test_Seq_reverse_complement_for_DNA_is_correct
154 @entry.seq = 'ATCGatcg'
156 assert_equal("cgatCGAT", @entry.reverse_complement)
159 def test_Seq_reverse_complement_for_RNA_is_correct
160 @entry.seq = 'AUCGaucg'
162 assert_equal("cgauCGAU", @entry.reverse_complement)
165 def test_Seq_generate_raises_if_length_lt_0
166 assert_raise(SeqError) { @entry.generate(-10, "dna") }
167 assert_raise(SeqError) { @entry.generate(0, "dna") }
170 def test_Seq_generate_raises_on_bad_type
171 assert_raise(SeqError) { @entry.generate(10, "foo") }
174 def test_Seq_generate_dont_raise_on_ok_type
175 %w[ dna DNA rna RNA protein Protein ].each do |type|
176 assert_nothing_raised { @entry.generate(10, type) }
180 def test_Digest_new_raises_on_bad_pattern_residue
181 assert_raise(DigestError) { Digest.new(@entry, "X", 4) }
184 def test_Digest_new_dont_raise_on_ok_pattern_residue
185 assert_nothing_raised { Digest.new(@entry, "AGCUTRYWSMKHDVBNagcutrywsmkhdvbn", 4) }
188 def test_Digest_positions_return_correctly_at_begin
189 @entry.seq = "TTTTaaa"
190 digest = Digest.new(@entry, "TTTT", 0)
191 assert_equal([], digest.positions)
194 def test_Digest_positions_return_correctly
195 @entry.seq = "TTTTaaa"
196 digest = Digest.new(@entry, "TTTT", 1)
197 assert_equal([0], digest.positions)
200 def test_Digest_positions_return_correctly_at_end
201 @entry.seq = "aaaTTTT"
202 digest = Digest.new(@entry, "TTTT", 3)
203 assert_equal([], digest.positions)
206 def test_Digest_positions_return_correctly_with_ambibuity_pattern
207 @entry.seq = "aaaTTTT"
208 digest = Digest.new(@entry, "TTNT", 1)
209 assert_equal([3], digest.positions)
212 def test_Digest_products_return_correctly
213 @entry.seq = "aaaaTTTTbbbbTTTT"
214 digest = Digest.new(@entry, "TTNT", 1)
215 assert_equal(["aaaaT", "TTTbbbbT", "TTT"], digest.products)
222 class TestSeq < Test::Unit::TestCase
223 # Testing Seq#guess_type
225 def test_guess_type_raise_if_no_sequence
228 assert_raise( ArgumentError ) { s.guess_type }
231 def test_guess_type_AA_uppercase
232 s1 = Seq.new( "SEQ" )
233 s2 = Seq::AA.new( "SEQ" )
234 assert_equal( s1.guess_type.class, s2.class )
237 def test_guess_type_AA_lowercase
238 s1 = Seq.new( "seq" )
239 s2 = Seq::AA.new( "seq" )
241 assert_equal( s1.guess_type.class, s2.class )
244 def test_guess_type_DNA_uppercase
245 s1 = Seq.new( "ATCG" )
246 s2 = Seq::NA::DNA.new( "ATCG" )
248 assert_equal( s1.guess_type.class, s2.class )
251 def test_guess_type_DNA_lowercase
252 s1 = Seq.new( "atcg" )
253 s2 = Seq::NA::DNA.new( "atcg" )
255 assert_equal( s1.guess_type.class, s2.class )
258 def test_guess_type_RNA_uppercase
259 s1 = Seq.new( "AUCG" )
260 s2 = Seq::NA::RNA.new( "AUCG" )
262 assert_equal( s1.guess_type.class, s2.class )
265 def test_guess_type_RNA_lowercase
266 s1 = Seq.new( "aucg" )
267 s2 = Seq::NA::RNA.new( "aucg" )
269 assert_equal( s1.guess_type.class, s2.class )
274 def test_wrap_arg_is_a_positive_number
277 assert_raise( ArgumentError ) { s.wrap( 0 ) }
278 assert_raise( ArgumentError ) { s.wrap( -10 ) }
281 def test_wrap_with_0_args
282 s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
284 assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap.to_s )
287 def test_wrap_with_1_args
288 s = Seq.new( "ATCG" )
290 assert_equal( "AT\nCG", s.wrap( 2 ).to_s )
293 def test_wrap_with_2_args
294 s = Seq.new( "ATCG" )
296 assert_equal( "AT\rCG", s.wrap( 2, "\r" ).to_s )
299 def test_wrap_dont_change_instance_var
300 s = Seq.new( "ATCG" )
304 assert_equal( "ATCG", s.to_s )
309 def test_wrap_with_0_args!
310 s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
314 assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.to_s )
317 def test_wrap_with_1_args!
318 s = Seq.new( "ATCG" )
322 assert_equal( "AT\nCG", s.to_s )
325 def test_wrap_with_2_args!
326 s = Seq.new( "ATCG" )
330 assert_equal( "AT\rCG", s.to_s )
333 # Testing Seq#generate
335 def test_generate_arg_is_a_positive_number
338 assert_raise( ArgumentError ) { s.generate( 0 ) }
339 assert_raise( ArgumentError ) { s.generate( -10 ) }
345 seq = s.generate( 40 )
347 assert_equal( 40, seq.length )
350 def test_generate_dont_change_instance_var
353 seq = s.generate( 40 )
355 assert_equal( "", s.to_s )
358 # Testing Seq#generate!
365 assert_equal( 40, s.length )
368 # Testing Seq::AA#residues
370 def test_Seq_AA_residues
373 assert_equal( %w{ F L S Y C W P H Q R I M T N K V A D E G }, s.residues )
376 # Testing Seq::AA#mol_weight
378 def test_Seq_aa_mol_weight_bad_residue
379 s = Seq::AA.new( "7" )
380 assert_raise( ArgumentError ) { s.mol_weight }
383 def test_Seq_aa_mol_wight_return_correct_uppercase
384 s = Seq::AA.new( "SEQ" )
385 assert_equal( 398.0, s.mol_weight )
388 def test_Seq_aa_mol_wight_return_correct_lowercase
389 s = Seq::AA.new( "seq" )
390 assert_equal( 398.0, s.mol_weight )
393 # Testing Seq::NA::DNA#residues
395 def test_Seq_NA_DNA_residues
398 assert_equal( %w{ A T C G }, s.residues )
401 # Testing Seq::NA::DNA#complement
403 def test_Seq_NA_DNA_complement_correct
404 s = Seq::NA::DNA.new( "ATCGatcg" )
405 assert_equal( "TAGCtagc", s.complement.to_s )
408 # Testing Seq::NA::DNA#to_RNA
410 def test_Seq_NA_DNA_to_RNA_returns_RNA_object
411 dna = Seq::NA::DNA.new( "ATCGatcg" )
412 rna = Seq::NA::RNA.new
416 assert_equal( rna.class, new_rna.class )
419 def test_Seq_NA_DNA_to_RNA_is_correct
420 dna = Seq::NA::DNA.new( "ATCGatcg" )
423 assert_equal( "AUCGaucg", rna.to_s )
426 # Testing Seq::NA::RNA#residues
428 def test_Seq_NA_RNA_residues
431 assert_equal( %w{ A U C G }, s.residues )
434 # Testing Seq::NA::RNA#complement
436 def test_Seq_NA_RNA_complement_correct
437 s = Seq::NA::RNA.new( "AUCGaucg" )
438 assert_equal( "UAGCuagc", s.complement.to_s )
441 # Testing Seq::NA::RNA#to_DNA
443 def test_Seq_NA_RNA_to_DNA_returns_DNA_object
444 rna = Seq::NA::RNA.new( "AUCGaucg" )
445 dna = Seq::NA::DNA.new
449 assert_equal( dna.class, new_dna.class )
452 def test_Seq_NA_RNA_to_DNA_is_correct
453 rna = Seq::NA::RNA.new( "AUCGaucg" )
456 assert_equal( "ATCGatcg", dna.to_s )