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_Seq_length_is_correct
47 assert_equal(4, @entry.length)
50 def test_Seq_indels_is_correct
51 @entry.seq = 'ATCG.-~_'
52 assert_equal(4, @entry.indels)
55 def test_Seq_to_rna_raises_if_no_sequence
57 assert_raise(SeqError) { @entry.to_rna }
60 def test_Seq_to_rna_raises_on_bad_type
63 assert_raise(SeqError) { @entry.to_rna }
66 def test_Seq_to_rna_transcribes_correctly
67 @entry.seq = 'ATCGatcg'
69 assert_equal("AUCGaucg", @entry.to_rna)
72 def test_Seq_to_rna_changes_entry_type_to_rna
73 @entry.seq = 'ATCGatcg'
76 assert_equal("rna", @entry.type)
79 def test_Seq_to_dna_raises_if_no_sequence
81 assert_raise(SeqError) { @entry.to_dna }
84 def test_Seq_to_dna_raises_on_bad_type
87 assert_raise(SeqError) { @entry.to_dna }
90 def test_Seq_to_dna_transcribes_correctly
91 @entry.seq = 'AUCGaucg'
93 assert_equal("ATCGatcg", @entry.to_dna)
96 def test_Seq_to_dna_changes_entry_type_to_dna
97 @entry.seq = 'AUCGaucg'
100 assert_equal("dna", @entry.type)
103 def test_Seq_to_bp_returns_correct_record
104 @entry.seq_name = 'test'
106 assert_equal({:SEQ_NAME=>"test", :SEQ=>"ATCG", :SEQ_LEN=>4}, @entry.to_bp)
109 def test_Seq_to_bp_raises_on_missing_seq_name
111 assert_raise(SeqError) { @entry.to_bp }
114 def test_Seq_to_bp_raises_on_missing_sequence
115 @entry.seq_name = 'test'
116 assert_raise(SeqError) { @entry.to_bp }
119 def test_Seq_to_fasta_returns_correct_entry
120 @entry.seq_name = 'test'
122 assert_equal(">test\nATCG\n", @entry.to_fasta)
125 def test_Seq_to_fasta_wraps_correctly
126 entry = Seq.new("test", "ATCG")
127 assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
130 def test_Seq_reverse_returns_correctly
132 assert_equal("GCTA", @entry.reverse)
135 def test_Seq_complement_raises_if_no_sequence
137 assert_raise(SeqError) { @entry.complement }
140 def test_Seq_complement_raises_on_bad_type
142 @entry.type = 'protein'
143 assert_raise(SeqError) { @entry.complement }
146 def test_Seq_complement_for_DNA_is_correct
147 @entry.seq = 'ATCGatcg'
149 assert_equal("TAGCtagc", @entry.complement)
152 def test_Seq_complement_for_RNA_is_correct
153 @entry.seq = 'AUCGaucg'
155 assert_equal("UAGCuagc", @entry.complement)
158 def test_Seq_reverse_complement_for_DNA_is_correct
159 @entry.seq = 'ATCGatcg'
161 assert_equal("cgatCGAT", @entry.reverse_complement)
164 def test_Seq_reverse_complement_for_RNA_is_correct
165 @entry.seq = 'AUCGaucg'
167 assert_equal("cgauCGAU", @entry.reverse_complement)
170 def test_Seq_generate_raises_if_length_lt_0
171 assert_raise(SeqError) { @entry.generate(-10, "dna") }
172 assert_raise(SeqError) { @entry.generate(0, "dna") }
175 def test_Seq_generate_raises_on_bad_type
176 assert_raise(SeqError) { @entry.generate(10, "foo") }
179 def test_Seq_generate_dont_raise_on_ok_type
180 %w[ dna DNA rna RNA protein Protein ].each do |type|
181 assert_nothing_raised { @entry.generate(10, type) }
185 def test_Seq_composition_returns_correctly
186 @entry.seq = "AAAATTTCCG"
187 assert_equal(4, @entry.composition["A"])
188 assert_equal(3, @entry.composition["T"])
189 assert_equal(2, @entry.composition["C"])
190 assert_equal(1, @entry.composition["G"])
191 assert_equal(0, @entry.composition["X"])
194 def test_Seq_homopol_max_returns_0_with_empty_sequence
196 assert_equal(0, @entry.homopol_max)
199 def test_Seq_homopol_max_returns_0_with_nil_sequence
201 assert_equal(0, @entry.homopol_max)
204 def test_Seq_homopol_max_returns_0_when_not_found
205 @entry.seq = "AtTcCcGggGnnNnn"
206 assert_equal(0, @entry.homopol_max(6))
209 def test_Seq_homopol_max_returns_correctly
210 @entry.seq = "AtTcCcGggGnnNnn"
211 assert_equal(5, @entry.homopol_max(3))
214 def test_Seq_hard_mask_returns_correctly
215 @entry.seq = "--AAAANn"
216 assert_equal(33.33, @entry.hard_mask)
219 def test_Seq_soft_mask_returns_correctly
220 @entry.seq = "--AAAa"
221 assert_equal(25.00, @entry.soft_mask)
224 def test_Digest_new_raises_on_bad_pattern_residue
225 assert_raise(DigestError) { Digest.new(@entry, "X", 4) }
228 def test_Digest_new_dont_raise_on_ok_pattern_residue
229 assert_nothing_raised { Digest.new(@entry, "AGCUTRYWSMKHDVBNagcutrywsmkhdvbn", 4) }
233 @entry.seq = "aaaaTTTTbbbbTTTT"
234 digest = Digest.new(@entry, "TTNT", 1)
235 assert_equal("aaaaT", digest.first.seq)
242 class TestSeq < Test::Unit::TestCase
243 # Testing Seq#guess_type
245 def test_guess_type_raise_if_no_sequence
248 assert_raise( ArgumentError ) { s.guess_type }
251 def test_guess_type_AA_uppercase
252 s1 = Seq.new( "SEQ" )
253 s2 = Seq::AA.new( "SEQ" )
254 assert_equal( s1.guess_type.class, s2.class )
257 def test_guess_type_AA_lowercase
258 s1 = Seq.new( "seq" )
259 s2 = Seq::AA.new( "seq" )
261 assert_equal( s1.guess_type.class, s2.class )
264 def test_guess_type_DNA_uppercase
265 s1 = Seq.new( "ATCG" )
266 s2 = Seq::NA::DNA.new( "ATCG" )
268 assert_equal( s1.guess_type.class, s2.class )
271 def test_guess_type_DNA_lowercase
272 s1 = Seq.new( "atcg" )
273 s2 = Seq::NA::DNA.new( "atcg" )
275 assert_equal( s1.guess_type.class, s2.class )
278 def test_guess_type_RNA_uppercase
279 s1 = Seq.new( "AUCG" )
280 s2 = Seq::NA::RNA.new( "AUCG" )
282 assert_equal( s1.guess_type.class, s2.class )
285 def test_guess_type_RNA_lowercase
286 s1 = Seq.new( "aucg" )
287 s2 = Seq::NA::RNA.new( "aucg" )
289 assert_equal( s1.guess_type.class, s2.class )
294 def test_wrap_arg_is_a_positive_number
297 assert_raise( ArgumentError ) { s.wrap( 0 ) }
298 assert_raise( ArgumentError ) { s.wrap( -10 ) }
301 def test_wrap_with_0_args
302 s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
304 assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap.to_s )
307 def test_wrap_with_1_args
308 s = Seq.new( "ATCG" )
310 assert_equal( "AT\nCG", s.wrap( 2 ).to_s )
313 def test_wrap_with_2_args
314 s = Seq.new( "ATCG" )
316 assert_equal( "AT\rCG", s.wrap( 2, "\r" ).to_s )
319 def test_wrap_dont_change_instance_var
320 s = Seq.new( "ATCG" )
324 assert_equal( "ATCG", s.to_s )
329 def test_wrap_with_0_args!
330 s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
334 assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.to_s )
337 def test_wrap_with_1_args!
338 s = Seq.new( "ATCG" )
342 assert_equal( "AT\nCG", s.to_s )
345 def test_wrap_with_2_args!
346 s = Seq.new( "ATCG" )
350 assert_equal( "AT\rCG", s.to_s )
353 # Testing Seq#generate
355 def test_generate_arg_is_a_positive_number
358 assert_raise( ArgumentError ) { s.generate( 0 ) }
359 assert_raise( ArgumentError ) { s.generate( -10 ) }
365 seq = s.generate( 40 )
367 assert_equal( 40, seq.length )
370 def test_generate_dont_change_instance_var
373 seq = s.generate( 40 )
375 assert_equal( "", s.to_s )
378 # Testing Seq#generate!
385 assert_equal( 40, s.length )
388 # Testing Seq::AA#residues
390 def test_Seq_AA_residues
393 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 )
396 # Testing Seq::AA#mol_weight
398 def test_Seq_aa_mol_weight_bad_residue
399 s = Seq::AA.new( "7" )
400 assert_raise( ArgumentError ) { s.mol_weight }
403 def test_Seq_aa_mol_wight_return_correct_uppercase
404 s = Seq::AA.new( "SEQ" )
405 assert_equal( 398.0, s.mol_weight )
408 def test_Seq_aa_mol_wight_return_correct_lowercase
409 s = Seq::AA.new( "seq" )
410 assert_equal( 398.0, s.mol_weight )
413 # Testing Seq::NA::DNA#residues
415 def test_Seq_NA_DNA_residues
418 assert_equal( %w{ A T C G }, s.residues )
421 # Testing Seq::NA::DNA#complement
423 def test_Seq_NA_DNA_complement_correct
424 s = Seq::NA::DNA.new( "ATCGatcg" )
425 assert_equal( "TAGCtagc", s.complement.to_s )
428 # Testing Seq::NA::DNA#to_RNA
430 def test_Seq_NA_DNA_to_RNA_returns_RNA_object
431 dna = Seq::NA::DNA.new( "ATCGatcg" )
432 rna = Seq::NA::RNA.new
436 assert_equal( rna.class, new_rna.class )
439 def test_Seq_NA_DNA_to_RNA_is_correct
440 dna = Seq::NA::DNA.new( "ATCGatcg" )
443 assert_equal( "AUCGaucg", rna.to_s )
446 # Testing Seq::NA::RNA#residues
448 def test_Seq_NA_RNA_residues
451 assert_equal( %w{ A U C G }, s.residues )
454 # Testing Seq::NA::RNA#complement
456 def test_Seq_NA_RNA_complement_correct
457 s = Seq::NA::RNA.new( "AUCGaucg" )
458 assert_equal( "UAGCuagc", s.complement.to_s )
461 # Testing Seq::NA::RNA#to_DNA
463 def test_Seq_NA_RNA_to_DNA_returns_DNA_object
464 rna = Seq::NA::RNA.new( "AUCGaucg" )
465 dna = Seq::NA::DNA.new
469 assert_equal( dna.class, new_dna.class )
472 def test_Seq_NA_RNA_to_DNA_is_correct
473 rna = Seq::NA::RNA.new( "AUCGaucg" )
476 assert_equal( "ATCGatcg", dna.to_s )