blib/conf/plugins/FilterTest.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 104 CC 7 SCAR 30.4
CC
7
Cov
0%
filter
56.0
new
2.0
name
2.0
CRAP 20.9
1 package Bio::Graphics::Browser2::Plugin::FilterTest;
2  
3 # $Id: FilterTest.pm,v 1.3 2009-05-22 21:37:09 lstein Exp $
4 # Filter plugin to filter features from the ORFs track
5  
6 use strict;
7 use vars qw($VERSION @ISA);
8 use constant DEBUG => 0;
9  
10 use Bio::Graphics::Browser2::Plugin;
11 use CGI qw(:standard *pre);
12  
13 $VERSION = '0.O1';
14  
15 @ISA = qw(Bio::Graphics::Browser2::Plugin);
16  
17 my @FILTERS = (
18 [
19 'Only ORFs on Watson strand', q{ $_[0]->name =~ /w$/i}
20 ],
21 [
22 'Only ORFs on Crick strand', q{ $_[0]->name =~ /c$/i}
23 ],
24 [
25 'ORF length < ', q{ $_[0]->length < $value }
26 ],
27 [
28 'ORF length >= ', q{ $_[0]->length >= $value }
29 ],
30 );
31 my %LABELS = map { $_ => $FILTERS[$_][0] } ( 0 .. $#FILTERS );
32  
33 sub new
34 {
35 my $class = shift;
36 bless { original_key => undef }, $class;
37 }
38  
39 sub name
40 {
41 'Genes';
42 }
43  
44 sub type
45 {
46 'filter';
47 }
48  
49  
50 sub description
51 {
52 my $key = shift ()->name;
53 p("This Filter plugin filters the features from the ORFS track ($key)")
54 . p("This plugin was written by Marc Logghe.");
55 }
56  
57 sub filter {
58 my $self = shift;
59 my $track = shift; # track label
60 my $key = shift;
61  
62 my $config = $self->configuration;
63 my $source = $self->browser_config;
64  
65 return unless $source;
66 return unless $track eq $self->name;
67 return unless $config->{filter_on} eq 'yes';
68 my $value = $config->{filter_value};
69  
70 # pass closure to browser object for filtering
71 my $filter = eval "sub { $FILTERS[$config->{filter}][1] }";
72  
73 warn $@ if $@;
74 return $filter,"$key (filter incorrect)" if $@; # error occurred
75
76 my $new_key = $FILTERS[ $config->{filter} ][1] =~ m/\$value/
77 ? "$key ($FILTERS[$config->{filter}][0] $value)"
78 : "$key ($FILTERS[$config->{filter}][0])" ;
79 return $filter,$new_key;
80 }
81  
82 sub config_defaults
83 {
84 my $self = shift;
85 return {
86 filter_on => 'no',
87 filter => 0,
88 filter_value => 150
89 };
90 }
91  
92 sub reconfigure
93 {
94 my $self = shift;
95 my $current_config = $self->configuration;
96  
97 my $objtype = $self->objtype();
98  
99 foreach my $p ( param() )
100 {
101 my ($c) = ( $p =~ /$objtype\.(\S+)/ ) or next;
102 $current_config->{$c} = param($p);
103 }
104 }
105  
106 sub configure_form
107 {
108 my $self = shift;
109 my $current_config = $self->configuration;
110 my $objtype = $self->objtype();
111 my @choices = TR(
112 { -class => 'searchtitle' },
113 th(
114 { -align => 'RIGHT', -width => '25%' },
115 'Filter on',
116 td(
117 radio_group(
118 -name => "$objtype.filter_on",
119 -values => [qw(yes no)],
120 -default => $current_config->{'filter_on'},
121 -override => 1
122 )
123 )
124 )
125 );
126 push @choices,
127 TR(
128 { -class => 'searchtitle' },
129 th(
130 { -align => 'RIGHT', -width => '25%' },
131 'Filter',
132 td(
133 popup_menu(
134 -name => "$objtype.filter",
135 -values => [ 0 .. $#FILTERS ],
136 -labels => \%LABELS,
137 -default => $current_config->{'filter'}
138 ),
139 textfield(
140 -name => "$objtype.filter_value",
141 -default => $current_config->{filter_value}
142 )
143 )
144 )
145 );
146  
147 my $html = table(@choices);
148 $html;
149 }
150  
151 sub objtype
152 {
153 ( split ( /::/, ref(shift) ) )[-1];
154 }
155  
156 1;