1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 109);
11 use_ok('Bio::Location::Simple');
12 use_ok('Bio::Location::Split');
13 use_ok('Bio::Location::Fuzzy');
14 use_ok('Bio::SeqFeature::Generic');
15 use_ok('Bio::SeqFeature::SimilarityPair');
16 use_ok('Bio::SeqFeature::FeaturePair');
17 use_ok('Bio::SeqFeature::Lite');
20 my $simple = Bio::Location::Simple->new('-start' => 10, '-end' => 20,
21 '-strand' => 1, -seq_id => 'my1');
22 isa_ok($simple, 'Bio::LocationI');
23 isa_ok($simple, 'Bio::RangeI');
25 is($simple->start, 10, 'Bio::Location::Simple tests');
27 is($simple->seq_id, 'my1');
29 my ($loc) = $simple->each_Location();
31 is("$loc", "$simple");
33 my $generic = Bio::SeqFeature::Generic->new('-start' => 5, '-end' => 30,
36 isa_ok($generic,'Bio::SeqFeatureI', 'Bio::SeqFeature::Generic' );
37 isa_ok($generic,'Bio::RangeI');
38 is($generic->start, 5);
39 is($generic->end, 30);
41 my $lite_pos = Bio::SeqFeature::Lite->new(-start => 1000, -stop => 2000, -strand => '+');
42 my $lite_neg = Bio::SeqFeature::Lite->new(-start => 1000, -end => 2000, -strand => '-');
43 my $lite_none = Bio::SeqFeature::Lite->new(-start => 1000, -stop => 2000, -strand => '.');
44 is($lite_pos->strand, 1);
45 is($lite_neg->strand, -1);
46 is($lite_neg->end, 2000);
47 is($lite_neg->stop, 2000);
48 is($lite_none->strand, 0);
50 my $similarity = Bio::SeqFeature::SimilarityPair->new();
52 my $feat1 = Bio::SeqFeature::Generic->new('-start' => 30, '-end' => 43,
54 my $feat2 = Bio::SeqFeature::Generic->new('-start' => 80, '-end' => 90,
57 my $featpair = Bio::SeqFeature::FeaturePair->new('-feature1' => $feat1,
58 '-feature2' => $feat2 );
60 my $feat3 = Bio::SeqFeature::Generic->new('-start' => 35, '-end' => 50,
63 is($featpair->start, 30,'Bio::SeqFeature::FeaturePair tests');
64 is($featpair->end, 43);
66 is($featpair->length, 14);
68 ok($featpair->overlaps($feat3));
69 ok($generic->overlaps($simple), 'Bio::SeqFeature::Generic tests');
70 ok($generic->contains($simple));
72 # fuzzy location tests
73 my $fuzzy = Bio::Location::Fuzzy->new('-start' =>'<10',
78 is($fuzzy->strand, 1, 'Bio::Location::Fuzzy tests');
79 is($fuzzy->start, 10);
81 ok(!defined $fuzzy->min_start);
82 is($fuzzy->max_start, 10);
83 is($fuzzy->min_end, 20);
84 is($fuzzy->max_end, 20);
85 is($fuzzy->location_type, 'EXACT');
86 is($fuzzy->start_pos_type, 'BEFORE');
87 is($fuzzy->end_pos_type, 'EXACT');
88 is($fuzzy->seq_id, 'my2');
89 is($fuzzy->seq_id('my3'), 'my3');
91 ($loc) = $fuzzy->each_Location();
95 # split location tests
96 my $splitlocation = Bio::Location::Split->new();
97 my $f = Bio::Location::Simple->new(-start => 13,
100 $splitlocation->add_sub_Location($f);
101 is($f->start, 13, 'Bio::Location::Split tests');
102 is($f->min_start, 13);
103 is($f->max_start,13);
106 $f = Bio::Location::Simple->new(-start =>30,
109 $splitlocation->add_sub_Location($f);
111 $f = Bio::Location::Simple->new(-start =>11,
114 $splitlocation->add_sub_Location($f);
116 $f = Bio::Location::Simple->new(-start =>19,
120 $splitlocation->add_sub_Location($f);
122 $f = Bio::Location::Fuzzy->new(-start =>"<50",
126 ok(! defined $f->min_start);
127 is($f->max_start, 50);
129 is(scalar($splitlocation->each_Location()), 4);
131 $splitlocation->add_sub_Location($f);
133 # For unsorted split locations like this:
134 # ('join(13..30,30..90,11..22,19..20,<50..61)'),
135 # BioPerl will assume Start and End belongs to the
136 # first and last segments respectively, because sorting
137 # would break real cases like circular cut by origin features
138 is($splitlocation->end, 61);
139 is($splitlocation->start, 13);
140 is($splitlocation->sub_Location(),5);
141 # Minimum Start and Maximum End in unsorted sublocations can be
142 # achieved by asking explicitly sub_Location to sort the segments
143 my @increase_sort_sublocs = $splitlocation->sub_Location(1); # Forward sort by Start
144 my @decrease_sort_sublocs = $splitlocation->sub_Location(-1); # Reverse sort by End
145 is($increase_sort_sublocs[0]->min_start, 11);
146 is($decrease_sort_sublocs[0]->max_end, 90);
148 is($fuzzy->to_FTstring(), '<10..20');
150 is($fuzzy->to_FTstring(), 'complement(<10..20)');
151 is($simple->to_FTstring(), '10..20');
153 is($simple->to_FTstring(), 'complement(10..20)');
154 is( $splitlocation->to_FTstring(),
155 'join(13..30,30..90,11..22,19..20,<50..61)');
158 $f = Bio::Location::Simple->new(-start => 5,
161 $splitlocation->add_sub_Location($f);
162 is( $splitlocation->to_FTstring(),
163 'join(13..30,30..90,11..22,19..20,<50..61,complement(5..12))',
165 $splitlocation->strand(-1);
166 is( $splitlocation->to_FTstring(),
167 'complement(join(13..30,30..90,11..22,19..20,<50..61,5..12))');
169 $f = Bio::Location::Fuzzy->new(-start => '45.60',
172 is($f->to_FTstring(), '(45.60)..(75^80)');
174 is($f->to_FTstring(), '>20..(75^80)');
176 # test that even when end < start that length is always positive
178 $f = Bio::Location::Simple->new(-verbose => -1,
183 is($f->length, 81, 'Positive length');
186 # test that can call seq_id() on a split location;
187 $splitlocation = Bio::Location::Split->new(-seq_id => 'mysplit1');
188 is($splitlocation->seq_id,'mysplit1', 'seq_id() on Bio::Location::Split');
189 is($splitlocation->seq_id('mysplit2'),'mysplit2');
192 # Test Bio::Location::Exact
194 ok(my $exact = Bio::Location::Simple->new(-start => 10,
198 isa_ok($exact, 'Bio::LocationI');
199 isa_ok($exact, 'Bio::RangeI');
201 is( $exact->start, 10, 'Bio::Location::Simple EXACT');
202 is( $exact->end, 20);
203 is( $exact->seq_id, 'my1');
204 is( $exact->length, 11);
205 is( $exact->location_type, 'EXACT');
207 ok ($exact = Bio::Location::Simple->new(-start => 10,
209 -location_type => 'IN-BETWEEN',
213 is($exact->start, 10, 'Bio::Location::Simple IN-BETWEEN');
215 is($exact->seq_id, 'my2');
216 is($exact->length, 0);
217 is($exact->location_type, 'IN-BETWEEN');
220 $exact = Bio::Location::Simple->new(-start => 10,
222 -location_type => 'IN-BETWEEN');
224 ok( $@, 'Testing error handling' );
226 # testing error when assigning 10^11 simple location into fuzzy
228 ok $fuzzy = Bio::Location::Fuzzy->new(-start => 10,
230 -location_type => '^',
236 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
241 eval { $fuzzy->end(11) };
244 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
254 # testing coodinate policy modules
256 use_ok('Bio::Location::WidestCoordPolicy');
257 use_ok('Bio::Location::NarrowestCoordPolicy');
258 use_ok('Bio::Location::AvWithinCoordPolicy');
260 $f = Bio::Location::Fuzzy->new(-start => '40.60',
262 is $f->start, 40, 'Default coodinate policy';
265 is $f->to_FTstring, '(40.60)..(80.100)';
266 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');
268 # this gives an odd location string; is it legal?
269 $f->coordinate_policy(Bio::Location::NarrowestCoordPolicy->new());
270 is $f->start, 60, 'Narrowest coodinate policy';
273 is $f->to_FTstring, '(60.60)..(80.80)';
274 isa_ok($f->coordinate_policy, 'Bio::Location::NarrowestCoordPolicy');
276 # this gives an odd location string
277 $f->coordinate_policy(Bio::Location::AvWithinCoordPolicy->new());
278 is $f->start, 50, 'Average coodinate policy';
281 is $f->to_FTstring, '(50.60)..(80.90)';
282 isa_ok($f->coordinate_policy, 'Bio::Location::AvWithinCoordPolicy');
284 # to complete the circle
285 $f->coordinate_policy(Bio::Location::WidestCoordPolicy->new());
286 is $f->start, 40, 'Widest coodinate policy';
289 is $f->to_FTstring, '(40.60)..(80.100)';
290 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');