[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.21, Thu Sep 30 14:33:50 2004 UTC revision 1.81, Tue Jan 24 23:51:22 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 Tracer;
21    use FIG;
22  use Carp;  use Carp;
23  use Data::Dumper;  use Data::Dumper;
24  use LWP::UserAgent;  use LWP::UserAgent;
25  use LWP::Simple;  use LWP::Simple;
26    use URI::Escape;  # uri_escape()
27  use URI::URL;  use URI::URL;
28  use HTTP::Request::Common;  use HTTP::Request::Common;
29  use POSIX;  use POSIX;
30    
31  sub show_page {  
32      my($cgi,$html,$no_home) = @_;  my $top_link_cache;
33      my $i;  
34    
35    sub new
36    {
37        my($class) = @_;
38    
39        my $self = {};
40    
41        return bless $self, $class;
42    }
43    
44    sub top_link
45    {
46    
47      #      #
48      # Find the HTML header      # Determine if this is a toplevel cgi or one in one of the subdirs (currently
49        # just /p2p).
50      #      #
51    
52      my $html_hdr_file = "./Html/html.hdr";      return $top_link_cache if ($top_link_cache);
53    
54        my @parts = split(/\//, $ENV{SCRIPT_NAME});
55        my $top;
56        if ($parts[-2] eq 'FIG')
57        {
58            $top = '.';
59    #       warn "toplevel @parts\n";
60        }
61        elsif ($parts[-3] eq 'FIG')
62        {
63            $top = '..';
64    #       warn "subdir @parts\n";
65        }
66        else
67        {
68            $top = $FIG_Config::cgi_base;
69    #       warn "other @parts\n";
70        }
71    
72        $top_link_cache = $top;
73        return $top;
74    }
75    
76    sub compute_html_header
77    {
78        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
79        my($additional_insert, $user, %options ) = @_;
80    
81        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
82        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
83    
84        my $html_hdr_file = "./Html/$header_name";
85      if (! -f $html_hdr_file)      if (! -f $html_hdr_file)
86      {      {
87          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
88      }      }
89        my @html_hdr = &FIG::file_read($html_hdr_file);
90    
91      my $html_tail_file = "./Html/html.tail";      # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
92      if (! -f $html_tail_file)  
93        #
94        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
95        # just /p2p).
96        #
97    
98        my @parts = split(/\//, $ENV{SCRIPT_NAME});
99        my $top;
100        if ($parts[-2] eq 'FIG')
101        {
102            $top = '.';
103    #       warn "toplevel @parts\n";
104        }
105        elsif ($parts[-3] eq 'FIG')
106      {      {
107          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $top = '..';
108    #       warn "subdir @parts\n";
109        }
110        else
111        {
112            $top = $FIG_Config::cgi_base;
113    #       warn "other @parts\n";
114      }      }
115    
116      my @html_hdr = &FIG::file_read($html_hdr_file);      $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
     my $user = $cgi->param('user') || "";  
     push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );  
117    
118      if (@html_hdr)      if (@html_hdr)
119      {      {
120          my $insert_stuff;          my $insert_stuff;
121    
122            if (not $options{no_release_info})
123            {
124          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
125          my $ver = $ver[0];          my $ver = $ver[0];
126          chomp $ver;          chomp $ver;
# Line 46  Line 132 
132          }          }
133          my $host = &FIG::get_local_hostname();          my $host = &FIG::get_local_hostname();
134          $insert_stuff = "SEED version <b>$ver</b> on $host";          $insert_stuff = "SEED version <b>$ver</b> on $host";
135            }
136    
137            if ($additional_insert)
138            {
139                $insert_stuff .= "<br>" . $additional_insert;
140            }
141    
142          for $_ (@html_hdr)          for $_ (@html_hdr)
143          {          {
144              s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;              s,(href|img\s+src)="/FIG/,$1="$top/,g;
145                    s,(\?user\=)\",$1$user",;
146              if ($_ eq "<!-- HEADER_INSERT -->\n")              if ($_ eq "<!-- HEADER_INSERT -->\n")
147              {              {
148                  $_ = $insert_stuff;                  $_ = $insert_stuff;
# Line 57  Line 150 
150          }          }
151      }      }
152    
153        return @html_hdr;
154    }
155    
156    sub show_page {
157        #warn "SHOWPAGE: cgi=", Dumper(@_);
158        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
159        my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie) = @_;
160        my $i;
161    
162        my $top = top_link();
163    
164        # ARGUMENTS:
165        #     $cgi is the CGI method
166        #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
167        #     $no_home eliminates ONLY the bottom FIG search link in a page
168        #     $alt_header is a reference to an array for an alternate header banner that you can replace the standard one with
169        #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls
170        #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css
171        #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css
172        #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "FIG/Html/css/styleswitcher.js")
173        #     $cookie is the name and value of the cookie to set. Note that you should probably use raelib->cookie to get/set your cookies
174        #
175        # Find the HTML header
176        #
177    
178        my $html_tail_file = "./Html/$tail_name";
179        if (! -f $html_tail_file)
180        {
181            $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
182        }
183    
184        my $user = $cgi->param('user') || "";
185        my @html_hdr;
186        if ($alt_header && ref($alt_header) eq "ARRAY")
187        {
188           @html_hdr = @$alt_header;
189        }
190        else
191        {
192            @html_hdr = compute_html_header(undef,$user);
193        }
194    
195        # RAE: I am offloading the handling of cookies to CGI.pm since I don't know how they are set up.
196        # This modification adds the cookies if necessary
197    
198        # Note: 3/10/05 commented this line out pending the discussion of adding cookies into the seed that we are waiting to see about
199        # to add cookies back in replace these two header lines with each other
200    
201      print $cgi->header;      #print $cgi->header(-cookie=>$cookie);
202        print $cgi->header();
203    
204      #      #
205      #  The SEED header file goes immediately after <BODY>.  Figure out      #  The SEED header file goes immediately after <BODY>.  Figure out
# Line 76  Line 217 
217                       meta     => 1,                       meta     => 1,
218                       nextid   => 1,                       nextid   => 1,
219                       style    => 1,                       style    => 1,
220                       title    => 1                       title    => 1,
221                     );                     );
222    
223      #      #
# Line 119  Line 260 
260          if ( $html->[$i] =~ /\<body[^0-9a-z]/i )          if ( $html->[$i] =~ /\<body[^0-9a-z]/i )
261          {          {
262              $body_line = $i;              $body_line = $i;
263              $last;              last;
264          }          }
265    
266          #  Now the general case.          #  Now the general case.
# Line 175  Line 316 
316      #      #
317      #  <BODY> goes after last head line      #  <BODY> goes after last head line
318      #      #
319      #  RAE: Added the javascript for the buttons immediately after body.      #  RAE:
320        #  Added the javascript for the buttons immediately after body.
321      #  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,
322      #  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!
323        #  RAE: This is now deprecated because everything is in an external file, FIG.js, included later
324    
325      if ( $body_line < 0 )      if ( $body_line < 0 )
326      {      {
         my $js=&javascript;  
327          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
328          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );          splice( @$html, $body_line, 0, "<BODY>\n" );
329      }      }
330    
331      #      #
# Line 205  Line 347 
347          splice( @$html, $body_line, 0, "</HEAD>\n" );          splice( @$html, $body_line, 0, "</HEAD>\n" );
348      }      }
349    
350        # RAE:
351        # Add css here
352        # Note that at the moment I define these two sheets here. I think this should
353        # be moved out, but I want to try it and see what happens.  css has the format:
354        #
355        # <link rel='stylesheet' title='default' href='/css/default.css' type='text/css'>
356    
357        # convert the default key to the right case. and eliminate dups
358        foreach my $k (keys %$css) {if (lc($k) eq "default") {$css->{'Default'}=$css->{$k}}}
359    
360        if (!$css || !$css->{'Default'})
361        {
362           $css->{'Default'} = "Html/css/default.css";
363        }
364        if (!$css->{"Sans Serif"})
365        {
366           $css->{'Sans Serif'} = "Html/css/sanserif.css";
367        }
368    
369        my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
370        $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
371    
372        foreach my $k (keys %$css)
373        {
374           next if (lc($k) eq "default" || lc($k) eq "sans serif");
375           $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";
376        }
377    
378        $csstext   .= "<link rel='alternate'  title='SEED RSS feeds' href='Html/rss/SEED.rss' type='application/rss+xml'>\n";
379    
380        # RAE: also added support for external javascripts here.
381        # we are cluttering the HTML code with all the javascripts when they could easily be in external files
382        # this solution allows us to source other files
383    
384        # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
385        # it will reduce our overhead.
386    
387        # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
388        push @$javasrc, "Html/css/FIG.js";
389        foreach my $script (@$javasrc) {
390            $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
391        }
392    
393    
394    
395        splice( @$html, $head_end_line, 1, "$csstext</HEAD>\n" );  # note here I am replacing the </head> line. Could be bad...? But it doesn't increment everything else.
396    
397      #      #
398      #  <BASE ...> goes before </HEAD>      #  <BASE ...> goes before </HEAD>
399      #      #
# Line 230  Line 419 
419  #       }  #       }
420    
421          $base_line = $head_end_line;          $base_line = $head_end_line;
422          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );          #
423            # RDO 2005-1006. Remove this so proxying works better.
424            #
425    #        splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
426      }      }
427    
428      #      #
# Line 280  Line 472 
472      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
473      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
474      #      #
   
