[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.41, Thu Apr 28 20:56:37 2005 UTC revision 1.76, Wed Dec 28 03:28:05 2005 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;  use FIG;
22  use Carp;  use Carp;
23  use Data::Dumper;  use Data::Dumper;
# Line 10  Line 28 
28  use HTTP::Request::Common;  use HTTP::Request::Common;
29  use POSIX;  use POSIX;
30    
31    
32    my $top_link_cache;
33    
34    
35  sub new  sub new
36  {  {
37      my($class) = @_;      my($class) = @_;
# Line 19  Line 41 
41      return bless $self, $class;      return bless $self, $class;
42  }  }
43    
44    sub top_link
45    {
46    
47        #
48        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
49        # just /p2p).
50        #
51    
52        return $top_link_cache if ($top_link_cache);
53    
54        my @parts = split(/\//, $ENV{SCRIPT_NAME});
55        my $top;
56        if ($parts[-2] eq 'FIG')
57        {
58            $top = '.';
59    #       warn "toplevel @parts\n";
60        }
61        elsif ($parts[-3] eq 'FIG')
62        {
63            $top = '..';
64    #       warn "subdir @parts\n";
65        }
66        else
67        {
68            $top = $FIG_Config::cgi_base;
69    #       warn "other @parts\n";
70        }
71    
72        $top_link_cache = $top;
73        return $top;
74    }
75    
76  sub compute_html_header  sub compute_html_header
77  {  {
78      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
79      my($additional_insert,$user) = @_;      my($additional_insert, $user, %options ) = @_;
80      my $html_hdr_file = "./Html/html.hdr";  
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);      my @html_hdr = &FIG::file_read($html_hdr_file);
90      push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );  
91        # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
92    
93        #
94        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
95        # just /p2p).
96        #
97    
98        my @parts = split(/\//, $ENV{SCRIPT_NAME});
99        my $top;
100        if ($parts[-2] eq 'FIG')
101        {
102            $top = '.';
103    #       warn "toplevel @parts\n";
104        }
105        elsif ($parts[-3] eq 'FIG')
106        {
107            $top = '..';
108    #       warn "subdir @parts\n";
109        }
110        else
111        {
112            $top = $FIG_Config::cgi_base;
113    #       warn "other @parts\n";
114        }
115    
116        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
117    
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 45  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)          if ($additional_insert)
138          {          {
139              $insert_stuff .= "<br>" . $additional_insert;              $insert_stuff .= "<br>" . $additional_insert;
# Line 52  Line 141 
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 66  Line 156 
156  sub show_page {  sub show_page {
157      #warn "SHOWPAGE: cgi=", Dumper(@_);      #warn "SHOWPAGE: cgi=", Dumper(@_);
158      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
159      my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;      my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie) = @_;
160      my $i;      my $i;
161    
162        my $top = top_link();
163    
164      # ARGUMENTS:      # ARGUMENTS:
165      #     $cgi is the CGI method      #     $cgi is the CGI method
# Line 79  Line 170 
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      #               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      #               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")      #     $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      # Find the HTML header
176      #      #
177    
178      my $html_tail_file = "./Html/html.tail";      my $html_tail_file = "./Html/$tail_name";
179      if (! -f $html_tail_file)      if (! -f $html_tail_file)
180      {      {
181          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
182      }      }
183    
184      my $user = $cgi->param('user') || "";      my $user = $cgi->param('user') || "";
# Line 100  Line 192 
192          @html_hdr = compute_html_header(undef,$user);          @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 119  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 162  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 222  Line 320 
320      #  Added the javascript for the buttons immediately after body.      #  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 261  Line 359 
359    
360      if (!$css || !$css->{'Default'})      if (!$css || !$css->{'Default'})
361      {      {
362         $css->{'Default'}="/FIG/Html/css/default.css";         $css->{'Default'} = "$top/Html/css/default.css";
363      }      }
364      if (!$css->{"Sans Serif"})      if (!$css->{"Sans Serif"})
365      {      {
366         $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";         $css->{'Sans Serif'} = "$top/Html/css/sanserif.css";
367      }      }
368    
369      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
370      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
371    
# Line 276  Line 375 
375         $csstext .= "<link rel='alternate stylesheet' title='$k' href='".$css->{$k}."' type='text/css'>\n";         $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='$top/Html/rss/SEED.rss' type='application/rss+xml'>\n";
379    
380      # RAE: also added support for external javascripts here.      # 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      # 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      # 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      # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
388      if ($javasrc && ref($javasrc) eq "ARRAY") {      push @$javasrc, "$top/Html/css/FIG.js";
389       foreach my $script (@$javasrc) {       foreach my $script (@$javasrc) {
390        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
391       }       }
     }  
392    
393    
394    
# Line 317  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 367  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 400  Line 508 
508      #      #
509      # Apparently the above still breaks things. This is the correct code:      # Apparently the above still breaks things. This is the correct code:
510    
511      print @$html;      foreach $_ (@$html)
512        {
513            print $_;
514        }
515    
516  }  }
517    
518  sub make_table {  sub make_table {
# Line 408  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"                  "\t<tr>\n\t\t"
528                . join( "\n", map { &expand($_, "th") } @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
# Line 428  Line 542 
542      return join("",@tab);      return join("",@tab);
543  }  }
544    
545    sub abstract_coupling_table {
546        my($cgi,$prot,$coupling) = @_;
547    
548        my $col_hdrs = ["coupled to","Score","Type of Coupling", "Type-specific Data"];
549        my $tab = [];
550        my %by_peg;
551        foreach my $x (@$coupling)
552        {
553            my($peg2,$psc,$type,$extra) = @$x;
554            $by_peg{$peg2} += $psc;
555        }
556    
557        foreach my $x (sort { ($by_peg{$b->[0]} <=> $by_peg{$a->[0]})
558                              or ($a->[0] cmp $b->[0])
559                              or ($b->[1] <=> $a->[1])
560                              or ($a->[2] cmp $b->[2]) } @$coupling)
561        {
562            my($peg2,$psc,$type,$extra) = @$x;
563            push(@$tab,[&fid_link($cgi,$peg2,1),$psc,$type,&set_prot_links($cgi,join(", ",@$extra))]);
564        }
565    
566    
567        my $help = "<a href=\"Html/abstract_coupling.html\" target=\"SEED_or_SPROUT_help\">for help</a>";
568    #    my @html = &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot");
569    #    push(@html,"<hr>\n",$cgi->h3($help),"<br>");
570    #    return @html;
571    
572        return &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot [$help]");
573    }
574    
575  sub expand {  sub expand {
576      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
577      my( $x, $tag ) = @_;      my( $x, $tag ) = @_;
# Line 440  Line 584 
584      # things like colspan and align. Note that in this case you need to include the td      # things like colspan and align. Note that in this case you need to include the td
585      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
586    
587      if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; if ($tag =~ /td/) { $endtag = "td" } }      # per GJO's request modified this line so it can take any tag.
588        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
589    
590      if ( $x =~ /^\@([^:]+)\:(.*)$/ )      if ( $x =~ /^\@([^:]+)\:(.*)$/ )
591      {      {
# Line 452  Line 597 
597      }      }
598  }  }
599    
600    
601    =head2 merge_table_rows()
602    
603    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
604    
605    Something like this:
606    
607        -----------------------
608        |    1     |    a     |
609        -----------------------
610        |    1     |    b     |
611        -----------------------
612        |    2     |    c     |
613        -----------------------
614        |    3     |    d     |
615        -----------------------
616        |    4     |    d     |
617        -----------------------
618        |    5     |    d     |
619        -----------------------
620    
621    Will become:
622    
623        -----------------------
624        |          |    a     |
625        |    1     |-----------
626        |          |    b     |
627        -----------------------
628        |    2     |    c     |
629        -----------------------
630        |    3     |          |
631        ------------          |
632        |    4     |    5     |
633        ------------          |
634        |    5     |          |
635        -----------------------
636    
637    
638    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.
639    
640     $tab=&HTML::merge_table_rows($tab);
641    
642     or
643    
644     $skip=(1=>1, 3=>1, 5=>1);
645     $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
646    
647    
648    =cut
649    
650    
651    
652    
653    sub merge_table_rows {
654     # RAE:
655     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
656     # this block should merge adjacent rows that have the same text in them.
657     # use like this:
658     #      $tab=&HTML::merge_table_rows($tab);
659     # before you do a make_table call
660    
661     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
662     my ($tab, $skip)=@_;
663    
664     my $newtable;
665     my $lastrow;
666     my $rowspan;
667     my $refs;
668    
669     for (my $y=0; $y <= $#$tab; $y++) {
670     #$y is the row in the table;
671      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
672       # this is the user definable columns not to merge
673       if ($skip->{$x})
674       {
675        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
676        next;
677       }
678    
679       #$x is the column in the table
680       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
681       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
682    
683       # handle cells that are references to arrays
684       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
685    
686       # now we go back through the table looking where to draw the merge line:
687       my $lasty=$y;
688       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
689       $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
690       if ($lasty == $y) {
691        # we always want to have something in rows that may otherwise be empty but should be there (see below)
692        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
693        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
694       }
695       else {$rowspan->[$lasty]->[$x]++}
696      }
697     }
698    
699     # now just join everything back together
700     for (my $y=0; $y <= $#$tab; $y++) {
701      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
702       if ($rowspan->[$y]->[$x]) {
703        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
704        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
705        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
706       }
707       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
708        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
709       }
710      }
711     }
712    
713    
714     # finally we have to remove any completely empty cells that have been added by the array mechanism
715     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
716     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
717     # I am sure that Gary can do this in one line, but I am hacking.
718     my @trimmed;
719     foreach my $a (@$newtable) {
720      my @row;
721      foreach my $b (@$a) {
722       push @row, $b if ($b);
723      }
724      push @trimmed, \@row;
725     }
726    
727     return \@trimmed;
728    }
729    
730    
731    
732    
733  sub set_ec_links {  sub set_ec_links {
734      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
735      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 502  Line 780 
780      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
781      my($n);      my($n);
782    
783        my $top = top_link();
784    
785      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
786      {      {
787          if ($local)          if ($local)
# Line 519  Line 799 
799          {          {
800              $n = $fid;              $n = $fid;
801          }          }
802          if ($1 ne "peg") { return $n }  
803            my $link;
804            #added to format prophage and path island links to feature.cgi
805            if ($1 ne "peg")
806            {
807               my $user = $cgi->param('user');
808               if (! $user) { $user = "" }
809               my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
810               $link = "$top/feature.cgi?feature=$fid&user=$user$trans$sprout";
811               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
812            }
813            else
814            {
815          my $user = $cgi->param('user');          my $user = $cgi->param('user');
816          if (! $user) { $user = "" }          if (! $user) { $user = "" }
817          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
818          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
819          my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";  ###a
         $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;  
         #  
         # Elimin the p2p part if we're in that subdir. Ugh.  
         #  
         $link =~ s,p2p/protein.cgi,protein.cgi,;  
820    
821    ### This used to be
822    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
823    ###
824    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
825    ###
826    ### RAO
827    
828                #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
829                #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
830                $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout";
831                $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
832            }
833          if ($just_url)          if ($just_url)
834          {          {
835              return $link;              return $link;
# Line 666  Line 965 
965          $after = $3;          $after = $3;
966          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);
967      }      }
968      elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)      elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
969      {      {
970          $before = $1;          $before = $1;
971          $match = $2;          $match = $2;
# Line 680  Line 979 
979          $after = $3;          $after = $3;
980          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);
981      }      }
982        elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
983        {
984            $before = $1;
985            $match = $2;
986            $after = $3;
987            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
988        }
989      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
990      {      {
991          $before = $1;          $before = $1;
# Line 708  Line 1014 
1014          $after = $3;          $after = $3;
1015          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);
1016      }      }
1017        elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
1018        {
1019            $before = $1;
1020            $match = $2;
1021            $after = $3;
1022            return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1023        }
1024        elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
1025        {
1026            $before = $1;
1027            $match = $2;
1028            $after = $3;
1029            return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
1030        }
1031        elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
1032        {
1033            $before = $1;
1034            $match = $2;
1035            $after = $3;
1036            return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
1037        }
1038        elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
1039        {
1040            $before = $1;
1041            $match = $2;
1042            $after = $3;
1043            return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
1044        }
1045        elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
1046        {
1047            $before = $1;
1048            $match = $2;
1049            $after = $3;
1050            return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1051        }
1052        elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1053        {
1054            #wormbase
1055    
1056            $before = $1;
1057            $match = $2;
1058            $after = $3;
1059            return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1060        }
1061        elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1062        {
1063            #flybase
1064    
1065            $before = $1;
1066            $match = $2;
1067            $after = $3;
1068            return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1069        }
1070        elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1071        {
1072            #flybase
1073    
1074            $before = $1;
1075            $match = $2;
1076            $after = $3;
1077            return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1078        }
1079        elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1080        {
1081            #flybase
1082    
1083            $before = $1;
1084            $match = $2;
1085            $after = $3;
1086            return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1087        }
1088      return $x;      return $x;
1089  }  }
1090    
# Line 719  Line 1096 
1096      {      {
1097          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>";
1098      }      }
1099        elsif ($id =~ /^[NXYZA]M_/)
1100        {
1101            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id>$id</a>";
1102        }
1103  }  }
1104    
1105  sub gi_link {  sub gi_link {
# Line 732  Line 1113 
1113      return $gi;      return $gi;
1114  }  }
1115    
1116    sub tigr_link {
1117        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1118        my($cgi,$tigr) = @_;
1119    
1120        if ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
1121        {
1122            return "<a href=\"http://pathema.tigr.org/tigr-scripts/CMR/GenePage.cgi?locus=$1\">$tigr</a>";
1123        }
1124        return $tigr;
1125    }
1126    
1127  sub uni_link {  sub uni_link {
1128      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1129      my($cgi,$uni) = @_;      my($cgi,$uni) = @_;
# Line 776  Line 1168 
1168      return $kegg;      return $kegg;
1169  }  }
1170    
1171    sub ensembl_link {
1172        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1173        my($cgi,$ensembl) = @_;
1174    
1175        if ($ensembl =~ /^(\S+):(\S+)$/)
1176        {
1177            my $what=$1;
1178            my $key=$2;
1179            my $idx="all";
1180            if ($what eq "EnsemblGene") { $idx = "Gene" }
1181            if ($what eq "EnsemblTranscript") { $idx = "all" }
1182            if ($what eq "EnsemblProtein") { $idx = "all" }
1183    
1184            #I really want to get right to the transcript and peptide pages, but
1185            #can't see how to do that without knowing the org name too, which
1186            #I don't know at this point. (ensembl org name, not real org name)
1187    
1188            return "<a href=http://www.ensembl.org/Homo_sapiens/textview?species=all&idx=$idx&q=$key>$ensembl</a>";
1189        }
1190        return $ensembl;
1191    }
1192    
1193    sub entrezgene_link {
1194        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1195        my($cgi,$entrezgene) = @_;
1196    
1197        if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1198        {
1199            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1>$entrezgene</a>";
1200        }
1201        return $entrezgene;
1202    }
1203    
1204    sub mim_link {
1205        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1206        my($cgi,$mim) = @_;
1207    
1208        if ($mim =~ /^MIM:(\S+)$/)
1209        {
1210            return "<a href=http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1>$mim</a>";
1211        }
1212        return $mim;
1213    }
1214    
1215    sub unigene_link {
1216        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1217        my($cgi,$unigene) = @_;
1218    
1219        if ($unigene =~ /^UniGene:(\S+)$/)
1220        {
1221            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1>$unigene</a>";
1222        }
1223        return $unigene;
1224    }
1225    
1226    sub ipi_link {
1227        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1228        my($cgi,$ipi) = @_;
1229    
1230        if ($ipi =~ /^IPI:(\S+)$/)
1231        {
1232            return "<a href=http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1>$ipi</a>";
1233        }
1234        return $ipi;
1235    }
1236    
1237    sub wp_link {
1238        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1239        my($cgi,$wp) = @_;
1240    
1241        #wormbase
1242    
1243        if ($wp =~ /^WP:(\S+)$/)
1244        {
1245            return "<a href=http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search>$wp</a>";
1246        }
1247        return $wp;
1248    }
1249    
1250    sub fb_link {
1251        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1252        my($cgi,$fb) = @_;
1253    
1254        #flybase
1255    
1256        if ($fb =~ /^FB:(\S+)$/)
1257        {
1258            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1259        }
1260        return $fb;
1261    }
1262    
1263    sub fborf_link {
1264        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1265        my($cgi,$fb) = @_;
1266    
1267        #flybase
1268    
1269        if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1270        {
1271            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1272        }
1273        return $fb;
1274    }
1275    
1276    sub sgd_link {
1277        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1278        my($cgi,$sgd) = @_;
1279    
1280        #yeast
1281    
1282        if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1283        {
1284            return "<a href=http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1>$sgd</a>";
1285        }
1286        return $sgd;
1287    }
1288    
1289    
1290    
1291    
1292  sub set_map_links {  sub set_map_links {
1293      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1294      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 793  Line 1306 
1306      return $x;      return $x;
1307  }  }
1308    
1309    
1310    
1311  sub map_link {  sub map_link {
1312      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1313      my($cgi,$map,$org) = @_;      my($cgi,$map,$org) = @_;
# Line 800  Line 1315 
1315      $user = $cgi->param('user');      $user = $cgi->param('user');
1316      $user = $user ? $user : "";      $user = $user ? $user : "";
1317      $org = $org ? $org : "";      $org = $org ? $org : "";
1318      my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";  
1319        my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1320    #rel    my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1321      my $link = "<a href=\"$url\">$map</a>";      my $link = "<a href=\"$url\">$map</a>";
1322      return $link;      return $link;
1323  }  }
1324    
 sub javascript {  
     shift if UNIVERSAL::isa($_[0],__PACKAGE__);  
         #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL  
         # This routine takes three arguments, $html, $form, and $button  
         # $html is the ref to the array with the html in it  
         # $form is the name of the form. This must be added whenever start_form is called  
         # by including a -name entry. This is only used for the javascript  
         # $button is the name of the button that should be checked/unchecked.  
         #  
         # At the moment this add's four buttons:  
         # Check all, check's all  
         # Check first half will check the first 50% of the entries  
         # Check second half will check the second 50% of the entries  
         # Uncheck all will remove the checks.  
   
         # Note that the other change is I added a -name=>'fig_checked' to the start_form  
         # field. The name is needed for the java script.  
         #  
   
           $java_script=<<EOF;  
   <SCRIPT LANGUAGE="JavaScript">  
   <!-- Begin  
   function checkAll(field)  
   {  
    for (i = 0; i < field.length; i++)  
    field[i].checked = true ;  
   }  
   
   function checkFirst(field)  
   {  
    for (i = 0; i < field.length/2; i++)  
    field[i].checked = true;  
   }  
   
   function checkSecond(field)  
   {  
    for (i=Math.round(field.length/2); i < field.length; i++)  
    field[i].checked = true ;  
   }  
   
   function uncheckAll(field)  
   {  
    for (i = 0; i < field.length; i++)  
    field[i].checked = false ;  
   }  
   //  End -->  
   </script>  
 EOF  
         return $java_script;  
 }  
   
