1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 45);
11 use_ok('Bio::SeqFeature::Generic');
14 my @funcs = qw(start end length strand overlaps contains
15 equals intersection union overlap_extent disconnected_ranges
16 offsetStranded subtract);
19 while (my $func = shift @funcs ) {
22 # test for presence of method
23 ok exists $Bio::RangeI::{$func};
25 # union get caught in an infinite loop w/o parameters; skip invoke test.
26 next if $func eq 'union';
28 # call to strand complains without a value; skip invoke test.
29 next if $func eq 'disconnected_ranges';
31 # test invocation of method
32 eval { $Bio::RangeI::{$func}->(); };
36 ### unit tests for subtract method ###
37 # contributed by Stephen Montgomery (sm8 at sanger.ac.uk), who also
38 # wrote the subtract method
39 my $feature1 = Bio::SeqFeature::Generic->new( -start => 1, -end =>
41 my $feature2 = Bio::SeqFeature::Generic->new( -start => 100, -end =>
44 my $subtracted = $feature1->subtract($feature2);
45 ok(defined($subtracted));
46 is(scalar(@$subtracted), 2);
47 foreach my $range (@$subtracted) {
48 ok($range->start == 1 || $range->start == 901);
49 ok($range->end == 99 || $range->end == 1000);
52 $subtracted = $feature2->subtract($feature1);
53 ok(!defined($subtracted));
54 $subtracted = $feature1->subtract($feature2, 'weak');
55 ok(!defined($subtracted));
56 $subtracted = $feature1->subtract($feature2, 'strong');
57 ok(!defined($subtracted));
59 my $feature3 = Bio::SeqFeature::Generic->new( -start => 500, -end =>
61 $subtracted = $feature1->subtract($feature3);
62 ok(defined($subtracted));
63 is scalar(@$subtracted), 1;
64 my $subtracted_i = @$subtracted[0];
65 is($subtracted_i->start, 1);
66 is($subtracted_i->end, 499);
70 # Added Bio::Location::SplitLocationI support to subtract(). --jhannah 20091018
71 $feature1 = Bio::SeqFeature::Generic->new();
72 $feature2 = Bio::SeqFeature::Generic->new();
73 my $loc = Bio::Location::Split->new();
74 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>100, -end=>200, -strand=>1));
75 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>300, -end=>400, -strand=>1));
76 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>500, -end=>600, -strand=>1));
77 $feature1->location($loc);
78 $loc = Bio::Location::Split->new();
79 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>350, -end=>400, -strand=>1));
80 $loc->add_sub_Location(Bio::Location::Simple->new(-start=>500, -end=>510, -strand=>1));
81 $feature2->location($loc);
82 $subtracted = $feature1->subtract($feature2);
83 is(@$subtracted, 3, "subtract() of split features");
84 is($subtracted->[0]->start, 100, " 0 start");
85 is($subtracted->[0]->end, 200, " 0 end");
86 is($subtracted->[1]->start, 300, " 1 start");
87 is($subtracted->[1]->end, 349, " 1 end");
88 is($subtracted->[2]->start, 511, " 2 start");
89 is($subtracted->[2]->end, 600, " 2 end");