1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 103);
12 use_ok('Bio::Location::Simple');
13 use_ok('Bio::Location::Split');
14 use_ok('Bio::Location::Fuzzy');
15 use_ok('Bio::SeqFeature::Generic');
16 use_ok('Bio::SeqFeature::SimilarityPair');
17 use_ok('Bio::SeqFeature::FeaturePair');
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 $similarity = Bio::SeqFeature::SimilarityPair->new();
43 my $feat1 = Bio::SeqFeature::Generic->new('-start' => 30, '-end' => 43,
45 my $feat2 = Bio::SeqFeature::Generic->new('-start' => 80, '-end' => 90,
48 my $featpair = Bio::SeqFeature::FeaturePair->new('-feature1' => $feat1,
49 '-feature2' => $feat2 );
51 my $feat3 = Bio::SeqFeature::Generic->new('-start' => 35, '-end' => 50,
54 is($featpair->start, 30,'Bio::SeqFeature::FeaturePair tests');
55 is($featpair->end, 43);
57 is($featpair->length, 14);
59 ok($featpair->overlaps($feat3));
60 ok($generic->overlaps($simple), 'Bio::SeqFeature::Generic tests');
61 ok($generic->contains($simple));
63 # fuzzy location tests
64 my $fuzzy = Bio::Location::Fuzzy->new('-start' =>'<10',
69 is($fuzzy->strand, 1, 'Bio::Location::Fuzzy tests');
70 is($fuzzy->start, 10);
72 ok(!defined $fuzzy->min_start);
73 is($fuzzy->max_start, 10);
74 is($fuzzy->min_end, 20);
75 is($fuzzy->max_end, 20);
76 is($fuzzy->location_type, 'EXACT');
77 is($fuzzy->start_pos_type, 'BEFORE');
78 is($fuzzy->end_pos_type, 'EXACT');
79 is($fuzzy->seq_id, 'my2');
80 is($fuzzy->seq_id('my3'), 'my3');
82 ($loc) = $fuzzy->each_Location();
86 # split location tests
87 my $splitlocation = Bio::Location::Split->new();
88 my $f = Bio::Location::Simple->new(-start => 13,
91 $splitlocation->add_sub_Location($f);
92 is($f->start, 13, 'Bio::Location::Split tests');
93 is($f->min_start, 13);
97 $f = Bio::Location::Simple->new(-start =>30,
100 $splitlocation->add_sub_Location($f);
102 $f = Bio::Location::Simple->new(-start =>18,
105 $splitlocation->add_sub_Location($f);
107 $f = Bio::Location::Simple->new(-start =>19,
111 $splitlocation->add_sub_Location($f);
113 $f = Bio::Location::Fuzzy->new(-start =>"<50",
117 ok(! defined $f->min_start);
118 is($f->max_start, 50);
120 is(scalar($splitlocation->each_Location()), 4);
122 $splitlocation->add_sub_Location($f);
124 is($splitlocation->max_end, 90);
125 is($splitlocation->min_start, 13);
126 is($splitlocation->end, 90);
127 is($splitlocation->start, 13);
128 is($splitlocation->sub_Location(),5);
131 is($fuzzy->to_FTstring(), '<10..20');
133 is($fuzzy->to_FTstring(), 'complement(<10..20)');
134 is($simple->to_FTstring(), '10..20');
136 is($simple->to_FTstring(), 'complement(10..20)');
137 is( $splitlocation->to_FTstring(),
138 'join(13..30,30..90,18..22,19..20,<50..61)');
141 $f = Bio::Location::Simple->new(-start => 5,
144 $splitlocation->add_sub_Location($f);
145 is( $splitlocation->to_FTstring(),
146 'join(13..30,30..90,18..22,19..20,<50..61,complement(5..12))',
148 $splitlocation->strand(-1);
149 is( $splitlocation->to_FTstring(),
150 'complement(join(13..30,30..90,18..22,19..20,<50..61,5..12))');
152 $f = Bio::Location::Fuzzy->new(-start => '45.60',
155 is($f->to_FTstring(), '(45.60)..(75^80)');
157 is($f->to_FTstring(), '>20..(75^80)');
159 # test that even when end < start that length is always positive
161 $f = Bio::Location::Simple->new(-verbose => -1,
166 is($f->length, 81, 'Positive length');
169 # test that can call seq_id() on a split location;
170 $splitlocation = Bio::Location::Split->new(-seq_id => 'mysplit1');
171 is($splitlocation->seq_id,'mysplit1', 'seq_id() on Bio::Location::Split');
172 is($splitlocation->seq_id('mysplit2'),'mysplit2');
175 # Test Bio::Location::Exact
177 ok(my $exact = Bio::Location::Simple->new(-start => 10,
181 isa_ok($exact, 'Bio::LocationI');
182 isa_ok($exact, 'Bio::RangeI');
184 is( $exact->start, 10, 'Bio::Location::Simple EXACT');
185 is( $exact->end, 20);
186 is( $exact->seq_id, 'my1');
187 is( $exact->length, 11);
188 is( $exact->location_type, 'EXACT');
190 ok ($exact = Bio::Location::Simple->new(-start => 10,
192 -location_type => 'IN-BETWEEN',
196 is($exact->start, 10, 'Bio::Location::Simple IN-BETWEEN');
198 is($exact->seq_id, 'my2');
199 is($exact->length, 0);
200 is($exact->location_type, 'IN-BETWEEN');
203 $exact = Bio::Location::Simple->new(-start => 10,
205 -location_type => 'IN-BETWEEN');
207 ok( $@, 'Testing error handling' );
209 # testing error when assigning 10^11 simple location into fuzzy
211 ok $fuzzy = Bio::Location::Fuzzy->new(-start => 10,
213 -location_type => '^',
219 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
224 eval { $fuzzy->end(11) };
227 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
237 # testing coodinate policy modules
239 use_ok('Bio::Location::WidestCoordPolicy');
240 use_ok('Bio::Location::NarrowestCoordPolicy');
241 use_ok('Bio::Location::AvWithinCoordPolicy');
243 $f = Bio::Location::Fuzzy->new(-start => '40.60',
245 is $f->start, 40, 'Default coodinate policy';
248 is $f->to_FTstring, '(40.60)..(80.100)';
249 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');
251 # this gives an odd location string; is it legal?
252 $f->coordinate_policy(Bio::Location::NarrowestCoordPolicy->new());
253 is $f->start, 60, 'Narrowest coodinate policy';
256 is $f->to_FTstring, '(60.60)..(80.80)';
257 isa_ok($f->coordinate_policy, 'Bio::Location::NarrowestCoordPolicy');
259 # this gives an odd location string
260 $f->coordinate_policy(Bio::Location::AvWithinCoordPolicy->new());
261 is $f->start, 50, 'Average coodinate policy';
264 is $f->to_FTstring, '(50.60)..(80.90)';
265 isa_ok($f->coordinate_policy, 'Bio::Location::AvWithinCoordPolicy');
267 # to complete the circle
268 $f->coordinate_policy(Bio::Location::WidestCoordPolicy->new());
269 is $f->start, 40, 'Widest coodinate policy';
272 is $f->to_FTstring, '(40.60)..(80.100)';
273 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');