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

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.129

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3