1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 109);
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');
18 use_ok('Bio::SeqFeature::Lite');
21 my $simple = Bio::Location::Simple->new('-start' => 10, '-end' => 20,
22 '-strand' => 1, -seq_id => 'my1');
23 isa_ok($simple, 'Bio::LocationI');
24 isa_ok($simple, 'Bio::RangeI');
26 is($simple->start, 10, 'Bio::Location::Simple tests');
28 is($simple->seq_id, 'my1');
30 my ($loc) = $simple->each_Location();
32 is("$loc", "$simple");
34 my $generic = Bio::SeqFeature::Generic->new('-start' => 5, '-end' => 30,
37 isa_ok($generic,'Bio::SeqFeatureI', 'Bio::SeqFeature::Generic' );
38 isa_ok($generic,'Bio::RangeI');
39 is($generic->start, 5);
40 is($generic->end, 30);
42 my $lite_pos = Bio::SeqFeature::Lite->new(-start => 1000, -stop => 2000, -strand => '+');
43 my $lite_neg = Bio::SeqFeature::Lite->new(-start => 1000, -end => 2000, -strand => '-');
44 my $lite_none = Bio::SeqFeature::Lite->new(-start => 1000, -stop => 2000, -strand => '.');
45 is($lite_pos->strand, 1);
46 is($lite_neg->strand, -1);
47 is($lite_neg->end, 2000);
48 is($lite_neg->stop, 2000);
49 is($lite_none->strand, 0);
51 my $similarity = Bio::SeqFeature::SimilarityPair->new();
53 my $feat1 = Bio::SeqFeature::Generic->new('-start' => 30, '-end' => 43,
55 my $feat2 = Bio::SeqFeature::Generic->new('-start' => 80, '-end' => 90,
58 my $featpair = Bio::SeqFeature::FeaturePair->new('-feature1' => $feat1,
59 '-feature2' => $feat2 );
61 my $feat3 = Bio::SeqFeature::Generic->new('-start' => 35, '-end' => 50,
64 is($featpair->start, 30,'Bio::SeqFeature::FeaturePair tests');
65 is($featpair->end, 43);
67 is($featpair->length, 14);
69 ok($featpair->overlaps($feat3));
70 ok($generic->overlaps($simple), 'Bio::SeqFeature::Generic tests');
71 ok($generic->contains($simple));
73 # fuzzy location tests
74 my $fuzzy = Bio::Location::Fuzzy->new('-start' =>'<10',
79 is($fuzzy->strand, 1, 'Bio::Location::Fuzzy tests');
80 is($fuzzy->start, 10);
82 ok(!defined $fuzzy->min_start);
83 is($fuzzy->max_start, 10);
84 is($fuzzy->min_end, 20);
85 is($fuzzy->max_end, 20);
86 is($fuzzy->location_type, 'EXACT');
87 is($fuzzy->start_pos_type, 'BEFORE');
88 is($fuzzy->end_pos_type, 'EXACT');
89 is($fuzzy->seq_id, 'my2');
90 is($fuzzy->seq_id('my3'), 'my3');
92 ($loc) = $fuzzy->each_Location();
96 # split location tests
97 my $splitlocation = Bio::Location::Split->new();
98 my $f = Bio::Location::Simple->new(-start => 13,
101 $splitlocation->add_sub_Location($f);
102 is($f->start, 13, 'Bio::Location::Split tests');
103 is($f->min_start, 13);
104 is($f->max_start,13);
107 $f = Bio::Location::Simple->new(-start =>30,
110 $splitlocation->add_sub_Location($f);
112 $f = Bio::Location::Simple->new(-start =>11,
115 $splitlocation->add_sub_Location($f);
117 $f = Bio::Location::Simple->new(-start =>19,
121 $splitlocation->add_sub_Location($f);
123 $f = Bio::Location::Fuzzy->new(-start =>"<50",
127 ok(! defined $f->min_start);
128 is($f->max_start, 50);
130 is(scalar($splitlocation->each_Location()), 4);
132 $splitlocation->add_sub_Location($f);
134 # For unsorted split locations like this:
135 # ('join(13..30,30..90,11..22,19..20,<50..61)'),
136 # BioPerl will assume Start and End belongs to the
137 # first and last segments respectively, because sorting
138 # would break real cases like circular cut by origin features
139 is($splitlocation->end, 61);
140 is($splitlocation->start, 13);
141 is($splitlocation->sub_Location(),5);
142 # Minimum Start and Maximum End in unsorted sublocations can be
143 # achieved by asking explicitly sub_Location to sort the segments
144 my @increase_sort_sublocs = $splitlocation->sub_Location(1); # Forward sort by Start
145 my @decrease_sort_sublocs = $splitlocation->sub_Location(-1); # Reverse sort by End
146 is($increase_sort_sublocs[0]->min_start, 11);
147 is($decrease_sort_sublocs[0]->max_end, 90);
149 is($fuzzy->to_FTstring(), '<10..20');
151 is($fuzzy->to_FTstring(), 'complement(<10..20)');
152 is($simple->to_FTstring(), '10..20');
154 is($simple->to_FTstring(), 'complement(10..20)');
155 is( $splitlocation->to_FTstring(),
156 'join(13..30,30..90,11..22,19..20,<50..61)');
159 $f = Bio::Location::Simple->new(-start => 5,
162 $splitlocation->add_sub_Location($f);
163 is( $splitlocation->to_FTstring(),
164 'join(13..30,30..90,11..22,19..20,<50..61,complement(5..12))',
166 $splitlocation->strand(-1);
167 is( $splitlocation->to_FTstring(),
168 'complement(join(13..30,30..90,11..22,19..20,<50..61,5..12))');
170 $f = Bio::Location::Fuzzy->new(-start => '45.60',
173 is($f->to_FTstring(), '(45.60)..(75^80)');
175 is($f->to_FTstring(), '>20..(75^80)');
177 # test that even when end < start that length is always positive
179 $f = Bio::Location::Simple->new(-verbose => -1,
184 is($f->length, 81, 'Positive length');
187 # test that can call seq_id() on a split location;
188 $splitlocation = Bio::Location::Split->new(-seq_id => 'mysplit1');
189 is($splitlocation->seq_id,'mysplit1', 'seq_id() on Bio::Location::Split');
190 is($splitlocation->seq_id('mysplit2'),'mysplit2');
193 # Test Bio::Location::Exact
195 ok(my $exact = Bio::Location::Simple->new(-start => 10,
199 isa_ok($exact, 'Bio::LocationI');
200 isa_ok($exact, 'Bio::RangeI');
202 is( $exact->start, 10, 'Bio::Location::Simple EXACT');
203 is( $exact->end, 20);
204 is( $exact->seq_id, 'my1');
205 is( $exact->length, 11);
206 is( $exact->location_type, 'EXACT');
208 ok ($exact = Bio::Location::Simple->new(-start => 10,
210 -location_type => 'IN-BETWEEN',
214 is($exact->start, 10, 'Bio::Location::Simple IN-BETWEEN');
216 is($exact->seq_id, 'my2');
217 is($exact->length, 0);
218 is($exact->location_type, 'IN-BETWEEN');
221 $exact = Bio::Location::Simple->new(-start => 10,
223 -location_type => 'IN-BETWEEN');
225 ok( $@, 'Testing error handling' );
227 # testing error when assigning 10^11 simple location into fuzzy
229 ok $fuzzy = Bio::Location::Fuzzy->new(-start => 10,
231 -location_type => '^',
237 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
242 eval { $fuzzy->end(11) };
245 $fuzzy = Bio::Location::Fuzzy->new(-location_type => '^',
255 # testing coodinate policy modules
257 use_ok('Bio::Location::WidestCoordPolicy');
258 use_ok('Bio::Location::NarrowestCoordPolicy');
259 use_ok('Bio::Location::AvWithinCoordPolicy');
261 $f = Bio::Location::Fuzzy->new(-start => '40.60',
263 is $f->start, 40, 'Default coodinate policy';
266 is $f->to_FTstring, '(40.60)..(80.100)';
267 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');
269 # this gives an odd location string; is it legal?
270 $f->coordinate_policy(Bio::Location::NarrowestCoordPolicy->new());
271 is $f->start, 60, 'Narrowest coodinate policy';
274 is $f->to_FTstring, '(60.60)..(80.80)';
275 isa_ok($f->coordinate_policy, 'Bio::Location::NarrowestCoordPolicy');
277 # this gives an odd location string
278 $f->coordinate_policy(Bio::Location::AvWithinCoordPolicy->new());
279 is $f->start, 50, 'Average coodinate policy';
282 is $f->to_FTstring, '(50.60)..(80.90)';
283 isa_ok($f->coordinate_policy, 'Bio::Location::AvWithinCoordPolicy');
285 # to complete the circle
286 $f->coordinate_policy(Bio::Location::WidestCoordPolicy->new());
287 is $f->start, 40, 'Widest coodinate policy';
290 is $f->to_FTstring, '(40.60)..(80.100)';
291 isa_ok($f->coordinate_policy, 'Bio::Location::WidestCoordPolicy');