~ubuntu-branches/ubuntu/trusty/bioperl/trusty

« back to all changes in this revision

Viewing changes to t/Tools/AmpliconSearch.t

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2013-09-22 13:39:48 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922133948-c6z62zegjyp7ztou
Tags: 1.6.922-1
* New upstream release.
* Replaces and Breaks grinder (<< 0.5.3-3~) because of overlaping contents.
  Closes: #722910
* Stop Replacing and Breaking bioperl ( << 1.6.9 ): not needed anymore. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
BEGIN {     
 
2
    use lib '.';
 
3
    use Bio::Root::Test;
 
4
 
 
5
    test_begin(-tests => 185);
 
6
 
 
7
    use_ok 'Bio::PrimarySeq';
 
8
    use_ok 'Bio::SeqFeature::Primer';
 
9
    use_ok 'Bio::Tools::AmpliconSearch';
 
10
}
 
11
 
 
12
 
 
13
my ($search, $amplicon, $seq, $seq2, $forward, $forward2, $reverse, $reverse2,
 
14
    $primer, $primer_seq, $annotated, $num_feats, $template_seq, $rna);
 
15
 
 
16
 
 
17
# Basic object
 
18
 
 
19
ok $search = Bio::Tools::AmpliconSearch->new(), 'Basic';
 
20
isa_ok $search, 'Bio::Tools::AmpliconSearch';
 
21
 
 
22
 
 
23
# Forward primer only
 
24
 
 
25
$seq = Bio::PrimarySeq->new(
 
26
   -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
 
27
);
 
28
 
 
29
$rna = Bio::PrimarySeq->new(
 
30
   -seq => 'acgAAACUUAAAGGAAUUGACGGacguacguacguGUACACACCGCCCGUacguac',
 
31
);
 
32
 
 
33
 
 
34
$forward = Bio::PrimarySeq->new(
 
35
   -seq => 'AAACTTAAAGGAATTGACGG',
 
36
);
 
