lib/Bio/PrimerDesigner/Tables.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 28 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 126 CC 9 SCAR 28.7
CC
9
Cov
0%
info_table
30.0
ePCR_row
30.0
PCR_header
2.0
CRAP 17.6
1 # $Id: Tables.pm,v 1.9 2004/03/04 23:23:38 kclark Exp $
2  
3 package Bio::PrimerDesigner::Tables;
4  
5 =pod
6  
7 =head1 NAME
8  
9 Bio::PrimerDesigner::Table -- Draw HTML tables for PCR primer display
10  
11 =head1 DESCRIPTION
12  
13 Draws simple HTML tables to display Bio::PrimerDesigner PCR primer
14 design and e-PCR results for web applications.
15  
16 =head1 METHODS
17  
18 =cut
19  
20 use strict;
21  
22 use base 'Class::Base';
23  
24 use vars '$VERSION';
25 $VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
26  
27 # -------------------------------------------------------------------
28 sub info_table {
29  
30 =head2 info_table
31  
32 Prints a two-column table for generic, key-value style annotations.
33 Expects to be passed the name of the gene/feature/etc. and a hash of
34 attributes. If there is an 'image' key, the value is assumed to be an
35 image URL, which is printed in a double-wide cell at the bottom of the
36 table.
37  
38  
39 my $gene = 'Abc-1';
40 my %gene_info = (
41 Chromosome => I,
42 Start => 100450,
43 Stop => 102893,
44 Strand => '+'
45 );
46  
47 my $page = Bio::PrimerDesigner::Tables->new;
48 $page->info_table( $gene, %gene_info );
49  
50 =cut
51  
52 my $self = shift;
53 my $name = shift or return $self->error('No name argument');
54 my %info = @_ or return $self->error('No attributes');
55 my $image = $info{'image'} || '';
56 delete $info{'image'} if $image;
57 my $table .= <<" END";
58 <table width=710 border=0 cellpadding=5>
59 <tr>
60 <th colspan=2 bgcolor=blue align="center">
61 <font size=+2 color=white>$name Information</font>
62 </th>
63 </tr>
64 END
65  
66 for my $key (sort keys %info) {
67 next if $key eq 'other';
68
69 my $ukey = ucfirst $key;
70
71 $table .= <<" END";
72 <tr valign=top>
73 <td width=20%>
74 <b>$ukey</b>
75 </td>
76 <td>
77 $info{$key}
78 </td>
79 </tr>
80 END
81 }
82
83 my $other = $info{'other'};
84 $table .= <<" END" if $other;
85 <tr valign=top>
86 <td width=20%>
87 <b>Other</b>
88 </td>
89 <td>
90 $other
91 </td>
92 </tr>
93 END
94
95 $table .= $image ? "<tr><td colspan=2>$image</td></tr><table>"
96 : "</table>";
97 }
98  
99 # -------------------------------------------------------------------
100 sub PCR_header {
101  
102 =head2 PCR_header
103  
104 Returns a generic header for the PCR primer table. Does not expect
105 any argumments.
106  
107 =cut
108  
109 my $self = shift;
110  
111 return "
112 <table align=center width=710>
113 <tr>
114 <th bgcolor='#3333FF' align=center>
115 <font color=white size=5>PCR Primers</font>
116 </th>
117 </tr>
118 </table>
119 "
120 }
121  
122 # -------------------------------------------------------------------
123 sub PCR_set {
124  
125 =head2 PCR_set
126  
127 Returns the top row for the PCR primer table. Expects the primer set
128 number as its only argument.
129  
130 =cut
131  
132 my $self = shift;
133 my $num = shift || '';
134  
135 return "
136 <table BORDER=0 WIDTH=710>
137 <tr BGCOLOR='#3399FF'>
138 <th bgcolor='#000066' align=center>
139 <font color=white><b>Set $num</b></font>
140 </th>
141 <th>Primer</th>
142 <th>Sequence</th>
143 <th>Tm</th>
144 <th ALIGN=CENTER>Coordinate</th>
145 <th ALIGN=CENTER>Primer Pair Quality</th>
146 </tr>
147 ";
148 }
149  
150 # -------------------------------------------------------------------
151 sub PCR_row {
152  
153 =head2 PCR_row
154  
155 Returns table rows with PCR primer info. Should be called once for
156 each primer pair. Expects to be passed a hash containing the
157 Bio::PrimerDesigner::Result object and the primer set number and an
158 (optional) label.
159  
160 my $pcr_row = PCR_row(
161 primers => $result_obj,
162 setnum => $set_number,
163 label => $label
164 );
165  
166 =cut
167  
168 my $self = shift;
169 my %primers = @_ or return $self->error('No arguments for PCR_row method');
170 my $set = $primers{'setnum'} || 1;
171 my $label = $primers{'label'} || 1;
172 my %args = %{$primers{'primers'}{$set}};
173
174 return "
175 <tr>
176 <td>$label</td>
177 <td>Forward</td>
178 <td>$args{'left'}</td>
179 <td>$args{'tmleft'}</td>
180 <td ALIGN=CENTER>$args{'startleft'}</td>
181 <td>&nbsp;</td>
182 </tr>
183 <tr>
184 <td>&nbsp;</td>
185 <td>Reverse</td>
186 <td>$args{'right'}</td>
187 <td>$args{'tmright'}</td>
188 <td ALIGN=CENTER>$args{'startright'}</td>
189 <td ALIGN=CENTER>$args{'qual'}</td>
190 </tr>
191 ";
192 }
193  
194 # -------------------------------------------------------------------
195 sub ePCR_row {
196  
197 =head2 ePCR_row
198  
199 Returns table rows summarizing e-PCR results. Expects to be passed an
200 Bio::PrimerDesigner::Result e-PCR results object and an optional e-PCR label.
201  
202 =cut
203  
204 my $self = shift;
205 my $args = shift or return $self->error('No arguments for ePCR_row method');
206 my %epcr = %$args;
207 my $label = shift;
208 my $num_prods = $epcr{1}{'products'};
209 my $s = $num_prods > 1 ? 's' : '';
210 $num_prods ||= 'No';
211 my $sizes = '';
212  
213 for (1..$num_prods) {
214 if ($_ == 1) {
215 $sizes = "Size$s $epcr{$_}{'size'}"
216 }
217 elsif ($_ < $num_prods) {
218 $sizes .= ", " . $epcr{$_}{'size'}
219 }
220 else {
221 $sizes .= "and " . $epcr{$_}{'size'}
222 }
223 }
224 $sizes .= " bp" if $num_prods ne 'No';
225 my $row = "
226 <tr BGCOLOR='#99FFFF'>
227 <th colspan=6 align=left>
228 <b>$label e-PCR Results:</b>
229 &nbsp;$num_prods product${s}
230 &nbsp;&nbsp;
231 $sizes
232 </th>
233 </tr>
234 <tr><td>&nbsp;</td></tr>
235 ";
236  
237 $row;
238 }
239  
240 # -------------------------------------------------------------------
241 sub render {
242  
243 =head2 render
244  
245 Renders the image URL. Expects to be passed a hash of the map start
246 and stop, and other features to be mapped (i.e.
247 gene,forward_primer,reverse_primer, label,start and stop of each
248 feature, and gene strand).
249  
250 my $image = $page->render(
251 start => $startleft,
252 stop => $startright,
253 feat => $features
254 );
255  
256 =cut
257  
258 my $self = shift;
259 my %draw = @_ or return $self->error('No name argument');
260 my $start = $draw{'start'} || 0;
261 my $stop = $draw{'stop'} || 0;
262 my $feat = $draw{'feat'} || '';
263  
264 (my $config = <<"END") =~ s/^\s+//gm;
265 [general]
266 bases = $start-$stop
267 height = 12
268  
269 [gene]
270 glyph = transcript2
271 bgcolor = cyan
272 label = 1
273 description = 1
274 height = 7
275  
276 [forward_primer]
277 glyph = triangle
278 bgcolor = blue
279 orient = E
280 height = 7
281 label = 1
282  
283 [reverse_primer]
284 glyph = triangle
285 bgcolor = green
286 orient = W
287 height = 7
288 label = 1
289  
290 $feat
291 END
292  
293 $config =~ s/\n/@@/gm;
294 $config =~ s/\s+/%20/g;
295  
296 $config = "<br><img src=\"http://elegans.bcgsc.bc.ca/".
297 "perl/render?width=700;text=\'$config\'\">";
298 return $config;
299 }
300  
301 # -------------------------------------------------------------------
302 sub PCR_map {
303  
304 =head2 PCR_map
305  
306 Returns a 6 column wide table cell with the <IMG ...> info.
307 Will display the image of mapped primers in the browser when
308 passed the image URL.
309  
310 =cut
311  
312 my $self = shift;
313 my $image_url = shift || '';
314
315 return "
316 <tr>
317 <td colspan=6>
318 $image_url
319 </td>
320 </tr>
321 <tr>
322 <td colspan=6>&nbsp;</td>
323 </tr>
324 ";
325 }
326  
327 1;
328  
329 # -------------------------------------------------------------------
330  
331 =pod
332  
333 =head1 AUTHOR
334  
335 Copyright (C) 2003-2008 Sheldon McKay E<lt>mckays@cshl.eduE<gt>.
336  
337 =head1 LICENSE
338  
339 This program is free software; you can redistribute it and/or modify
340 it under the terms of the GNU General Public License as published by
341 the Free Software Foundation; version 2.
342  
343 This program is distributed in the hope that it will be useful, but
344 WITHOUT ANY WARRANTY; without even the implied warranty of
345 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
346 General Public License for more details.
347  
348 You should have received a copy of the GNU General Public License
349 along with this program; if not, write to the Free Software
350 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
351 USA.
352  
353 =head1 SEE ALSO
354  
355 Bio::PrimerDesigner::primer3, Bio::PrimerDesigner::epcr.
356  
357 =cut