1325  sub java_buttons {  sub java_buttons {
1326      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1327    ## ADDED BY RAE    ## ADDED BY RAE
# Line 890  Line 1356 
1356      return $sub_link;      return $sub_link;
1357  }  }
1358    
1359  1  sub reaction_link {
1360        my($reaction) = @_;
1361    
1362        if ($reaction =~ /^R\d+/)
1363        {
1364            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$reaction\" target=reaction$$>$reaction</a>";
1365        }
1366        return $reaction;
1367    }
1368    
1369    sub html_for_assignments {
1370        my($fig,$user,$peg_sets) = @_;
1371        my $i;
1372    
1373        my @vals = ();
1374        my $set = 1;
1375        foreach $peg_set (@$peg_sets)
1376        {
1377            for ($i=0; ($i < @$peg_set); $i++)
1378            {
1379                $peg = $peg_set->[$i];
1380                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1381            }
1382            $set++;
1383        }
1384    
1385        $ENV{'REQUEST_METHOD'} = 'GET';
1386        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1387        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1388        $out =~ s/^.*?<form/<form/si;
1389        $out =~ s/^(.*)<table.*/$1/si;
1390        return $out;
1391    }
1392    
1393    =head1 rss_feed
1394    
1395    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1396            SEED.rss                - everything gets written here
1397            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1398            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1399    
1400    
1401    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.
1402    
1403    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.
1404    
1405    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.
1406    
1407    The has can have these keys:
1408    
1409    REQUIRED:
1410    title       : the title. This is usually what is seen by the user in the pull down menu
1411    description : a more complete description that is often seen is rss viewers but not always
1412    link        : link to the item that was added/edited
1413    All other keys are treated as optional RSS arguments and written to the file.
1414    
1415    At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1416    
1417    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.
1418    
1419    
1420    =cut
1421    
1422    sub rss_feed {
1423     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1424     my ($files, $args)=@_;
1425    
1426     # how many entries to store in the file
1427     my $max_entries=50;
1428    
1429     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1430    
1431     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1432     # check for the directory and if not, make it
1433     mkdir $filepath unless (-d $filepath);
1434    
1435     # note that $info is a hash of references to hashes that are written out as headers in the file
1436     my $info=
1437     {
1438      "SEED.rss" =>
1439       {
1440            title           => "The SEED",
1441            description     => "Latest news from the SEED",
1442            link            => "Html/rss/SEED.rss",
1443       },
1444    
1445      "SEEDsubsystems.rss" =>
1446      {
1447            title           => "SEED Subsystems",
1448            description     => "Recently updated SEED subsystems",
1449            link            => "Html/rss/SEEDsubsystems.rss",
1450      },
1451    
1452      "SEEDsubsystems.rss" =>
1453      {
1454            title           => "SEED Genomes",
1455            description     => "Genomes recently added to the SEED",
1456            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1457      },
1458    
1459     };
1460    
1461    
1462     # build the new xml
1463     my $xml = "\t<item>\n";
1464     foreach my $qw ("title", "description", "link") {
1465      unless ($args->{$qw}) {
1466       print STDERR "You need to include a $qw tag in your RSS description\n";
1467       return(0);
1468      }
1469      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1470      # so we are going to pull out the links and uri_escape just the part after the .cgi
1471      if ($qw eq "link")
1472      {
1473       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1474       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1475      }
1476    
1477      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1478      delete $args->{$qw};
1479     }
1480    
1481     foreach my $tag (grep {!/type/i} keys %$args)
1482     {
1483      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1484     }
1485    
1486     $xml .= "\t</item>\n";
1487    
1488    
1489     my @files=("SEED.rss");
1490     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1491    
1492     foreach my $file ("SEED.rss", @$files)
1493     {
1494      if (-e "$filepath/$file")
1495      {
1496       my @out; # the new content of the file
1497       my $itemcount=0; # how many <item> </item>'s are we keeping
1498       my $initem; # are we in an item?
1499       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1500       while (<IN>)
1501       {
1502        if (/\<item\>/) {
1503         push @out, $xml, unless ($itemcount);
1504         $itemcount++;
1505         $initem=1;
1506        }
1507        if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1508        next if ($initem && $itemcount > $max_entries);
1509        push @out, $_;
1510       }
1511       close IN;
1512       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1513       print OUT @out;
1514      }
1515      else
1516      {
1517       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1518       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1519       if ($info->{$file})
1520       {
1521         # we're going to sanity check each of the three options we output, just to be sure
1522         foreach my $qw ("title", "description", "link")
1523         {
1524           if ($info->{$file}->{$qw})
1525           {
1526              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1527           } else {
1528              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1529           }
1530         }
1531       }
1532       else {
1533        print STDERR "Please define title, link, and description information for $file\n";
1534        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1535       }
1536       print OUT "\n", $xml;
1537       print OUT "\n", "</channel>\n</rss>\n"
1538      }
1539     }
1540    }
1541    
1542    
1543    
1544    1;
1545    

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.76

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3