t/*: remove "use lib '.'" and t/lib/Error.pm
[bioperl-live.git] / t / Map / Cyto.t
blob1cceae054b1a66ddbab19e1b10e61b2d610ce563
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         use Bio::Root::Test;
8         
9         test_begin(-tests => 110);
10     
11     use_ok('Bio::Map::CytoMap');
12     use_ok('Bio::Map::CytoPosition');
13     use_ok('Bio::Map::CytoMarker');
17 # Let's test first the map class : Bio::Map::CytoMap
20 ok my $map = Bio::Map::CytoMap->new(-name  => 'my');
21 is $map->type, 'cyto'; 
22 is $map->units, ''; 
23 is $map->length, 0;
24 is $map->name, 'my';
25 is $map->species('human'), 'human';
26 is $map->species, 'human';
27 is $map->unique_id, '1';
31 # Secondly, we make sure the location calculations in
32 #           Bio::Map::CytoPosition make sense
35 my($a, $b, $r);
36 my $string = 'b';
37 is Bio::Map::CytoPosition::_pad($string, 5, 'z'), 'bzzzz';
39 ok $a = Bio::Map::CytoPosition->new();
40 isa_ok $a, 'Bio::Map::CytoPosition';
41 is $a->cytorange, undef;
44 $a->verbose(2);
45 eval {
46     is $a->value('C'), 'C'; 
47     is $a->cytorange, undef ;
49 ok $@;
50 $a->verbose(0);
52 is $a->value('X'), 'X';
53 $r = $a->cytorange;
54 isa_ok $r, 'Bio::Range';
55 is $r->start, 100000000;
56 is $r->end, 100200000;
58 $a->value('1p');
59 is $a->cytorange->start, 1000000;
60 is $a->cytorange->end, 1100000;
62 $a->value('2qter');
63 is $a->cytorange->start, 2200000;
64 is $a->cytorange->end, 2200000;
66 $a->value('2qcen');
67 is $a->cytorange->start, 2100000;
68 is $a->cytorange->end, 2100000;
70 eval {
71     $a->value('2qcen2');
72     $a->cytorange->start;
74 ok 1 if $@;
76 $a->value('2q22');
77 is $a->cytorange->start, 2122000;
78 is $a->cytorange->end, 2122999;
80 $a->value('2p22');
81 is $a->cytorange->start, 2077001;
82 is $a->cytorange->end, 2078000;
84 $a->value('2p21');
85 is $a->cytorange->start, 2078001;
86 is $a->cytorange->end, 2079000;
88 $a->value('10p22.1-cen');
89 is $a->cytorange->start, 10022199;
90 is $a->cytorange->end, 10100000;
92 eval {
93     $a->value('10q22.1-cen');
94     $a->cytorange->start;
96 ok 1 if $@;
98 $a->value('10q22.1-ter');
99 is $a->cytorange->start, 10122100;
100 is $a->cytorange->end, 10200000;
103 eval {
104     $a->value('10q22.1-p');
105     $a->cytorange->start;
107 ok 1 if $@;
109 $a->value('10qcen-qter');
110 is $a->cytorange->start, 10100000;
111 is $a->cytorange->end, 10200000;
113 $a->value('10pcen-qter');
114 is $a->cytorange->start, 10100000;
115 is $a->cytorange->end, 10200000;
117 $a->value('10q22.1-q23');
118 is $a->cytorange->start, 10122100;
119 is $a->cytorange->end, 10123999;
120 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
122 $a->value('10p22.1-p23');
123 is $a->cytorange->start, 10076001;
124 is $a->cytorange->end,  10077900;
125 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
127 $a->value('10cen-p23');
128 is $a->cytorange->start, 10076001;
129 is $a->cytorange->end, 10100000;
130 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
132 $a->value('10q22.1-p23');
133 is $a->cytorange->start, 10076001;
134 is $a->cytorange->end, 10122199;
135 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
137 $a->value('10p22.1-q23');
138 is $a->cytorange->start, 10077801;
139 is $a->cytorange->end, 10123999;
140 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
142 $a->value('10q22.1-p22');
143 is $a->cytorange->start, 10077001 ;
144 is $a->cytorange->end, 10122199 ;
146 $b = Bio::Map::CytoPosition->new();
147 $b->value('10p22-p22.1');
148 is $b->cytorange->start, 10077801 ;
149 is $b->cytorange->end, 10078000;
150 ok $a->cytorange->overlaps($b->cytorange);
152 $a->value('10p22.1-q23');
153 is $a->cytorange->start, 10077801;
154 is $a->cytorange->end, 10123999;
155 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
157 $a->value('17p13-pter');
158 is $a->cytorange->start, 17000000;
159 is $a->cytorange->end, 17087000;
160 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
162 $a->value('17cen-pter');
163 is $a->cytorange->start, 17000000;
164 is $a->cytorange->end, 17100000;
165 cmp_ok ($a->cytorange->start, '<', $a->cytorange->end );
168 #-----------------------------------------
169 #my $s;
171 sub test {
172     my ($s) = @_;
173     my $a = Bio::Map::CytoPosition->new();
174     $a->value($s);
175     $r = $a->cytorange;
176     is $a->range2value($r), $s;
179 test '1';
180 test '2p';
181 test '3q';
182 test '4cen';
184 test '5pter';
185 test '6qter';
186 test '7p21';
187 test '8q11.1';
189 test '9q13.13-15';
190 test '10p13.13-q15';
191 test '11p13.13-qter';
192 test '12p13.13-qter';
193 test '13p13.13-14';
194 test '14p13.13-pter';
195 test '15cen-q2';
196 test '16cen-p2';
197 #test '17cen-pter'; eq 17p
198 #test '18cen-qter'; eq 18q 
201 # by now we should be convinced that band conversion to a range works
202 # so lets try to use it for comparing markers.
204 ok my $marker1 = Bio::Map::CytoMarker->new();
205 is $marker1->name('gene1'), 'gene1' ;
206 ok $marker1->position($map, '10p33.13-q15');
208 ok my $marker2 = Bio::Map::CytoMarker->new(-name => 'gene2' );
209 ok $marker2->position($map, '10p10-15');
210 is $marker1->get_chr, 10;
212 ok my $marker3 = Bio::Map::CytoMarker->new(-name => '3' );
213 ok $marker3->position($map, '10p1');
215 ok my $marker4 = Bio::Map::CytoMarker->new(-name => '4' );
216 ok $marker4->position($map, '10q2');
219 # Lastly, let's test the comparison methods
222 ok $marker1->equals($marker1);
223 ok ! $marker1->equals($marker2);
225 ok $marker3->less_than($marker4);
226 ok ! $marker3->greater_than($marker4);
227 ok ! $marker4->less_than($marker3);
228 ok $marker4->greater_than($marker3);
230 ok ! $marker4->overlaps($marker3);
231 ok $marker1->overlaps($marker3);
233 ok ! $marker4->contains($marker3);
234 ok $marker1->contains($marker3);
237 # Test throw() in some private functions
240 eval { Bio::Map::CytoPosition::_pad('string', -1, 'x'); };
241 like($@, qr/positive integer/);
242 eval { Bio::Map::CytoPosition::_pad('string', +1, 'toolong'); };
243 like($@, qr/single character/);