5 test_begin(-tests => 185);
7 use_ok 'Bio::PrimarySeq';
8 use_ok 'Bio::SeqFeature::Primer';
9 use_ok 'Bio::Tools::AmpliconSearch';
13 my ($search, $amplicon, $seq, $seq2, $forward, $forward2, $reverse, $reverse2,
14 $primer, $primer_seq, $annotated, $num_feats, $template_seq, $rna);
19 ok $search = Bio::Tools::AmpliconSearch->new(), 'Basic';
20 isa_ok $search, 'Bio::Tools::AmpliconSearch';
25 $seq = Bio::PrimarySeq->new(
26 -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
29 $rna = Bio::PrimarySeq->new(
30 -seq => 'acgAAACUUAAAGGAAUUGACGGacguacguacguGUACACACCGCCCGUacguac',
34 $forward = Bio::PrimarySeq->new(
35 -seq => 'AAACTTAAAGGAATTGACGG',
37 ok $search = Bio::Tools::AmpliconSearch->new(
39 -fwd_primer => $forward,
41 ), 'Forward primer only';
42 is $search->fwd_primer->seq, 'AAACTTAAAGGAATTGACGG';
43 is $search->rev_primer, undef;
44 ok $template_seq = $search->template;
45 isa_ok $template_seq, 'Bio::Seq';
46 is $template_seq->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
47 ok $amplicon = $search->next_amplicon;
48 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
49 is $amplicon->start, 4;
50 is $amplicon->end, 56;
51 is $amplicon->strand, 1;
52 is $amplicon->seq->seq, 'AAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
53 ok $primer = $amplicon->fwd_primer;
54 ok $primer_seq = $primer->seq;
55 is $primer_seq->seq, 'AAACTTAAAGGAATTGACGG';
58 is $primer->strand, 1;
59 is $amplicon = $search->next_amplicon, undef;
64 $seq = Bio::PrimarySeq->new(
65 -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
67 $reverse = Bio::SeqFeature::Primer->new(
68 -seq => 'ACGGGCGGTGTGTAC',
70 ok $search = Bio::Tools::AmpliconSearch->new(
72 -rev_primer => $reverse,
74 ), 'Reverse primer only';
75 is $search->fwd_primer, undef;
76 is $search->rev_primer->seq->seq, 'ACGGGCGGTGTGTAC';
77 is $search->template->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
78 ok $amplicon = $search->next_amplicon;
79 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
80 is $amplicon->start, 1;
81 is $amplicon->end, 50;
82 is $amplicon->strand, 1;
83 is $amplicon->seq->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGT';
84 is $amplicon->fwd_primer, undef;
85 is $amplicon->rev_primer, undef;
86 is $search->next_amplicon, undef;
89 # Forward and reverse primers, no amplicon
91 $seq = Bio::PrimarySeq->new(
92 -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
94 $forward = Bio::PrimarySeq->new(
95 -seq => 'AAACTTAAAGGAATTGACGG',
97 $reverse = Bio::PrimarySeq->new(
100 ok $search = Bio::Tools::AmpliconSearch->new(
102 -fwd_primer => $forward,
103 -rev_primer => $reverse,
104 ), 'Two primers, no match';
105 is $search->fwd_primer->seq, 'AAACTTAAAGGAATTGACGG';
106 is $search->rev_primer->seq, 'CCCCCCCCCC';
107 is $search->template->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
108 is $search->next_amplicon, undef;
111 # Degenerate forward and reverse primers from file, single amplicon
113 ok $search = Bio::Tools::AmpliconSearch->new(
115 -primer_file => test_input_file('forward_reverse_primers.fa'),
116 ), 'Two degenerate primers from a file';
117 is $search->fwd_primer->seq, 'AAACTYAAAKGAATTGRCGG';
118 is $search->rev_primer->seq, 'ACGGGCGGTGTGTRC';
119 is $search->template->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
120 ok $amplicon = $search->next_amplicon;
121 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
122 is $amplicon->start, 4;
123 is $amplicon->end, 50;
124 is $amplicon->strand, 1;
125 is $amplicon->seq->seq, 'AAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGT';
126 is $search->next_amplicon, undef;
129 # Same thing but with RNA template
131 ok $search = Bio::Tools::AmpliconSearch->new(
133 -primer_file => test_input_file('forward_reverse_primers.fa'),
135 is $search->fwd_primer->seq, 'AAACTYAAAKGAATTGRCGG';
136 is $search->rev_primer->seq, 'ACGGGCGGTGTGTRC';
137 is $search->template->seq, 'acgAAACUUAAAGGAAUUGACGGacguacguacguGUACACACCGCCCGUacguac';
138 ok $amplicon = $search->next_amplicon;
139 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
140 is $amplicon->start, 4;
141 is $amplicon->end, 50;
142 is $amplicon->strand, 1;
143 is $amplicon->seq->seq, 'AAACUUAAAGGAAUUGACGGacguacguacguGUACACACCGCCCGU';
144 is $search->next_amplicon, undef;
147 # Forward primer only, in sequence file
149 ok $search = Bio::Tools::AmpliconSearch->new(
150 -primer_file => test_input_file('forward_primer.fa'),
151 ), 'Forward primer from file';
152 ok $search->template($seq);
153 is $search->fwd_primer->seq, 'AAACTTAAAGGAATTGACGG';
154 is $search->rev_primer, undef;
155 ok $template_seq = $search->template;
156 isa_ok $template_seq, 'Bio::Seq';
157 is $template_seq->seq, 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
158 ok $amplicon = $search->next_amplicon;
159 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
160 is $amplicon->start, 4;
161 is $amplicon->end, 56;
162 is $amplicon->strand, 1;
163 is $amplicon->seq->seq, 'AAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
164 is $amplicon = $search->next_amplicon, undef;
169 $seq = Bio::PrimarySeq->new(
170 -seq => 'acgtaCCCCacgtacgtacTTTTTTacgtaCCCCacgtaTTTTTTacgtacgtac',
172 $forward = Bio::PrimarySeq->new(
175 $reverse = Bio::PrimarySeq->new(
178 ok $search = Bio::Tools::AmpliconSearch->new(
180 -fwd_primer => $forward,
181 -rev_primer => $reverse,
182 ), 'Multiple amplicons';
183 ok $amplicon = $search->next_amplicon;
184 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
185 is $amplicon->start, 6;
186 is $amplicon->end, 25;
187 is $amplicon->strand, 1;
188 is $amplicon->seq->seq, 'CCCCacgtacgtacTTTTTT';
189 ok $amplicon = $search->next_amplicon;
190 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
191 is $amplicon->start, 31;
192 is $amplicon->end, 45;
193 is $amplicon->strand, 1;
194 is $amplicon->seq->seq, 'CCCCacgtaTTTTTT';
195 is $search->next_amplicon, undef;
198 # Amplicon on reverse strand
200 $seq = Bio::PrimarySeq->new(
201 # Reverse-complement of previous sequence... should have same amplicons
202 -seq => 'gtacgtacgtAAAAAAtacgtGGGGtacgtAAAAAAgtacgtacgtGGGGtacgt',
204 $forward = Bio::PrimarySeq->new(
207 $reverse = Bio::PrimarySeq->new(
210 ok $search = Bio::Tools::AmpliconSearch->new(
212 -fwd_primer => $forward,
213 -rev_primer => $reverse,
214 ), 'Amplicon on reverse strand';
215 ok $amplicon = $search->next_amplicon;
216 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
217 is $amplicon->start, 11;
218 is $amplicon->end, 25;
219 is $amplicon->strand, -1;
220 is $amplicon->seq->seq, 'CCCCacgtaTTTTTT';
221 ok $amplicon = $search->next_amplicon;
222 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
223 is $amplicon->start, 31;
224 is $amplicon->end, 50;
225 is $amplicon->strand, -1;
226 is $amplicon->seq->seq, 'CCCCacgtacgtacTTTTTT';
227 is $search->next_amplicon, undef;
230 # Overlapping amplicons (1)
232 $seq = Bio::PrimarySeq->new(
233 -seq => 'acgtaCCCCacgtacgtacgtacgCCCCacgtaTTTTTTacgtacgtac',
235 $forward = Bio::PrimarySeq->new(
238 $reverse = Bio::PrimarySeq->new(
241 ok $search = Bio::Tools::AmpliconSearch->new(
243 -fwd_primer => $forward,
244 -rev_primer => $reverse,
245 ), 'Overlapping amplicons (1)';
246 ok $amplicon = $search->next_amplicon;
247 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
248 is $amplicon->start, 25;
249 is $amplicon->end, 39;
250 is $amplicon->strand, 1;
251 is $amplicon->seq->seq, 'CCCCacgtaTTTTTT';
252 is $search->next_amplicon, undef;
255 # Overlapping amplicons (2)
257 $seq = Bio::PrimarySeq->new(
258 -seq => 'acgtaCCCCacgtacgtacgtacgTTTTTTacgtaTTTTTTacgtacgtac',
260 $forward = Bio::PrimarySeq->new(
263 $reverse = Bio::PrimarySeq->new(
266 ok $search = Bio::Tools::AmpliconSearch->new(
268 -fwd_primer => $forward,
269 -rev_primer => $reverse,
270 ), 'Overlapping amplicons (2)';
271 ok $amplicon = $search->next_amplicon;
272 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
273 is $amplicon->start, 6;
274 is $amplicon->end, 30;
275 is $amplicon->strand, 1;
276 is $amplicon->seq->seq, 'CCCCacgtacgtacgtacgTTTTTT';
277 is $search->next_amplicon, undef;
280 # Overlapping amplicons (3)
282 $seq = Bio::PrimarySeq->new(
283 -seq => 'acgtaCCCCacgtacgCCCCacgtacgaTTTTTTacgtaTTTTTTaaaaaaaaaa',
285 $forward = Bio::PrimarySeq->new(
288 $reverse = Bio::PrimarySeq->new(
291 ok $search = Bio::Tools::AmpliconSearch->new(
293 -fwd_primer => $forward,
294 -rev_primer => $reverse,
295 ), 'Overlapping amplicons (3)';
296 ok $amplicon = $search->next_amplicon;
297 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
298 is $amplicon->start, 17;
299 is $amplicon->end, 34;
300 is $amplicon->strand, 1;
301 is $amplicon->seq->seq, 'CCCCacgtacgaTTTTTT';
302 is $search->next_amplicon, undef;
305 # Amplicons on both strands
307 $seq = Bio::PrimarySeq->new(
308 -seq => 'acgtaCCCCacgtaacgtaTTTTTTacAAAAAAgtGGGGacgtaacgta',
310 $forward = Bio::PrimarySeq->new(
313 $reverse = Bio::PrimarySeq->new(
316 ok $search = Bio::Tools::AmpliconSearch->new(
318 -fwd_primer => $forward,
319 -rev_primer => $reverse,
320 ), 'Amplicons on both strands';
321 ok $amplicon = $search->next_amplicon;
322 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
323 is $amplicon->start, 6;
324 is $amplicon->end, 25;
325 is $amplicon->strand, 1;
326 is $amplicon->seq->seq, 'CCCCacgtaacgtaTTTTTT';
327 ok $amplicon = $search->next_amplicon;
328 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
329 is $amplicon->start, 28;
330 is $amplicon->end, 39;
331 is $amplicon->strand, -1;
332 is $amplicon->seq->seq, 'CCCCacTTTTTT';
333 is $search->next_amplicon, undef;
336 # Overlapping amplicons on both strands
338 $seq = Bio::PrimarySeq->new(
339 -seq => 'acgtaCCCCacgtacgtacagAAAAAATTTTTTacgtGGGGacgtacgtac',
341 $forward = Bio::PrimarySeq->new(
344 $reverse = Bio::PrimarySeq->new(
347 ok $search = Bio::Tools::AmpliconSearch->new(
349 -fwd_primer => $forward,
350 -rev_primer => $reverse,
351 ), 'Overlapping amplicons on both strands';
352 ok $amplicon = $search->next_amplicon;
353 isa_ok $amplicon, 'Bio::SeqFeature::Amplicon';
354 is $amplicon->start, 22;
355 is $amplicon->end, 41;
356 is $amplicon->strand, -1;
357 is $amplicon->seq->seq, 'CCCCacgtAAAAAATTTTTT';
358 is $search->next_amplicon, undef;
363 $seq = Bio::PrimarySeq->new(
364 -seq => 'acgtaCCCCacgtacgtacTTTTTTacAAAAAAgtGGGGacgtacgtac',
366 $forward = Bio::PrimarySeq->new(
369 $reverse = Bio::PrimarySeq->new(
372 ok $search = Bio::Tools::AmpliconSearch->new(
374 -fwd_primer => $forward,
375 -rev_primer => $reverse,
376 ), 'Annotated template';
377 ok $annotated = $search->annotate_template;
378 isa_ok $annotated, 'Bio::Seq';
380 for my $feat ( $annotated->get_SeqFeatures ) {
382 isa_ok $feat, 'Bio::SeqFeature::Amplicon';
385 is $search->next_amplicon, undef;
390 $seq = Bio::PrimarySeq->new(
391 -seq => 'acgtaCCCCacgtacgtacTTTTTTacCTCTCTgtTGTGTGacgtacgtac',
393 $forward = Bio::PrimarySeq->new(
396 $reverse = Bio::PrimarySeq->new(
399 $forward2 = Bio::PrimarySeq->new(
402 $reverse2 = Bio::PrimarySeq->new(
405 ok $search = Bio::Tools::AmpliconSearch->new(
408 ok $search->fwd_primer($forward);
409 is $search->fwd_primer->seq, 'CTCTCT';
410 ok $search->rev_primer($reverse);
411 is $search->rev_primer->seq, 'CACACA';
412 ok $amplicon = $search->next_amplicon;
413 is $amplicon->seq->seq, 'CTCTCTgtTGTGTG';
414 is $search->next_amplicon, undef;
415 ok $search->fwd_primer($forward2);
416 ok $search->rev_primer($reverse2);
417 is $search->fwd_primer->seq, 'CCCC';
418 is $search->rev_primer->seq, 'AAAAAA';
419 ok $amplicon = $search->next_amplicon;
420 is $amplicon->seq->seq, 'CCCCacgtacgtacTTTTTT';
421 is $search->next_amplicon, undef;
426 $seq = Bio::PrimarySeq->new(
427 -seq => 'acgtaCCCCacgtacgtacTTTTTTa',
429 $seq2 = Bio::PrimarySeq->new(
430 -seq => 'aCCCCgaTTTTTTgacgtacgtac',
432 $forward = Bio::PrimarySeq->new(
435 $reverse = Bio::PrimarySeq->new(
438 ok $search = Bio::Tools::AmpliconSearch->new(
439 -fwd_primer => $forward,
440 -rev_primer => $reverse,
441 ), 'Update template';
442 ok $search->template($seq);
443 is $search->template->seq, 'acgtaCCCCacgtacgtacTTTTTTa';
444 ok $amplicon = $search->next_amplicon;
445 is $amplicon->seq->seq, 'CCCCacgtacgtacTTTTTT';
446 is $search->next_amplicon, undef;
447 ok $search->template($seq2);
448 is $search->template->seq, 'aCCCCgaTTTTTTgacgtacgtac';
449 ok $amplicon = $search->next_amplicon;
450 is $amplicon->seq->seq, 'CCCCgaTTTTTT';
451 is $search->next_amplicon, undef;