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

« back to all changes in this revision

Viewing changes to t/SeqTools/SeqUtils.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:
8
8
#    use List::MoreUtils qw(uniq);
9
9
    use Bio::Root::Test;
10
10
    
11
 
    test_begin(-tests => 53);
12
 
        
13
 
        use_ok('Bio::PrimarySeq');
14
 
        use_ok('Bio::SeqUtils');
15
 
        use_ok('Bio::LiveSeq::Mutation');
16
 
        use_ok('Bio::SeqFeature::Generic');
17
 
        use_ok('Bio::Annotation::SimpleValue');
 
11
    test_begin(-tests => 133);
 
12
 
 
13
    use_ok('Bio::PrimarySeq');
 
14
    use_ok('Bio::SeqUtils');
 
15
    use_ok('Bio::LiveSeq::Mutation');
 
16
    use_ok('Bio::SeqFeature::Generic');
 
17
    use_ok('Bio::Annotation::SimpleValue');
 
18
    use_ok('Bio::Annotation::Collection');
 
19
    use_ok('Bio::Annotation::Comment');
18
20
}
19
21
 
20
22
my ($seq, $util, $ascii, $ascii_aa, $ascii3);
27
29
    'AlaAsxCysAspGluPheGlyHisIleXleLysLeuMetAsnPylProGlnArgSerThrSecValTrpXaaTyrGlx';
28
30
 
29
31
$seq = Bio::PrimarySeq->new('-seq'=> $ascii,
30
 
                            '-alphabet'=>'protein', 
31
 
                               '-id'=>'test');
 
32
                            '-alphabet'=>'protein', 
 
33
                            '-id'=>'test');
32
34
 
33
35
# one letter amino acid code to three letter code
34
36
ok $util = Bio::SeqUtils->new();
54
56
#
55
57
 
56
58
$seq = Bio::PrimarySeq->new('-seq'=> 'agctgctgatcggattgtgatggctggatggcttgggatgctgg',
57
 
                            '-alphabet'=>'dna', 
58
 
                            '-id'=>'test2');
 
59
                            '-alphabet'=>'dna', 
 
60
                            '-id'=>'test2');
59
61
 
60
62
my @a = $util->translate_3frames($seq);
61
63
is scalar @a, 3;
93
95
 
94
96
my $string1 = 'aggt';
95
97
$seq = Bio::PrimarySeq->new('-seq'=> 'aggt',
96
 
                            '-alphabet'=>'dna',
97
 
                            '-id'=>'test3');
 
98
                            '-alphabet'=>'dna',
 
99
                            '-id'=>'test3');
98
100
 
99
101
# point
100
102
Bio::SeqUtils->mutate($seq,
171
173
my $simple3 = Bio::Annotation::SimpleValue->new(
172
174
                                                -tagname => 'colour',
173
175
                                                -value   => 'red'
174
 
                                                 ), ;
 
176
                                               );
175
177
$ac3->add_Annotation('simple',$simple3);
176
178
$seq3->annotation($ac3);
177
179
 
183
185
 
184
186
# seq features
185
187
my $ft2 = Bio::SeqFeature::Generic->new( -start => 1,
186
 
                                      -end => 4,
187
 
                                      -strand => 1,
188
 
                                      -primary => 'source',
189
 
                                      -tag     => {note => 'note2'},
190
 
                                       );
 
188
                                         -end => 4,
 
189
                                         -strand => 1,
 
190
                                         -primary => 'source',
 
191
                                         -tag     => {note => 'note2'},
 
192
                                       );
191
193
 
192
194
 
193
195
my $ft3 = Bio::SeqFeature::Generic->new( -start => 3,
194
 
                                      -end => 3,
195
 
                                      -strand => 1,
196
 
                                      -primary => 'hotspot',
197
 
                                      -tag     => {note => ['note3a','note3b'], 
198
 
                                                   comment => 'c1'},
199
 
                                       );
 
196
                                         -end => 3,
 
197
                                         -strand => 1,
 
198
                                         -primary => 'hotspot',
 
199
                                         -tag     => {note => ['note3a','note3b'],
 
200
                                                      comment => 'c1'},
 
201
                                       );
200
202
 
201
203
$seq2->add_SeqFeature($ft2);
202
204
$seq2->add_SeqFeature($ft3);
203
205
 
