]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/test/maasha/test_seq.rb
refactoring of revcomp in seq.rb
[biopieces.git] / code_ruby / test / maasha / test_seq.rb
1 #!/usr/bin/env ruby
2
3 require 'maasha/seq'
4 require 'test/unit'
5 require 'pp'
6
7 class TestSeq < Test::Unit::TestCase 
8   def setup
9     @entry = Seq.new
10   end
11
12   #  # autoremoves whitespace, newlines, and carriage returns
13   #  def test_Seq_strip
14   #    dna = Seq.new
15   #    dna.seq = "A\tT\r\tC\nG  "
16   #    assert_equal(dna.seq, "ATCG")
17   #  end
18   
19   def test_Seq_new_bp_returns_correctly
20     record = {:SEQ_NAME => "test", :SEQ => "ATCG", :SEQ_TYPE => "dna", :SCORES => "hhhh"}
21     seq    = Seq.new_bp(record)
22     assert_equal("test", seq.seq_name)
23     assert_equal("ATCG", seq.seq)
24     assert_equal("dna",  seq.type)
25     assert_equal("hhhh", seq.qual)
26   end
27
28   def test_Seq_is_dna_with_no_sequence_type_returns_false
29     assert(@entry.is_dna? == false)
30   end
31
32   def test_Seq_is_dna_with_dna_sequence_type_returns_true
33     @entry.type = 'dna'
34     assert(@entry.is_dna? == true)
35   end
36
37   def test_Seq_is_rna_with_no_sequence_type_returns_false
38     assert(@entry.is_rna? == false)
39   end
40
41   def test_Seq_is_rna_with_rna_sequence_type_returns_true
42     @entry.type = 'rna'
43     assert(@entry.is_rna? == true)
44   end
45
46   def test_Seq_is_protein_with_no_sequence_type_returns_false
47     assert(@entry.is_protein? == false)
48   end
49
50   def test_Seq_is_protein_with_protein_sequence_type_returns_true
51     @entry.type = 'protein'
52     assert_equal(true, @entry.is_protein?)
53   end
54
55   def test_Seq_type_guess_without_sequence_raises
56     assert_raise(SeqError) { @entry.type_guess }
57   end
58
59   def test_Seq_type_guess_with_protein_returns_protein
60     @entry.seq = 'atcatcrFgatcg'
61     assert_equal('protein', @entry.type_guess)
62   end
63
64   def test_Seq_type_guess_with_rna_returns_rna
65     @entry.seq = 'atcatcrUgatcg'
66     assert_equal('rna', @entry.type_guess)
67   end
68
69   def test_Seq_type_guess_with_dna_returns_dna
70     @entry.seq = 'atcatcgatcg'
71     assert_equal('dna', @entry.type_guess)
72   end
73
74   def test_Seq_type_guess_EM_without_sequence_raises
75     assert_raise(SeqError) { @entry.type_guess! }
76   end
77
78   def test_Seq_type_guess_EM_with_protein_returns_protein
79     @entry.seq = 'atcatcrFgatcg'
80     @entry.type_guess!
81     assert_equal('protein', @entry.type)
82   end
83
84   def test_Seq_type_guess_EM_with_rna_returns_rna
85     @entry.seq = 'atcatcrUgatcg'
86     @entry.type_guess!
87     assert_equal('rna', @entry.type)
88   end
89
90   def test_Seq_type_guess_EM_with_dna_returns_dna
91     @entry.seq = 'atcatcgatcg'
92     @entry.type_guess!
93     assert_equal('dna', @entry.type)
94   end
95
96   def test_Seq_length_is_correct
97     @entry.seq = 'ATCG'
98     assert_equal(4, @entry.length)
99   end
100
101   def test_Seq_indels_is_correct
102     @entry.seq = 'ATCG.-~_'
103     assert_equal(4, @entry.indels)
104   end
105
106   def test_Seq_to_rna_raises_if_no_sequence
107     @entry.type = 'dna'
108     assert_raise(SeqError) { @entry.to_rna }
109   end
110
111   def test_Seq_to_rna_raises_on_bad_type
112     @entry.seq  = 'ATCG'
113     @entry.type = 'rna'
114     assert_raise(SeqError) { @entry.to_rna }
115   end
116
117   def test_Seq_to_rna_transcribes_correctly
118     @entry.seq  = 'ATCGatcg'
119     @entry.type = 'dna'
120     assert_equal("AUCGaucg", @entry.to_rna)
121   end
122
123   def test_Seq_to_rna_changes_entry_type_to_rna
124     @entry.seq  = 'ATCGatcg'
125     @entry.type = 'dna'
126     @entry.to_rna
127     assert_equal("rna", @entry.type)
128   end
129
130   def test_Seq_to_dna_raises_if_no_sequence
131     @entry.type = 'rna'
132     assert_raise(SeqError) { @entry.to_dna }
133   end
134
135   def test_Seq_to_dna_raises_on_bad_type
136     @entry.seq  = 'AUCG'
137     @entry.type = 'dna'
138     assert_raise(SeqError) { @entry.to_dna }
139   end
140
141   def test_Seq_to_dna_transcribes_correctly
142     @entry.seq  = 'AUCGaucg'
143     @entry.type = 'rna'
144     assert_equal("ATCGatcg", @entry.to_dna)
145   end
146
147   def test_Seq_to_dna_changes_entry_type_to_dna
148     @entry.seq  = 'AUCGaucg'
149     @entry.type = 'rna'
150     @entry.to_dna
151     assert_equal("dna", @entry.type)
152   end
153
154   def test_Seq_to_bp_returns_correct_record
155     @entry.seq_name = 'test'
156     @entry.seq      = 'ATCG'
157     assert_equal({:SEQ_NAME=>"test", :SEQ=>"ATCG", :SEQ_LEN=>4}, @entry.to_bp)
158   end
159
160   def test_Seq_to_bp_raises_on_missing_seq_name
161     @entry.seq = 'ATCG'
162     assert_raise(SeqError) { @entry.to_bp }
163   end
164
165   def test_Seq_to_bp_raises_on_missing_sequence
166     @entry.seq_name = 'test'
167     assert_raise(SeqError) { @entry.to_bp }
168   end
169
170   def test_Seq_to_fasta_raises_on_missing_seq_name
171     @entry.seq = 'ATCG'
172     assert_raise(SeqError) { @entry.to_fasta }
173   end
174
175   def test_Seq_to_fasta_raises_on_empty_seq_name
176     @entry.seq_name = ''
177     @entry.seq      = 'ATCG'
178     assert_raise(SeqError) { @entry.to_fasta }
179   end
180
181   def test_Seq_to_fasta_raises_on_missing_seq
182     @entry.seq_name = 'test'
183     assert_raise(SeqError) { @entry.to_fasta }
184   end
185
186   def test_Seq_to_fasta_raises_on_empty_seq
187     @entry.seq_name = 'test'
188     @entry.seq      = ''
189     assert_raise(SeqError) { @entry.to_fasta }
190   end
191
192   def test_Seq_to_fasta_returns_correct_entry
193     @entry.seq_name = 'test'
194     @entry.seq      = 'ATCG'
195     assert_equal(">test\nATCG\n", @entry.to_fasta)
196   end
197
198   def test_Seq_to_fasta_wraps_correctly
199     entry = Seq.new("test", "ATCG")
200     assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
201   end
202
203   def test_Seq_to_fastq_returns_correct_entry
204     @entry.seq_name = 'test'
205     @entry.seq      = 'ATCG'
206     @entry.qual     = 'hhhh'
207     assert_equal("@test\nATCG\n+\nhhhh\n", @entry.to_fastq)
208   end
209
210   def test_Seq_to_key_with_bad_residue_raises
211     entry = Seq.new("test", "AUCG")
212     assert_raise(SeqError) { entry.to_key }
213   end
214
215   def test_Seq_to_key_returns_correctly
216     entry = Seq.new("test", "ATCG")
217     assert_equal(54, entry.to_key)
218   end
219
220   def test_Seq_reverse_returns_correctly
221     @entry.seq = "ATCG"
222     new_entry  = @entry.reverse
223     assert_equal("GCTA", new_entry.seq)
224     assert_equal("ATCG", @entry.seq)
225   end
226
227   def test_Seq_reverse_bang_returns_correctly
228     @entry.seq = "ATCG"
229     @entry.reverse!
230     assert_equal("GCTA", @entry.seq)
231   end
232
233   def test_Seq_complement_raises_if_no_sequence
234     @entry.type = 'dna'
235     assert_raise(SeqError) { @entry.complement }
236   end
237
238   def test_Seq_complement_raises_on_bad_type
239     @entry.seq  = 'ATCG'
240     @entry.type = 'protein'
241     assert_raise(SeqError) { @entry.complement }
242   end
243
244   def test_Seq_complement_for_DNA_is_correct
245     @entry.seq  = 'ATCGatcg'
246     @entry.type = 'dna'
247     comp        = @entry.complement
248     assert_equal("TAGCtagc", comp.seq)
249     assert_equal("ATCGatcg", @entry.seq)
250   end
251
252   def test_Seq_complement_for_RNA_is_correct
253     @entry.seq  = 'AUCGaucg'
254     @entry.type = 'rna'
255     comp        = @entry.complement
256     assert_equal("UAGCuagc", comp.seq)
257     assert_equal("AUCGaucg", @entry.seq)
258   end
259
260   def test_Seq_complement_bang_raises_if_no_sequence
261     @entry.type = 'dna'
262     assert_raise(SeqError) { @entry.complement! }
263   end
264
265   def test_Seq_complement_bang_raises_on_bad_type
266     @entry.seq  = 'ATCG'
267     @entry.type = 'protein'
268     assert_raise(SeqError) { @entry.complement! }
269   end
270
271   def test_Seq_complement_bang_for_DNA_is_correct
272     @entry.seq  = 'ATCGatcg'
273     @entry.type = 'dna'
274     assert_equal("TAGCtagc", @entry.complement!.seq)
275   end
276
277   def test_Seq_complement_bang_for_RNA_is_correct
278     @entry.seq  = 'AUCGaucg'
279     @entry.type = 'rna'
280     assert_equal("UAGCuagc", @entry.complement!.seq)
281   end
282
283
284   def test_Seq_hamming_distance_returns_correctly
285     seq1 = Seq.new("test1", "ATCG")
286     seq2 = Seq.new("test2", "atgg")
287     assert_equal(1, seq1.hamming_distance(seq2))
288   end
289
290   def test_Seq_generate_with_length_lt_1_raises
291     assert_raise(SeqError) { @entry.generate(-10, "dna") }
292     assert_raise(SeqError) { @entry.generate(0, "dna") }
293   end
294
295   def test_Seq_generate_with_bad_type_raises
296     assert_raise(SeqError) { @entry.generate(10, "foo") }
297   end
298
299   def test_Seq_generate_with_ok_type_dont_raise
300     %w[dna DNA rna RNA protein Protein].each do |type|
301       assert_nothing_raised { @entry.generate(10, type) }
302     end
303   end
304
305   def test_Seq_shuffle_returns_correctly
306     orig       = "actgactgactgatcgatcgatcgatcgtactg" 
307     @entry.seq = "actgactgactgatcgatcgatcgatcgtactg"
308     entry_shuf = @entry.shuffle
309     assert_equal(orig, @entry.seq)
310     assert_not_equal(@entry.seq, entry_shuf.seq)
311   end
312
313   def test_Seq_shuffle_bang_returns_correctly
314     @entry.seq = "actgactgactgatcgatcgatcgatcgtactg"
315     assert_not_equal(@entry.seq, @entry.shuffle!.seq)
316   end
317
318   def test_Seq_subseq_with_start_lt_0_raises
319     @entry.seq = "ATCG"
320     assert_raise(SeqError) { @entry.subseq(-1, 1) }
321   end
322
323   def test_Seq_subseq_with_start_plus_length_gt_seq_raises
324     @entry.seq = "ATCG"
325     assert_raise(SeqError) { @entry.subseq(0, 5) }
326   end
327
328   def test_Seq_subseq_returns_correct_sequence
329     @entry.seq  = "ATCG"
330     assert_equal("AT", @entry.subseq(0, 2).seq)
331     assert_equal("CG", @entry.subseq(2, 2).seq)
332   end
333
334   def test_Seq_subseq_without_len_returns_correct_sequence
335     @entry.seq  = "ATCG"
336     assert_equal("ATCG", @entry.subseq(0).seq)
337     assert_equal("CG",   @entry.subseq(2).seq)
338   end
339
340   def test_Seq_subseq_returns_correct_qual
341     @entry.seq  = "ATCG"
342     @entry.qual = "abcd"
343     assert_equal("ab", @entry.subseq(0, 2).qual)
344     assert_equal("cd", @entry.subseq(2, 2).qual)
345   end
346
347   def test_Seq_subseq_without_len_returns_correct_qual
348     @entry.seq  = "ATCG"
349     @entry.qual = "abcd"
350     assert_equal("abcd", @entry.subseq(0).qual)
351     assert_equal("cd",   @entry.subseq(2).qual)
352   end
353
354   def test_Seq_subseq_bang_with_start_lt_0_raises
355     @entry.seq = "ATCG"
356     assert_raise(SeqError) { @entry.subseq!(-1, 1) }
357   end
358
359   def test_Seq_subseq_bang_with_start_plus_length_gt_seq_raises
360     @entry.seq = "ATCG"
361     assert_raise(SeqError) { @entry.subseq!(0, 5) }
362   end
363
364   def test_Seq_subseq_bang_returns_correct_sequence
365     @entry.seq  = "ATCG"
366     @entry.subseq!(0, 2)
367     assert_equal("AT", @entry.seq)
368     @entry.seq  = "ATCG"
369     @entry.subseq!(2, 2)
370     assert_equal("CG", @entry.seq)
371   end
372
373   def test_Seq_subseq_bang_without_len_returns_correct_sequence
374     @entry.seq  = "ATCG"
375     @entry.subseq!(0)
376     assert_equal("ATCG", @entry.seq)
377     @entry.seq  = "ATCG"
378     @entry.subseq!(2)
379     assert_equal("CG", @entry.seq)
380   end
381
382   def test_Seq_subseq_bang_with_pos_and_len_returns_correct_qual
383     @entry.seq  = "ATCG"
384     @entry.qual = "abcd"
385     @entry.subseq!(0, 2)
386     assert_equal("ab", @entry.qual)
387     @entry.seq  = "ATCG"
388     @entry.qual = "abcd"
389     @entry.subseq!(2, 2)
390     assert_equal("cd", @entry.qual)
391   end
392
393   def test_Seq_subseq_bang_with_pos_returns_correct_qual
394     @entry.seq  = "ATCG"
395     @entry.qual = "abcd"
396     @entry.subseq!(0)
397     assert_equal("abcd", @entry.qual)
398     @entry.seq  = "ATCG"
399     @entry.qual = "abcd"
400     @entry.subseq!(2)
401     assert_equal("cd", @entry.qual)
402   end
403
404   def test_Seq_subseq_rand_returns_correct_sequence
405     @entry.seq  = "ATCG"
406     assert_equal("ATCG", @entry.subseq_rand(4).seq)
407   end
408
409   def test_Seq_indels_remove_without_qual_returns_correctly
410     @entry.seq  = "A-T.CG~CG"
411     @entry.qual = nil
412     assert_equal("ATCGCG", @entry.indels_remove.seq)
413   end
414
415   def test_Seq_indels_remove_with_qual_returns_correctly
416     @entry.seq  = "A-T.CG~CG"
417     @entry.qual = "a@b@cd@fg"
418     assert_equal("ATCGCG", @entry.indels_remove.seq)
419     assert_equal("abcdfg", @entry.indels_remove.qual)
420   end
421
422   def test_Seq_composition_returns_correctly
423     @entry.seq = "AAAATTTCCG"
424     assert_equal(4, @entry.composition["A"])
425     assert_equal(3, @entry.composition["T"])
426     assert_equal(2, @entry.composition["C"])
427     assert_equal(1, @entry.composition["G"])
428     assert_equal(0, @entry.composition["X"])
429   end
430
431   def test_Seq_homopol_max_returns_0_with_empty_sequence
432     @entry.seq = ""
433     assert_equal(0, @entry.homopol_max)
434   end
435
436   def test_Seq_homopol_max_returns_0_with_nil_sequence
437     @entry.seq = nil
438     assert_equal(0, @entry.homopol_max)
439   end
440
441   def test_Seq_homopol_max_returns_0_when_not_found
442     @entry.seq = "AtTcCcGggGnnNnn"
443     assert_equal(0, @entry.homopol_max(6))
444   end
445
446   def test_Seq_homopol_max_returns_correctly
447     @entry.seq = "AtTcCcGggGnnNnn"
448     assert_equal(5, @entry.homopol_max(3))
449   end
450
451   def test_Seq_hard_mask_returns_correctly
452     @entry.seq = "--AAAANn"
453     assert_equal(33.33, @entry.hard_mask)
454   end
455
456   def test_Seq_soft_mask_returns_correctly
457     @entry.seq = "--AAAa"
458     assert_equal(25.00, @entry.soft_mask)
459   end
460
461   def test_Seq_mask_seq_hard_bang_with_nil_seq_raises
462     @entry.seq  = nil
463     @entry.qual = ""
464
465     assert_raise(SeqError) { @entry.mask_seq_hard!(20) }
466   end
467
468   def test_Seq_mask_seq_hard_bang_with_nil_qual_raises
469     @entry.seq  = ""
470     @entry.qual = nil
471
472     assert_raise(SeqError) { @entry.mask_seq_hard!(20) }
473   end
474
475   def test_Seq_mask_seq_hard_bang_with_bad_cutoff_raises
476     assert_raise(SeqError) { @entry.mask_seq_hard!(-1) }
477     assert_raise(SeqError) { @entry.mask_seq_hard!(41) }
478   end
479
480   def test_Seq_mask_seq_hard_bang_with_OK_cutoff_dont_raise
481     @entry.seq  = "ATCG"
482     @entry.qual = "RSTU"
483
484     assert_nothing_raised { @entry.mask_seq_hard!(0) }
485     assert_nothing_raised { @entry.mask_seq_hard!(40) }
486   end
487
488   def test_Seq_mask_seq_hard_bang_returns_correctly
489     @entry.seq  = "-ATCG"
490     @entry.qual = "RRSTU"
491
492     assert_equal("-NNCG", @entry.mask_seq_hard!(20).seq)
493   end
494
495   def test_Seq_mask_seq_soft_bang_with_nil_seq_raises
496     @entry.seq  = nil
497     @entry.qual = ""
498
499     assert_raise(SeqError) { @entry.mask_seq_soft!(20) }
500   end
501
502   def test_Seq_mask_seq_soft_bang_with_nil_qual_raises
503     @entry.seq  = ""
504     @entry.qual = nil
505
506     assert_raise(SeqError) { @entry.mask_seq_soft!(20) }
507   end
508
509   def test_Seq_mask_seq_soft_bang_with_bad_cutoff_raises
510     assert_raise(SeqError) { @entry.mask_seq_soft!(-1) }
511     assert_raise(SeqError) { @entry.mask_seq_soft!(41) }
512   end
513
514   def test_Seq_mask_seq_soft_bang_with_OK_cutoff_dont_raise
515     @entry.seq  = "ATCG"
516     @entry.qual = "RSTU"
517
518     assert_nothing_raised { @entry.mask_seq_soft!(0) }
519     assert_nothing_raised { @entry.mask_seq_soft!(40) }
520   end
521
522   def test_Seq_mask_seq_soft_bang_returns_correctly
523     @entry.seq  = "-ATCG"
524     @entry.qual = "RRSTU"
525
526     assert_equal("-atCG", @entry.mask_seq_soft!(20).seq)
527   end
528
529   # qual score detection
530
531   def test_Seq_qual_base33_returns_correctly
532     # self.qual.match(/[!-:]/)
533     @entry.qual = '!"#$%&\'()*+,-./0123456789:'
534     assert_equal(true,  @entry.qual_base33? )
535     @entry.qual = 32.chr
536     assert_equal(false, @entry.qual_base33? )
537     @entry.qual = 59.chr
538     assert_equal(false, @entry.qual_base33? )
539   end
540
541   def test_Seq_qual_base64_returns_correctly
542     # self.qual.match(/[K-h]/)
543     @entry.qual = 'KLMNOPQRSTUVWXYZ[\]^_`abcdefgh'
544     assert_equal(true,  @entry.qual_base64? )
545     @entry.qual = 74.chr
546     assert_equal(false, @entry.qual_base64? )
547     @entry.qual = 105.chr
548     assert_equal(false, @entry.qual_base64? )
549   end
550
551   def test_Seq_qual_valid_with_nil_qual_raises
552     assert_raise(SeqError) { @entry.qual_valid?("illumina1.8") }
553   end
554
555   def test_Seq_qual_valid_with_bad_encoding_raises
556     @entry.qual = "abc"
557     assert_raise(SeqError) { @entry.qual_valid?("foobar") }
558   end
559
560   def test_Seq_qual_valid_returns_correctly
561     tests = [["sanger",      0, 93, 33],
562              ["454",         0, 62, 64],
563              ["solexa",     -5, 62, 64],
564              ["illumina13",  0, 62, 64],
565              ["illumina15",  0, 62, 64],
566              ["illumina18",  0, 93, 33]]
567
568     tests.each do |test|
569       @entry.qual = (test[1] + test[-1]).chr + (test[2] + test[-1]).chr
570       assert_equal(true, @entry.qual_valid?(test[0]))
571       @entry.qual = (test[1] + test[-1] - 1).chr
572       assert_equal(false, @entry.qual_valid?(test[0]))
573       @entry.qual = (test[2] + test[-1] + 1).chr
574       assert_equal(false, @entry.qual_valid?(test[0]))
575     end
576   end
577
578   # convert sanger to ...
579
580   def test_Seq_convert_scores_bang_from_sanger_to_sanger_returns_OK
581     @entry.qual = 'BCDEFGHI'
582     assert_equal('BCDEFGHI', @entry.convert_scores!('sanger', 'sanger').qual)
583   end
584
585   def test_Seq_convert_scores_bang_from_sanger_to_solexa_returns_OK
586     @entry.qual = 'BCDEFGHI'
587     assert_equal('abcdefgh', @entry.convert_scores!('sanger', 'solexa').qual)
588   end
589
590   def test_Seq_convert_scores_bang_from_sanger_to_illumina13_returns_OK
591     @entry.qual = 'BCDEFGHI'
592     assert_equal('abcdefgh', @entry.convert_scores!('sanger', 'illumina13').qual)
593   end
594
595   def test_Seq_convert_scores_bang_from_sanger_to_illumina15_returns_OK
596     @entry.qual = 'BCDEFGHI'
597     assert_equal('abcdefgh', @entry.convert_scores!('sanger', 'illumina15').qual)
598   end
599
600   def test_Seq_convert_scores_bang_from_sanger_to_illumina18_returns_OK
601     @entry.qual = 'BCDEFGHI'
602     assert_equal('BCDEFGHI', @entry.convert_scores!('sanger', 'illumina18').qual)
603   end
604
605   # convert solexa to ...
606
607   def test_Seq_convert_scores_bang_from_solexa_to_sanger_returns_OK
608     @entry.qual = 'BCDEFGHI'
609     assert_equal(%q[#$%&'()*], @entry.convert_scores!('solexa', 'sanger').qual)
610   end
611
612   def test_Seq_convert_scores_bang_from_solexa_to_solexa_returns_OK
613     @entry.qual = 'BCDEFGHI'
614     assert_equal('BCDEFGHI', @entry.convert_scores!('solexa', 'solexa').qual)
615   end
616
617   def test_Seq_convert_scores_bang_from_solexa_to_illumina13_returns_OK
618     @entry.qual = 'BCDEFGHI'
619     assert_equal('BCDEFGHI', @entry.convert_scores!('solexa', 'illumina13').qual)
620   end
621
622   def test_Seq_convert_scores_bang_from_solexa_to_illumina15_returns_OK
623     @entry.qual = 'BCDEFGHI'
624     assert_equal('BCDEFGHI', @entry.convert_scores!('solexa', 'illumina15').qual)
625   end
626
627   def test_Seq_convert_scores_bang_from_solexa_to_illumina18_returns_OK
628     @entry.qual = 'BCDEFGHI'
629     assert_equal(%q[#$%&'()*], @entry.convert_scores!('solexa', 'illumina18').qual)
630   end
631
632   # convert illumina13 to ...
633
634   def test_Seq_convert_scores_bang_from_illumina13_to_sanger_returns_OK
635     @entry.qual = 'BCDEFGHI'
636     assert_equal(%q[#$%&'()*], @entry.convert_scores!('illumina13', 'sanger').qual)
637   end
638
639   def test_Seq_convert_scores_bang_from_illumina13_to_solexa_returns_OK
640     @entry.qual = 'BCDEFGHI'
641     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina13', 'solexa').qual)
642   end
643
644   def test_Seq_convert_scores_bang_from_illumina13_to_illumina13_returns_OK
645     @entry.qual = 'BCDEFGHI'
646     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina13', 'illumina13').qual)
647   end
648
649   def test_Seq_convert_scores_bang_from_illumina13_to_illumina15_returns_OK
650     @entry.qual = 'BCDEFGHI'
651     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina13', 'illumina15').qual)
652   end
653
654   def test_Seq_convert_scores_bang_from_illumina13_to_illumina18_returns_OK
655     @entry.qual = 'BCDEFGHI'
656     assert_equal(%q[#$%&'()*], @entry.convert_scores!('illumina13', 'illumina18').qual)
657   end
658
659   # convert illumina15 to ...
660
661   def test_Seq_convert_scores_bang_from_illumina15_to_sanger_returns_OK
662     @entry.qual = 'BCDEFGHI'
663     assert_equal(%q[#$%&'()*], @entry.convert_scores!('illumina15', 'sanger').qual)
664   end
665
666   def test_Seq_convert_scores_bang_from_illumina15_to_solexa_returns_OK
667     @entry.qual = 'BCDEFGHI'
668     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina15', 'solexa').qual)
669   end
670
671   def test_Seq_convert_scores_bang_from_illumina15_to_illumina13_returns_OK
672     @entry.qual = 'BCDEFGHI'
673     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina15', 'illumina13').qual)
674   end
675
676   def test_Seq_convert_scores_bang_from_illumina15_to_illumina15_returns_OK
677     @entry.qual = 'BCDEFGHI'
678     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina15', 'illumina15').qual)
679   end
680
681   def test_Seq_convert_scores_bang_from_illumina15_to_illumina18_returns_OK
682     @entry.qual = 'BCDEFGHI'
683     assert_equal(%q[#$%&'()*], @entry.convert_scores!('illumina15', 'illumina18').qual)
684   end
685
686   # convert illumina18 to ...
687
688   def test_Seq_convert_scores_bang_from_illumina18_to_sanger_returns_OK
689     @entry.qual = 'BCDEFGHI'
690     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina18', 'sanger').qual)
691   end
692
693   def test_Seq_convert_scores_bang_from_illumina18_to_solexa_returns_OK
694     @entry.qual = 'BCDEFGHI'
695     assert_equal('abcdefgh', @entry.convert_scores!('illumina18', 'solexa').qual)
696   end
697
698   def test_Seq_convert_scores_bang_from_illumina18_to_illumina13_returns_OK
699     @entry.qual = 'BCDEFGHI'
700     assert_equal('abcdefgh', @entry.convert_scores!('illumina18', 'illumina13').qual)
701   end
702
703   def test_Seq_convert_scores_bang_from_illumina18_to_illumina15_returns_OK
704     @entry.qual = 'BCDEFGHI'
705     assert_equal('abcdefgh', @entry.convert_scores!('illumina18', 'illumina15').qual)
706   end
707
708   def test_Seq_convert_scores_bang_from_illumina18_to_illumina18_returns_OK
709     @entry.qual = 'BCDEFGHI'
710     assert_equal('BCDEFGHI', @entry.convert_scores!('illumina18', 'illumina18').qual)
711   end
712
713   def test_Seq_scores_mean_without_qual_raises
714     @entry.qual = nil
715     assert_raise(SeqError) { @entry.scores_mean }
716   end
717
718   def test_Seq_scores_mean_returns_correctly
719     @entry.qual = '@@hh'
720     assert_equal(20.0, @entry.scores_mean)
721   end
722 end
723
724 __END__