~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

Viewing changes to t/Location.t

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*-Perl-*-
2
2
## Bioperl Test Harness Script for Modules
3
 
## $Id: Location.t,v 1.21 2002/02/03 21:00:19 jason Exp $
 
3
## $Id: Location.t,v 1.26 2002/08/12 04:25:35 lapp Exp $
4
4
 
5
5
# Before `make install' is performed this script should be runnable with
6
6
# `make test'. After `make install' it should work as `perl test.t'
7
7
 
8
8
use strict;
9
 
BEGIN {     
 
9
BEGIN {
10
10
    # to handle systems with no installed Test module
11
11
    # we include the t dir (where a copy of Test.pm is located)
12
12
    # as a fallback
15
15
        use lib 't';
16
16
    }
17
17
    use Test;
18
 
    plan tests => 45;
 
18
    plan tests => 72;
19
19
}
20
20
 
21
21
use Bio::Location::Simple;
29
29
ok(1);
30
30
 
31
31
my $simple = new Bio::Location::Simple('-start' => 10, '-end' => 20,
32
 
                                       '-strand' => 1);
 
32
                                       '-strand' => 1, -seq_id => 'my1');
33
33
ok $simple->isa('Bio::LocationI') && $simple->isa('Bio::RangeI');
34
34
 
35
35
ok $simple->start, 10;
36
36
ok $simple->end, 20;
 
37
ok $simple->seq_id, 'my1';
 
38
 
 
39
my ($loc) = $simple->each_Location();
 
40
ok $loc;
 
41
ok ("$loc", "$simple");
37
42
 
38
43
my $generic = new Bio::SeqFeature::Generic('-start' => 5, '-end' => 30, 
39
44
                                           '-strand' => 1);
65
70
ok($generic->contains($simple));
66
71
 
67
72
# fuzzy location tests
68
 
my $fuzzy = new Bio::Location::Fuzzy('-start' =>'<10', '-end' => 20, 
69
 
                                     -strand=>1);
70
 
                                     
 
73
my $fuzzy = new Bio::Location::Fuzzy('-start' =>'<10', '-end' => 20,
 
74
                                     -strand=>1, -seq_id=>'my2');
 
75
 
71
76
ok($fuzzy->strand, 1);
72
77
ok($fuzzy->start, 10);
73
78
ok($fuzzy->end,20);
78
83
ok($fuzzy->location_type, 'EXACT');
79
84
ok($fuzzy->start_pos_type, 'BEFORE');
80
85
ok($fuzzy->end_pos_type, 'EXACT');
 
86
ok $fuzzy->seq_id, 'my2';
 
87
ok $fuzzy->seq_id('my3'), 'my3';
 
88
 
 
89
($loc) = $fuzzy->each_Location();
 
90
ok $loc;
 
91
ok ("$loc", "$fuzzy");
81
92
 
82
93
# split location tests
83
94
my $splitlocation = new Bio::Location::Split;
89
100
ok($f->min_start, 13);
90
101
ok($f->max_start,13);
91
102
 
 
103
 
92
104
$f = new Bio::Location::Simple('-start'=>30,
93
105
                               '-end'=>90,
94
106
                               '-strand'=>1);
112
124
ok(! defined $f->min_start);
113
125
ok($f->max_start, 50);
114
126
 
 
127
ok (scalar($splitlocation->each_Location()), 4);
 
128
 
115
129
$splitlocation->add_sub_Location($f);
116
130
 
117
131
ok($splitlocation->max_end, 90);
127
141
ok($simple->to_FTstring(), '10..20');
128
142
$simple->strand(-1);
129
143
ok($simple->to_FTstring(), 'complement(10..20)');
130
 
ok( $splitlocation->to_FTstring(), 'join(13..30,30..90,18..22,19..20,<50..61)');
 
144
ok( $splitlocation->to_FTstring(), 
 
145
    'join(13..30,30..90,18..22,19..20,<50..61)');
131
146
# test for bug #1074
132
147
$f = new Bio::Location::Simple(-start => 5,
133
148
                               -end   => 12,
134
149
                               -strand => -1);