204
 
 
 
206
my $seq1_length = $seq1->length;
205
207
ok (Bio::SeqUtils->cat($seq1, $seq2));
206
208
is $seq1->seq, 'aaaattttcccctttt';
207
209
is scalar $seq1->annotation->get_Annotations, 5;
212
214
  @tags = map{$_->get_tag_values(q(note))}$seq1->get_SeqFeatures ;
213
215
} 'cat - note tag transfered (no throw)';
214
216
cmp_ok(scalar(@tags),'==',3, 'cat - note tag values transfered (correct count)') ;
 
217
my ($ft3_precat) = grep ($_->primary_tag eq 'hotspot', $seq2->get_SeqFeatures);
 
218
is ($ft3_precat->start, 3, "get correct start of feature before 'cat'");
 
219
my ($ft3_cat) = grep ($_->primary_tag eq 'hotspot', $seq1->get_SeqFeatures);
 
220
is ($ft3_cat->start, 3+$seq1_length, "get correct start of feature after 'cat'");
215
221
 
216
222
 
217
223
my $protseq = Bio::PrimarySeq->new(-id => 2, -seq => 'MVTF'); # protein seq
240
246
$simple3 = Bio::Annotation::SimpleValue->new(
241
247
                                                -tagname => 'colour',
242
248
                                                -value   => 'red'
243
 
                                                 ), ;
 
249
                                            );
244
250
$ac3->add_Annotation('simple',$simple3);
245
251
$seq2->annotation($ac3);
246
252
$ft2 = Bio::SeqFeature::Generic->new( -start => 1,
248
254
                                      -strand => 1,
249
255
                                      -primary => 'source',
250
256
                                      -tag     => {note => 'note2'},
251
 
                                       );
 
257
                                    );
252
258
 
253
259
 
254
260
$ft3 = Bio::SeqFeature::Generic->new( -start => 5,
257
263
                                      -primary => 'hotspot',
258
264
                                      -tag     => {note => ['note3a','note3b'], 
259
265
                                                   comment => 'c1'},
260
 
                                       );
 
266
                                    );
 
267
 
 
268
my $ft4 = Bio::SeqFeature::Generic->new(-primary => 'CDS');
 
269
$ft4->location(Bio::Location::Fuzzy->new(-start=>'<1',
 
270
                                         -end=>5,
 
271
                                         -strand=>-1));
 
272
 
261
273
$seq2->add_SeqFeature($ft2);
262
274
$seq2->add_SeqFeature($ft3);
 
275
$seq2->add_SeqFeature($ft4);
263
276
 
264
277
my $trunc=Bio::SeqUtils->trunc_with_features($seq2, 2, 7);
265
278
is $trunc->seq, 'gttaaa';
266
279
my @feat=$trunc->get_SeqFeatures;
267
280
is $feat[0]->location->to_FTstring, '<1..3';
268
281
is $feat[1]->location->to_FTstring, 'complement(4..>6)';
 
282
is $feat[2]->location->to_FTstring, 'complement(<1..4)';
269
283
is_deeply([uniq_sort(map{$_->get_all_tags}$trunc->get_SeqFeatures)], [sort qw(note comment)], 'trunc_with_features - has expected tags');
270
284
is_deeply([sort map{$_->get_tagset_values('note')}$trunc->get_SeqFeatures], [sort qw(note2 note3a note3b)], 'trunc_with_features - has expected tag values');
271
285
 
279
293
is $rf2->primary_tag, $ft2->primary_tag, 'primary_tag matches original feature...';
280
294
is $rf2->location->to_FTstring, 'complement(5..8)', 'but tagged sf is now revcom';
281
295
 
 
296
my ($rf3) = $revcom->get_SeqFeatures('CDS');
 
297
is $rf3->primary_tag, $ft4->primary_tag, 'primary_tag matches original feature...';
 
298
is $rf3->location->to_FTstring, '4..>8', 'but tagged sf is now revcom';
 
299
 
