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

Annotation of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3