File Coverage

blib/lib/Bio/GeneDesign/RestrictionEnzymes.pm
Criterion Covered Total %
statement 64 64 100.0
branch 8 10 80.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 82 84 97.6


line stmt bran cond sub pod time code
1             #
2             # GeneDesign module for sequence segmentation
3             #
4              
5             =head1 NAME
6              
7             Bio::GeneDesign::RestrictionEnzymes
8              
9             =head1 VERSION
10              
11             Version 5.52
12              
13             =head1 DESCRIPTION
14              
15             GeneDesign functions for handling restriction enzymes
16              
17             =head1 AUTHOR
18              
19             Sarah Richardson <SMRichardson@lbl.gov>
20              
21             =cut
22              
23             package Bio::GeneDesign::RestrictionEnzymes;
24              
25 11     11   105 use Exporter;
  11         21  
  11         499  
26 11     11   63 use Bio::GeneDesign::Basic qw(:GD);
  11         21  
  11         2493  
27 11     11   7789 use Bio::GeneDesign::RestrictionEnzyme;
  11         37  
  11         426  
28 11     11   150 use Carp;
  11         28  
  11         866  
29              
30 11     11   70 use strict;
  11         30  
  11         353  
31 11     11   64 use warnings;
  11         26  
  11         560  
32              
33             our $VERSION = 5.52;
34              
35 11     11   66 use base qw(Exporter);
  11         22  
  11         9031  
36             our @EXPORT_OK = qw(
37             _define_sites
38             _define_site_status
39             _parse_enzyme_list
40             $VERSION
41             );
42             our %EXPORT_TAGS = (GD => \@EXPORT_OK);
43              
44             =head2 define_sites()
45              
46             Generates a hash reference where the keys are enzyme names and the values are
47             L<Bio::GeneDesign::RestrictionEnzyme> objects.
48              
49             =cut
50              
51             sub _define_sites
52             {
53 3     3   7 my ($file) = @_;
54 3 50       186 open (my $REFILE, '<', $file) || croak ("Can't find $file!\n");
55 3         8 my $ref = do { local $/ = <$REFILE> };
  3         206  
56 3         41 close $REFILE;
57 3         669 my @data = split(m{\n}x, $ref);
58 3         80 my %RES;
59 3         11 my @lines = grep {$_ !~ m{^ \# }x} @data;
  771         1474  
60 3         13 foreach my $line (@lines)
61             {
62 768         9439 my ($name, $site, $temp, $inact, $buf1, $buf2, $buf3, $buf4, $bufu, $dam,
63             $dcm, $cpg, $score, $star, $vendor, $aggress) = split("\t", $line);
64 768         5540 my $buffhsh = {NEB1 => $buf1, NEB2 => $buf2, NEB3 => $buf3,
65             NEB4 => $buf4, Other => $bufu};
66 768 100       2279 $star = undef unless ($star eq 'y');
67 768         5400 my $re = Bio::GeneDesign::RestrictionEnzyme->new(
68             -id => $name,
69             -cutseq => $site,
70             -temp => $temp,
71             -tempin => $inact,
72             -score => $score,
73             -methdam => $dam,
74             -methdcm => $dcm,
75             -methcpg => $cpg,
76             -staract => $star,
77             -vendors => $vendor,
78             -buffers => $buffhsh,
79             -aggress => $aggress);
80 768         5060 $RES{$re->{id}} = $re;
81             }
82             #Make exclusion lists
83 3         69 foreach my $re (values %RES)
84             {
85 768         1462 my %excl;
86 768         27774 foreach my $ar (sort grep {$_->id ne $re->id} values %RES)
  196608         540188  
87             {
88 195840         265821 foreach my $arreg (@{$ar->{regex}})
  195840         485601  
89             {
90 246330 100       1218303 $excl{$ar->{id}}++ if ($re->{recseq} =~ $arreg)
91             }
92 195840         265154 foreach my $rereg (@{$re->{regex}})
  195840         387929  
93             {
94 246330 100       1224620 $excl{$ar->{id}}++ if ($ar->{recseq} =~ $rereg)
95             }
96             }
97 768         8846 my @skips = sort keys %excl;
98 768         9671 $re->exclude(\@skips);
99             }
100 3         355 return \%RES;
101             }
102              
103             =head2 define_site_status
104              
105             Generates a hash describing the restriction count of a nucleotide sequence.
106              
107             Arguments: nucleotide sequence as a string
108             an arrayref of L<Bio::GeneDesign::RestrictionEnzyme> objects
109            
110             Returns: reference to a hash where the keys are enzyme ids and the value is
111             a count of their occurence in the nucleotide sequence
112              
113             =cut
114              
115             sub _define_site_status
116             {
117 1     1   4 my ($seq, $RES) = @_;
118 1         3 my $SITE_STATUS = {};
119 1         2 foreach my $re (@{$RES})
  1         4  
120             {
121 29         97 my $tmphsh = $re->positions($seq);
122 29         40 $SITE_STATUS->{$re->id} = scalar keys %{$tmphsh};
  29         112  
123             }
124 1         9 return $SITE_STATUS;
125             }
126              
127             =head2 _parse_enzyme_list
128              
129             =cut
130              
131             sub _parse_enzyme_list
132             {
133 3     3   12 my ($path) = @_;
134 3 50       194 open (my $REFILE, '<', $path) || croak ("Can't read $path!\n");
135 3         10 my $ref = do { local $/ = <$REFILE> };
  3         216  
136 3         120 close $REFILE;
137 3         119 my @list = split m{\s}x, $ref;
138 3         37 return \@list;
139             }
140              
141             1;
142              
143             __END__
144              
145             =head1 COPYRIGHT AND LICENSE
146              
147             Copyright (c) 2013, GeneDesign developers
148             All rights reserved.
149              
150             Redistribution and use in source and binary forms, with or without modification,
151             are permitted provided that the following conditions are met:
152              
153             * Redistributions of source code must retain the above copyright notice, this
154             list of conditions and the following disclaimer.
155              
156             * Redistributions in binary form must reproduce the above copyright notice, this
157             list of conditions and the following disclaimer in the documentation and/or
158             other materials provided with the distribution.
159              
160             * The names of Johns Hopkins, the Joint Genome Institute, the Lawrence Berkeley
161             National Laboratory, the Department of Energy, and the GeneDesign developers may
162             not be used to endorse or promote products derived from this software without
163             specific prior written permission.
164              
165             THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
166             ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
167             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
168             DISCLAIMED. IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
169             INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
170             LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
171             PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
172             LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
173             OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
174             ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
175              
176             =cut