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_to_key_with_bad_residue_raises
131 entry = Seq.new("test", "AUCG")
132 assert_raise(SeqError) { entry.to_key }
135 def test_Seq_to_key_returns_correctly
136 entry = Seq.new("test", "ATCG")
137 assert_equal(54, entry.to_key)
140 def test_Seq_reverse_returns_correctly
142 assert_equal("GCTA", @entry.reverse)
145 def test_Seq_complement_raises_if_no_sequence
147 assert_raise(SeqError) { @entry.complement }
150 def test_Seq_complement_raises_on_bad_type
152 @entry.type = 'protein'
153 assert_raise(SeqError) { @entry.complement }
156 def test_Seq_complement_for_DNA_is_correct
157 @entry.seq = 'ATCGatcg'
159 assert_equal("TAGCtagc", @entry.complement)
162 def test_Seq_complement_for_RNA_is_correct
163 @entry.seq = 'AUCGaucg'
165 assert_equal("UAGCuagc", @entry.complement)
168 def test_Seq_reverse_complement_for_DNA_is_correct
169 @entry.seq = 'ATCGatcg'
171 assert_equal("cgatCGAT", @entry.reverse_complement)
174 def test_Seq_reverse_complement_for_RNA_is_correct
175 @entry.seq = 'AUCGaucg'
177 assert_equal("cgauCGAU", @entry.reverse_complement)
180 def test_Seq_generate_with_length_lt_1_raises
181 assert_raise(SeqError) { @entry.generate(-10, "dna") }
182 assert_raise(SeqError) { @entry.generate(0, "dna") }
185 def test_Seq_generate_with_bad_type_raises
186 assert_raise(SeqError) { @entry.generate(10, "foo") }
189 def test_Seq_generate_with_ok_type_dont_raise
190 %w[dna DNA rna RNA protein Protein].each do |type|
191 assert_nothing_raised { @entry.generate(10, type) }
195 def test_Seq_subseq_with_start_lt_0_raises
197 assert_raise(SeqError) { @entry.subseq(-1, 1) }
200 def test_Seq_subseq_with_length_lt_1_raises
202 assert_raise(SeqError) { @entry.subseq(0, 0) }
205 def test_Seq_subseq_with_start_plus_length_gt_seq_raises
207 assert_raise(SeqError) { @entry.subseq(0, 5) }
210 def test_Seq_subseq_returns_correct_sequence
212 assert_equal("AT", @entry.subseq(0, 2).seq)
213 assert_equal("CG", @entry.subseq(2, 2).seq)
216 def test_Seq_subseq_returns_correct_qual
219 assert_equal("ab", @entry.subseq(0, 2).qual)
220 assert_equal("cd", @entry.subseq(2, 2).qual)
223 def test_Seq_subseq_rand_returns_correct_sequence
225 assert_equal("ATCG", @entry.subseq_rand(4).seq)
228 def test_Seq_composition_returns_correctly
229 @entry.seq = "AAAATTTCCG"
230 assert_equal(4, @entry.composition["A"])
231 assert_equal(3, @entry.composition["T"])
232 assert_equal(2, @entry.composition["C"])
233 assert_equal(1, @entry.composition["G"])
234 assert_equal(0, @entry.composition["X"])
237 def test_Seq_homopol_max_returns_0_with_empty_sequence
239 assert_equal(0, @entry.homopol_max)
242 def test_Seq_homopol_max_returns_0_with_nil_sequence
244 assert_equal(0, @entry.homopol_max)
247 def test_Seq_homopol_max_returns_0_when_not_found
248 @entry.seq = "AtTcCcGggGnnNnn"
249 assert_equal(0, @entry.homopol_max(6))
252 def test_Seq_homopol_max_returns_correctly
253 @entry.seq = "AtTcCcGggGnnNnn"
254 assert_equal(5, @entry.homopol_max(3))
257 def test_Seq_hard_mask_returns_correctly
258 @entry.seq = "--AAAANn"
259 assert_equal(33.33, @entry.hard_mask)
262 def test_Seq_soft_mask_returns_correctly
263 @entry.seq = "--AAAa"
264 assert_equal(25.00, @entry.soft_mask)
267 def test_Seq_adaptor_locate_right_returns_correctly
268 @entry.seq = "nnnnncgat"
269 assert_equal(-1, @entry.adaptor_locate_right("X"))
270 assert_equal(8, @entry.adaptor_locate_right("TX"))
271 assert_equal(7, @entry.adaptor_locate_right("ATX"))
272 assert_equal(6, @entry.adaptor_locate_right("GATX"))
273 assert_equal(5, @entry.adaptor_locate_right("CGATX"))
274 assert_equal(0, @entry.adaptor_locate_right("NNNNNCGAT"))
277 def test_Seq_adaptor_locate_left_returns_correctly
278 @entry.seq = "cgatnnnnn"
279 assert_equal(-1, @entry.adaptor_locate_left("X"))
280 assert_equal(0, @entry.adaptor_locate_left("XC"))
281 assert_equal(1, @entry.adaptor_locate_left("XCG"))
282 assert_equal(2, @entry.adaptor_locate_left("XCGA"))
283 assert_equal(3, @entry.adaptor_locate_left("XCGAT"))
284 assert_equal(8, @entry.adaptor_locate_left("CGATNNNNN"))
287 def test_Seq_adaptor_clip_right_returns_correct_sequence
288 @entry.seq = "nnnnncgat"
289 @entry.adaptor_clip_right("cgat")
290 assert_equal( "nnnnn", @entry.seq)
293 def test_Seq_adaptor_clip_right_returns_correct_qual
294 @entry.seq = "nnnnncgat"
295 @entry.qual = "abcdefghi"
296 @entry.adaptor_clip_right("cgat")
297 assert_equal( "abcde", @entry.qual)
300 def test_Seq_adaptor_clip_left_returns_correct_sequence
301 @entry.seq = "cgatnnnnn"
302 @entry.adaptor_clip_left("cgat")
303 assert_equal( "nnnnn", @entry.seq)
306 def test_Seq_adaptor_clip_left_returns_correct_qual
307 @entry.seq = "cgatnnnnn"
308 @entry.qual = "abcdefghi"
309 @entry.adaptor_clip_left("cgat")
310 assert_equal( "efghi", @entry.qual)
313 def test_Digest_new_raises_on_bad_pattern_residue
314 assert_raise(DigestError) { Digest.new(@entry, "X", 4) }
317 def test_Digest_new_dont_raise_on_ok_pattern_residue
318 assert_nothing_raised { Digest.new(@entry, "AGCUTRYWSMKHDVBNagcutrywsmkhdvbn", 4) }
322 @entry.seq = "aaaaTTTTbbbbTTTT"
323 digest = Digest.new(@entry, "TTNT", 1)
324 assert_equal("aaaaT", digest.first.seq)