bug 1825
[bioperl-live.git] / t / CytoMap.t
blob2b7d679bfad3f54a507be4b4add06d21cc5bb12d
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib 't/lib';
8         use BioperlTest;
9         
10         test_begin(-tests => 110);
11     
12     use_ok('Bio::Map::CytoMap');
13     use_ok('Bio::Map::CytoPosition');
14     use_ok('Bio::Map::CytoMarker');
18 # Let's test first the map class : Bio::Map::CytoMap
21 ok my $map = Bio::Map::CytoMap->new(-name  => 'my');
22 is $map->type, 'cyto'; 
23 is $map->units, ''; 
24 is $map->length, 0;
25 is $map->name, 'my';
26 is $map->species('human'), 'human';
27 is $map->species, 'human';
28 is $map->unique_id, '1';
32 # Secondly, we make sure the location calculations in
33 #           Bio::Map::CytoPosition make sense
36 my($a, $b, $r);
37 my $string = 'b';
38 is Bio::Map::CytoPosition::_pad($string, 5, 'z'), 'bzzzz';
40 ok $a = Bio::Map::CytoPosition->new();
41 isa_ok $a, 'Bio::Map::CytoPosition';
42 is $a->cytorange, undef;
45 $a->verbose(2);
46 eval {
47     is $a->value('C'), 'C'; 
48     is $a->cytorange, undef ;
50 ok $@;
51 $a->verbose(0);
53 is $a->value('X'), 'X';
54 $r = $a->cytorange;
55 isa_ok $r, 'Bio::Range';
56 is $r->start, 100000000;
57 is $r->end, 100200000;
59 $a->value('1p');
60 is $a->cytorange->start, 1000000;
61 is $a->cytorange->end, 1100000;
63 $a->value('2qter');
64 is $a->cytorange->start, 2200000;
65 is $a->cytorange->end, 2200000;
67 $a->value('2qcen');
68 is $a->cytorange->start, 2100000;
69 is $a->cytorange->end, 2100000;
71 eval {
72     $a->value('2qcen2');
73     $a->cytorange->start;
75 ok 1 if $@;
77 $a->value('2q22');
78 is $a->cytorange->start, 2122000;
79 is $a->cytorange->end, 2122999;
81 $a->value('2p22');
82 is $a->cytorange->start, 2077001;
83 is $a->cytorange->end, 2078000;
85 $a->value('2p21');
86 is $a->cytorange->start, 2078001;
87 is $a->cytorange->end, 2079000;
89 $a->value('10p22.1-cen');
90 is $a->cytorange->start, 10022199;
91 is $a->cytorange->end, 10100000;
93 eval {
94     $a->value('10q22.1-cen');
95     $a->cytorange->start;
97 ok 1 if $@;
99 $a->value('10q22.1-ter');
100 is $a->cytorange->start, 10122100;
101 is $a->cytorange->end, 10200000;
104 eval {
105     $a->value('10q22.1-p');
106     $a->cytorange->start;
108 ok 1 if $@;
110 $a->value('10qcen-qter');
111 is $a->cytorange->start, 10100000;
112 is $a->cytorange->end, 10200000;
114 $a->value('10pcen-qter');
115 is $a->cytorange->start, 10100000;
116 is $a->cytorange->end, 10200000;
118 $a->value('10q22.1-q23');
119 is $a->cytorange->start, 10122100;
120 is $a->cytorange->end, 10123999;
121 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
123 $a->value('10p22.1-p23');
124 is $a->cytorange->start, 10076001;
125 is $a->cytorange->end,  10077900;
126 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
128 $a->value('10cen-p23');
129 is $a->cytorange->start, 10076001;
130 is $a->cytorange->end, 10100000;
131 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
133 $a->value('10q22.1-p23');
134 is $a->cytorange->start, 10076001;
135 is $a->cytorange->end, 10122199;
136 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
138 $a->value('10p22.1-q23');
139 is $a->cytorange->start, 10077801;
140 is $a->cytorange->end, 10123999;
141 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
143 $a->value('10q22.1-p22');
144 is $a->cytorange->start, 10077001 ;
145 is $a->cytorange->end, 10122199 ;
147 $b = Bio::Map::CytoPosition->new();
148 $b->value('10p22-p22.1');
149 is $b->cytorange->start, 10077801 ;
150 is $b->cytorange->end, 10078000;
151 ok $a->cytorange->overlaps($b->cytorange);
153 $a->value('10p22.1-q23');
154 is $a->cytorange->start, 10077801;
155 is $a->cytorange->end, 10123999;
156 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
158 $a->value('17p13-pter');
159 is $a->cytorange->start, 17000000;
160 is $a->cytorange->end, 17087000;
161 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
163 $a->value('17cen-pter');
164 is $a->cytorange->start, 17000000;
165 is $a->cytorange->end, 17100000;
166 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
169 #-----------------------------------------
170 #my $s;
172 sub test {
173     my ($s) = @_;
174     my $a = Bio::Map::CytoPosition->new();
175     $a->value($s);
176     $r = $a->cytorange;
177     is $a->range2value($r), $s;
180 test '1';
181 test '2p';
182 test '3q';
183 test '4cen';
185 test '5pter';
186 test '6qter';
187 test '7p21';
188 test '8q11.1';
190 test '9q13.13-15';
191 test '10p13.13-q15';
192 test '11p13.13-qter';
193 test '12p13.13-qter';
194 test '13p13.13-14';
195 test '14p13.13-pter';
196 test '15cen-q2';
197 test '16cen-p2';
198 #test '17cen-pter'; eq 17p
199 #test '18cen-qter'; eq 18q 
202 # by now we should be convinced that band conversion to a range works
203 # so lets try to use it for comparing markers.
205 ok my $marker1 = Bio::Map::CytoMarker->new();
206 is $marker1->name('gene1'), 'gene1' ;
207 ok $marker1->position($map, '10p33.13-q15');
209 ok my $marker2 = Bio::Map::CytoMarker->new(-name => 'gene2' );
210 ok $marker2->position($map, '10p10-15');
211 is $marker1->get_chr, 10;
213 ok my $marker3 = Bio::Map::CytoMarker->new(-name => '3' );
214 ok $marker3->position($map, '10p1');
216 ok my $marker4 = Bio::Map::CytoMarker->new(-name => '4' );
217 ok $marker4->position($map, '10q2');
220 # Lastly, let's test the comparison methods
223 ok $marker1->equals($marker1);
224 ok ! $marker1->equals($marker2);
226 ok $marker3->less_than($marker4);
227 ok ! $marker3->greater_than($marker4);
228 ok ! $marker4->less_than($marker3);
229 ok $marker4->greater_than($marker3);
231 ok ! $marker4->overlaps($marker3);
232 ok $marker1->overlaps($marker3);
234 ok ! $marker4->contains($marker3);
235 ok $marker1->contains($marker3);
238 # Test throw() in some private functions
241 eval { Bio::Map::CytoPosition::_pad('string', -1, 'x'); };
242 like($@, qr/positive integer/);
243 eval { Bio::Map::CytoPosition::_pad('string', +1, 'toolong'); };
244 like($@, qr/single character/);