282
300
is_deeply([uniq_sort(map{$_->get_all_tags}$revcom->get_SeqFeatures)], [sort qw(note comment)], 'revcom_with_features - has expected tags');
283
301
is_deeply([sort map{$_->get_tagset_values('note')}$revcom->get_SeqFeatures], [sort qw(note2 note3a note3b)], 'revcom_with_features - has expected tag values');
284
302
# check circularity
286
304
$seq3 = Bio::Seq->new(-id => 3, -seq => 'ggttaaaa', -description => 'third', -is_circular => 1);
287
305
is(Bio::SeqUtils->revcom_with_features($seq3)->is_circular, 1, 'still circular');
288
306
 
 
307
 
 
308
# delete, insert and ligate
 
309
# prepare some sequence objects
 
310
my $seq_obj = Bio::Seq->new( 
 
311
  -seq =>'aaaaaaaaaaccccccccccggggggggggtttttttttt',
 
312
  -display_id => 'seq1',
 
313
  -desc       => 'some sequence for testing'
 
314
); 
 
315
my $subfeat1 = Bio::SeqFeature::Generic->new(
 
316
  -primary_tag => 'sf1',
 
317
  -seq_id      => 'seq1',
 
318
  -start       => 2,
 
319
  -end         => 12
 
320
);
 
321
 
 
322
my $subfeat2 = Bio::SeqFeature::Generic->new(
 
323
  -primary_tag => 'sf2',
 
324
  -seq_id      => 'seq1',
 
325
  -start       => 14,
 
326
  -end         => 16
 
327
);
 
328
my $subfeat3 = Bio::SeqFeature::Generic->new(
 
329
  -primary_tag => 'sf3',
 
330
  -seq_id      => 'seq1',
 
331
  -start       => 21,
 
332
  -end         => 25
 
333
);
 
334
 
 
335
my $composite_feat1 = Bio::SeqFeature::Generic->new(
 
336
  -primary_tag => 'comp_feat1',
 
337
  -seq_id      => 'seq1',
 
338
  -start       => 2,
 
339
  -end         => 30
 
340
);
 
341
my $coll_sf = Bio::Annotation::Collection->new;
 
342
$coll_sf->add_Annotation(
 
343
  'comment', Bio::Annotation::Comment->new( '-text' => 'a comment on sf1')
 
344
);
 
345
$subfeat1->annotation($coll_sf);
 
346
 
 
347
$composite_feat1->add_SeqFeature( $subfeat1);
 
348
$composite_feat1->add_SeqFeature( $subfeat2);
 
349
$composite_feat1->add_SeqFeature( $subfeat3);
 
350
my $feature1 = Bio::SeqFeature::Generic->new(
 
351
  -primary_tag => 'feat1',
 
352
  -seq_id      => 'seq1',
 
353
  -start       => 2,
 
354
  -end         => 25
 
355
);
 
356
my $feature2 = Bio::SeqFeature::Generic->new(
 
357
  -primary_tag => 'feat2',
 
358
  -seq_id      => 'seq1',
 
359
  -start       => 15,
 
360
  -end         => 25,
 
361
  -strand      => -1,
 
362
);
 
363
my $feature3 = Bio::SeqFeature::Generic->new(
 
364
  -primary_tag => 'feat3',
 
365
  -seq_id      => 'seq1',
 
366
  -start       => 30,
 
367
  -end         => 40
 
368
);
 
369
my $feature4 = Bio::SeqFeature::Generic->new(
 
370
  -primary_tag => 'feat4',
 
371
  -seq_id      => 'seq1',
 
372
  -start       => 1,
 
373
  -end         => 10
 
374
);
 
375
my $feature5 = Bio::SeqFeature::Generic->new(
 
376
  -primary_tag => 'feat5',
 
377
  -seq_id      => 'seq1',
 
378
  -start       => 11,
 
379
  -end         => 20
 
380
);
 
381
 
 
382
my $feature6 = Bio::SeqFeature::Generic->new(
 
383
  -primary_tag => 'feat6',
 
384
  -seq_id      => 'seq1',
 
385
  -start       => 11,
 
386
  -end         => 25
 
387
);
 
388
$seq_obj->add_SeqFeature( $composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5, $feature6);
 
389
 
 
390
my $coll = Bio::Annotation::Collection->new;
 
391
$coll->add_Annotation(
 
392
  'comment', Bio::Annotation::Comment->new( '-text' => 'a comment on the whole sequence')
 
393
);
 
394
$seq_obj->annotation($coll);
 
