File: Range.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (123 lines) | stat: -rw-r--r-- 3,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*-Perl-*- Test Harness script for Bioperl
# $Id: Range.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN { 
	use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 49);
	
    use_ok('Bio::Range');
}

my $range = Bio::Range->new(-start=>10,
                            -end=>20,
						    -strand=>1);

isa_ok($range,'Bio::Range', 'BioRange object');
is($range->strand, 1);

my $range2 = Bio::Range->new(-start=>15,
                             -end=>25,
						     -strand=>1);

isa_ok($range2,'Bio::Range', 'BioRange object');
is($range2->strand, 1);

my $r = Bio::Range->new();
is ( $r->strand(0), 0 ) ;
is ( $r->start(27), 27 );
is ( $r->end(28), 28 ) ;

ok(! defined $r->intersection($range2));

$r = $range->union($range2);
is($r->start, 10);
is($r->end, 25);

$r = $range->intersection($range2);
is ( $r->start, 15  ) ;
is ( $r->end, 20    );
is ( $r->strand, 1  );

# intersection and union can also take lists
my $range3 = Bio::Range->new(-start=>18,-end=>30);
isa_ok($range3,'Bio::Range', 'BioRange object');

$r = $range->intersection([$range2, $range3]);
ok( ( $r->start == 18 ) && ( $r->end == 20 ));
$r = Bio::Range->intersection([$range, $range2, $range3]);
ok($r->start == 18 && $r->end == 20);
$r = $range->union($range2, $range3);
ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
$r = Bio::Range->union($range, $range2, $range3);
ok( ( $r->start == 10 ) && ( $r->end == 30 ) );
$range3->start(21);
ok (! $range->intersection([$range2, $range3]));

ok (! $range->contains($range2));
ok (! $range2->contains($range));
ok ($range->overlaps($range2));
ok ($range2->overlaps($range));

# testing strand
$range3 = Bio::Range->new(-start => 15,
                           -end => 25,
						   -strand => 1);

my $range4 = Bio::Range->new(-start => 15,
						    -end => 25,
							-strand => -1);

isa_ok($range4,'Bio::Range', 'BioRange object');

my $range5 = Bio::Range->new(-start => 15,
                             -end => 25,
						     -strand => 0);

isa_ok($range5,'Bio::Range', 'BioRange object');

my $range6 = Bio::Range->new(-start => 20,
							 -end => 30,
							 -strand => -1);

isa_ok($range6,'Bio::Range', 'BioRange object');

ok $range3->_ignore($range4), ' 1 & -1' ;     
ok $range3->_weak($range3),' 1 & 1 true' ;       
ok $range3->_weak($range5), ' 1 & 0 true' ;       
ok (! $range3->_weak($range4), ' 1 & -1 false' );   
ok $range3->_strong($range3), ' 1 & 1 true' ;     
ok (! $range3->_strong($range5), ' 1 & 0 false' ); 
ok (! $range3->_strong($range4), ' 1 & -1 false' ); 

ok ! ( $range3->overlaps($range4,'weak'));
ok ! ( $range4->overlaps($range3,'weak'));
ok ! ( $range3->overlaps($range4,'strong')); 
ok ! ( $range4->overlaps($range3,'strong')); 

$range3->strand(0);

ok  ( $range3->overlaps($range4,'weak'));
ok  ( $range4->overlaps($range3,'weak')); 
ok ! ( $range3->overlaps($range4,'strong'));
ok ! ( $range4->overlaps($range3,'strong')); 

# if strands are different then intersection() should return 0...
$r = $range3->intersection($range4);
is ( $r->strand, 0 );

# or if both strands are -1 then -1 should be returned
$r = $range6->intersection($range4);
is ( $r->strand, -1 );

# test implemention of offsetStranded:
$r = Bio::Range->new(-start => 30, -end => 40, -strand => -1);
isa_ok($r, 'Bio::Range', 'Bio::Range object') ;
is ($r->offsetStranded(-5,10)->toString, '(20, 45) strand=-1');
is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=-1');
$r->strand(1);
is ($r->offsetStranded(-5,10)->toString, '(25, 50) strand=1');
is ($r->offsetStranded(+5,-10)->toString, '(30, 40) strand=1');