37
ok $search = Bio::Tools::AmpliconSearch->new(
 
38
   -template       => $seq,
 
39
   -fwd_primer     => $forward,
 
40
   -attach_primers => 1,
 
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';
 
56
is $primer->start, 4;
 
57
is $primer->end, 23;
 
58
is $primer->strand, 1;
 
59
is $amplicon = $search->next_amplicon, undef;
 
60
 
 
61
 
 
62
# Reverse primer only
 
63
 
 
64
$seq = Bio::PrimarySeq->new(
 
65
   -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
 
66
);
 
67
$reverse = Bio::SeqFeature::Primer->new(
 
68
   -seq => 'ACGGGCGGTGTGTAC',
 
69
);
 
70
ok $search = Bio::Tools::AmpliconSearch->new(
 
71
   -template       => $seq,
 
72
   -rev_primer     => $reverse,
 
73
   -attach_primers => 0,
 
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;
 
87
 
 
88
 
 
89
# Forward and reverse primers, no amplicon
 
90
 
 
91
$seq = Bio::PrimarySeq->new(
 
92
   -seq => 'acgAAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac',
 
93
);
 
94
$forward = Bio::PrimarySeq->new(
 
95
   -seq => 'AAACTTAAAGGAATTGACGG',
 
96
);
 
97
$reverse = Bio::PrimarySeq->new(
 
98
   -seq => 'CCCCCCCCCC',
 
99
);
 
100
ok $search = Bio::Tools::AmpliconSearch->new(
 
101
   -template   => $seq,
 
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;
 
109
 
 
110
 
 
111
# Degenerate forward and reverse primers from file, single amplicon
 
112
 
 
113
ok $search = Bio::Tools::AmpliconSearch->new(
 
114
   -template    => $seq,
 
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;
 
127
 
 
128
 
 
129
# Same thing but with RNA template
 
130
 
 
131
ok $search = Bio::Tools::AmpliconSearch->new(
 
132
   -template    => $rna,
 
133
   -primer_file => test_input_file('forward_reverse_primers.fa'),
 
134
), 'RNA template';
 
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;
 
145
 
 
146
 
 
147
# Forward primer only, in sequence file
 
148
 
 
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;
 
165
 
 
166
 
 
167
# Multiple amplicons
 
168
 
 
169
$seq = Bio::PrimarySeq->new(
 
170
   -seq => 'acgtaCCCCacgtacgtacTTTTTTacgtaCCCCacgtaTTTTTTacgtacgtac',
 
171
);
 
172
$forward = Bio::PrimarySeq->new(
 
173
   -seq => 'CCCC',
 
174
);
 
175
$reverse = Bio::PrimarySeq->new(
 
176
   -seq => 'AAAAAA',
 
177
);
 
178
ok $search = Bio::Tools::AmpliconSearch->new(
 
179
   -template   => $seq,
 
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;
 
196
 
 
197
 
 
198
# Amplicon on reverse strand
 
199
 
 
200
$seq = Bio::PrimarySeq->new(
 
201
   # Reverse-complement of previous sequence... should have same amplicons
 
202
   -seq => 'gtacgtacgtAAAAAAtacgtGGGGtacgtAAAAAAgtacgtacgtGGGGtacgt',
 
203
);
 
204
$forward = Bio::PrimarySeq->new(
 
205
   -seq => 'CCCC',
 
206
);
 
207
$reverse = Bio::PrimarySeq->new(
 
208
   -seq => 'AAAAAA',
 
209
);
 
210
ok $search = Bio::Tools::AmpliconSearch->new(
 
211
   -template   => $seq,
 
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;
 
228
 
 
229
 
 
230
# Overlapping amplicons (1)
 
231
 
 
232
$seq = Bio::PrimarySeq->new(
 
233
   -seq => 'acgtaCCCCacgtacgtacgtacgCCCCacgtaTTTTTTacgtacgtac',
 
234
);
 
235
$forward = Bio::PrimarySeq->new(
 
236
   -seq => 'CCCC',
 
237
);
 
238
$reverse = Bio::PrimarySeq->new(
 
239
   -seq => 'AAAAAA',
 
240
);
 
241
ok $search = Bio::Tools::AmpliconSearch->new(
 
242
   -template   => $seq,
 
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;
 
253
 
 
254
 
 
255
# Overlapping amplicons (2)
 
256
 
 
257
$seq = Bio::PrimarySeq->new(
 
258
   -seq => 'acgtaCCCCacgtacgtacgtacgTTTTTTacgtaTTTTTTacgtacgtac',
 
259
);
 
260
$forward = Bio::PrimarySeq->new(
 
261
   -seq => 'CCCC',
 
262
);
 
263
$reverse = Bio::PrimarySeq->new(
 
264
   -seq => 'AAAAAA',
 
265
);
 
266
ok $search = Bio::Tools::AmpliconSearch->new(
 
267
   -template   => $seq,
 
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;
 
278
 
 
279
 
 
280
# Overlapping amplicons (3)
 
281
 
 
282
$seq = Bio::PrimarySeq->new(
 
283
   -seq => 'acgtaCCCCacgtacgCCCCacgtacgaTTTTTTacgtaTTTTTTaaaaaaaaaa',
 
284
);
 
285
$forward = Bio::PrimarySeq->new(
 
286
   -seq => 'CCCC',
 
287
);
 
288
$reverse = Bio::PrimarySeq->new(
 
289
   -seq => 'AAAAAA',
 
290
);
 
291
ok $search = Bio::Tools::AmpliconSearch->new(
 
292
   -template   => $seq,
 
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;
 
303
 
 
304
 
 
305
# Amplicons on both strands
 
306
 
 
307
$seq = Bio::PrimarySeq->new(
 
308
   -seq => 'acgtaCCCCacgtaacgtaTTTTTTacAAAAAAgtGGGGacgtaacgta',
 
309
);
 
310
$forward = Bio::PrimarySeq->new(
 
311
   -seq => 'CCCC',
 
312
);
 
313
$reverse = Bio::PrimarySeq->new(
 
314
   -seq => 'AAAAAA',
 
315
);
 
316
ok $search = Bio::Tools::AmpliconSearch->new(
 
317
   -template   => $seq,
 
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;
 
334
 
 
335
 
 
336
# Overlapping amplicons on both strands
 
337
 
 
338
$seq = Bio::PrimarySeq->new(
 
339
   -seq => 'acgtaCCCCacgtacgtacagAAAAAATTTTTTacgtGGGGacgtacgtac',
 
340
);
 
341
$forward = Bio::PrimarySeq->new(
 
342
   -seq => 'CCCC',
 
343
);
 
344
$reverse = Bio::PrimarySeq->new(
 
345
   -seq => 'AAAAAA',
 
346
);
 
347
ok $search = Bio::Tools::AmpliconSearch->new(
 
348
   -template   => $seq,
 
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;
 
359
 
 
360
 
 
361
# Annotate template
 
362
 
 
363
$seq = Bio::PrimarySeq->new(
 
364
   -seq => 'acgtaCCCCacgtacgtacTTTTTTacAAAAAAgtGGGGacgtacgtac',
 
365
);
 
366
$forward = Bio::PrimarySeq->new(
 
367
   -seq => 'CCCC',
 
368
);
 
369
$reverse = Bio::PrimarySeq->new(
 
370
   -seq => 'AAAAAA',
 
371
);
 
372
ok $search = Bio::Tools::AmpliconSearch->new(
 
373
   -template   => $seq,
 
374
   -fwd_primer => $forward,
 
375
   -rev_primer => $reverse,
 
376
), 'Annotated template';
 
377
ok $annotated = $search->annotate_template;
 
378
isa_ok $annotated, 'Bio::Seq';
 
379
$num_feats = 0;
 
380
for my $feat ( $annotated->get_SeqFeatures ) {
 
381
   $num_feats++;
 
382
   isa_ok $feat, 'Bio::SeqFeature::Amplicon';
 
383
}
 
384
is $num_feats, 2;
 
385
is $search->next_amplicon, undef;
 
386
 
 
387
 
 
388
# Update primers
 
389
 
 
390
$seq = Bio::PrimarySeq->new(
 
391
   -seq => 'acgtaCCCCacgtacgtacTTTTTTacCTCTCTgtTGTGTGacgtacgtac',
 
392
);
 
393
$forward = Bio::PrimarySeq->new(
 
394
   -seq => 'CTCTCT',
 
395
);
 
396
$reverse = Bio::PrimarySeq->new(
 
397
   -seq => 'CACACA',
 
398
);
 
399
$forward2 = Bio::PrimarySeq->new(
 
400
   -seq => 'CCCC',
 
401
);
 
402
$reverse2 = Bio::PrimarySeq->new(
 
403
   -seq => 'AAAAAA',
 
404
);
 
405
ok $search = Bio::Tools::AmpliconSearch->new(
 
406
   -template   => $seq,
 
407
), 'Update primers';
 
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;
 
422
 
 
423
 
 
424
# Update template
 
425
 
 
426
$seq = Bio::PrimarySeq->new(
 
427
   -seq => 'acgtaCCCCacgtacgtacTTTTTTa',
 
428
);
 
429
$seq2 = Bio::PrimarySeq->new(
 
430
   -seq => 'aCCCCgaTTTTTTgacgtacgtac',
 
431
);
 
432
$forward = Bio::PrimarySeq->new(
 
433
   -seq => 'CCCC',
 
434
);
 
435
$reverse = Bio::PrimarySeq->new(
 
436
   -seq => 'AAAAAA',
 
437
);
 
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;
 
452