395
 
 
396
 
 
397
my $fragment_obj = Bio::Seq->new( 
 
398
  -seq =>'atatatatat',
 
399
  -display_id => 'fragment1',
 
400
  -desc       => 'some fragment to insert'
 
401
); 
 
402
my $frag_feature1 = Bio::SeqFeature::Generic->new(
 
403
  -primary_tag => 'frag_feat1',
 
404
  -seq_id      => 'fragment1',
 
405
  -start       => 2,
 
406
  -end         => 4,
 
407
  -strand      => -1,
 
408
);
 
409
$fragment_obj->add_SeqFeature( $frag_feature1 );
 
410
my $frag_coll = Bio::Annotation::Collection->new;
 
411
$frag_coll->add_Annotation(
 
412
  'comment', Bio::Annotation::Comment->new( '-text' => 'a comment on the fragment')
 
413
);
 
414
$fragment_obj->annotation($frag_coll);
 
415
 
 
416
# delete
 
417
my $product;
 
418
lives_ok(
 
419
  sub {
 
420
    $product = Bio::SeqUtils->delete( $seq_obj, 11, 20 );
 
421
  },
 
422
  "No error thrown when deleting a segment of the sequence"
 
423
);
 
424
 
 
425
my ($seq_obj_comment) = $seq_obj->annotation->get_Annotations('comment');
 
426
my ($product_comment) = $product->annotation->get_Annotations('comment');
 
427
is( $seq_obj_comment, $product_comment, 'annotation of whole sequence has been moved to new molecule');
 
428
 
 
429
ok( 
 
430
  grep ($_ eq 'deletion of 10bp', 
 
431
    map ($_->get_tag_values('note'), 
 
432
      grep ($_->primary_tag eq 'misc_feature', $product->get_SeqFeatures)
 
433
    )
 
434
  ),
 
435
  "the product has an additional 'misc_feature' and the note specifies the lengths of the deletion'"
 
436
);
 
437
 
 
438
my ($composite_feat1_del) = grep ($_->primary_tag eq 'comp_feat1', $product->get_SeqFeatures);
 
439
ok ($composite_feat1_del, "The composite feature is still present");
 
440
isa_ok( $composite_feat1_del, 'Bio::SeqFeature::Generic');
 
441
isa_ok( $composite_feat1_del->location, 'Bio::Location::Split', "a composite feature that spanned the deletion site has been split up, Location");
 
442
 
 
443
is( $composite_feat1_del->get_SeqFeatures, 2, 'one of the sub-eatures of the composite feature has been deleted completely');
 
444
my ($subfeat1_del) = grep ($_->primary_tag eq 'sf1', $composite_feat1_del->get_SeqFeatures);
 
445
ok ($subfeat1_del, "sub-feature 1 of the composite feature is still present");
 
446
is ($subfeat1->end, 12, "the original end of sf1 is 12");
 
447
is ($subfeat1_del->end, 10, "after deletion, the end of sf1 is 1nt before the deletion site");
 
448
is ($subfeat1->location->end_pos_type, 'EXACT', 'the original end location of sf1 EXACT');
 
449
 
 
450
my ($subfeat1_comment) = $subfeat1->annotation->get_Annotations('comment');
 
451
my ($subfeat1_del_comment) = $subfeat1_del->annotation->get_Annotations('comment');
 
452
is( $subfeat1_comment, $subfeat1_del_comment, 'annotation of subeature 1 has been moved to new molecule');
 
453
 
 
454
my ($feature1_del) = grep ($_->primary_tag eq 'feat1', $product->get_SeqFeatures);
 
455
ok ($feature1_del, "feature1 is till present");
 
456
isa_ok( $feature1_del->location, 'Bio::Location::Split', 'feature1 location has now been split by the deletion and location object');
 
457
is( my @feature1_del_sublocs = $feature1_del->location->each_Location, 2, 'feature1 has two locations after the deletion');
 
458
is( $feature1_del_sublocs[0]->start, 2, 'feature1 start is unaffected by the deletion');
 
459
is( $feature1_del_sublocs[0]->end, 10, 'feature1 end of first split is 1nt before deletion site');
 
460
is( $feature1_del_sublocs[1]->start, 11, 'feature1 start of second split is 1nt after deletion site');
 
461
is( $feature1_del_sublocs[1]->end, 15, 'feature1 end of second split has been adjusted correctly');
 
