blib/conf/plugins/Submitter.pm untested

filter: Statementstmt 0.0% 0 / 99 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 160 CC 10 SCAR 32.1
CC
10
Cov
0%
dump
72.0
targets
12.0
hide
2.0
CRAP 24.7
1 package Bio::Graphics::Browser2::Plugin::Submitter;
2  
3 # $Id: Submitter.pm,v 1.2 2008-10-19 02:37:59 lstein Exp $
4 # Submitter is an invisible plugin (Does not appear in the "Reports and Analysis" menu)
5 # designed to support rubber-band select menu items that submit sequence data and
6 # other parameters to external web sites such as NCBI blast. Check the GMOD wiki
7 # for documentation.
8 # This plugin: http://www.gmod.org/wiki/index.php/Submitter.pm
9 # Rubber-band selection: http://www.gmod.org/wiki/index.php/GBrowse_Rubber_Band_Selection.pm
10  
11 use strict;
12 use CGI qw/standard escape unescape/;
13 use CGI 'html3';
14 use Bio::Graphics::Browser2::Plugin;
15 use Bio::Graphics::Browser2::Util;
16 use Bio::Graphics::FeatureFile;
17 use CGI qw(:standard *pre);
18 use vars qw($VERSION @ISA);
19 use Data::Dumper;
20  
21 $VERSION = 0.1;
22  
23 @ISA = qw(Bio::Graphics::Browser2::Plugin);
24  
25 # not visible in plugin menu
26 sub hide {1}
27  
28 sub mime_type {'text/html'}
29  
30 # Gets the configuration for inidivual web site "targets"
31 # in a config stanze that looks like this:
32 #[Submitter:plugin]
33 #submitter = [UCSC_BLAT]
34 # confirm = 1
35 # url = http://genome.ucsc.edu/cgi-bin/hgBlat
36 # seq_label = userSeq
37 # output = hyperlink
38 # type = DNA
39 # org = Human
40 #
41 # [NCBI_BLAST]
42 # confirm = 1
43 # url = http://www.ncbi.nlm.nih.gov/blast/Blast.cgi
44 # seq_label = QUERY
45 # PAGE = Nucleotides
46 # PROGRAM = blastn
47 # DATABASE = nr
48 # CLIENT = web
49 # CMD = put
50 sub targets {
51 my $self = shift;
52 return $self->{targets} if $self->{targets};
53  
54 my $submitter_cfg = $self->browser_config->plugin_setting('submitter');
55 my $text = _prepare_text($submitter_cfg);
56 my %config_values = $text =~ /\[([^\]]+)\]([^\[]+)/gm;
57  
58 for my $target (keys %config_values) {
59 my %config = $config_values{$target} =~ /(\w+)\s*=(.+)$/gm;
60 next unless %config >= 2;
61 for (keys %config) {
62 $config{$_} =~ s/^\s+|\s+$//g;
63 }
64 $self->{targets}->{$target} = \%config;
65 }
66  
67 $self->{targets}
68 }
69  
70 # The text needs a bit of pre-processing to
71 # make sure the sub-stanza key-value pairs are
72 # respected and and embedded HTML is escaped
73 # Bio::Graphics FeatureFile.pm is not used for parsing
74 # because it does not respect case-sensitive keys
75 sub _prepare_text {
76 my $text = shift;
77 my @html = $text =~ /(\<.+\>)\[?/;
78 for my $html (@html) {
79 $text =~ s/$html/escape($html)/em;
80 }
81 $text =~ s/\[/\n\[/g;
82 $text =~ s/(\w+\s*=)/\n$1/g;
83 $text;
84 }
85  
86  
87 sub dump {
88 my $self = shift;
89 my $segment = shift;
90 my $targets = $self->targets;
91  
92 my $target = $self->config_param('target')
93 || fatal_error(qq(Error: A target for the submitter must be included in the URL "Submitter.target=target"));
94  
95 my $config = $targets->{$target}
96 || fatal_error(qq(Error: No configuration for target $target!));
97  
98 my $seq = $segment->seq;
99 $seq = $seq->seq if ref $seq;
100 my $name = $segment->name;
101
102 my $url = $config->{url}
103 || fatal_error('Error: a url for the external website is required');
104 my $seq_label = $config->{seq_label}
105 || fatal_error('Error: a label is required for the sequence submission');
106  
107 # Other form elements to include
108 my $extra_html = unescape($config->{extra_html});
109  
110 # Whether to print a confirmation page before external submission
111 my $confirm = $config->{confirm};
112  
113 # Format the display sequence as fasta
114 my $fasta = $seq;
115 $fasta =~ s/(\S{60})/$1\n/g;
116 $fasta = ">$name\n$fasta\n";
117  
118 unless ($url =~ /^http/i) {
119 $url = "http://$url";
120 }
121  
122 # pass-thru arguments -- to be sent to the extertnal web-site
123 my %args;
124 for my $arg (keys %$config) {
125 next if $arg =~ /^seq_label$|^confirm$|^url$|^fasta$|^extra_html$/;
126 $args{$arg} = unescape($config->{$arg});
127 }
128  
129 # print a hidden form and a summary of the data. The "extra_html"
130 # configuration key will trigger inclusion of other form input
131 # elemants if required.
132 print start_form(-name=>'f1', -method=>'POST', -action=>$url), "\n";
133 for my $arg (keys %args) {
134 print hidden($arg => $args{$arg}), "\n";
135 }
136 print hidden($seq_label => $seq);
137  
138 if ($extra_html || $confirm) {
139 my @rows = th({-colspan => 2, -style => "background:lightsteelblue"},
140 b("The following data will be submitted to $url"),
141 p(submit(-name => 'Confirm'),'&nbsp;&nbsp;',
142 button(-name => 'Cancel', -onclick => 'javascript:window.close()')));
143
144 for my $arg (keys %args) {
145 next if $arg eq $seq_label;
146 $arg =~ s/extra_html/Additional options/;
147 push @rows, td({-width => 100, -style => 'background:lightyellow'},
148 [b("$arg:"), unescape($args{$arg})]);
149 }
150  
151 if ($extra_html) {
152 push @rows, td({-width => 100, -style => 'background:lightyellow'},
153 [b("Other options"), pre(unescape($extra_html))]);
154 }
155 push @rows, td({-width => 100, -style => 'background:lightyellow'},
156 [b($seq_label), pre($fasta)]);
157  
158 print table({-border=> 1}, Tr({-valign => 'top'}, \@rows));
159 }
160  
161 print end_form;
162  
163 unless ($confirm || $extra_html) {
164 print qq(<script type="text/javascript">document.f1.submit();</script>);
165 }
166 }
167  
168 sub description{'A plugin to submit the selected region to an external website'}
169 sub config_defaults {{}}
170 sub configure_form {''}
171  
172 1;
173