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

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.120

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3