462
my @fd1_notes = $feature1_del->get_tag_values('note');
 
463
is( @fd1_notes,1, 'split feature now has a note');
 
464
is (shift @fd1_notes, '10bp internal deletion between pos 10 and 11', 'got the expected note about length and position of deletion');
 
465
 
 
466
my ($feature3_del) = grep ($_->primary_tag eq 'feat3', $product->get_SeqFeatures);
 
467
ok ($feature3_del, "feature3 is till present");
 
468
is_deeply ( [$feature3_del->start, $feature3_del->end], [$feature3->start - 10, $feature3->end - 10], 'a feature downstream of the deletion site is shifted entirely by 10nt to the left');
 
469
 
 
470
my ($feature4_del) = grep ($_->primary_tag eq 'feat4', $product->get_SeqFeatures);
 
471
ok ($feature4_del, "feature4 is till present");
 
472
is_deeply ( [$feature4_del->start, $feature4_del->end], [$feature4->start, $feature4->end], 'a feature upstream of the deletion site is not repositioned by the deletion');
 
473
 
 
474
my ($feature2_del) = grep ($_->primary_tag eq 'feat2', $product->get_SeqFeatures);
 
475
ok ($feature2_del, "feature2 is till present");
 
476
is ( $feature2_del->start, 11, 'start pos of a feature that started in the deletion site has been altered accordingly');
 
477
my @fd2_notes = $feature2_del->get_tag_values('note');
 
478
is( @fd2_notes,1, 'feature 2 now has a note');
 
479
is (shift @fd2_notes, "6bp deleted from feature 3' end", "note added to feature2 about deletion at 3' end");
 
480
 
 
481
ok (!grep ($_->primary_tag eq 'feat5', $product->get_SeqFeatures), 'a feature that was completely positioned inside the deletion site is not present on the new molecule');
 
482
 
 
483
my ($feature6_del) = grep ($_->primary_tag eq 'feat6', $product->get_SeqFeatures);
 
484
ok ($feature6_del, "feature6 is till present");
 
485
is ( $feature6_del->start, 11, 'start pos of a feature that started in the deletion site has been altered accordingly');
 
486
is ( $feature6_del->end, 15, 'end pos of a feature that started in the deletion site has been altered accordingly');
 
487
 
 
488
 
 
489
# insert
 
490
lives_ok(
 
491
  sub {
 
492
    $product = Bio::SeqUtils->insert( $seq_obj, $fragment_obj, 10 );
 
493
  },
 
494
  "No error thrown when inserting a fragment into recipient sequence"
 
495
);
 
496
($seq_obj_comment) = $seq_obj->annotation->get_Annotations('comment');
 
497
($product_comment) = $product->annotation->get_Annotations('comment');
 
498
is( $seq_obj_comment, $product_comment, 'annotation of whole sequence has been moved to new molecule');
 
499
 
 
500
my ($composite_feat1_ins) = grep ($_->primary_tag eq 'comp_feat1', $product->get_SeqFeatures);
 
501
ok ($composite_feat1_ins, "The composite feature is still present");
 
502
isa_ok( $composite_feat1_ins, 'Bio::SeqFeature::Generic');
 
503
isa_ok( $composite_feat1_ins->location, 'Bio::Location::Split', "a composite feature that spanned the insertion site has been split up, Location");
 
504
is( $composite_feat1_ins->get_SeqFeatures, 3, 'all of the parts of the composite feature are still present');
 
505
 
 
506
my ($subfeat1_ins) = grep ($_->primary_tag eq 'sf1', $composite_feat1_ins->get_SeqFeatures);
 
507
ok ($subfeat1_ins, "sub-feature 1 of the composite feature is still present");
 
508
is ($subfeat1->end, 12, "the original end of sf1 is 12");
 
509
is ($subfeat1_ins->end, $subfeat1->end + $fragment_obj->length, "after insertion, the end of sf1 has been shifted by the length of the insertion");
 
510
isa_ok( $subfeat1_ins->location, 'Bio::Location::Split', 'sub-feature 1 (spans insertion site) is now split up and');
 
511
is_deeply (
 
512
  [$subfeat1->location->end_pos_type, $subfeat1->location->start_pos_type],
 
513
  [$subfeat1_ins->location->end_pos_type, $subfeat1_ins->location->start_pos_type],
 
514
  'the start and end position types of sub-feature1 have not changed'
 
515
);
 
