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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3