[Bio] / FigKernelPackages / HTML.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.112 - (view) (download) (as text)

1 : olson 1.72 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : efrank 1.1 package HTML;
19 :    
20 : parrello 1.100 use strict;
21 : parrello 1.49 use Tracer;
22 : olson 1.25 use FIG;
23 : efrank 1.1 use Carp;
24 :     use Data::Dumper;
25 :     use LWP::UserAgent;
26 :     use LWP::Simple;
27 : golsen 1.41 use URI::Escape; # uri_escape()
28 : efrank 1.1 use URI::URL;
29 :     use HTTP::Request::Common;
30 : olson 1.16 use POSIX;
31 : parrello 1.111 use CGI;
32 : efrank 1.1
33 : parrello 1.100 #use raelib; # now used for the excel function, that should eventually end up in here. Way too experimental!
34 :     my $raelib;
35 : overbeek 1.90
36 : redwards 1.61
37 : overbeek 1.68 my $top_link_cache;
38 :    
39 :    
40 : olson 1.31 sub new
41 :     {
42 :     my($class) = @_;
43 :    
44 :     my $self = {};
45 :    
46 :     return bless $self, $class;
47 :     }
48 :    
49 : overbeek 1.68 sub top_link
50 :     {
51 :    
52 :     #
53 :     # Determine if this is a toplevel cgi or one in one of the subdirs (currently
54 :     # just /p2p).
55 :     #
56 :    
57 :     return $top_link_cache if ($top_link_cache);
58 :    
59 :     my @parts = split(/\//, $ENV{SCRIPT_NAME});
60 :     my $top;
61 : parrello 1.103 if (defined $parts[-2] && $parts[-2] eq 'FIG')
62 : overbeek 1.68 {
63 :     $top = '.';
64 :     # warn "toplevel @parts\n";
65 :     }
66 : parrello 1.103 elsif (defined $parts[-3] && $parts[-3] eq 'FIG')
67 : overbeek 1.68 {
68 :     $top = '..';
69 :     # warn "subdir @parts\n";
70 :     }
71 :     else
72 :     {
73 :     $top = $FIG_Config::cgi_base;
74 :     # warn "other @parts\n";
75 :     }
76 :    
77 :     $top_link_cache = $top;
78 :     return $top;
79 :     }
80 :    
81 : olson 1.25 sub compute_html_header
82 :     {
83 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
84 : olson 1.42 my($additional_insert, $user, %options ) = @_;
85 :    
86 : overbeek 1.88 local $/ = "\n";
87 :    
88 : olson 1.42 my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
89 :     my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
90 :    
91 :     my $html_hdr_file = "./Html/$header_name";
92 : olson 1.2 if (! -f $html_hdr_file)
93 :     {
94 : parrello 1.49 $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
95 : olson 1.2 }
96 : olson 1.15 my @html_hdr = &FIG::file_read($html_hdr_file);
97 : olson 1.42
98 : olson 1.67 # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
99 :    
100 :     #
101 :     # Determine if this is a toplevel cgi or one in one of the subdirs (currently
102 :     # just /p2p).
103 :     #
104 :    
105 :     my @parts = split(/\//, $ENV{SCRIPT_NAME});
106 :     my $top;
107 :     if ($parts[-2] eq 'FIG')
108 :     {
109 :     $top = '.';
110 :     # warn "toplevel @parts\n";
111 :     }
112 :     elsif ($parts[-3] eq 'FIG')
113 :     {
114 :     $top = '..';
115 :     # warn "subdir @parts\n";
116 :     }
117 :     else
118 :     {
119 :     $top = $FIG_Config::cgi_base;
120 :     # warn "other @parts\n";
121 :     }
122 :    
123 :     $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
124 : overbeek 1.18
125 : olson 1.15 if (@html_hdr)
126 :     {
127 : parrello 1.49 my $insert_stuff;
128 : olson 1.42
129 : parrello 1.49 if (not $options{no_release_info})
130 :     {
131 :     my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
132 :     my $ver = $ver[0];
133 :     chomp $ver;
134 :     if ($ver =~ /^cvs\.(\d+)$/)
135 :     {
136 :     my $d = asctime(localtime($1));
137 :     chomp($d);
138 :     $ver .= " ($d)";
139 :     }
140 :     my $host = &FIG::get_local_hostname();
141 :     $insert_stuff = "SEED version <b>$ver</b> on $host";
142 :     }
143 :    
144 :     if ($additional_insert)
145 :     {
146 :     $insert_stuff .= "<br>" . $additional_insert;
147 :     }
148 :    
149 :     for $_ (@html_hdr)
150 :     {
151 : parrello 1.71 s,(href|img\s+src)="/FIG/,$1="$top/,g;
152 :     s,(\?user\=)\",$1$user",;
153 : parrello 1.49 if ($_ eq "<!-- HEADER_INSERT -->\n")
154 :     {
155 :     $_ = $insert_stuff;
156 :     }
157 :     }
158 : olson 1.15 }
159 :    
160 : olson 1.25 return @html_hdr;
161 :     }
162 :    
163 :     sub show_page {
164 : efrank 1.32 #warn "SHOWPAGE: cgi=", Dumper(@_);
165 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
166 : overbeek 1.87 my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie, $options) = @_;
167 : olson 1.25 my $i;
168 : parrello 1.111 Trace("Setting top link.") if T(3);
169 : overbeek 1.70 my $top = top_link();
170 :    
171 : redwards 1.34 # ARGUMENTS:
172 :     # $cgi is the CGI method
173 :     # $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
174 : redwards 1.35 # $no_home eliminates ONLY the bottom FIG search link in a page
175 : parrello 1.49 # $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
176 : redwards 1.34 # $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls
177 :     # the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css
178 :     # the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css
179 : overbeek 1.79 # $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "FIG/Html/css/styleswitcher.js")
180 : redwards 1.61 # $cookie is the name and value of the cookie to set. Note that you should probably use raelib->cookie to get/set your cookies
181 : overbeek 1.87 # $options is a reference to a hash of options that you can pass around the pages
182 : olson 1.25 #
183 :     # Find the HTML header
184 :     #
185 : parrello 1.111 Trace("Reading tail.") if T(3);
186 : olson 1.101 my $tail_name = $options->{tail_name} ? $options->{tail_name} : "html.tail";
187 :     my $html_tail_file = "./Html/$tail_name";
188 :     if (! -f $html_tail_file)
189 :     {
190 :     $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
191 :     }
192 : parrello 1.111 Trace("Extracting user name and header data.") if T(3);
193 : overbeek 1.33 my $user = $cgi->param('user') || "";
194 : redwards 1.35 my @html_hdr;
195 : redwards 1.39 if ($alt_header && ref($alt_header) eq "ARRAY")
196 : redwards 1.35 {
197 :     @html_hdr = @$alt_header;
198 :     }
199 :     else
200 :     {
201 : overbeek 1.87 @html_hdr = compute_html_header(undef,$user,%$options);
202 : redwards 1.35 }
203 : olson 1.25
204 : redwards 1.61 # RAE: I am offloading the handling of cookies to CGI.pm since I don't know how they are set up.
205 :     # This modification adds the cookies if necessary
206 : redwards 1.63
207 :     # Note: 3/10/05 commented this line out pending the discussion of adding cookies into the seed that we are waiting to see about
208 :     # to add cookies back in replace these two header lines with each other
209 : parrello 1.111 #my $hdr_thing = $cgi->header(-cookie=>$cookie);
210 :     my $hdr_thing = $cgi->header();
211 :     Trace("Printing HTML header: $hdr_thing.") if T(3);
212 :     print $hdr_thing;
213 :     Trace("Header printed.") if T(3);
214 : golsen 1.5 #
215 : golsen 1.6 # The SEED header file goes immediately after <BODY>. Figure out
216 :     # what parts of the HTML document skeleton are there, and fill in
217 :     # missing ones.
218 : golsen 1.5 #
219 : golsen 1.6 # This list should be as comprehensive as feasible:
220 : golsen 1.5 #
221 :    
222 : golsen 1.6 my %head_tag = ( base => 1,
223 :     basefont => 1,
224 :     html => 1,
225 :     isindex => 1,
226 :     link => 1,
227 :     meta => 1,
228 :     nextid => 1,
229 :     style => 1,
230 : redwards 1.61 title => 1,
231 : golsen 1.6 );
232 :    
233 :     #
234 :     # This list need not be comprehensive; it is just stopping conditions:
235 :     #
236 :    
237 :     my %body_tag = ( a => 1,
238 :     br => 1,
239 :     center => 1,
240 :     form => 1,
241 :     h1 => 1,
242 :     h2 => 1,
243 :     h3 => 1,
244 :     hr => 1,
245 :     img => 1,
246 :     p => 1,
247 :     pre => 1,
248 :     table => 1
249 :     );
250 :    
251 :     my $html_line = -1;
252 :     my $head_line = -1;
253 :     my $base_line = -1;
254 :     my $head_end_line = -1;
255 :     my $body_line = -1;
256 :     my $last_head_line = -1; # If no head tags are found, text goes at top.
257 :     my $done = 0;
258 : parrello 1.111 Trace("Processing special cases.") if T(3);
259 : golsen 1.6 for ( $i = 0; $i < @$html; $i++ )
260 :     {
261 : parrello 1.49 # Some special cases:
262 : golsen 1.6
263 : parrello 1.49 if ( $html->[$i] =~ /\<html[^0-9a-z]/i ) { $html_line = $i }
264 :     if ( $html->[$i] =~ /\<head[^0-9a-z]/i ) { $head_line = $i }
265 :     if ( $html->[$i] =~ /\<base[^0-9a-z]/i ) { $base_line = $i }
266 :     if ( $html->[$i] =~ /\<\/head\>/i ) { $head_end_line = $i }
267 :    
268 :     # The content goes after this line:
269 :    
270 :     if ( $html->[$i] =~ /\<body[^0-9a-z]/i )
271 :     {
272 :     $body_line = $i;
273 : parrello 1.71 last;
274 : parrello 1.49 }
275 :    
276 :     # Now the general case.
277 :     # Analyze all the html tags on the line:
278 :    
279 :     foreach ( $html->[$i] =~ /\<\/?([0-9a-z]+)/ig )
280 :     {
281 :     # At first body tag, we stop the search and put the text
282 :     # after the last line with a head tag:
283 :    
284 :     if ( $body_tag{ lc $_ } )
285 :     {
286 :     $done = 1;
287 :     last;
288 :     }
289 :    
290 :     # If this is a head tag, then move the marker forward
291 :    
292 :     elsif ( $head_tag{ lc $_ } )
293 :     {
294 :     $last_head_line = $i;
295 :     }
296 :     }
297 :     last if $done; # When done, break loop to avoid increment
298 : efrank 1.1 }
299 : golsen 1.6
300 :     # Some sanity checks on structure:
301 :    
302 :     if ( 1 )
303 : efrank 1.1 {
304 : parrello 1.111 Trace("Sanity checks in progress.") if T(3);
305 : parrello 1.49 if ( $html_line >= 0 )
306 :     {
307 :     if ( ( $head_line >= 0 ) && ( $html_line > $head_line ) )
308 :     {
309 : parrello 1.111 Trace("<HTML> tag follows <HEAD> tag.") if T(1);
310 : parrello 1.49 }
311 :     if ( ( $head_end_line >= 0 ) && ( $html_line > $head_end_line ) )
312 :     {
313 : parrello 1.111 Trace("<HTML> tag follows </HEAD> tag.") if T(1);
314 : parrello 1.49 }
315 :     }
316 :     if ( $head_line >= 0 )
317 :     {
318 :     if ( ( $head_end_line >= 0 ) && ( $head_line > $head_end_line ) )
319 :     {
320 : parrello 1.111 Trace("<HEAD> tag follows </HEAD> tag.") if T(1);
321 : parrello 1.49 }
322 :     }
323 : efrank 1.1 }
324 : parrello 1.111 Trace("Sanity checks complete.") if T(3);
325 : golsen 1.6 #
326 :     # Okay. Let's put in the html header file, and missing tags:
327 :     #
328 :     # <BODY> goes after last head line
329 :     #
330 : redwards 1.34 # RAE:
331 :     # Added the javascript for the buttons immediately after body.
332 : redwards 1.20 # Note if no buttons are added we still (at the moment) add the script,
333 :     # but it only adds a little text (495 characters) to the html and noone will notice!
334 : redwards 1.46 # RAE: This is now deprecated because everything is in an external file, FIG.js, included later
335 : golsen 1.6 if ( $body_line < 0 )
336 :     {
337 : parrello 1.49 $body_line = $last_head_line + 1;
338 : parrello 1.111 Trace("Splicing body line at $body_line.") if T(3);
339 : parrello 1.49 splice( @$html, $body_line, 0, "<BODY>\n" );
340 : golsen 1.6 }
341 :    
342 :     #
343 :     # Seed page header (if it exists) goes after <BODY>
344 :     #
345 :    
346 : olson 1.15 if (@html_hdr)
347 : golsen 1.6 {
348 : parrello 1.111 Trace("Splicing SEED page header after $body_line.") if T(3);
349 : parrello 1.49 splice( @$html, $body_line + 1, 0, @html_hdr );
350 : golsen 1.6 }
351 :    
352 :     #
353 :     # </HEAD> goes before <BODY>
354 :     #
355 :    
356 :     if ( $head_end_line < 0 )
357 :     {
358 : parrello 1.49 $head_end_line = $body_line;
359 : parrello 1.111 Trace("Splicing header terminater at $body_line.") if T(3);
360 : parrello 1.49 splice( @$html, $body_line, 0, "</HEAD>\n" );
361 : golsen 1.6 }
362 :    
363 : redwards 1.34 # RAE:
364 :     # Add css here
365 : golsen 1.40 # Note that at the moment I define these two sheets here. I think this should
366 :     # be moved out, but I want to try it and see what happens. css has the format:
367 :     #
368 : redwards 1.34 # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
369 : parrello 1.111 Trace("Formatting CSS.") if T(3);
370 : redwards 1.35 # convert the default key to the right case. and eliminate dups
371 :     foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
372 : golsen 1.40
373 : redwards 1.34 if (!$css || !$css->{'Default'})
374 :     {
375 : overbeek 1.79 $css->{'Default'} = "Html/css/default.css";
376 : redwards 1.34 }
377 :     if (!$css->{"Sans Serif"})
378 :     {
379 : overbeek 1.79 $css->{'Sans Serif'} = "Html/css/sanserif.css";
380 : redwards 1.34 }
381 : redwards 1.55
382 : redwards 1.34 my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
383 :     $csstext .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
384 :    
385 :     foreach my $k (keys %$css)
386 :     {
387 :     next if (lc($k) eq "default" || lc($k) eq "sans serif");
388 : redwards 1.38 $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
389 :     }
390 :    
391 : overbeek 1.79 $csstext .= "<link rel='alternate' title='SEED RSS feeds' href='Html/rss/SEED.rss' type='application/rss+xml'>\n";
392 : redwards 1.38
393 :     # RAE: also added support for external javascripts here.
394 :     # we are cluttering the HTML code with all the javascripts when they could easily be in external files
395 :     # this solution allows us to source other files
396 :    
397 : redwards 1.46 # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
398 :     # it will reduce our overhead.
399 : parrello 1.111 Trace("Formatting javascript.") if T(3);
400 : redwards 1.38 # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
401 : overbeek 1.79 push @$javasrc, "Html/css/FIG.js";
402 : redwards 1.46 foreach my $script (@$javasrc) {
403 : parrello 1.49 $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
404 : redwards 1.34 }
405 : redwards 1.38
406 : parrello 1.111 Trace("Re-splicing the header terminator at $head_end_line.") if T(3);
407 : redwards 1.34 splice( @$html, $head_end_line, 1, "$csstext</HEAD>\n" ); # note here I am replacing the </head> line. Could be bad...? But it doesn't increment everything else.
408 :    
409 : golsen 1.6 #
410 :     # <BASE ...> goes before </HEAD>
411 :     #
412 :    
413 :     if ( $base_line < 0 )
414 :     {
415 : parrello 1.49 #
416 :     # Use a relative base address for pages. Also, because I am
417 :     # worried about when FIG_config.pm gets updated (clean installs
418 :     # only, or every update?), I provide an alternative derivation
419 :     # from $cgi_url. -- GJO
420 :     #
421 :     # BASE href needs to be absolute. RDO.
422 :     #
423 :     #
424 : parrello 1.100 # $base_url = &FIG::cgi_url;
425 : parrello 1.49 # my $base_url = $FIG_Config::cgi_base;
426 :     # if ( ! $base_url ) # if cgi_base was not defined
427 :     # {
428 :     # $base_url = $FIG_Config::cgi_url; # get the full cgi url
429 :     # $base_url =~ s~^http://[^/]*~~; # remove protocol and host
430 :     # $base_url =~ m~/$~ || $base_url =~ s~$~/~; # check trailing slash
431 :     # }
432 : golsen 1.6
433 : parrello 1.49 $base_line = $head_end_line;
434 : overbeek 1.64 #
435 :     # RDO 2005-1006. Remove this so proxying works better.
436 :     #
437 :     # splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
438 : golsen 1.6 }
439 :    
440 :     #
441 :     # <HTML> goes at the top of the output
442 :     #
443 :    
444 :     if ( $html_line < 0 )
445 :     {
446 : parrello 1.49 $html_line = 0;
447 : parrello 1.111 Trace("Splicing the HTML tag at $html_line.") if T(3);
448 : parrello 1.49 splice( @$html, $html_line, 0, "<HTML>\n" );
449 : golsen 1.6 }
450 :    
451 :     #
452 :     # <HEAD> goes after <HTML>
453 :     #
454 :    
455 :     if ( $head_line < 0 )
456 :     {
457 : parrello 1.49 $head_line = $html_line + 1;
458 : parrello 1.111 Trace("Splicing the HEAD tag at $head_line.") if T(3);
459 : parrello 1.49 splice( @$html, $head_line, 0, "<HEAD>\n" );
460 : golsen 1.6 }
461 :    
462 :     #
463 :     # Place FIG search link at bottom of page
464 :     #
465 : parrello 1.111 Trace("Placing FIG search link.") if T(3);
466 : golsen 1.6 my @tail = -f $html_tail_file ? `cat $html_tail_file` : ();
467 : efrank 1.1 if (! $no_home)
468 :     {
469 : parrello 1.49 my $user = $cgi->param('user') || "";
470 :     push( @tail, "<hr><a href=\"index.cgi?user=$user\">FIG search</a>\n" );
471 : efrank 1.1 }
472 :    
473 : golsen 1.6 #
474 : olson 1.21 # See if we have a site-specific tail (for disclaimers, etc).
475 :     #
476 : parrello 1.111 Trace("Placing site tail.") if T(3);
477 : olson 1.21 my $site_tail = "$FIG_Config::fig_disk/config/site_tail.html";
478 :     my $site_fh;
479 :     if (open($site_fh, "<$site_tail"))
480 :     {
481 : parrello 1.49 push(@tail, <$site_fh>);
482 :     close($site_fh);
483 : olson 1.21 }
484 :    
485 :     #
486 : golsen 1.6 # Figure out where to insert The SEED tail. Before </body>,
487 :     # or before </html>, or at end of page.
488 :     #
489 :     my @tags = ();
490 : parrello 1.111 Trace("Processing closing tags.") if T(3);
491 : golsen 1.6 for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
492 :     if ($i >= @$html) # </body> not found; look for </html>
493 : efrank 1.1 {
494 : parrello 1.49 push @tags, "\n</BODY>\n";
495 :     # Even if tag is not found, index points to correct place for splice
496 :     for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/html\>/i); $i++) {}
497 :     if ($i >= @$html) # </html> not found; add it
498 :     {
499 :     push @tags, "</HTML>\n";
500 :     }
501 : efrank 1.1 }
502 : golsen 1.6
503 :     if ( @tail )
504 :     {
505 : parrello 1.111 Trace("Splicing tail.") if T(3);
506 : parrello 1.49 splice( @$html, $i, 0, @tail, @tags );
507 : golsen 1.6 }
508 :     elsif ( @tags )
509 :     {
510 : parrello 1.111 Trace("Splicing tags.") if T(3);
511 : parrello 1.49 splice( @$html, $i, 0, @tags );
512 : golsen 1.6 }
513 :    
514 : parrello 1.111 Trace("Printing the HTML array.") if T(3);
515 : golsen 1.40 # RAE the chomp will return any new lines at the ends of elements in the array,
516 :     # and then we can join with a "\n". This is because somethings put newlines in,
517 :     # and others don't. This should make nicer looking html
518 :     #
519 :     # chomp(@$html);
520 :     # print join "\n", @$html;
521 :     #
522 :     # Apparently the above still breaks things. This is the correct code:
523 : overbeek 1.43 foreach $_ (@$html)
524 :     {
525 : parrello 1.111 my $line = $_;
526 :     if (T(4)) {
527 :     my $escapedLine = CGI::escapeHTML($line);
528 :     Trace("Printing:\n$escapedLine") if T(4);
529 :     }
530 :     print $line;
531 : overbeek 1.43 }
532 : parrello 1.49
533 : efrank 1.1 }
534 :    
535 : overbeek 1.90
536 :     =head1 make_table
537 :    
538 :     The main method to convert an array into a table.
539 :    
540 :     The col_hdrs are set to the <th> headers, the $tab is an array of arrays. The first is the rows, and the second is the columns. The title is the title of the table.
541 :    
542 :     The options define the settings for the table such as border, width, and class for css formatting. If the option "excelfile" is set to a filename that will be created in FIG_Config::temp, and the link included that allows the user to download the file as an excel file.
543 :    
544 :     =cut
545 :    
546 : efrank 1.1 sub make_table {
547 : olson 1.17 my($col_hdrs,$tab,$title, %options ) = @_;
548 : efrank 1.1 my(@tab);
549 :    
550 : olson 1.17 my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
551 : parrello 1.103 my $width = defined $options{width} ? "width=\"$options{width}\"" : "";
552 :     my $class = defined $options{class} ? "class=\"$options{class}\"" : "";
553 : overbeek 1.73 push( @tab, "\n<table $border $width $class>\n",
554 : golsen 1.6 "\t<caption><b>$title</b></caption>\n",
555 : olson 1.27 "\t<tr>\n\t\t"
556 :     . join( "\n", map { &expand($_, "th") } @$col_hdrs )
557 :     . "\n\t</tr>\n"
558 : golsen 1.6 );
559 : overbeek 1.9 my($i);
560 : efrank 1.1
561 : overbeek 1.3 my $row;
562 :     foreach $row (@$tab)
563 : efrank 1.1 {
564 : parrello 1.49 push( @tab, "\t<tr>\n"
565 :     . join( "\n", map { &expand($_) } @$row )
566 :     . "\n\t</tr>\n"
567 :     );
568 : efrank 1.1 }
569 :     push(@tab,"</table>\n");
570 : overbeek 1.90
571 :     # excelfile should be appropriate for a filename (no spaces/special characters)
572 : parrello 1.100 if (defined $options{"excelfile"}) {
573 :     if (! defined($raelib)) {
574 :     require raelib;
575 :     $raelib = new raelib;
576 :     }
577 :     push @tab, $raelib->tab2excel($col_hdrs,$tab,$title,\%options,$options{"excelfile"})}
578 : overbeek 1.90
579 : efrank 1.1 return join("",@tab);
580 :     }
581 :    
582 : overbeek 1.74 sub abstract_coupling_table {
583 : overbeek 1.75 my($cgi,$prot,$coupling) = @_;
584 : overbeek 1.77 my %fc;
585 : overbeek 1.74
586 :     my $col_hdrs = ["coupled to","Score","Type of Coupling", "Type-specific Data"];
587 :     my $tab = [];
588 : overbeek 1.76 my %by_peg;
589 : overbeek 1.74 foreach my $x (@$coupling)
590 :     {
591 :     my($peg2,$psc,$type,$extra) = @$x;
592 : overbeek 1.78 if (($type !~ /^[ID]FC$/) || (! $fc{$peg2}))
593 :     {
594 :     if ($type =~ /^[ID]FC$/)
595 :     {
596 :     $fc{$peg2} = 1;
597 :     }
598 :    
599 :     $by_peg{$peg2} += $psc;
600 :     }
601 : overbeek 1.76 }
602 :    
603 :     foreach my $x (sort { ($by_peg{$b->[0]} <=> $by_peg{$a->[0]})
604 :     or ($a->[0] cmp $b->[0])
605 :     or ($b->[1] <=> $a->[1])
606 :     or ($a->[2] cmp $b->[2]) } @$coupling)
607 :     {
608 :     my($peg2,$psc,$type,$extra) = @$x;
609 : overbeek 1.78 push(@$tab,[&fid_link($cgi,$peg2,1),$psc,$type,&set_prot_links($cgi,join(", ",@$extra))]);
610 : overbeek 1.74 }
611 : overbeek 1.75
612 : overbeek 1.76
613 : overbeek 1.77 my $help = "<a href=\"Html/abstract_coupling.html\" target=\"SEED_or_SPROUT_help\">for help</a>";
614 : overbeek 1.75 # my @html = &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot");
615 :     # push(@html,"<hr>\n",$cgi->h3($help),"<br>");
616 :     # return @html;
617 :    
618 :     return &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot [$help]");
619 : overbeek 1.74 }
620 :    
621 : overbeek 1.3 sub expand {
622 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
623 : golsen 1.40 my( $x, $tag ) = @_;
624 :    
625 : olson 1.27 $tag = "td" unless $tag;
626 : golsen 1.40 my $endtag = $tag;
627 :    
628 :     # RAE modified this so that you can pass in a reference to an array where
629 :     # the first element is the data to display and the second element is optional
630 :     # things like colspan and align. Note that in this case you need to include the td
631 : redwards 1.30 # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
632 : overbeek 1.3
633 : redwards 1.47 # per GJO's request modified this line so it can take any tag.
634 :     if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
635 : golsen 1.40
636 :     if ( $x =~ /^\@([^:]+)\:(.*)$/ )
637 : overbeek 1.3 {
638 : parrello 1.49 return "\t\t<$tag $1>$2</$endtag>";
639 : overbeek 1.3 }
640 :     else
641 :     {
642 : parrello 1.49 return "\t\t<$tag>$x</$endtag>";
643 : overbeek 1.3 }
644 :     }
645 :    
646 : redwards 1.47
647 : redwards 1.62 =head2 merge_table_rows()
648 :    
649 :     Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
650 :    
651 :     Something like this:
652 :    
653 :     -----------------------
654 :     | 1 | a |
655 :     -----------------------
656 :     | 1 | b |
657 :     -----------------------
658 :     | 2 | c |
659 :     -----------------------
660 :     | 3 | d |
661 :     -----------------------
662 :     | 4 | d |
663 :     -----------------------
664 :     | 5 | d |
665 :     -----------------------
666 :    
667 :     Will become:
668 :    
669 :     -----------------------
670 :     | | a |
671 :     | 1 |-----------
672 :     | | b |
673 :     -----------------------
674 :     | 2 | c |
675 :     -----------------------
676 :     | 3 | |
677 :     ------------ |
678 :     | 4 | 5 |
679 :     ------------ |
680 :     | 5 | |
681 :     -----------------------
682 :    
683 :    
684 :     The method takes two arguments. The reference to the array that is the table ($tab). This is the standard table that is created for HTML.pm to draw, and a reference to a hash of columns that you don't want to merge together. The reference to the hash is optional, and if not included, everything will be merged.
685 :    
686 :     $tab=&HTML::merge_table_rows($tab);
687 :    
688 :     or
689 :    
690 :     $skip=(1=>1, 3=>1, 5=>1);
691 :     $tab=&HTML::merge_table_rows($tab, $skip); # will merge all columns except 1, 3 and 5. Note the first column in the table is #0
692 :    
693 :    
694 :     =cut
695 :    
696 :    
697 :    
698 :    
699 : redwards 1.47 sub merge_table_rows {
700 :     # RAE:
701 :     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
702 :     # this block should merge adjacent rows that have the same text in them.
703 :     # use like this:
704 :     # $tab=&HTML::merge_table_rows($tab);
705 :     # before you do a make_table call
706 :    
707 :     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
708 : redwards 1.62 my ($tab, $skip)=@_;
709 : redwards 1.47
710 :     my $newtable;
711 :     my $lastrow;
712 :     my $rowspan;
713 :     my $refs;
714 :    
715 :     for (my $y=0; $y <= $#$tab; $y++) {
716 :     #$y is the row in the table;
717 :     for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
718 : redwards 1.62 # this is the user definable columns not to merge
719 :     if ($skip->{$x})
720 :     {
721 :     $newtable->[$y]->[$x] = $tab->[$y]->[$x];
722 :     next;
723 :     }
724 :    
725 : redwards 1.47 #$x is the column in the table
726 :     # if the column in the row we are looking at is the same as the column in the previous row, we don't add
727 :     # this cell to $newtable. Instead we increment the rowspan of the previous row by one
728 :    
729 :     # handle cells that are references to arrays
730 :     if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
731 :    
732 :     # now we go back through the table looking where to draw the merge line:
733 :     my $lasty=$y;
734 : redwards 1.52 while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
735 : redwards 1.47 $lasty++; # this is the last identical cell. If lasty==y it is the current cell, so we just save the data. Otherwise we increment the rowspan
736 :     if ($lasty == $y) {
737 :     # we always want to have something in rows that may otherwise be empty but should be there (see below)
738 :     unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
739 :     $newtable->[$y]->[$x] = $tab->[$y]->[$x];
740 :     }
741 :     else {$rowspan->[$lasty]->[$x]++}
742 :     }
743 :     }
744 :    
745 :     # now just join everything back together
746 :     for (my $y=0; $y <= $#$tab; $y++) {
747 :     for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
748 :     if ($rowspan->[$y]->[$x]) {
749 :     if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
750 :     else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
751 :     $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
752 :     }
753 :     elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
754 :     $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
755 :     }
756 :     }
757 :     }
758 :    
759 :    
760 :     # finally we have to remove any completely empty cells that have been added by the array mechanism
761 :     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
762 :     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
763 :     # I am sure that Gary can do this in one line, but I am hacking.
764 :     my @trimmed;
765 :     foreach my $a (@$newtable) {
766 :     my @row;
767 :     foreach my $b (@$a) {
768 :     push @row, $b if ($b);
769 :     }
770 :     push @trimmed, \@row;
771 :     }
772 :    
773 :     return \@trimmed;
774 :     }
775 :    
776 :    
777 :    
778 :    
779 : overbeek 1.11 sub set_ec_links {
780 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
781 : overbeek 1.11 my($cgi,$x) = @_;
782 :     my($before,$match,$after);
783 :    
784 :     if ($x =~ /^(.*)(EC \d+\.\d+\.\d+\.\d+)(.*)/s)
785 :     {
786 : parrello 1.49 $before = $1;
787 :     $match = $2;
788 :     $after = $3;
789 :     return &set_ec_links($cgi,$before) . &HTML::ec_link($match) . &set_ec_links($cgi,$after);
790 : overbeek 1.11 }
791 :     return $x;
792 :     }
793 :    
794 : efrank 1.1 sub ec_link {
795 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
796 : efrank 1.1 my($role) = @_;
797 :    
798 :     if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
799 :     {
800 : parrello 1.49 return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?ec:$1\">$role</a>";
801 : efrank 1.1 }
802 :     else
803 :     {
804 : parrello 1.49 return $role;
805 : efrank 1.1 }
806 :     }
807 :    
808 :     sub role_link {
809 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
810 : efrank 1.1 my($cgi,$role) = @_;
811 :    
812 :     my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
813 :     my $user = $cgi->param('user');
814 :     if (! $user) { $user = "" }
815 :     my $link = $cgi->url() . "?role=$roleR&user=$user";
816 :     $link =~ s/[a-z]+\.cgi\?/pom.cgi?/;
817 :     return "<a href=$link>$role</a>";
818 :     }
819 :    
820 : redwards 1.102 =head2 fid_link
821 :    
822 :     Get a link to a fid.
823 :    
824 :     use: my $html=&HTML::fid_link($cgi, $fid, Local, Just_URL, Full_Path);
825 :    
826 :     Local is a boolean means to eliminate the fig|org.peg from the text of the link.
827 :    
828 :     Just_URL will only return the URL and not the HTML code. The default is to return the full code.
829 :    
830 :     Full_Path is a boolean that will get the full path to the URL not just a relative path. This is required in pages where the base href changes (e.g. if an image is imported like on the metabolic pages).
831 :    
832 :     =cut
833 :    
834 :    
835 : efrank 1.1 sub fid_link {
836 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
837 : redwards 1.102 my($cgi,$fid,$local,$just_url,$fullpath) = @_;
838 : parrello 1.105 Trace("Creating link for feature $fid.") if T(4);
839 : redwards 1.102 my $err=join(" ", $cgi,$fid,$local,$just_url,$fullpath);
840 :    
841 : efrank 1.1 my($n);
842 :    
843 : overbeek 1.68 my $top = top_link();
844 : redwards 1.102 if ($fullpath) {$top=$FIG_Config::cgi_url}
845 :    
846 : efrank 1.1 if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
847 :     {
848 : parrello 1.49 if ($local)
849 :     {
850 :     if ($1 eq "peg")
851 :     {
852 :     $n = $2;
853 :     }
854 :     else
855 :     {
856 :     $n = "$1.$2";
857 :     }
858 :     }
859 :     else
860 :     {
861 :     $n = $fid;
862 :     }
863 : overbeek 1.60
864 :     my $link;
865 : overbeek 1.95 my $new_framework = $cgi->param('new_framework') ? 1 : 0;
866 : mkubal 1.57 #added to format prophage and path island links to feature.cgi
867 : parrello 1.98 my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
868 : olson 1.109 my $virt = "&48hr_job=" . $cgi->param("48hr_job");
869 : parrello 1.105 Trace("Sprout mode is \"$sprout\".") if T(4);
870 : parrello 1.98 if ($1 ne "peg" && ! $sprout)
871 : parrello 1.105 {
872 :     Trace("Creating feature link for $fid.") if T(4);
873 : mkubal 1.57 my $user = $cgi->param('user');
874 :     if (! $user) { $user = "" }
875 : olson 1.109 $link = "$top/feature.cgi?feature=$fid&user=$user$sprout$virt";
876 : mkubal 1.57 $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
877 :     }
878 : overbeek 1.60 else
879 : mkubal 1.57 {
880 : parrello 1.105 Trace("Creating protein link for $fid.") if T(4);
881 : mkubal 1.57 my $user = $cgi->param('user');
882 :     if (! $user) { $user = "" }
883 :     my $trans = $cgi->param('translate') ? "&translate=1" : "";
884 :     my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
885 : overbeek 1.56 ###a
886 :    
887 :     ### This used to be
888 :     ### my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
889 :     ###
890 :     ### The cost became prohibitive in the subsystem spreadsheets. Hence, we cache the value
891 :     ###
892 :     ### RAO
893 :    
894 : overbeek 1.64 #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
895 :     #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
896 : olson 1.109 $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout$virt\&new_framework=$new_framework";
897 : mkubal 1.57 $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
898 : overbeek 1.60 }
899 :     if ($just_url)
900 :     {
901 :     return $link;
902 :     }
903 :     else
904 :     {
905 : overbeek 1.86 return "<a href='$link'>$n</a>";
906 : mkubal 1.59 }
907 : efrank 1.1 }
908 :     return $fid;
909 :     }
910 :    
911 :     sub family_link {
912 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
913 : efrank 1.1 my($family,$user) = @_;
914 :    
915 :     return $family;
916 :     }
917 :    
918 : paczian 1.108 =head2 evidence_codes_explain
919 :    
920 :     Given an evidence code, returns a string that explains this eveidence code.
921 :    
922 :     =cut
923 :    
924 :     sub evidence_codes_explain {
925 :     my($ec)=@_;
926 :     return unless ($ec);
927 :    
928 :     $ec=uc($ec);
929 :     return "IDA: Inferred from Direct Assay" if ($ec =~ /IDA/);
930 :     return "IGI: Inferred from Genetic Interaction" if ($ec =~ /IGI/);
931 :     return "TAS: Traceable Author Statement" if ($ec =~ /TAS/);
932 :     return "ISU: in subsystem unique" if ($ec =~ /ISU/);
933 :     return "$ec: in subsystem duplicates" if ($ec =~ /IDU/);
934 :     return "$ec: in cluster with" if ($ec =~ /ICW/);
935 :     return "FF: in FIGfam" if ($ec =~ /FF/);
936 :     return "CWN: clustered with nonhypothetical" if ($ec =~ /CWN/);
937 :     return "CWH: clustered, but only with hypotheticals" if ($ec =~ /CWH/);
938 :     return "DLIT: literature references to this gene exist" if ($ec =~ /DLIT/);
939 :     return "ILIT: no references to this gene exist, but they do to other genes with the same functional role" if ($ec =~ /ILIT/);
940 : paczian 1.110 return "$ec: unknown!";
941 : paczian 1.108 }
942 : efrank 1.1
943 :     sub get_html {
944 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
945 : efrank 1.1 my( $url, $type, $kv_pairs) = @_;
946 :     my( $encoded, $ua, $args, @args, $out, @output, $x );
947 :    
948 :     $ua = new LWP::UserAgent;
949 :     $ua->timeout( 900 );
950 :     if ($type =~/post/i)
951 :     {
952 : parrello 1.49 $args = [];
953 :     foreach $x (@$kv_pairs)
954 :     {
955 :     push(@$args, ( $x->[0], $x->[1]) );
956 :     }
957 :     my $request = POST $url, $args;
958 :     my $response = $ua->request($request);
959 :     $out = $response->content;
960 : efrank 1.1 }
961 : hwang 1.94
962 : hwang 1.92 if ($type =~/get/i)
963 : efrank 1.1 {
964 : parrello 1.49 @args = ();
965 :     foreach $x (@$kv_pairs)
966 :     {
967 :     push( @args, "$x->[0]=" . uri_escape($x->[1]) );
968 :     }
969 :    
970 :     if (@args > 0)
971 :     {
972 :     $url .= "?" . join("&",@args);
973 :     }
974 : parrello 1.100 my $request = new HTTP::Request('GET', $url);
975 : parrello 1.49 my $response = $ua->request($request);
976 :    
977 :     if ($response->is_success)
978 :     {
979 :     $out = $response->content;
980 :     }
981 :     else
982 :     {
983 :     $out = "<H1>Error: " . $response->code . "</H1>" . $response->message;
984 :     }
985 : efrank 1.1 }
986 :     # set up a document with proper eol characters
987 :     @output = split(/[\012\015]+/,$out);
988 :     foreach $out (@output) { $out .= "\n"; }
989 :    
990 :     # Now splice in a line of the form <base href=URL> to cause all relative links to work
991 :     # properly. Remove the header.
992 : parrello 1.100 my $i;
993 : efrank 1.1 for ($i=0; ($i < @output) && ($output[$i] !~ /^\s*\</); $i++) {}
994 : parrello 1.100 if ($i < @output) {
995 : parrello 1.49 splice(@output,0,$i);
996 : efrank 1.1 }
997 :    
998 :     for ($i=0; ($i < @output) && ($output[$i] !~ /\<body\>/i); $i++) {}
999 :     if ($i == @output)
1000 :     {
1001 : parrello 1.49 $i = -1;
1002 : efrank 1.1 }
1003 :     splice(@output,$i+1,0,"<base href=\"$url\">\n");
1004 :     return @output;
1005 :     }
1006 :    
1007 :     sub trim_output {
1008 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1009 : efrank 1.1 my($out) = @_;
1010 : parrello 1.100 my ($i, $j);
1011 : efrank 1.1
1012 :     for ($i=0; ($i < @$out) && ($out->[$i] !~ /^\</); $i++) {}
1013 :     splice(@$out,0,$i);
1014 :    
1015 :     for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<body\>/i); $i++) {}
1016 :     if ($i == @$out)
1017 :     {
1018 : parrello 1.49 for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<html\>/i); $i++) {}
1019 :     if ($i == @$out)
1020 :     {
1021 :     $i = -1;
1022 :     }
1023 : efrank 1.1 }
1024 :     for ($j=$i+1; ($j < @$out) && ($out->[$j] !~ /^\<hr\>$/); $j++) {}
1025 :     if ($j < @$out)
1026 :     {
1027 : parrello 1.49 splice(@$out,$i+1,($j-$i));
1028 : efrank 1.1 }
1029 :    
1030 :     for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/body\>/i); $i++) {}
1031 :     if ($i == @$out)
1032 :     {
1033 : parrello 1.49 for ($i=0; ($i < @$out) && ($out->[$i] !~ /\<\/html\>/i); $i++) {}
1034 : efrank 1.1 }
1035 :    
1036 :     for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}
1037 :     if ($j > 0)
1038 :     {
1039 : olson 1.101 #
1040 :     # Hm. We would have tried using the options here:
1041 :     # my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
1042 :     # but they're not passed in. So use the default html.tail.
1043 :     #
1044 :     my $html_tail_file = "./Html/html.tail";
1045 :     my @tmp = `cat $html_tail_file`;
1046 :     my $n = @tmp;
1047 :     splice(@$out,$j-$n,$n+1);
1048 : efrank 1.1 }
1049 :     }
1050 :    
1051 :     sub set_prot_links {
1052 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1053 : efrank 1.1 my($cgi,$x) = @_;
1054 :     my($before,$match,$after);
1055 :    
1056 : overbeek 1.11 if ($x =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)/s)
1057 : efrank 1.1 {
1058 : parrello 1.49 $before = $1;
1059 :     $match = $2;
1060 :     $after = $3;
1061 :     return &set_prot_links($cgi,$before) . &HTML::fid_link($cgi,$match) . &set_prot_links($cgi,$after);
1062 : efrank 1.1 }
1063 : efrank 1.69 elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
1064 : overbeek 1.19 {
1065 : parrello 1.49 $before = $1;
1066 :     $match = $2;
1067 :     $after = $3;
1068 :     return &set_prot_links($cgi,$before) . &HTML::refseq_link($cgi,$match) . &set_prot_links($cgi,$after);
1069 : overbeek 1.19 }
1070 : overbeek 1.11 elsif ($x =~ /^(.*)(gi\|\d+)(.*)/s)
1071 : efrank 1.1 {
1072 : parrello 1.49 $before = $1;
1073 :     $match = $2;
1074 :     $after = $3;
1075 :     return &set_prot_links($cgi,$before) . &HTML::gi_link($cgi,$match) . &set_prot_links($cgi,$after);
1076 : efrank 1.1 }
1077 : olson 1.112 elsif ($x =~ /^(.*)(img\|\d+)(.*)/s)
1078 :     {
1079 :     $before = $1;
1080 :     $match = $2;
1081 :     $after = $3;
1082 :     return &set_prot_links($cgi,$before) . &HTML::img_link($cgi,$match) . &set_prot_links($cgi,$after);
1083 :     }
1084 : overbeek 1.87 elsif ($x =~ /^(.*)(tigr\|\w+)(.*)/s)
1085 : overbeek 1.44 {
1086 : parrello 1.49 $before = $1;
1087 :     $match = $2;
1088 :     $after = $3;
1089 :     return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
1090 : overbeek 1.44 }
1091 : overbeek 1.84 elsif ($x =~ /^(.*)\b(eric\|\S+)\b(.*)/s)
1092 : overbeek 1.80 {
1093 :     $before = $1;
1094 :     $match = $2;
1095 :     $after = $3;
1096 :     return &set_prot_links($cgi,$before) . &HTML::eric_link($cgi,$match) . &set_prot_links($cgi,$after);
1097 :     }
1098 :    
1099 : overbeek 1.93 elsif ($x =~ /^(.*)\b(bhb\|.*?)\b(.*)/s)
1100 : overbeek 1.80 {
1101 :     $before = $1;
1102 :     $match = $2;
1103 :     $after = $3;
1104 :     return &set_prot_links($cgi,$before) . &HTML::bhb_link($cgi,$match) . &set_prot_links($cgi,$after);
1105 :     }
1106 :    
1107 : overbeek 1.93 elsif ($x =~ /^(.*)\b(apidb\|[0-9\.a-z_]+)\b(.*)/s)
1108 : overbeek 1.80 {
1109 :     $before = $1;
1110 :     $match = $2;
1111 :     $after = $3;
1112 :     return &set_prot_links($cgi,$before) . &HTML::apidb_link($cgi,$match) . &set_prot_links($cgi,$after);
1113 :     }
1114 :    
1115 : overbeek 1.93 elsif ($x =~ /^(.*)\b(patric\|.*?)\b(.*)/s)
1116 : overbeek 1.80 {
1117 :     $before = $1;
1118 :     $match = $2;
1119 :     $after = $3;
1120 :     return &set_prot_links($cgi,$before) . &HTML::patric_link($cgi,$match) . &set_prot_links($cgi,$after);
1121 :     }
1122 :    
1123 : overbeek 1.93 elsif ($x =~ /^(.*)\b(vbrc\|.*?)\b(.*)/s)
1124 : overbeek 1.80 {
1125 :     $before = $1;
1126 :     $match = $2;
1127 :     $after = $3;
1128 :     return &set_prot_links($cgi,$before) . &HTML::vbrc_link($cgi,$match) . &set_prot_links($cgi,$after);
1129 :     }
1130 :    
1131 : overbeek 1.93 elsif ($x =~ /^(.*)\b(vectorbase\|.*?)\b(.*)/s)
1132 : overbeek 1.80 {
1133 :     $before = $1;
1134 :     $match = $2;
1135 :     $after = $3;
1136 :     return &set_prot_links($cgi,$before) . &HTML::vectorbase_link($cgi,$match) . &set_prot_links($cgi,$after);
1137 :     }
1138 : overbeek 1.14 elsif ($x =~ /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
1139 :     {
1140 : parrello 1.49 $before = $1;
1141 :     $match = $2;
1142 :     $after = $3;
1143 :     return &set_prot_links($cgi,$before) . &HTML::uni_link($cgi,$match) . &set_prot_links($cgi,$after);
1144 : overbeek 1.14 }
1145 : overbeek 1.11 elsif ($x =~ /^(.*)(sp\|[A-Z0-9]{6})(.*)/s)
1146 : efrank 1.1 {
1147 : parrello 1.49 $before = $1;
1148 :     $match = $2;
1149 :     $after = $3;
1150 :     return &set_prot_links($cgi,$before) . &HTML::sp_link($cgi,$match) . &set_prot_links($cgi,$after);
1151 : efrank 1.1 }
1152 : overbeek 1.11 elsif ($x =~ /^(.*)(pirnr\|NF\d+)(.*)/s)
1153 : efrank 1.1 {
1154 : parrello 1.49 $before = $1;
1155 :     $match = $2;
1156 :     $after = $3;
1157 :     return &set_prot_links($cgi,$before) . &HTML::pir_link($cgi,$match) . &set_prot_links($cgi,$after);
1158 : efrank 1.1 }
1159 : overbeek 1.12 elsif ($x =~ /^(.*)(kegg\|[a-z]{2,4}:[a-zA-Z_0-9]+)(.*)/s)
1160 :     {
1161 : parrello 1.49 $before = $1;
1162 :     $match = $2;
1163 :     $after = $3;
1164 :     return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
1165 : overbeek 1.12 }
1166 : efrank 1.69 elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
1167 :     {
1168 :     $before = $1;
1169 :     $match = $2;
1170 :     $after = $3;
1171 :     return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1172 :     }
1173 :     elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
1174 :     {
1175 :     $before = $1;
1176 :     $match = $2;
1177 :     $after = $3;
1178 :     return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
1179 :     }
1180 :     elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
1181 :     {
1182 :     $before = $1;
1183 :     $match = $2;
1184 :     $after = $3;
1185 :     return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
1186 :     }
1187 : efrank 1.89 elsif ($x =~ /^(.*)(HGNC:[a-zA-Z_0-9\.]+)(.*)/s)
1188 : efrank 1.69 {
1189 :     $before = $1;
1190 :     $match = $2;
1191 :     $after = $3;
1192 : efrank 1.89 return &set_prot_links($cgi,$before) . &HTML::hgnc_link($cgi,$match) . &set_prot_links($cgi,$after);
1193 : efrank 1.69 }
1194 : efrank 1.89 elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
1195 : efrank 1.69 {
1196 :     $before = $1;
1197 :     $match = $2;
1198 :     $after = $3;
1199 : efrank 1.89 return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
1200 : efrank 1.69 }
1201 : efrank 1.89 # IPI stopped working. turn off for now.
1202 :     # elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
1203 :     # {
1204 :     # $before = $1;
1205 :     # $match = $2;
1206 :     # $after = $3;
1207 :     # return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1208 :     # }
1209 : efrank 1.69 elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1210 :     {
1211 :     #wormbase
1212 :    
1213 :     $before = $1;
1214 :     $match = $2;
1215 :     $after = $3;
1216 :     return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1217 :     }
1218 :     elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1219 :     {
1220 :     #flybase
1221 :    
1222 :     $before = $1;
1223 :     $match = $2;
1224 :     $after = $3;
1225 :     return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1226 :     }
1227 :     elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1228 :     {
1229 :     #flybase
1230 :    
1231 :     $before = $1;
1232 :     $match = $2;
1233 :     $after = $3;
1234 :     return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1235 :     }
1236 :     elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1237 :     {
1238 :     #flybase
1239 :    
1240 :     $before = $1;
1241 :     $match = $2;
1242 :     $after = $3;
1243 :     return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1244 :     }
1245 : paczian 1.96 elsif ($x =~ /^(.*)(tr\|[a-zA-Z0-9]+)(.*)/s)
1246 :     {
1247 :    
1248 :     $before = $1;
1249 :     $match = $2;
1250 :     $after = $3;
1251 :    
1252 :     return &set_prot_links($cgi,$before) . &HTML::trembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1253 :     }
1254 : efrank 1.1 return $x;
1255 :     }
1256 :    
1257 : paczian 1.96 sub trembl_link {
1258 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1259 :     my($cgi,$id) = @_;
1260 :    
1261 :     if ($id =~ /^tr\|(.*)/) {
1262 : paczian 1.97 return "<a href='http://ca.expasy.org/uniprot/$1' target=_blank>$id</a>";
1263 : paczian 1.96 } else {
1264 :     return "invalid call to trembl link";
1265 :     }
1266 :     }
1267 :    
1268 : overbeek 1.19 sub refseq_link {
1269 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1270 : overbeek 1.19 my($cgi,$id) = @_;
1271 :    
1272 :     if ($id =~ /^[NXYZA]P_/)
1273 :     {
1274 : paczian 1.97 return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id' target=_blank>$id</a>";
1275 : efrank 1.69 }
1276 :     elsif ($id =~ /^[NXYZA]M_/)
1277 :     {
1278 : paczian 1.97 return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id' target=_blank>$id</a>";
1279 : overbeek 1.19 }
1280 :     }
1281 :    
1282 : efrank 1.1 sub gi_link {
1283 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1284 : efrank 1.1 my($cgi,$gi) = @_;
1285 :    
1286 :     if ($gi =~ /^gi\|(\d+)$/)
1287 :     {
1288 : paczian 1.97 return "<a href='http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=Protein&list_uids=$1&dopt=GenPept' target=_blank>$gi</a>";
1289 : efrank 1.1 }
1290 :     return $gi;
1291 :     }
1292 :    
1293 : overbeek 1.44 sub tigr_link {
1294 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1295 :     my($cgi,$tigr) = @_;
1296 :    
1297 : overbeek 1.82 if ($tigr =~ /^tigr\|(NT|ntbp|ntbpA|BA|BMAA|BXB|GBA)(\w+)$/)
1298 : overbeek 1.44 {
1299 : overbeek 1.81 my $id=$1.$2;
1300 : paczian 1.97 return "<a href=\"http://pathema.tigr.org/tigr-scripts/pathema/shared/GenePage.cgi?locus=$id\" target=_blank>$tigr</a> (Pathema)";
1301 : overbeek 1.81 }
1302 : overbeek 1.83 elsif ($tigr =~ /^tigr\|(\S+)$/)
1303 : overbeek 1.81 {
1304 : paczian 1.97 return "<a href=\"http://www.tigr.org/tigr-scripts/CMR2/GenePage.spl?locus=$1\" target=_blank>$tigr</a>";
1305 : overbeek 1.44 }
1306 :     return $tigr;
1307 :     }
1308 :    
1309 : overbeek 1.80 sub eric_link {
1310 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1311 :     my($cgi,$eric) = @_;
1312 :    
1313 : overbeek 1.83 if ($eric =~ /^eric\|(\S+)/)
1314 : overbeek 1.80 {
1315 : paczian 1.97 return "<a href=\"https://asap.ahabs.wisc.edu/asap/feature_info.php?FeatureID=$1\" target=_blank>$eric</a>";
1316 : overbeek 1.80 }
1317 :     return $eric;
1318 :     }
1319 :    
1320 :     sub bhb_link {
1321 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1322 :     my($cgi,$bhb) = @_;
1323 :    
1324 : paczian 1.97 return "<a href=\"http://www.biohealthbase.org\" target=_blank>$bhb</a>";
1325 : overbeek 1.80 }
1326 :    
1327 :     sub apidb_link {
1328 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1329 :     my($cgi,$api) = @_;
1330 :    
1331 :     if ($api =~ /apidb\|(.*?)\.(.*)$/)
1332 :     {
1333 : paczian 1.97 return "<a href=\"http://www.apidb.org/cgi-bin/redirect.cgi?taxon_id=$1&source_id=$2\" target=_blank>$api</a>";
1334 : overbeek 1.80 }
1335 :     return $api;
1336 :     }
1337 :    
1338 :     sub patric_link {
1339 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1340 :     my($cgi,$patric) = @_;
1341 :    
1342 :     if ($patric =~ /patric\|(.*)/)
1343 :     {
1344 : paczian 1.97 return "<a href=\"https://patric.vbi.vt.edu/software/curationTool/gep/pgiCuration.php?locus_name=$1\" target=_blank>$patric</a>";
1345 : overbeek 1.80 }
1346 :     return $patric;
1347 :     }
1348 :    
1349 :     sub vbrc_link {
1350 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1351 :     my($cgi,$vbrc) = @_;
1352 :    
1353 :     if ($vbrc =~ /vbrc\|(.*)/)
1354 :     {
1355 : paczian 1.97 return "<a href=\"http://www.biovirus.org/gene_detail.asp?name=$1\" target=_blank>$vbrc</a>";
1356 : overbeek 1.80 }
1357 :     return $vbrc;
1358 :     }
1359 :    
1360 :     sub vectorbase_link {
1361 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1362 :     my($cgi,$vec) = @_;
1363 : paczian 1.97 return "<a href=\"http://www.vectorbase.org\" target=_blank>$vec</a>";
1364 : overbeek 1.80 }
1365 :    
1366 :    
1367 : overbeek 1.14 sub uni_link {
1368 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1369 : overbeek 1.14 my($cgi,$uni) = @_;
1370 :    
1371 :     if ($uni =~ /^uni\|(\S+)$/)
1372 :     {
1373 : overbeek 1.91 #return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
1374 : paczian 1.97 return "<a href='http://www.ebi.uniprot.org/uniprot-srv/uniProtView.do?proteinAc=$1' target=_blank>$uni</a>";
1375 : overbeek 1.14 }
1376 :     return $uni;
1377 :     }
1378 :    
1379 : efrank 1.1 sub sp_link {
1380 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1381 : efrank 1.1 my($cgi,$sp) = @_;
1382 :    
1383 :     if ($sp =~ /^sp\|(\S+)$/)
1384 :     {
1385 : paczian 1.97 return "<a href='http://us.expasy.org/cgi-bin/get-sprot-entry?$1' target=_blank>$sp</a>";
1386 : efrank 1.1 }
1387 :     return $sp;
1388 :     }
1389 :    
1390 :     sub pir_link {
1391 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1392 : efrank 1.1 my($cgi,$pir) = @_;
1393 :    
1394 :     if ($pir =~ /^pirnr\|(NF\d+)$/)
1395 :     {
1396 : paczian 1.97 return "<a href='http://pir.georgetown.edu/cgi-bin/nfEntry.pl?id=$1' target=_blank>$pir</a>";
1397 : efrank 1.1 }
1398 :     return $pir;
1399 :     }
1400 :    
1401 : overbeek 1.12 sub kegg_link {
1402 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1403 : overbeek 1.12 my($cgi,$kegg) = @_;
1404 :    
1405 :     if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
1406 :     {
1407 : paczian 1.97 return "<a href='http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2' target=_blank>$kegg</a>";
1408 : overbeek 1.12 }
1409 :     return $kegg;
1410 :     }
1411 :    
1412 : olson 1.112 sub img_link {
1413 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1414 :     my($cgi,$img) = @_;
1415 :    
1416 :     if ($img =~ /^img\|(\S+)$/)
1417 :     {
1418 :     return "<a href='http://img.jgi.doe.gov/cgi-bin/pub/main.cgi?page=geneDetail&gene_oid=$1' target=_blank>$img</a>";
1419 :     }
1420 :     return $img;
1421 :     }
1422 :    
1423 : efrank 1.69 sub ensembl_link {
1424 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1425 :     my($cgi,$ensembl) = @_;
1426 :    
1427 :     if ($ensembl =~ /^(\S+):(\S+)$/)
1428 :     {
1429 :     my $what=$1;
1430 :     my $key=$2;
1431 : efrank 1.89 my $idx="All";
1432 : efrank 1.69 if ($what eq "EnsemblGene") { $idx = "Gene" }
1433 : efrank 1.89 if ($what eq "EnsemblTranscript") { $idx = "All" }
1434 :     if ($what eq "EnsemblProtein") { $idx = "All" }
1435 : efrank 1.69
1436 :     #I really want to get right to the transcript and peptide pages, but
1437 :     #can't see how to do that without knowing the org name too, which
1438 :     #I don't know at this point. (ensembl org name, not real org name)
1439 :    
1440 : paczian 1.97 return "<a href='http://www.ensembl.org/Homo_sapiens/searchview?species=all&idx=$idx&q=$key' target=_blank>$ensembl</a>";
1441 : efrank 1.69 }
1442 :     return $ensembl;
1443 :     }
1444 :    
1445 :     sub entrezgene_link {
1446 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1447 :     my($cgi,$entrezgene) = @_;
1448 :    
1449 :     if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1450 :     {
1451 : paczian 1.97 return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1' target=_blank>$entrezgene</a>";
1452 : efrank 1.69 }
1453 :     return $entrezgene;
1454 :     }
1455 :    
1456 :     sub mim_link {
1457 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1458 :     my($cgi,$mim) = @_;
1459 :    
1460 :     if ($mim =~ /^MIM:(\S+)$/)
1461 :     {
1462 : paczian 1.97 return "<a href='http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1' target=_blank>$mim</a>";
1463 : efrank 1.69 }
1464 :     return $mim;
1465 :     }
1466 :    
1467 : efrank 1.89 sub hgnc_link {
1468 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1469 :     my($cgi,$hgnc) = @_;
1470 :    
1471 :     if ($hgnc =~ /^HGNC:(\S+)$/)
1472 :     {
1473 : paczian 1.97 return "<a href='http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/searchgenes.pl?field=symbol&anchor=equals&match=$1&symbol_search=Search&number=50&format=html&sortby=symbol' target=_blank>$hgnc</a>";
1474 : efrank 1.89 }
1475 : olson 1.101
1476 : parrello 1.100 return $hgnc;
1477 : efrank 1.89 }
1478 :    
1479 : efrank 1.69 sub unigene_link {
1480 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1481 :     my($cgi,$unigene) = @_;
1482 :    
1483 :     if ($unigene =~ /^UniGene:(\S+)$/)
1484 :     {
1485 : paczian 1.97 return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1' target=_blank>$unigene</a>";
1486 : efrank 1.69 }
1487 :     return $unigene;
1488 :     }
1489 :    
1490 :     sub ipi_link {
1491 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1492 :     my($cgi,$ipi) = @_;
1493 :    
1494 :     if ($ipi =~ /^IPI:(\S+)$/)
1495 :     {
1496 : paczian 1.97 return "<a href='http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1' target=_blank>$ipi</a>";
1497 : efrank 1.69 }
1498 :     return $ipi;
1499 :     }
1500 :    
1501 :     sub wp_link {
1502 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1503 :     my($cgi,$wp) = @_;
1504 :    
1505 :     #wormbase
1506 :    
1507 :     if ($wp =~ /^WP:(\S+)$/)
1508 :     {
1509 : paczian 1.97 return "<a href='http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search' target=_blank>$wp</a>";
1510 : efrank 1.69 }
1511 :     return $wp;
1512 :     }
1513 :    
1514 :     sub fb_link {
1515 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1516 :     my($cgi,$fb) = @_;
1517 :    
1518 :     #flybase
1519 :    
1520 :     if ($fb =~ /^FB:(\S+)$/)
1521 :     {
1522 : paczian 1.97 return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
1523 : efrank 1.69 }
1524 :     return $fb;
1525 :     }
1526 :    
1527 :     sub fborf_link {
1528 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1529 :     my($cgi,$fb) = @_;
1530 :    
1531 :     #flybase
1532 :    
1533 :     if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1534 :     {
1535 : paczian 1.97 return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
1536 : efrank 1.69 }
1537 :     return $fb;
1538 :     }
1539 :    
1540 :     sub sgd_link {
1541 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1542 :     my($cgi,$sgd) = @_;
1543 :    
1544 :     #yeast
1545 :    
1546 :     if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1547 :     {
1548 : paczian 1.97 return "<a href='http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1' target=_blank>$sgd</a>";
1549 : efrank 1.69 }
1550 :     return $sgd;
1551 :     }
1552 :    
1553 :    
1554 :    
1555 :    
1556 : overbeek 1.11 sub set_map_links {
1557 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1558 : overbeek 1.11 my($cgi,$x) = @_;
1559 :     my($before,$match,$after);
1560 : efrank 1.1
1561 : overbeek 1.11 my $org = ($cgi->param('org') || $cgi->param('genome') || "");
1562 :    
1563 :     if ($x =~ /^(.*)(MAP\d+)(.*)/s)
1564 :     {
1565 : parrello 1.49 $before = $1;
1566 :     $match = $2;
1567 :     $after = $3;
1568 :     return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
1569 : overbeek 1.11 }
1570 :     return $x;
1571 :     }
1572 :    
1573 : efrank 1.69
1574 :    
1575 : overbeek 1.11 sub map_link {
1576 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1577 : overbeek 1.11 my($cgi,$map,$org) = @_;
1578 :    
1579 : parrello 1.100 my $user = $cgi->param('user');
1580 : overbeek 1.11 $user = $user ? $user : "";
1581 :     $org = $org ? $org : "";
1582 : olson 1.51
1583 : overbeek 1.64 my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1584 :     #rel my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1585 : overbeek 1.11 my $link = "<a href=\"$url\">$map</a>";
1586 :     return $link;
1587 :     }
1588 : redwards 1.20
1589 :     sub java_buttons {
1590 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1591 : redwards 1.20 ## ADDED BY RAE
1592 :     # Provides code to include check all/first half/second half/none for javascrspt
1593 :     # this takes two variables - the form name provided in start_form with the
1594 :     # -name => field and the checkbox name
1595 :     my ($form, $button)=@_;
1596 :    
1597 : parrello 1.100 my $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
1598 : redwards 1.20 $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
1599 :     $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
1600 :     $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
1601 : parrello 1.49
1602 : redwards 1.20 return $java_script;
1603 :     }
1604 :    
1605 : parrello 1.106 =head3 sub_link
1606 :    
1607 :     C<< my $htmlText = HTML::sub_link($cgi, $sub); >>
1608 :    
1609 :     Create a subsystem link. The link will be to the display page if there is no
1610 :     user or we are in SPROUT mode; otherwise it will be to the edit page.
1611 :    
1612 :     =over 4
1613 :    
1614 :     =item cgi
1615 :    
1616 :     CGI query object for the current web session. The parameters of special interest
1617 :     are C<SPROUT> and C<user>. If the user is non-blank and SPROUT mode is 0, then
1618 :     the subsystem's edit page will be shown rather than its display page.
1619 :    
1620 :     =item sub
1621 :    
1622 :     Name of the desired subsystem. It will be cleaned of underscores before the
1623 :     hyperlink is applied.
1624 :    
1625 :     =back
1626 :    
1627 :     =cut
1628 :    
1629 : overbeek 1.22 sub sub_link {
1630 : parrello 1.106 # Allow call as an instance in addition to the authorized method.
1631 : olson 1.31 shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1632 : parrello 1.106 # Get the parameters.
1633 :     my ($cgi, $sub) = @_;
1634 :     # Declare the return variable.
1635 :     my $retVal;
1636 :     # Clean the subsystem name for display purposes. This is a very
1637 :     # different thing from URL-escaping.
1638 : parrello 1.107 my $cleaned = CGI::escapeHTML($sub);
1639 : parrello 1.106 $cleaned =~ s/_/ /g;
1640 :     # URL-escape the subsystem name for use in the link.
1641 :     my $linkable = uri_escape($sub);
1642 :     # Determine the mode. Note we use the little OR trick to insure that
1643 :     # we have the correct value for plugging into the output link.
1644 :     my $user = $cgi->param('user') || "";
1645 :     my $sproutMode = $cgi->param('SPROUT') || 0;
1646 :     if ($user && ! $sproutMode) {
1647 :     # A SEED user is calling, so we go to the edit page.
1648 :     $retVal = "<a href=\"subsys.cgi?ssa_name=$linkable&request=show_ssa&user=$user\">$cleaned</a>";
1649 :     } else {
1650 :     # A visitor or SPROUT user is calling, so we go to the display page.
1651 :     $retVal = "<a href=\"display_subsys.cgi?ssa_name=$linkable;request=show_ssa;sort=by_phylo;SPROUT=$sproutMode\">$cleaned</a>";
1652 : overbeek 1.22 }
1653 : parrello 1.106 # Return the result.
1654 :     return $retVal;
1655 : overbeek 1.22 }
1656 :    
1657 : parrello 1.106
1658 : overbeek 1.50 sub reaction_link {
1659 :     my($reaction) = @_;
1660 : mkubal 1.99 if ($reaction =~ /^(\*)?(R\d+)/)
1661 : overbeek 1.50 {
1662 : mkubal 1.99 return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$2\" target=reaction$$>$reaction</a>";
1663 : overbeek 1.50 }
1664 :     return $reaction;
1665 :     }
1666 :    
1667 : mkubal 1.99
1668 : overbeek 1.53 sub html_for_assignments {
1669 :     my($fig,$user,$peg_sets) = @_;
1670 :     my $i;
1671 :    
1672 :     my @vals = ();
1673 :     my $set = 1;
1674 : parrello 1.100 foreach my $peg_set (@$peg_sets)
1675 : overbeek 1.53 {
1676 :     for ($i=0; ($i < @$peg_set); $i++)
1677 :     {
1678 : parrello 1.100 my $peg = $peg_set->[$i];
1679 : overbeek 1.53 push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1680 :     }
1681 :     $set++;
1682 :     }
1683 :    
1684 :     $ENV{'REQUEST_METHOD'} = 'GET';
1685 :     $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1686 :     my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1687 :     $out =~ s/^.*?<form/<form/si;
1688 :     $out =~ s/^(.*)<table.*/$1/si;
1689 :     return $out;
1690 :     }
1691 :    
1692 : redwards 1.55 =head1 rss_feed
1693 :    
1694 :     Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1695 :     SEED.rss - everything gets written here
1696 :     SEEDgenomes.rss - whenever a genome is added to the SEED
1697 :     SEEDsubsystems.rss - whenever a subsystem is edited (or should this be added?)
1698 :    
1699 :    
1700 :     RSS feeds must contain a title, description, and link. The title is what is seen e.g. from the firefox or safari pull down menu. The description is seen from within an rss aggregator, and may be displayed on web pages and so on.
1701 :    
1702 :     The method takes a reference to an array containing the file names for the RSS feeds to add your item to, and a hash of items for the xml. Only title, description, and link are required tags in the XML.
1703 :    
1704 :     The file names are the full name of the file, eg SEEDsubsystems.rss, SEEDgenomes.rss. Be aware that this is a file name, though, so don't uses special characters. The path will be added.
1705 :    
1706 :     The has can have these keys:
1707 :    
1708 :     REQUIRED:
1709 :     title : the title. This is usually what is seen by the user in the pull down menu
1710 :     description : a more complete description that is often seen is rss viewers but not always
1711 :     link : link to the item that was added/edited
1712 : redwards 1.65 All other keys are treated as optional RSS arguments and written to the file.
1713 :    
1714 :     At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1715 : redwards 1.55
1716 :     RSS files are quite simple, and contain some standard header information, and then individual items surrounded by an <item> </item> tag. Note that there is also an initial title/description/link set that describes the file.
1717 :    
1718 :    
1719 :     =cut
1720 :    
1721 :     sub rss_feed {
1722 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1723 :     my ($files, $args)=@_;
1724 : redwards 1.65
1725 :     # how many entries to store in the file
1726 :     my $max_entries=50;
1727 :    
1728 : redwards 1.55 foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1729 :    
1730 :     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1731 :     # check for the directory and if not, make it
1732 :     mkdir $filepath unless (-d $filepath);
1733 :    
1734 :     # note that $info is a hash of references to hashes that are written out as headers in the file
1735 :     my $info=
1736 :     {
1737 :     "SEED.rss" =>
1738 :     {
1739 :     title => "The SEED",
1740 :     description => "Latest news from the SEED",
1741 : overbeek 1.66 link => "Html/rss/SEED.rss",
1742 : redwards 1.55 },
1743 :    
1744 :     "SEEDsubsystems.rss" =>
1745 :     {
1746 :     title => "SEED Subsystems",
1747 :     description => "Recently updated SEED subsystems",
1748 : overbeek 1.66 link => "Html/rss/SEEDsubsystems.rss",
1749 : redwards 1.55 },
1750 :    
1751 :     "SEEDsubsystems.rss" =>
1752 :     {
1753 :     title => "SEED Genomes",
1754 :     description => "Genomes recently added to the SEED",
1755 :     link => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1756 :     },
1757 :    
1758 :     };
1759 :    
1760 :    
1761 :     # build the new xml
1762 :     my $xml = "\t<item>\n";
1763 :     foreach my $qw ("title", "description", "link") {
1764 :     unless ($args->{$qw}) {
1765 :     print STDERR "You need to include a $qw tag in your RSS description\n";
1766 :     return(0);
1767 :     }
1768 :     # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1769 :     # so we are going to pull out the links and uri_escape just the part after the .cgi
1770 :     if ($qw eq "link")
1771 :     {
1772 :     $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1773 :     $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1774 :     }
1775 :    
1776 :     $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1777 :     delete $args->{$qw};
1778 :     }
1779 :    
1780 :     foreach my $tag (grep {!/type/i} keys %$args)
1781 :     {
1782 :     $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1783 :     }
1784 :    
1785 :     $xml .= "\t</item>\n";
1786 :    
1787 :    
1788 :     my @files=("SEED.rss");
1789 : parrello 1.100 if ($args->{"type"}) {
1790 :     my $type = $args->{type};
1791 :     push @files, "SEED.$type.rss"
1792 :     }
1793 : redwards 1.55
1794 :     foreach my $file ("SEED.rss", @$files)
1795 :     {
1796 :     if (-e "$filepath/$file")
1797 :     {
1798 :     my @out; # the new content of the file
1799 :     my $itemcount=0; # how many <item> </item>'s are we keeping
1800 :     my $initem; # are we in an item?
1801 :     open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1802 :     while (<IN>)
1803 :     {
1804 :     if (/\<item\>/) {
1805 :     push @out, $xml, unless ($itemcount);
1806 :     $itemcount++;
1807 :     $initem=1;
1808 :     }
1809 : redwards 1.65 if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1810 :     next if ($initem && $itemcount > $max_entries);
1811 : redwards 1.55 push @out, $_;
1812 :     }
1813 :     close IN;
1814 :     open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1815 :     print OUT @out;
1816 :     }
1817 :     else
1818 :     {
1819 :     open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1820 :     print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1821 :     if ($info->{$file})
1822 :     {
1823 :     # we're going to sanity check each of the three options we output, just to be sure
1824 :     foreach my $qw ("title", "description", "link")
1825 :     {
1826 :     if ($info->{$file}->{$qw})
1827 :     {
1828 :     print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1829 :     } else {
1830 :     print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1831 :     }
1832 :     }
1833 :     }
1834 :     else {
1835 :     print STDERR "Please define title, link, and description information for $file\n";
1836 :     print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1837 :     }
1838 :     print OUT "\n", $xml;
1839 :     print OUT "\n", "</channel>\n</rss>\n"
1840 :     }
1841 :     }
1842 :     }
1843 : redwards 1.61
1844 :    
1845 :    
1846 : redwards 1.55 1;
1847 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3