516
($subfeat1_comment) = $subfeat1->annotation->get_Annotations('comment');
 
517
my ($subfeat1_ins_comment) = $subfeat1_ins->annotation->get_Annotations('comment');
 
518
is( $subfeat1_comment, $subfeat1_ins_comment, 'annotation of subeature 1 has been moved to new molecule');
 
519
my @sf1ins_notes = $subfeat1_ins->get_tag_values('note');
 
520
is( @sf1ins_notes,1, 'split feature now has a note');
 
521
is (shift @sf1ins_notes, '10bp internal insertion between pos 10 and 21', 'got the expected note about length and position of insertion');
 
522
 
 
523
my ($feature3_ins) = grep ($_->primary_tag eq 'feat3', $product->get_SeqFeatures);
 
524
ok ($feature3_ins, "feature3 is till present");
 
525
is_deeply ( 
 
526
  [$feature3_ins->start, $feature3_ins->end],
 
527
  [$feature3->start + $fragment_obj->length, $feature3->end + $fragment_obj->length],
 
528
  'a feature downstream of the insertion site is shifted entirely to the left by the length of the insertion');
 
529
 
 
530
my ($feature4_ins) = grep ($_->primary_tag eq 'feat4', $product->get_SeqFeatures);
 
531
ok ($feature4_ins, "feature4 is till present");
 
532
is_deeply ( [$feature4_ins->start, $feature4_ins->end], [$feature4->start, $feature4->end], 'a feature upstream of the insertion site is not repositioned');
 
533
 
 
534
my ($frag_feature1_ins) = grep ($_->primary_tag eq 'frag_feat1', $product->get_SeqFeatures);
 
535
ok( $frag_feature1_ins, 'a feature on the inserted fragment is present on the product molecule');
 
536
is_deeply (
 
537
  [$frag_feature1_ins->start, $frag_feature1_ins->end],
 
538
  [12, 14],
 
539
  'position of the feature on the insert has been adjusted to product coordinates'
 
540
);
 
541
is( $frag_feature1_ins->strand, $frag_feature1->strand, 'strand of the feature on insert has not changed');
 
542
like( $product->desc, qr/some fragment to insert/, 'desctription of the product contains description of the fragment');
 
543
like( $product->desc, qr/some sequence for testing/, 'desctription of the product contains description of the recipient');
 
544
 
 
545
ok( 
 
546
  grep ($_ eq 'inserted fragment', 
 
547
    map ($_->get_tag_values('note'), 
 
548
      grep ($_->primary_tag eq 'misc_feature', $product->get_SeqFeatures)
 
549
    )
 
550
  ),
 
551
  "the product has an additional 'misc_feature' with note='inserted fragment'"
 
552
);
 
553
 
 
554
# ligate
 
555
lives_ok(
 
556
  sub {
 
557
    $product = Bio::SeqUtils->ligate( 
 
558
      -recipient => $seq_obj, 
 
559
      -fragment  => $fragment_obj, 
 
560
      -left      => 10, 
 
561
      -right     => 31,
 
562
      -flip      => 1
 
563
    ); 
 
564
  },
 
565
  "No error thrown using 'ligate' of fragment into recipient"
 
566
);
 
567
 
 
568
is ($product->length, 30, 'product has the expected length');
 
569
is ($product->subseq(11,20), 'atatatatat', 'the sequence of the fragment is inserted into the product');
 
570
 
 
571
my ($inserted_fragment_feature) = grep( 
 
572
  grep($_ eq 'inserted fragment', $_->get_tag_values('note')),
 
573
  grep( $_->has_tag('note'), $product->get_SeqFeatures)
 
574
);
 
575
 
 
576
ok($inserted_fragment_feature, 'we have a feature annotating the ligated fragment');
 
577
is_deeply ( 
 
578
  [$inserted_fragment_feature->start, $inserted_fragment_feature->end],
 
579
  [11, 20],
 
580
  'coordinates of the feature annotating the ligated feature are correct'
 
581
);
 
582
 
 
583
my ($fragment_feat_lig) = grep ($_->primary_tag eq 'frag_feat1', $product->get_SeqFeatures);
 
584
ok( $fragment_feat_lig, 'the fragment feature1 is now a feature of the product');
 
