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

Annotation of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3