bug 1825
[bioperl-live.git] / t / RestrictionAnalysis.t
bloba0076db264e1a7feac55b415b2fbd327f48b3351
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
5 use strict;
7 BEGIN {
8     use lib 't/lib';
9     use BioperlTest;
10     
11     test_begin(-tests => 172);
12         
13     use_ok('Bio::Restriction::Enzyme');
14     use_ok('Bio::Restriction::Enzyme::MultiCut');
15     use_ok('Bio::Restriction::Enzyme::MultiSite');
16     use_ok('Bio::Restriction::EnzymeCollection');
17     use_ok('Bio::Restriction::Analysis');
18     use_ok('Bio::SeqIO');
22 # Bio::Restriction::Enzyme
25 my ($re, $seq, $iso, %meth, $microbe, $source, @vendors, @refs, $name);
26 ok $re=Bio::Restriction::Enzyme->new(-enzyme=>'EcoRI', -site=>'G^AATTC');
27 isa_ok($re, 'Bio::Restriction::EnzymeI');
28 is $re->cut, 1;
29 ok ! $re->cut(0);
30 is $re->complementary_cut, 6;
31 ok $re->cut(1);
33 is $re->complementary_cut,5;
34 is $re->site,'G^AATTC';
35 ok $seq = $re->seq;
36 isa_ok($seq, 'Bio::PrimarySeqI');
37 is $seq->seq, 'GAATTC';
38 is $re->string,'GAATTC';
39 is $re->revcom, 'GAATTC';
40 is $re->recognition_length, 6;
41 is $re->cutter, 6;
42 is $re->palindromic, 1;
43 is $re->overhang, "5'";
44 is $re->overhang_seq, 'AATT';
45 is $re->is_ambiguous, 0;
47 ok $re->compatible_ends($re);
49 ok $re->isoschizomers('BamHI', 'AvaI'); # not really true :)
51 is my @isos=$re->isoschizomers, 2;
52 is $isos[0],'BamHI';
53 ok $re->purge_isoschizomers;
54 is scalar($re->isoschizomers), 0;
55 ok $re->methylation_sites(2,5); # not really true :)
56 ok %meth = $re->methylation_sites;
57 is $meth{2}, 5;
58 ok $re->purge_methylation_sites;
59 is scalar($re->methylation_sites), 0;
62 ok $re->microbe('E. coli');
63 ok $microbe = $re->microbe;
64 is $microbe, "E. coli";
65 ok $re->source("Rob"); # not really true :)
67 ok $source = $re->source;
68 is $source, "Rob";
70 ok !$re->vendor;
71 ok $re->vendors('NEB'); # my favorite
72 ok @vendors = $re->vendors;
73 is $vendors[0], "NEB";
74 $re->purge_vendors;
75 is scalar($re->vendors), 0;
77 ok $re->references('Rob et al');
78 ok @refs = $re->references;
79 is $refs[0], "Rob et al";
80 $re->purge_references;
81 is scalar($re->references), 0;
83 ok $re->name('BamHI');
84 ok $name = $re->name;
85 is $name, "BamHI";
87 is $re->is_prototype, 0;
88 ok $re->is_prototype(1);
89 is $re->is_prototype, 1;
91 is $re->prototype_name, $re->name;
92 ok ! $re->is_prototype(0);
93 is $re->prototype_name('XxxI'), 'XxxI';
94 is $re->prototype_name, 'XxxI';
97 is $re->cutter, 6;
98 ok $re->seq->seq('RCATGY');
99 is $re->cutter, 5;
101 ok my $re2 = $re->clone;
102 isnt $re, $re2;
103 is $re->name, $re2->name;
105 ok $re = Bio::Restriction::Enzyme->new(-enzyme=>'AciI', 
106                                                                                 -site=>'C^CGC');
107 is $re->palindromic, 0;
108 is $re->is_palindromic, 0;
111 # Bio::Restriction::Enzyme::MultiSite
114 ok $re=Bio::Restriction::Enzyme::MultiSite->new(-enzyme=>'TaqII',
115                                               -site=>'GACCGA',
116                                               -cut=>17,
117                                               -complementary_cut=>15
118                                              );
119 ok $re2=Bio::Restriction::Enzyme::MultiSite->new(-enzyme=>'TaqII',
120                                                 -site=>'CACCCA',
121                                                 -cut=>17,
122                                                 -complementary_cut=>15
123                                                );
124 isa_ok( $re, 'Bio::Restriction::EnzymeI');
125 isa_ok( $re2, 'Bio::Restriction::EnzymeI');
126 ok $re->others($re2);
127 ok $re2->others($re);
129 is $re->others, 1;
130 is $re2->others, 1;
132 ok my $re3 = $re->clone;
133 isnt $re, $re3;
134 is $re->name , $re3->name; # wouldn't this be a circular reference???
135 #print Dumper $re, $re3;exit;
138 # Bio::Restriction::Enzyme::MultiCut
140 #Hin4I has four cut sites [(8/13)GAYNNNNNVTC(13/8)],
142 ok $re = Bio::Restriction::Enzyme::MultiCut->new(-enzyme=>'Hin4I',
143                                               -site=>'GAYNNNNNVTC',
144                                               -cut=>-8,
145                                               -complementary_cut=>-13
146                                              );
147 ok $re2 = Bio::Restriction::Enzyme::MultiCut->new(-enzyme=>'Hin4I',
148                                                -site=>'GAYNNNNNVTC',
149                                                -cut=>13,
150                                                -complementary_cut=>8
151                                               );
152 isa_ok($re, 'Bio::Restriction::EnzymeI');
153 isa_ok($re2, 'Bio::Restriction::EnzymeI');
154 ok $re->others($re2);
155 ok $re2->others($re);
157 ok $re3 = $re->clone;
158 isnt $re, $re3;
159 is $re->name, $re3->name;
160 #print Dumper $re, $re3;exit;
163 # Bio::Restriction::EnzymeCollection
166 my ($collection, $enz, $new_set);
168 ok $collection = Bio::Restriction::EnzymeCollection->new(-empty=>1);
169 is $collection->each_enzyme, 0;
170 # default set
171 $collection = Bio::Restriction::EnzymeCollection->new;
172 is $collection->each_enzyme, 532;
173 is $collection->each_enzyme, 532;
175 ok $enz = $collection->get_enzyme('AclI');
176 isa_ok($enz, 'Bio::Restriction::Enzyme');
177 is my @enzymes=$collection->available_list, 532;
179 ok $new_set = $collection->blunt_enzymes;
180 isa_ok($enz, 'Bio::Restriction::Enzyme');
181 is $new_set->each_enzyme, 114;
183 #map {print $_->name, ": ", $_->cutter, "\n"; } $collection->each_enzyme;
185 ok $new_set = $collection->cutters(8);
186 is $new_set->each_enzyme, 17;
188 ok $new_set=$collection->cutters(-start => 8, -end => 8);
189 is $new_set->each_enzyme, 17;
191 ok $new_set=$collection->cutters(-start => 6, -end => 8);
192 is $new_set->each_enzyme, 293;
194 ok $new_set=$collection->cutters(-start => 6, -end => 8,  -exclusive => 1);
195 is $new_set->each_enzyme, 10;
199 # Restriction::Analysis
203 ok my $seqio=Bio::SeqIO->new(-file=>test_input_file('dna1.fa'),
204                          -format=>'fasta');
205 ok $seq=$seqio->next_seq;
207 ok my $ra = Bio::Restriction::Analysis->new(-seq=>$seq);
208 ok my $uniq = $ra->unique_cutters;
210 # test most objects
211 is $ra->unique_cutters->each_enzyme, 42, 'number of unique cutters';
212 is $ra->fragments('RsaI'), 2, 'number of RsaI fragments';
213 is $ra->max_cuts, 9, 'number of maximum cutters';
214 is $ra->zero_cutters->each_enzyme, 477, 'number of zero cutters';
215 is $ra->cutters->each_enzyme, 55, 'number of cutters';
216 is $ra->cutters(3)->each_enzyme, 8, 'number of 3x cutters';
217 is $ra->fragments('MseI'), 4, '4 MseI fragments';
218 is $ra->cuts_by_enzyme('MseI'), 3, '3 MseI cut sites';
220 #my $z = $ra->cutters(3);
221 #my $out=Bio::Restriction::IO->new;
222 #$out->write($z);
225 is $ra->fragments('PspEI'), 2, 'expected 2 PspEI fragments';
226 is $ra->cuts_by_enzyme('PspEI'), 1;
227 is $ra->cuts_by_enzyme('XxxI'), undef;
230 is my @ss = $ra->sizes('PspEI'), 2, 'expected 2 sizes for PspEI';
231 is $ss[0] + $ss[1], $seq->length;
233 is $ra->fragments('MwoI'), 1, 'not circular expected 1 fragments for MwoI as it doesnt cut';
235 # circularise the sequence, regenerate the cuts and test again
236 # note that there is one less fragment now!
237 ok $seq->is_circular(1);
239 # we need to regenerate all the cuts
240 ok $ra->cut;
242 is $ra->fragments('RsaI'), 1, 'number of RsaI fragments';
243 is $ra->fragments('MseI'), 3, '3 circular MseI fragments';
244 is $ra->cuts_by_enzyme('MseI'), 3, '3 circular MseI cut sites';
245 is $ra->fragments('AciI'), 1, 'number for AciI a non-palindromic enzyme';
247 is $ra->fragments('MwoI'), 1, '1 fragment for MwoI as it cuts across the circ point';
249 ok my @rb=($collection->get_enzyme("AluI"), $collection->get_enzyme("MseI"), $collection->get_enzyme("MaeIII"));
251 # test multiple digests
252 ok my $rbc=Bio::Restriction::EnzymeCollection->new(-empty=>1);
253 ok $rbc->enzymes(@rb);
254 ok $ra->cut('multiple', $rbc);
255 is $ra->fragments('multiple_digest'),7, '7 fragments in the multiple digest';
256 is my @pos=$ra->positions('multiple_digest'),7, '7 positions in the multiple digest';
257 is my @ssm = $ra->sizes('multiple_digest'),7, '7 sizes in the multiple digest';
258 my $check_len;
259 map {$check_len+=$_}@ssm;
260 is $check_len, $seq->length;
262 # now test the non-palindromic part
263 # HindI is a non palindromic enzyme that cuts 9 times
264 is $ra->positions('HindI'), 9, ' expected 9 cuts for HindI';
266 # now we need to test the fragment maps
267 # lets do this for HindI
268 is my @fm=$ra->fragment_maps('HindI'), 9, 'expect 9 fragment maps for HindI';
269 foreach my $fm (@fm) {
270  is exists $fm->{'seq'}, 1, "sequence for ".$fm->{'seq'};
271  is exists $fm->{'start'}, 1, "start at ".$fm->{'start'};
272  is exists $fm->{'end'}, 1, "end at ".$fm->{'end'};
275 # bug 2139
277 eval {$re = Bio::Restriction::Enzyme->new(
278         -name    => 'Invalid',
279         -site    => 'G^AATTE' );};
281 ok $@;
282 like($@, qr(Unrecognized characters in site), 'bug 2139');