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

Annotation of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3