135
150
$splitlocation->add_sub_Location($f);
136
 
ok( $splitlocation->to_FTstring(), 'join(13..30,30..90,18..22,19..20,<50..61,complement(5..12))');
 
151
ok( $splitlocation->to_FTstring(), 
 
152
    'join(13..30,30..90,18..22,19..20,<50..61,complement(5..12))');
137
153
$splitlocation->strand(-1);
138
 
ok( $splitlocation->to_FTstring(), 'join(13..30,30..90,18..22,19..20,<50..61,complement(5..12))');
 
154
ok( $splitlocation->to_FTstring(), 
 
155
    'join(complement(13..30),complement(30..90),complement(18..22),complement(19..20),complement(<50..61),complement(5..12))');
139
156
 
140
157
$f = new Bio::Location::Fuzzy(-start => '45.60',
141
158
                              -end   => '75^80');
142
159
 
143
 
ok($f->to_FTstring(), '45.60..75^80');
 
160
ok($f->to_FTstring(), '(45.60)..(75^80)');
144
161
$f->start('20>');
145
 
ok($f->to_FTstring(), '>20..75^80');
 
162
ok($f->to_FTstring(), '>20..(75^80)');
146
163
 
147
164
# test that even when end < start that length is always positive
148
165
 
152
169
ok($f->length, 81);
153
170
ok($f->strand,-1);
154
171
 
 
172
# test that can call seq_id() on a split location;
 
173
$splitlocation = new Bio::Location::Split(-seq_id => 'mysplit1');
 
174
ok $splitlocation->seq_id,'mysplit1';
 
175
ok $splitlocation->seq_id('mysplit2'),'mysplit2';
 
176
 
 
177
 
 
178
# Test Bio::Location::Exact
 
179
 
 
180
ok my $exact = new Bio::Location::Simple('-start' => 10, '-end' => 20,
 
181
                                         '-strand' => 1, -seq_id => 'my1');
 
182
ok $exact->isa('Bio::LocationI') && $exact->isa('Bio::RangeI');
 
183
 
 
184
ok $exact->start, 10;
 
185
ok $exact->end, 20;
 
186
ok $exact->seq_id, 'my1';
 
187
ok $exact->length, 11;
 
188
ok $exact->location_type, 'EXACT';
 
189
 
 
190
ok $exact = new Bio::Location::Simple('-start' => 10, '-end' => 11,
 
191
                                      -location_type => 'IN-BETWEEN',
 
192
                                      '-strand' => 1, -seq_id => 'my2');
 
193
 
 
194
ok $exact->start, 10;
 
195
ok $exact->end, 11;
 
196
ok $exact->seq_id, 'my2';
 
197
ok $exact->length, 0;
 
198
ok $exact->location_type, 'IN-BETWEEN';
 
199
 
 
200
eval {
 
201
    $exact = new Bio::Location::Simple('-start' => 10, '-end' => 12,
 
202
                                       -location_type => 'IN-BETWEEN');
 
203
};
 
204
ok 1 if $@;
 
205
 
 
206
# testing error when assigning 10^11 simple location into fuzzy
 
207
eval {
 
208
    ok $fuzzy = new Bio::Location::Fuzzy('-start' =>'10', '-end' => 11,
 
209
                                         -location_type => '^',
 
210
                                         -strand=>1, -seq_id=>'my2');
 
211
};
 
212
ok 1 if $@;
 
213
 
 
214
$fuzzy = new Bio::Location::Fuzzy(-location_type => '^',
 
215
                                     -strand=>1, -seq_id=>'my2');
 
216
 
 
217
$fuzzy->start(10);
 
218
eval {
 
219
    $fuzzy->end(11);
 
220
};
 
221
ok 1 if $@;
 
222
 
 
223
$fuzzy = new Bio::Location::Fuzzy(-location_type => '^',
 
224
                                     -strand=>1, -seq_id=>'my2');
 
225
 
 
226
$fuzzy->end(11);
 
227
eval {
 
228
    $fuzzy->start(10);
 
229
};
 
230
ok 1 if $@;