blib/conf/plugins/RestrictionAnnotator.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 121 CC 9 SCAR 33.3
CC
9
Cov
0%
annotate
72.0
configure_form
6.0
name
2.0
CRAP 27.8
1 package Bio::Graphics::Browser2::Plugin::RestrictionAnnotator;
2 # $Id: RestrictionAnnotator.pm,v 1.16 2009-01-02 20:57:37 lstein Exp $
3 # test plugin
4 use strict;
5 use Bio::Graphics::Browser2::Plugin;
6 use CGI qw(:standard *table);
7  
8 use vars '$VERSION';
9 $VERSION = '0.25';
10  
11 use base 'Bio::Graphics::Browser2::Plugin';
12 my %SITES;
13  
14 my @COLORS = qw(red green blue orange cyan black
15 turquoise brown indigo wheat yellow emerald);
16  
17 sub name { "Restriction Sites" }
18  
19 sub description {
20 p("The restriction site plugin generates a restriction map",
21 "on the current view.").
22 p("This plugin was written Elizabeth Nickerson & Lincoln Stein.");
23 }
24  
25 sub type { 'annotator' }
26  
27 sub init {shift->configure_enzymes}
28  
29 sub config_defaults {
30 my $self = shift;
31 return {
32 on => 1,
33 EcoRI => 1,
34 ClaI => 1,
35 BamHI => 1,
36 PvuII => 1,
37 };
38 }
39  
40 sub reconfigure {
41 my $self = shift;
42 my $current_config = $self->configuration;
43 %$current_config = map {$_=>1} $self->config_param('enzyme');
44 $current_config->{on} = $self->config_param('on');
45 }
46  
47  
48  
49 sub configure_form {
50 my $self = shift;
51 my $current_config = $self->configuration;
52 configure_enzymes() unless %SITES;
53 my @buttons = checkbox_group(-name => $self->config_name('enzyme'),
54 -values => [sort keys %SITES],
55 -cols => 4,
56 -defaults => [grep {$current_config->{$_}} keys %$current_config]
57 );
58 return table(TR({-class=>'searchtitle'},
59 th("Select Restriction Sites To Annotate")),
60 TR({-class=>'searchtitle'},
61 th({-align=>'LEFT'},
62 "Restriction Site Display ",
63 radio_group(-name=>$self->config_name('on'),
64 -values =>[0,1],
65 -labels => {0=>'off',1=>'on'},
66 -default => $current_config->{on},
67 -override=>1,
68 ))),
69 TR({-class=>'searchbody'},
70 td(@buttons)));
71 }
72  
73 sub annotate {
74 my $self = shift;
75 my $segment = shift;
76 my $config = $self->configuration;
77 configure_enzymes() unless %SITES;
78 return unless %SITES;
79 return unless %$config;
80 return unless $config->{on};
81  
82 my $ref = $segment->seq_id;
83 my $abs_start = $segment->start;
84 my $dna = $segment->seq;
85 $dna = $dna->seq if ref $dna; # API changes -darn!
86  
87 my $feature_list = $self->new_feature_list;
88  
89 # find restriction sites
90 my $i = 0;
91 for my $type (keys %$config) {
92 next if $type eq 'on';
93 next unless $SITES{$type};
94 my ($pattern,$offset) = @{$SITES{$type}};
95 $feature_list->add_type($type=>{glyph => 'generic',
96 key => "$type restriction site",
97 fgcolor => $COLORS[$i % @COLORS],
98 bgcolor => $COLORS[$i % @COLORS],
99 point => 0,
100 orient => 'N',
101 link => 'http://www.google.com/search?q=$name',
102 });
103 $i++;
104 while ($dna =~ /($pattern)/ig) {
105 my $pos = $abs_start + pos($dna) - length($1) + $offset;
106 my $feature = Bio::Graphics::Feature->new(-start=>$pos,-stop=>$pos,
107 -ref=>$ref,
108 -name=>$type,
109 -type=>$type,
110 -class=>'RestrictionSite',
111 -source=>'RestrictionAnnotator.pm');
112 $feature_list->add_feature($feature,$type);
113 }
114 }
115 return $feature_list;
116 }
117  
118 sub configure_enzymes {
119 my $self = shift;
120 my $conf_dir = $self->config_path();
121 my $file = "$conf_dir/enzymes.txt";
122 open (ENZYMES, "$file") or die "Error: cannot open file $file: $!.\n";
123 while (<ENZYMES>) {
124 chomp;
125 my @hold_enzyme = split(/\t/,$_);
126 my $enzyme_name = shift(@hold_enzyme);
127 $SITES{$enzyme_name} = \@hold_enzyme;
128 next;
129 }
130 close(ENZYMES);
131 }
132  
133 1;
134  
135 __END__