585
is_deeply( [$fragment_feat_lig->start, $fragment_feat_lig->end], [17,19], 'start and end of a feature on the fragment are correct after insertion with "flip" option');
 
586
 
 
587
 
 
588
SKIP: {
 
589
    skip("Storable::dclone not supported yet for Bio::SeqUtils, see ", 9) if $Bio::Root::Root::CLONE_CLASS eq 'Storable';
 
590
 
 
591
    # test clone_obj option (create new objects via clone not 'new')
 
592
    my $foo_seq_obj = Bio::Seq::Foo->new(
 
593
      -seq =>'aaaaaaaaaaccccccccccggggggggggtttttttttt',
 
594
      -display_id => 'seq1',
 
595
      -desc       => 'some sequence for testing'
 
596
    );
 
597
    for ($composite_feat1, $feature1, $feature2, $feature3, $feature4, $feature5) {
 
598
        $foo_seq_obj->add_SeqFeature( $_ );
 
599
    }
 
600
    $foo_seq_obj->annotation($coll);
 
601
 
 
602
    dies_ok(
 
603
      sub {
 
604
        $product = Bio::SeqUtils->delete( $foo_seq_obj, 11, 20, { clone_obj => 0} );
 
605
      },
 
606
      "Trying to delete from an object of a custom Bio::Seq subclass that doesn't allow calling 'new' throws an error"
 
607
    );
 
608
 
 
609
    lives_ok(
 
610
      sub {
 
611
        $product = Bio::SeqUtils->delete( $foo_seq_obj, 11, 20, { clone_obj => 1} );
 
612
      },
 
613
      "Deleting from Bio::Seq::Foo does not throw an error when using the 'clone_obj' option to clone instead of calling 'new'"
 
614
    );
 
615
 
 
616
    isa_ok( $product, 'Bio::Seq::Foo');
 
617
 
 
618
    # just repeat some of the tests for the cloned feature
 
619
    ok(
 
620
      grep ($_ eq 'deletion of 10bp',
 
621
        map ($_->get_tag_values('note'),
 
622
          grep ($_->primary_tag eq 'misc_feature', $product->get_SeqFeatures)
 
623
        )
 
624
      ),
 
625
      "the product has an additional 'misc_feature' and the note specifies the lengths of the deletion'"
 
626
    );
 
627
    ($composite_feat1_del) = grep ($_->primary_tag eq 'comp_feat1', $product->get_SeqFeatures);
 
628
    ok ($composite_feat1_del, "The composite feature is still present");
 
629
    isa_ok( $composite_feat1_del, 'Bio::SeqFeature::Generic');
 
630
    isa_ok( $composite_feat1_del->location, 'Bio::Location::Split', "a composite feature that spanned the deletion site has been split up, Location");
 
631
 
 
632
    # ligate with clone_obj
 
633
    dies_ok(
 
634
      sub {
 
635
        $product = Bio::SeqUtils->ligate(
 
636
          -recipient => $foo_seq_obj,
 
637
          -fragment  => $fragment_obj,
 
638
          -left      => 10,
 
639
          -right     => 31,
 
640
          -flip      => 1
 
641
        );
 
642
      },
 
643
      "'ligate' without clone_obj option dies with a Bio::Seq::Foo object that can't call new"
 
644
    );
 
645
 
 
646
    lives_ok(
 
647
      sub {
 
648
        $product = Bio::SeqUtils->ligate(
 
649
          -recipient => $foo_seq_obj,
 
650
          -fragment  => $fragment_obj,
 
651
          -left      => 10,
 
652
          -right     => 31,
 
653
          -flip      => 1,
 
654
          -clone_obj => 1,
 
655
        );
 
656
      },
 
657
      "'ligate' with clone_obj option works with a Bio::Seq::Foo object that can't call new"
 
658
    );
 
659
}
 
660
 
289
661
sub uniq_sort {
290
662
    my @args = @_;
291
663
    my %uniq;
293
665
    @uniq{@args} = (0..$#args);
294
666
    return sort {$uniq{$a} <=> $uniq{$b}} keys %uniq;
295
667
}
 
668
 
 
669
package Bio::Seq::Foo;
 
670
 
 
671
use base 'Bio::Seq';
 
672
 
 
673
sub can_call_new { 0 }
 
674
 
 
675