475      my @tags = ();      my @tags = ();
476        # Check for a tracing queue.
477        my $traceString = QTrace("HTML");
478        if ($traceString) {
479            push @tags, $traceString;
480        }
481      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
482      if ($i >= @$html)        # </body> not found; look for </html>      if ($i >= @$html)        # </body> not found; look for </html>
483      {      {
# Line 304  Line 499 
499          splice( @$html, $i, 0, @tags );          splice( @$html, $i, 0, @tags );
500      }      }
501    
502      print @$html;      # RAE the chomp will return any new lines at the ends of elements in the array,
503        # and then we can join  with a "\n". This is because somethings put newlines in,
504        # and others don't. This should make nicer looking html
505        #
506        # chomp(@$html);
507        # print join "\n", @$html;
508        #
509        # Apparently the above still breaks things. This is the correct code:
510    
511        foreach $_ (@$html)
512        {
513            print $_;
514        }
515    
516  }  }
517    
518  sub make_table {  sub make_table {
# Line 312  Line 520 
520      my(@tab);      my(@tab);
521    
522      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
523      push( @tab, "\n<table $border>\n",      my $width = defined $options{width} ? "width=\"$options{width}\"" : undef;
524        my $class = defined $options{class} ? "class=\"$options{class}\"" : undef;
525        push( @tab, "\n<table $border $width $class>\n",
526                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
527                  "\t<tr>\n\t\t<th>"                  "\t<tr>\n\t\t"
528                . join( "</th>\n\t\t<th>", @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
529                . "</th>\n\t</tr>\n"                . "\n\t</tr>\n"
530          );          );
531      my($i);      my($i);
532    
# Line 332  Line 542 
542      return join("",@tab);      return join("",@tab);
543  }  }
544    
545    sub abstract_coupling_table {
546        my($cgi,$prot,$coupling) = @_;
547        my %fc;
548    
549        my $col_hdrs = ["coupled to","Score","Type of Coupling", "Type-specific Data"];
550        my $tab = [];
551        my %by_peg;
552        foreach my $x (@$coupling)
553        {
554            my($peg2,$psc,$type,$extra) = @$x;
555            if (($type !~ /^[ID]FC$/) || (! $fc{$peg2}))
556            {
557                if ($type =~  /^[ID]FC$/)
558                {
559                    $fc{$peg2} = 1;
560                }
561    
562                $by_peg{$peg2} += $psc;
563            }
564        }
565    
566        foreach my $x (sort { ($by_peg{$b->[0]} <=> $by_peg{$a->[0]})
567                              or ($a->[0] cmp $b->[0])
568                              or ($b->[1] <=> $a->[1])
569                              or ($a->[2] cmp $b->[2]) } @$coupling)
570        {
571            my($peg2,$psc,$type,$extra) = @$x;
572            push(@$tab,[&fid_link($cgi,$peg2,1),$psc,$type,&set_prot_links($cgi,join(", ",@$extra))]);
573        }
574    
575    
576         my $help = "<a href=\"Html/abstract_coupling.html\" target=\"SEED_or_SPROUT_help\">for help</a>";
577    #    my @html = &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot");
578    #    push(@html,"<hr>\n",$cgi->h3($help),"<br>");
579    #    return @html;
580    
581        return &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot [$help]");
582    }
583    
584  sub expand {  sub expand {
585      my($x) = @_;      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
586        my( $x, $tag ) = @_;
587    
588        $tag = "td" unless $tag;
589        my $endtag = $tag;
590    
591        # RAE modified this so that you can pass in a reference to an array where
592        # the first element is the data to display and the second element is optional
593        # things like colspan and align. Note that in this case you need to include the td
594        # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
595    
596        # per GJO's request modified this line so it can take any tag.
597        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
598    
599      if ($x =~ /^\@([^:]+)\:(.*)$/)      if ($x =~ /^\@([^:]+)\:(.*)$/)
600      {      {
601          return "\t\t<td $1>$2</td>";          return "\t\t<$tag $1>$2</$endtag>";
602      }      }
603      else      else
604      {      {
605          return "\t\t<td>$x</td>";          return "\t\t<$tag>$x</$endtag>";
606      }      }
607  }  }
608    
609    
610    =head2 merge_table_rows()
611    
612    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
613    
614    Something like this:
615    
616        -----------------------
617        |    1     |    a     |
618        -----------------------
619        |    1     |    b     |
620        -----------------------
621        |    2     |    c     |
622        -----------------------
623        |    3     |    d     |
624        -----------------------
625        |    4     |    d     |
626        -----------------------
627        |    5     |    d     |
628        -----------------------
629    
630    Will become:
631    
632        -----------------------
633        |          |    a     |
634        |    1     |-----------
635        |          |    b     |
636        -----------------------
637        |    2     |    c     |
638        -----------------------
639        |    3     |          |
640        ------------          |
641        |    4     |    5     |
642        ------------          |
643        |    5     |          |
644        -----------------------
645    
646    
647    The method takes two arguments. The reference to the array that is the table ($tab). This is the standard table that is created for HTML.pm to draw, and a reference to a hash of columns that you don't want to merge together. The reference to the hash is optional, and if not included, everything will be merged.
648    
649     $tab=&HTML::merge_table_rows($tab);
650    
651     or
652    
653     $skip=(1=>1, 3=>1, 5=>1);
654     $tab=&HTML::merge_table_rows($tab, $skip);  # will merge all columns except 1, 3 and 5. Note the first column in the table is #0
655    
656    
657    =cut
658    
659    
660    
661    
662    sub merge_table_rows {
663     # RAE:
664     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
665     # this block should merge adjacent rows that have the same text in them.
666     # use like this:
667     #      $tab=&HTML::merge_table_rows($tab);
668     # before you do a make_table call
669    
670     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
671     my ($tab, $skip)=@_;
672    
673     my $newtable;
674     my $lastrow;
675     my $rowspan;
676     my $refs;
677    
678     for (my $y=0; $y <= $#$tab; $y++) {
679     #$y is the row in the table;
680      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
681       # this is the user definable columns not to merge
682       if ($skip->{$x})
683       {
684        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
685        next;
686       }
687    
688       #$x is the column in the table
689       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
690       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
691    
692       # handle cells that are references to arrays
693       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
694    
695       # now we go back through the table looking where to draw the merge line:
696       my $lasty=$y;
697       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
698       $lasty++; # this is the last identical cell. If lasty==y it is the current cell, so we just save the data. Otherwise we increment the rowspan
699       if ($lasty == $y) {
700        # we always want to have something in rows that may otherwise be empty but should be there (see below)
701        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
702        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
703       }
704       else {$rowspan->[$lasty]->[$x]++}
705      }
706     }
707    
708     # now just join everything back together
709     for (my $y=0; $y <= $#$tab; $y++) {
710      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
711       if ($rowspan->[$y]->[$x]) {
712        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
713        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
714        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
715       }
716       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
717        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
718       }
719      }
720     }
721    
722    
723     # finally we have to remove any completely empty cells that have been added by the array mechanism
724     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
725     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
726     # I am sure that Gary can do this in one line, but I am hacking.
727     my @trimmed;
728     foreach my $a (@$newtable) {
729      my @row;
730      foreach my $b (@$a) {
731       push @row, $b if ($b);
732      }
733      push @trimmed, \@row;
734     }
735    
736     return \@trimmed;
737    }
738    
739    
740    
741    
742  sub set_ec_links {  sub set_ec_links {
743        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
744      my($cgi,$x) = @_;      my($cgi,$x) = @_;
745      my($before,$match,$after);      my($before,$match,$after);
746    
# Line 360  Line 755 
755  }  }
756    
757  sub ec_link {  sub ec_link {
758        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
759      my($role) = @_;      my($role) = @_;
760    
761      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)      if ($role =~ /(\d+\.\d+\.\d+\.\d+)/)
# Line 373  Line 769 
769  }  }
770    
771  sub role_link {  sub role_link {
772        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
773      my($cgi,$role) = @_;      my($cgi,$role) = @_;
774    
775      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;      my $roleR = ($role =~ /^(\d+\.\d+\.\d+\.\d+)\s+-\s+/) ? $1 : $role;
# Line 388  Line 785 
785  # text of the link.  # text of the link.
786  #  #
787  sub fid_link {  sub fid_link {
788        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
789      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
790      my($n);      my($n);
791    
792        my $top = top_link();
793    
794      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
795      {      {
796          if ($local)          if ($local)
# Line 408  Line 808 
808          {          {
809              $n = $fid;              $n = $fid;
810          }          }
811          if ($1 ne "peg") { return $n }  
812            my $link;
813            #added to format prophage and path island links to feature.cgi
814            if ($1 ne "peg")
815            {
816               my $user = $cgi->param('user');
817               if (! $user) { $user = "" }
818               my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
819               $link = "$top/feature.cgi?feature=$fid&user=$user$trans$sprout";
820               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
821            }
822            else
823            {
824          my $user = $cgi->param('user');          my $user = $cgi->param('user');
825          if (! $user) { $user = "" }          if (! $user) { $user = "" }
826          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
827          my $link = $cgi->url() . "?prot=$fid&user=$user$trans";              my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
828          $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;  ###a
         #  
         # Elimin the p2p part if we're in that subdir. Ugh.  
         #  
         $link =~ s,p2p/protein.cgi,protein.cgi,;  
829    
830    ### This used to be
831    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
832    ###
833    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
834    ###
835    ### RAO
836    
837                #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
838                #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
839                $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout";
840                $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
841            }
842          if ($just_url)          if ($just_url)
843          {          {
844              return $link;              return $link;
# Line 432  Line 852 
852  }  }
853    
854  sub family_link {  sub family_link {
855        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
856      my($family,$user) = @_;      my($family,$user) = @_;
857    
858      return $family;      return $family;
859  }  }
860    
 use URI::Escape;  
861    
862  sub get_html {  sub get_html {
863        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
864      my( $url, $type, $kv_pairs) = @_;      my( $url, $type, $kv_pairs) = @_;
865      my( $encoded, $ua, $args, @args, $out, @output, $x );      my( $encoded, $ua, $args, @args, $out, @output, $x );
866    
867      $ua = new LWP::UserAgent;      $ua = new LWP::UserAgent;
868      $ua->timeout( 900 );      $ua->timeout( 900 );
   
869      if ($type =~/post/i)      if ($type =~/post/i)
870      {      {
871          $args = [];          $args = [];
# Line 505  Line 925 
925  }  }
926    
927  sub trim_output {  sub trim_output {
928        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
929      my($out) = @_;      my($out) = @_;
930      my $i;      my $i;
931    
# Line 542  Line 963 
963  }  }
964    
965  sub set_prot_links {  sub set_prot_links {
966        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
967      my($cgi,$x) = @_;      my($cgi,$x) = @_;
968      my($before,$match,$after);      my($before,$match,$after);
969    
# Line 552  Line 974 
974          $after = $3;          $after = $3;
975          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);
976      }      }
977      elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)      elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
978      {      {
979          $before = $1;          $before = $1;
980          $match = $2;          $match = $2;
# Line 566  Line 988 
988          $after = $3;          $after = $3;
989          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);
990      }      }
991        elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
992        {
993            $before = $1;
994            $match = $2;
995            $after = $3;
996            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
997        }
998        elsif ($x =~ /^(.*)\beric\|\w+\b(.*)/s)
999        {
1000            $before = $1;
1001            $match = $2;
1002            $after = $3;
1003            return &set_prot_links($cgi,$before) . &HTML::eric_link($cgi,$match) . &set_prot_links($cgi,$after);
1004        }
1005    
1006        elsif ($x =~ /^(.*)\bbhb\|.*?\b(.*)/s)
1007        {
1008            $before = $1;
1009            $match = $2;
1010            $after = $3;
1011            return &set_prot_links($cgi,$before) . &HTML::bhb_link($cgi,$match) . &set_prot_links($cgi,$after);
1012        }
1013    
1014        elsif ($x =~ /^(.*)\bapidb\|.*?\..*\b(.*)/s)
1015        {
1016            $before = $1;
1017            $match = $2;
1018            $after = $3;
1019            return &set_prot_links($cgi,$before) . &HTML::apidb_link($cgi,$match) . &set_prot_links($cgi,$after);
1020        }
1021    
1022        elsif ($x =~ /^(.*)\bpatric\|.*?\b(.*)/s)
1023        {
1024            $before = $1;
1025            $match = $2;
1026            $after = $3;
1027            return &set_prot_links($cgi,$before) . &HTML::patric_link($cgi,$match) . &set_prot_links($cgi,$after);
1028        }
1029    
1030        elsif ($x =~ /^(.*)\bvbrc\|.*?\b(.*)/s)
1031        {
1032            $before = $1;
1033            $match = $2;
1034            $after = $3;
1035            return &set_prot_links($cgi,$before) . &HTML::vbrc_link($cgi,$match) . &set_prot_links($cgi,$after);
1036        }
1037    
1038        elsif ($x =~ /^(.*)\bvectorbase\|.*?\b(.*)/s)
1039        {
1040            $before = $1;
1041            $match = $2;
1042            $after = $3;
1043            return &set_prot_links($cgi,$before) . &HTML::vectorbase_link($cgi,$match) . &set_prot_links($cgi,$after);
1044        }
1045      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
1046      {      {
1047          $before = $1;          $before = $1;
# Line 594  Line 1070 
1070          $after = $3;          $after = $3;
1071          return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);          return &set_prot_links($cgi,$before) . &HTML::kegg_link($cgi,$match) . &set_prot_links($cgi,$after);
1072      }      }
1073        elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
1074        {
1075            $before = $1;
1076            $match = $2;
1077            $after = $3;
1078            return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1079        }
1080        elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
1081        {
1082            $before = $1;
1083            $match = $2;
1084            $after = $3;
1085            return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
1086        }
1087        elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
1088        {
1089            $before = $1;
1090            $match = $2;
1091            $after = $3;
1092            return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
1093        }
1094        elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
1095        {
1096            $before = $1;
1097            $match = $2;
1098            $after = $3;
1099            return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
1100        }
1101        elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
1102        {
1103            $before = $1;
1104            $match = $2;
1105            $after = $3;
1106            return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1107        }
1108        elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1109        {
1110            #wormbase
1111    
1112            $before = $1;
1113            $match = $2;
1114            $after = $3;
1115            return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1116        }
1117        elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1118        {
1119            #flybase
1120    
1121            $before = $1;
1122            $match = $2;
1123            $after = $3;
1124            return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1125        }
1126        elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1127        {
1128            #flybase
1129    
1130            $before = $1;
1131            $match = $2;
1132            $after = $3;
1133            return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1134        }
1135        elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1136        {
1137            #flybase
1138    
1139            $before = $1;
1140            $match = $2;
1141            $after = $3;
1142            return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1143        }
1144      return $x;      return $x;
1145  }  }
1146    
1147  sub refseq_link {  sub refseq_link {
1148        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1149      my($cgi,$id) = @_;      my($cgi,$id) = @_;
1150    
1151      if ($id =~ /^[NXYZA]P_/)      if ($id =~ /^[NXYZA]P_/)
1152      {      {
1153          return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";          return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=protein&cmd=search&term=$id>$id</a>";
1154      }      }
1155        elsif ($id =~ /^[NXYZA]M_/)
1156        {
1157            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id>$id</a>";
1158        }
1159  }  }
1160    
1161  sub gi_link {  sub gi_link {
1162        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1163      my($cgi,$gi) = @_;      my($cgi,$gi) = @_;
1164    
1165      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
# Line 616  Line 1169 
1169      return $gi;      return $gi;
1170  }  }
1171    
1172    sub tigr_link {
1173        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1174        my($cgi,$tigr) = @_;
1175    
1176        if ($tigr =~ /^tigr\|(NT|ntbp|ntbpA|BA|BMAA|BXB|GBA)([0-9a-zA-Z]+)$/)
1177        {
1178            my $id=$1.$2;
1179            return "<a href=\"http://pathema.tigr.org/tigr-scripts/pathema/shared/GenePage.cgi?locus=$id\">$tigr</a> (Pathema)";
1180        }
1181        elsif ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
1182        {
1183            return "<a href=\"http://www.tigr.org/tigr-scripts/CMR2/GenePage.spl?locus=$1\">$?tigr</a>";
1184        }
1185        return $tigr;
1186    }
1187    
1188    sub eric_link {
1189        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1190        my($cgi,$eric) = @_;
1191    
1192        if ($eric =~ /^eric\|(\w+)$/)
1193        {
1194            return "<a href=\"https://asap.ahabs.wisc.edu/asap/feature_info.php?FeatureID=$1\">$eric</a>";
1195        }
1196        return $eric;
1197    }
1198    
1199    sub bhb_link {
1200        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1201        my($cgi,$bhb) = @_;
1202    
1203        return "<a href=\"http://www.biohealthbase.org\">$bhb</a>";
1204    }
1205    
1206    sub apidb_link {
1207        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1208        my($cgi,$api) = @_;
1209    
1210        if ($api =~ /apidb\|(.*?)\.(.*)$/)
1211        {
1212            return "<a href=\"http://www.apidb.org/cgi-bin/redirect.cgi?taxon_id=$1&source_id=$2\">$api</a>";
1213        }
1214        return $api;
1215    }
1216    
1217    sub patric_link {
1218        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1219        my($cgi,$patric) = @_;
1220    
1221        if ($patric =~ /patric\|(.*)/)
1222        {
1223            return "<a href=\"https://patric.vbi.vt.edu/software/curationTool/gep/pgiCuration.php?locus_name=$1\">$patric</a>";
1224        }
1225        return $patric;
1226    }
1227    
1228    sub vbrc_link {
1229        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1230        my($cgi,$vbrc) = @_;
1231    
1232        if ($vbrc =~ /vbrc\|(.*)/)
1233        {
1234            return "<a href=\"http://www.biovirus.org/gene_detail.asp?name=$1\">$vbrc</a>";
1235        }
1236        return $vbrc;
1237    }
1238    
1239    sub vectorbase_link {
1240        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1241        my($cgi,$vec) = @_;
1242        return "<a href=\"http://www.vectorbase.org\">$vec</a>";
1243    }
1244    
1245    
1246  sub uni_link {  sub uni_link {
1247        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1248      my($cgi,$uni) = @_;      my($cgi,$uni) = @_;
1249    
1250      if ($uni =~ /^uni\|(\S+)$/)      if ($uni =~ /^uni\|(\S+)$/)
# Line 627  Line 1255 
1255  }  }
1256    
1257  sub sp_link {  sub sp_link {
1258        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1259      my($cgi,$sp) = @_;      my($cgi,$sp) = @_;
1260    
1261      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
# Line 637  Line 1266 
1266  }  }
1267    
1268  sub pir_link {  sub pir_link {
1269        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1270      my($cgi,$pir) = @_;      my($cgi,$pir) = @_;
1271    
1272      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
# Line 647  Line 1277 
1277  }  }
1278    
1279  sub kegg_link {  sub kegg_link {
1280        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1281      my($cgi,$kegg) = @_;      my($cgi,$kegg) = @_;
1282    
1283      if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)      if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
# Line 656  Line 1287 
1287      return $kegg;      return $kegg;
1288  }  }
1289    
1290    sub ensembl_link {
1291        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1292        my($cgi,$ensembl) = @_;
1293    
1294        if ($ensembl =~ /^(\S+):(\S+)$/)
1295        {
1296            my $what=$1;
1297            my $key=$2;
1298            my $idx="all";
1299            if ($what eq "EnsemblGene") { $idx = "Gene" }
1300            if ($what eq "EnsemblTranscript") { $idx = "all" }
1301            if ($what eq "EnsemblProtein") { $idx = "all" }
1302    
1303            #I really want to get right to the transcript and peptide pages, but
1304            #can't see how to do that without knowing the org name too, which
1305            #I don't know at this point. (ensembl org name, not real org name)
1306    
1307            return "<a href=http://www.ensembl.org/Homo_sapiens/textview?species=all&idx=$idx&q=$key>$ensembl</a>";
1308        }
1309        return $ensembl;
1310    }
1311    
1312    sub entrezgene_link {
1313        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1314        my($cgi,$entrezgene) = @_;
1315    
1316        if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1317        {
1318            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1>$entrezgene</a>";
1319        }
1320        return $entrezgene;
1321    }
1322    
1323    sub mim_link {
1324        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1325        my($cgi,$mim) = @_;
1326    
1327        if ($mim =~ /^MIM:(\S+)$/)
1328        {
1329            return "<a href=http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1>$mim</a>";
1330        }
1331        return $mim;
1332    }
1333    
1334    sub unigene_link {
1335        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1336        my($cgi,$unigene) = @_;
1337    
1338        if ($unigene =~ /^UniGene:(\S+)$/)
1339        {
1340            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1>$unigene</a>";
1341        }
1342        return $unigene;
1343    }
1344    
1345    sub ipi_link {
1346        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1347        my($cgi,$ipi) = @_;
1348    
1349        if ($ipi =~ /^IPI:(\S+)$/)
1350        {
1351            return "<a href=http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1>$ipi</a>";
1352        }
1353        return $ipi;
1354    }
1355    
1356    sub wp_link {
1357        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1358        my($cgi,$wp) = @_;
1359    
1360        #wormbase
1361    
1362        if ($wp =~ /^WP:(\S+)$/)
1363        {
1364            return "<a href=http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search>$wp</a>";
1365        }
1366        return $wp;
1367    }
1368    
1369    sub fb_link {
1370        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1371        my($cgi,$fb) = @_;
1372    
1373        #flybase
1374    
1375        if ($fb =~ /^FB:(\S+)$/)
1376        {
1377            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1378        }
1379        return $fb;
1380    }
1381    
1382    sub fborf_link {
1383        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1384        my($cgi,$fb) = @_;
1385    
1386        #flybase
1387    
1388        if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1389        {
1390            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1391        }
1392        return $fb;
1393    }
1394    
1395    sub sgd_link {
1396        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1397        my($cgi,$sgd) = @_;
1398    
1399        #yeast
1400    
1401        if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1402        {
1403            return "<a href=http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1>$sgd</a>";
1404        }
1405        return $sgd;
1406    }
1407    
1408    
1409    
1410    
1411  sub set_map_links {  sub set_map_links {
1412        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1413      my($cgi,$x) = @_;      my($cgi,$x) = @_;
1414      my($before,$match,$after);      my($before,$match,$after);
1415    
# Line 672  Line 1425 
1425      return $x;      return $x;
1426  }  }
1427    
1428    
1429    
1430  sub map_link {  sub map_link {
1431        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1432      my($cgi,$map,$org) = @_;      my($cgi,$map,$org) = @_;
1433    
1434      $user = $cgi->param('user');      $user = $cgi->param('user');
1435      $user = $user ? $user : "";      $user = $user ? $user : "";
1436      $org = $org ? $org : "";      $org = $org ? $org : "";
1437      my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";  
1438        my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1439    #rel    my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1440      my $link = "<a href=\"$url\">$map</a>";      my $link = "<a href=\"$url\">$map</a>";
1441      return $link;      return $link;
1442  }  }
1443    
1444  sub javascript {  sub java_buttons {
1445          #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1446          # This routine takes three arguments, $html, $form, and $button    ## ADDED BY RAE
1447          # $html is the ref to the array with the html in it    # Provides code to include check all/first half/second half/none for javascrspt
1448          # $form is the name of the form. This must be added whenever start_form is called    # this takes two variables - the form name provided in start_form with the
1449          # by including a -name entry. This is only used for the javascript    # -name => field and the checkbox name
1450          # $button is the name of the button that should be checked/unchecked.    my ($form, $button)=@_;
         #  
         # 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.  
1451    
1452          # Note that the other change is I added a -name=>'fig_checked' to the start_form    $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
1453          # 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";
1454          #    $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
1455      $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
1456    
1457      return $java_script;
1458    }
1459    
1460            $java_script=<<EOF;  sub sub_link {
1461    <SCRIPT LANGUAGE="JavaScript">      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1462    <!-- Begin      my($cgi,$sub) = @_;
1463    function checkAll(field)      my($sub_link);
1464    
1465        my $user = $cgi->param('user');
1466        if ($user)
1467    {    {
1468     for (i = 0; i < field.length; i++)          my $esc_sub = uri_escape( $sub );
1469     field[i].checked = true ;          $sub =~ s/\_/ /g;
1470            $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
1471    }    }
1472        else
1473        {
1474            $sub_link = $sub;
1475        }
1476        return $sub_link;
1477    }
1478    
1479    sub reaction_link {
1480        my($reaction) = @_;
1481    
1482    function checkFirst(field)      if ($reaction =~ /^R\d+/)
1483    {    {
1484     for (i = 0; i < field.length/2; i++)          return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$reaction\" target=reaction$$>$reaction</a>";
    field[i].checked = true;  
1485    }    }
1486        return $reaction;
1487    }
1488    
1489    sub html_for_assignments {
1490        my($fig,$user,$peg_sets) = @_;
1491        my $i;
1492    
1493    function checkSecond(field)      my @vals = ();
1494        my $set = 1;
1495        foreach $peg_set (@$peg_sets)
1496        {
1497            for ($i=0; ($i < @$peg_set); $i++)
1498    {    {
1499     for (i=Math.round(field.length/2); i < field.length; i++)              $peg = $peg_set->[$i];
1500     field[i].checked = true ;              push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1501            }
1502            $set++;
1503        }
1504    
1505        $ENV{'REQUEST_METHOD'} = 'GET';
1506        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1507        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1508        $out =~ s/^.*?<form/<form/si;
1509        $out =~ s/^(.*)<table.*/$1/si;
1510        return $out;
1511    }    }
1512    
1513    function uncheckAll(field)  =head1 rss_feed
1514    
1515    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1516            SEED.rss                - everything gets written here
1517            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1518            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1519    
1520    
1521    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.
1522    
1523    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.
1524    
1525    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.
1526    
1527    The has can have these keys:
1528    
1529    REQUIRED:
1530    title       : the title. This is usually what is seen by the user in the pull down menu
1531    description : a more complete description that is often seen is rss viewers but not always
1532    link        : link to the item that was added/edited
1533    All other keys are treated as optional RSS arguments and written to the file.
1534    
1535    At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1536    
1537    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.
1538    
1539    
1540    =cut
1541    
1542    sub rss_feed {
1543     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1544     my ($files, $args)=@_;
1545    
1546     # how many entries to store in the file
1547     my $max_entries=50;
1548    
1549     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1550    
1551     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1552     # check for the directory and if not, make it
1553     mkdir $filepath unless (-d $filepath);
1554    
1555     # note that $info is a hash of references to hashes that are written out as headers in the file
1556     my $info=
1557     {
1558      "SEED.rss" =>
1559       {
1560            title           => "The SEED",
1561            description     => "Latest news from the SEED",
1562            link            => "Html/rss/SEED.rss",
1563       },
1564    
1565      "SEEDsubsystems.rss" =>
1566      {
1567            title           => "SEED Subsystems",
1568            description     => "Recently updated SEED subsystems",
1569            link            => "Html/rss/SEEDsubsystems.rss",
1570      },
1571    
1572      "SEEDsubsystems.rss" =>
1573    {    {
1574     for (i = 0; i < field.length; i++)          title           => "SEED Genomes",
1575     field[i].checked = false ;          description     => "Genomes recently added to the SEED",
1576            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1577      },
1578    
1579     };
1580    
1581    
1582     # build the new xml
1583     my $xml = "\t<item>\n";
1584     foreach my $qw ("title", "description", "link") {
1585      unless ($args->{$qw}) {
1586       print STDERR "You need to include a $qw tag in your RSS description\n";
1587       return(0);
1588    }    }
1589    //  End -->    # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1590    </script>    # so we are going to pull out the links and uri_escape just the part after the .cgi
1591  EOF    if ($qw eq "link")
1592          return $java_script;    {
1593       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1594       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1595  }  }
1596    
1597  sub java_buttons {    $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1598    ## ADDED BY RAE    delete $args->{$qw};
1599    # 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)=@_;  
1600    
1601    $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";   foreach my $tag (grep {!/type/i} keys %$args)
1602    $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";   {
1603    $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";    $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1604    $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";   }
1605    
1606    return $java_script;   $xml .= "\t</item>\n";
1607    
1608    
1609     my @files=("SEED.rss");
1610     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1611    
1612     foreach my $file ("SEED.rss", @$files)
1613     {
1614      if (-e "$filepath/$file")
1615      {
1616       my @out; # the new content of the file
1617       my $itemcount=0; # how many <item> </item>'s are we keeping
1618       my $initem; # are we in an item?
1619       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1620       while (<IN>)
1621       {
1622        if (/\<item\>/) {
1623         push @out, $xml, unless ($itemcount);
1624         $itemcount++;
1625         $initem=1;
1626        }
1627        if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1628        next if ($initem && $itemcount > $max_entries);
1629        push @out, $_;
1630       }
1631       close IN;
1632       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1633       print OUT @out;
1634      }
1635      else
1636      {
1637       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1638       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1639       if ($info->{$file})
1640       {
1641         # we're going to sanity check each of the three options we output, just to be sure
1642         foreach my $qw ("title", "description", "link")
1643         {
1644           if ($info->{$file}->{$qw})
1645           {
1646              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1647           } else {
1648              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1649           }
1650         }
1651  }  }
1652       else {
1653        print STDERR "Please define title, link, and description information for $file\n";
1654        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1655       }
1656       print OUT "\n", $xml;
1657       print OUT "\n", "</channel>\n</rss>\n"
1658      }
1659     }
1660    }
1661    
1662    
1663    
1664    1;
1665    
 1  

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.81

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3