[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.69, Fri Oct 14 20:24:27 2005 UTC
# Line 1  Line 1 
1  package HTML;  package HTML;
2    
3    use Tracer;
4  use FIG;  use FIG;
5  use Carp;  use Carp;
6  use Data::Dumper;  use Data::Dumper;
# Line 10  Line 11 
11  use HTTP::Request::Common;  use HTTP::Request::Common;
12  use POSIX;  use POSIX;
13    
14    
15    my $top_link_cache;
16    
17    
18  sub new  sub new
19  {  {
20      my($class) = @_;      my($class) = @_;
# Line 19  Line 24 
24      return bless $self, $class;      return bless $self, $class;
25  }  }
26    
27    sub top_link
28    {
29    
30        #
31        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
32        # just /p2p).
33        #
34    
35        return $top_link_cache if ($top_link_cache);
36    
37        my @parts = split(/\//, $ENV{SCRIPT_NAME});
38        my $top;
39        if ($parts[-2] eq 'FIG')
40        {
41            $top = '.';
42    #       warn "toplevel @parts\n";
43        }
44        elsif ($parts[-3] eq 'FIG')
45        {
46            $top = '..';
47    #       warn "subdir @parts\n";
48        }
49        else
50        {
51            $top = $FIG_Config::cgi_base;
52    #       warn "other @parts\n";
53        }
54    
55        $top_link_cache = $top;
56        return $top;
57    }
58    
59  sub compute_html_header  sub compute_html_header
60  {  {
61      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
62      my($additional_insert,$user) = @_;      my($additional_insert, $user, %options ) = @_;
63      my $html_hdr_file = "./Html/html.hdr";  
64        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
65        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
66    
67        my $html_hdr_file = "./Html/$header_name";
68      if (! -f $html_hdr_file)      if (! -f $html_hdr_file)
69      {      {
70          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
71      }      }
72      my @html_hdr = &FIG::file_read($html_hdr_file);      my @html_hdr = &FIG::file_read($html_hdr_file);
73      push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );  
74        # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
75    
76        #
77        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
78        # just /p2p).
79        #
80    
81        my @parts = split(/\//, $ENV{SCRIPT_NAME});
82        my $top;
83        if ($parts[-2] eq 'FIG')
84        {
85            $top = '.';
86    #       warn "toplevel @parts\n";
87        }
88        elsif ($parts[-3] eq 'FIG')
89        {
90            $top = '..';
91    #       warn "subdir @parts\n";
92        }
93        else
94        {
95            $top = $FIG_Config::cgi_base;
96    #       warn "other @parts\n";
97        }
98    
99        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
100    
101      if (@html_hdr)      if (@html_hdr)
102      {      {
103          my $insert_stuff;          my $insert_stuff;
104    
105            if (not $options{no_release_info})
106            {
107          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
108          my $ver = $ver[0];          my $ver = $ver[0];
109          chomp $ver;          chomp $ver;
# Line 45  Line 115 
115          }          }
116          my $host = &FIG::get_local_hostname();          my $host = &FIG::get_local_hostname();
117          $insert_stuff = "SEED version <b>$ver</b> on $host";          $insert_stuff = "SEED version <b>$ver</b> on $host";
118            }
119    
120          if ($additional_insert)          if ($additional_insert)
121          {          {
122              $insert_stuff .= "<br>" . $additional_insert;              $insert_stuff .= "<br>" . $additional_insert;
# Line 52  Line 124 
124    
125          for $_ (@html_hdr)          for $_ (@html_hdr)
126          {          {
127              s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;              s,(href|img\s+src)="/FIG/,\1="$top/,g;
128                s,(\?user\=)\",$1$user",;
129              if ($_ eq "<!-- HEADER_INSERT -->\n")              if ($_ eq "<!-- HEADER_INSERT -->\n")
130              {              {
131                  $_ = $insert_stuff;                  $_ = $insert_stuff;
# Line 66  Line 139 
139  sub show_page {  sub show_page {
140      #warn "SHOWPAGE: cgi=", Dumper(@_);      #warn "SHOWPAGE: cgi=", Dumper(@_);
141      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
142      my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;      my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie) = @_;
143      my $i;      my $i;
144    
   
145      # ARGUMENTS:      # ARGUMENTS:
146      #     $cgi is the CGI method      #     $cgi is the CGI method
147      #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>      #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
# Line 79  Line 151 
151      #               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
152      #               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
153      #     $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")
154        #     $cookie is the name and value of the cookie to set. Note that you should probably use raelib->cookie to get/set your cookies
155      #      #
156      # Find the HTML header      # Find the HTML header
157      #      #
158    
159      my $html_tail_file = "./Html/html.tail";      my $html_tail_file = "./Html/$tail_name";
160      if (! -f $html_tail_file)      if (! -f $html_tail_file)
161      {      {
162          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
163      }      }
164    
165      my $user = $cgi->param('user') || "";      my $user = $cgi->param('user') || "";
# Line 100  Line 173 
173          @html_hdr = compute_html_header(undef,$user);          @html_hdr = compute_html_header(undef,$user);
174      }      }
175    
176        # RAE: I am offloading the handling of cookies to CGI.pm since I don't know how they are set up.
177        # This modification adds the cookies if necessary
178    
179        # Note: 3/10/05 commented this line out pending the discussion of adding cookies into the seed that we are waiting to see about
180        # to add cookies back in replace these two header lines with each other
181    
182      print $cgi->header;      #print $cgi->header(-cookie=>$cookie);
183        print $cgi->header();
184    
185      #      #
186      #  The SEED header file goes immediately after <BODY>.  Figure out      #  The SEED header file goes immediately after <BODY>.  Figure out
# Line 119  Line 198 
198                       meta     => 1,                       meta     => 1,
199                       nextid   => 1,                       nextid   => 1,
200                       style    => 1,                       style    => 1,
201                       title    => 1                       title    => 1,
202                     );                     );
203    
204      #      #
# Line 222  Line 301 
301      #  Added the javascript for the buttons immediately after body.      #  Added the javascript for the buttons immediately after body.
302      #  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,
303      #  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!
304        #  RAE: This is now deprecated because everything is in an external file, FIG.js, included later
305    
306      if ( $body_line < 0 )      if ( $body_line < 0 )
307      {      {
         my $js=&javascript;  
308          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
309          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );          splice( @$html, $body_line, 0, "<BODY>\n" );
310      }      }
311    
312      #      #
# Line 261  Line 340 
340    
341      if (!$css || !$css->{'Default'})      if (!$css || !$css->{'Default'})
342      {      {
343         $css->{'Default'}="/FIG/Html/css/default.css";         $css->{'Default'} = &FIG::cgi_url() . "/Html/css/default.css";
344      }      }
345      if (!$css->{"Sans Serif"})      if (!$css->{"Sans Serif"})
346      {      {
347         $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";         $css->{'Sans Serif'} = &FIG::cgi_url() . "/Html/css/sanserif.css";
348      }      }
349    
350      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";
351      $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";
352    
# Line 276  Line 356 
356         $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";
357      }      }
358    
359        $csstext   .= "<link rel='alternate'  title='SEED RSS feeds' href='".&FIG::cgi_url()."/Html/rss/SEED.rss' type='application/rss+xml'>\n";
360    
361      # RAE: also added support for external javascripts here.      # RAE: also added support for external javascripts here.
362      # 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
363      # this solution allows us to source other files      # this solution allows us to source other files
364    
365        # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
366        # it will reduce our overhead.
367    
368      # $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
369      if ($javasrc && ref($javasrc) eq "ARRAY") {      push @$javasrc, &FIG::cgi_url() . "/Html/css/FIG.js";
370       foreach my $script (@$javasrc) {       foreach my $script (@$javasrc) {
371        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
372       }       }
     }  
373    
374    
375    
# Line 317  Line 400 
400  #       }  #       }
401    
402          $base_line = $head_end_line;          $base_line = $head_end_line;
403          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );          #
404            # RDO 2005-1006. Remove this so proxying works better.
405            #
406    #        splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
407      }      }
408    
409      #      #
# Line 367  Line 453 
453      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
454      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
455      #      #
   
456      my @tags = ();      my @tags = ();
457        # Check for a tracing queue.
458        my $traceString = QTrace("HTML");
459        if ($traceString) {
460            push @tags, $traceString;
461        }
462      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
463      if ($i >= @$html)        # </body> not found; look for </html>      if ($i >= @$html)        # </body> not found; look for </html>
464      {      {
# Line 400  Line 489 
489      #      #
490      # Apparently the above still breaks things. This is the correct code:      # Apparently the above still breaks things. This is the correct code:
491    
492      print @$html;      foreach $_ (@$html)
493        {
494            print $_;
495        }
496    
497  }  }
498    
499  sub make_table {  sub make_table {
# Line 408  Line 501 
501      my(@tab);      my(@tab);
502    
503      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
504      push( @tab, "\n<table $border>\n",      my $width = defined $options{width} ? "width=\"$options{width}\"" : undef;
505        push( @tab, "\n<table $border $width>\n",
506                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
507                  "\t<tr>\n\t\t"                  "\t<tr>\n\t\t"
508                . join( "\n", map { &expand($_, "th") } @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
# Line 440  Line 534 
534      # 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
535      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
536    
537      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.
538        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
539    
540      if ( $x =~ /^\@([^:]+)\:(.*)$/ )      if ( $x =~ /^\@([^:]+)\:(.*)$/ )
541      {      {
# Line 452  Line 547 
547      }      }
548  }  }
549    
550    
551    =head2 merge_table_rows()
552    
553    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
554    
555    Something like this:
556    
557        -----------------------
558        |    1     |    a     |
559        -----------------------
560        |    1     |    b     |
561        -----------------------
562        |    2     |    c     |
563        -----------------------
564        |    3     |    d     |
565        -----------------------
566        |    4     |    d     |
567        -----------------------
568        |    5     |    d     |
569        -----------------------
570    
571    Will become:
572    
573        -----------------------
574        |          |    a     |
575        |    1     |-----------
576        |          |    b     |
577        -----------------------
578        |    2     |    c     |
579        -----------------------
580        |    3     |          |
581        ------------          |
582        |    4     |    5     |
583        ------------          |
584        |    5     |          |
585        -----------------------
586    
587    
588    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.
589    
590     $tab=&HTML::merge_table_rows($tab);
591    
592     or
593    
594     $skip=(1=>1, 3=>1, 5=>1);
595     $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
596    
597    
598    =cut
599    
600    
601    
602    
603    sub merge_table_rows {
604     # RAE:
605     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
606     # this block should merge adjacent rows that have the same text in them.
607     # use like this:
608     #      $tab=&HTML::merge_table_rows($tab);
609     # before you do a make_table call
610    
611     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
612     my ($tab, $skip)=@_;
613    
614     my $newtable;
615     my $lastrow;
616     my $rowspan;
617     my $refs;
618    
619     for (my $y=0; $y <= $#$tab; $y++) {
620     #$y is the row in the table;
621      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
622       # this is the user definable columns not to merge
623       if ($skip->{$x})
624       {
625        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
626        next;
627       }
628    
629       #$x is the column in the table
630       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
631       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
632    
633       # handle cells that are references to arrays
634       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
635    
636       # now we go back through the table looking where to draw the merge line:
637       my $lasty=$y;
638       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
639       $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
640       if ($lasty == $y) {
641        # we always want to have something in rows that may otherwise be empty but should be there (see below)
642        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
643        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
644       }
645       else {$rowspan->[$lasty]->[$x]++}
646      }
647     }
648    
649     # now just join everything back together
650     for (my $y=0; $y <= $#$tab; $y++) {
651      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
652       if ($rowspan->[$y]->[$x]) {
653        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
654        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
655        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
656       }
657       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
658        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
659       }
660      }
661     }
662    
663    
664     # finally we have to remove any completely empty cells that have been added by the array mechanism
665     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
666     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
667     # I am sure that Gary can do this in one line, but I am hacking.
668     my @trimmed;
669     foreach my $a (@$newtable) {
670      my @row;
671      foreach my $b (@$a) {
672       push @row, $b if ($b);
673      }
674      push @trimmed, \@row;
675     }
676    
677     return \@trimmed;
678    }
679    
680    
681    
682    
683  sub set_ec_links {  sub set_ec_links {
684      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
685      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 502  Line 730 
730      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url) = @_;
731      my($n);      my($n);
732    
733        my $top = top_link();
734    
735      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
736      {      {
737          if ($local)          if ($local)
# Line 519  Line 749 
749          {          {
750              $n = $fid;              $n = $fid;
751          }          }
752          if ($1 ne "peg") { return $n }  
753            my $link;
754            #added to format prophage and path island links to feature.cgi
755            if ($1 ne "peg")
756            {
757               my $user = $cgi->param('user');
758               if (! $user) { $user = "" }
759               my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
760               $link = "$top/feature.cgi?feature=$fid&user=$user$trans$sprout";
761               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
762            }
763            else
764            {
765          my $user = $cgi->param('user');          my $user = $cgi->param('user');
766          if (! $user) { $user = "" }          if (! $user) { $user = "" }
767          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
768          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
769          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,;  
770    
771    ### This used to be
772    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
773    ###
774    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
775    ###
776    ### RAO
777    
778                #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
779                #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
780                $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout";
781                $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
782            }
783          if ($just_url)          if ($just_url)
784          {          {
785              return $link;              return $link;
# Line 666  Line 915 
915          $after = $3;          $after = $3;
916          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);
917      }      }
918      elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)      elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
919      {      {
920          $before = $1;          $before = $1;
921          $match = $2;          $match = $2;
# Line 680  Line 929 
929          $after = $3;          $after = $3;
930          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);
931      }      }
932        elsif ($x =~ /^(.*)(tigr\|[0-9a-zA-Z]+)(.*)/s)
933        {
934            $before = $1;
935            $match = $2;
936            $after = $3;
937            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
938        }
939      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
940      {      {
941          $before = $1;          $before = $1;
# Line 708  Line 964 
964          $after = $3;          $after = $3;
965          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);
966      }      }
967        elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
968        {
969            $before = $1;
970            $match = $2;
971            $after = $3;
972            return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
973        }
974        elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
975        {
976            $before = $1;
977            $match = $2;
978            $after = $3;
979            return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
980        }
981        elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
982        {
983            $before = $1;
984            $match = $2;
985            $after = $3;
986            return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
987        }
988        elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
989        {
990            $before = $1;
991            $match = $2;
992            $after = $3;
993            return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
994        }
995        elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
996        {
997            $before = $1;
998            $match = $2;
999            $after = $3;
1000            return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1001        }
1002        elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1003        {
1004            #wormbase
1005    
1006            $before = $1;
1007            $match = $2;
1008            $after = $3;
1009            return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1010        }
1011        elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1012        {
1013            #flybase
1014    
1015            $before = $1;
1016            $match = $2;
1017            $after = $3;
1018            return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1019        }
1020        elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1021        {
1022            #flybase
1023    
1024            $before = $1;
1025            $match = $2;
1026            $after = $3;
1027            return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1028        }
1029        elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1030        {
1031            #flybase
1032    
1033            $before = $1;
1034            $match = $2;
1035            $after = $3;
1036            return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1037        }
1038      return $x;      return $x;
1039  }  }
1040    
# Line 719  Line 1046 
1046      {      {
1047          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>";
1048      }      }
1049        elsif ($id =~ /^[NXYZA]M_/)
1050        {
1051            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id>$id</a>";
1052        }
1053  }  }
1054    
1055  sub gi_link {  sub gi_link {
# Line 732  Line 1063 
1063      return $gi;      return $gi;
1064  }  }
1065    
1066    sub tigr_link {
1067        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1068        my($cgi,$tigr) = @_;
1069    
1070        if ($tigr =~ /^tigr\|([0-9a-zA-Z]+)$/)
1071        {
1072            return "<a href=\"http://pathema.tigr.org/tigr-scripts/CMR/GenePage.cgi?locus=$1\">$tigr</a>";
1073        }
1074        return $tigr;
1075    }
1076    
1077  sub uni_link {  sub uni_link {
1078      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1079      my($cgi,$uni) = @_;      my($cgi,$uni) = @_;
# Line 776  Line 1118 
1118      return $kegg;      return $kegg;
1119  }  }
1120    
1121    sub ensembl_link {
1122        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1123        my($cgi,$ensembl) = @_;
1124    
1125        if ($ensembl =~ /^(\S+):(\S+)$/)
1126        {
1127            my $what=$1;
1128            my $key=$2;
1129            my $idx="all";
1130            if ($what eq "EnsemblGene") { $idx = "Gene" }
1131            if ($what eq "EnsemblTranscript") { $idx = "all" }
1132            if ($what eq "EnsemblProtein") { $idx = "all" }
1133    
1134            #I really want to get right to the transcript and peptide pages, but
1135            #can't see how to do that without knowing the org name too, which
1136            #I don't know at this point. (ensembl org name, not real org name)
1137    
1138            return "<a href=http://www.ensembl.org/Homo_sapiens/textview?species=all&idx=$idx&q=$key>$ensembl</a>";
1139        }
1140        return $ensembl;
1141    }
1142    
1143    sub entrezgene_link {
1144        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1145        my($cgi,$entrezgene) = @_;
1146    
1147        if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1148        {
1149            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1>$entrezgene</a>";
1150        }
1151        return $entrezgene;
1152    }
1153    
1154    sub mim_link {
1155        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1156        my($cgi,$mim) = @_;
1157    
1158        if ($mim =~ /^MIM:(\S+)$/)
1159        {
1160            return "<a href=http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1>$mim</a>";
1161        }
1162        return $mim;
1163    }
1164    
1165    sub unigene_link {
1166        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1167        my($cgi,$unigene) = @_;
1168    
1169        if ($unigene =~ /^UniGene:(\S+)$/)
1170        {
1171            return "<a href=http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1>$unigene</a>";
1172        }
1173        return $unigene;
1174    }
1175    
1176    sub ipi_link {
1177        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1178        my($cgi,$ipi) = @_;
1179    
1180        if ($ipi =~ /^IPI:(\S+)$/)
1181        {
1182            return "<a href=http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1>$ipi</a>";
1183        }
1184        return $ipi;
1185    }
1186    
1187    sub wp_link {
1188        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1189        my($cgi,$wp) = @_;
1190    
1191        #wormbase
1192    
1193        if ($wp =~ /^WP:(\S+)$/)
1194        {
1195            return "<a href=http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search>$wp</a>";
1196        }
1197        return $wp;
1198    }
1199    
1200    sub fb_link {
1201        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1202        my($cgi,$fb) = @_;
1203    
1204        #flybase
1205    
1206        if ($fb =~ /^FB:(\S+)$/)
1207        {
1208            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1209        }
1210        return $fb;
1211    }
1212    
1213    sub fborf_link {
1214        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1215        my($cgi,$fb) = @_;
1216    
1217        #flybase
1218    
1219        if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1220        {
1221            return "<a href=http://flybase.bio.indiana.edu/.bin/fbidq.html?$1>$fb</a>";
1222        }
1223        return $fb;
1224    }
1225    
1226    sub sgd_link {
1227        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1228        my($cgi,$sgd) = @_;
1229    
1230        #yeast
1231    
1232        if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1233        {
1234            return "<a href=http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1>$sgd</a>";
1235        }
1236        return $sgd;
1237    }
1238    
1239    
1240    
1241    
1242  sub set_map_links {  sub set_map_links {
1243      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1244      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 793  Line 1256 
1256      return $x;      return $x;
1257  }  }
1258    
1259    
1260    
1261  sub map_link {  sub map_link {
1262      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1263      my($cgi,$map,$org) = @_;      my($cgi,$map,$org) = @_;
# Line 800  Line 1265 
1265      $user = $cgi->param('user');      $user = $cgi->param('user');
1266      $user = $user ? $user : "";      $user = $user ? $user : "";
1267      $org = $org ? $org : "";      $org = $org ? $org : "";
1268      my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";  
1269        my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1270    #rel    my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1271      my $link = "<a href=\"$url\">$map</a>";      my $link = "<a href=\"$url\">$map</a>";
1272      return $link;      return $link;
1273  }  }
1274    
 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;  
 }  
   
1275  sub java_buttons {  sub java_buttons {
1276      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1277    ## ADDED BY RAE    ## ADDED BY RAE
# Line 890  Line 1306 
1306      return $sub_link;      return $sub_link;
1307  }  }
1308    
1309  1  sub reaction_link {
1310        my($reaction) = @_;
1311    
1312        if ($reaction =~ /^R\d+/)
1313        {
1314            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$reaction\" target=reaction$$>$reaction</a>";
1315        }
1316        return $reaction;
1317    }
1318    
1319    sub html_for_assignments {
1320        my($fig,$user,$peg_sets) = @_;
1321        my $i;
1322    
1323        my @vals = ();
1324        my $set = 1;
1325        foreach $peg_set (@$peg_sets)
1326        {
1327            for ($i=0; ($i < @$peg_set); $i++)
1328            {
1329                $peg = $peg_set->[$i];
1330                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1331            }
1332            $set++;
1333        }
1334    
1335        $ENV{'REQUEST_METHOD'} = 'GET';
1336        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1337        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1338        $out =~ s/^.*?<form/<form/si;
1339        $out =~ s/^(.*)<table.*/$1/si;
1340        return $out;
1341    }
1342    
1343    =head1 rss_feed
1344    
1345    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1346            SEED.rss                - everything gets written here
1347            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1348            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1349    
1350    
1351    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.
1352    
1353    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.
1354    
1355    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.
1356    
1357    The has can have these keys:
1358    
1359    REQUIRED:
1360    title       : the title. This is usually what is seen by the user in the pull down menu
1361    description : a more complete description that is often seen is rss viewers but not always
1362    link        : link to the item that was added/edited
1363    All other keys are treated as optional RSS arguments and written to the file.
1364    
1365    At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1366    
1367    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.
1368    
1369    
1370    =cut
1371    
1372    sub rss_feed {
1373     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1374     my ($files, $args)=@_;
1375    
1376     # how many entries to store in the file
1377     my $max_entries=50;
1378    
1379     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1380    
1381     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1382     # check for the directory and if not, make it
1383     mkdir $filepath unless (-d $filepath);
1384    
1385     # note that $info is a hash of references to hashes that are written out as headers in the file
1386     my $info=
1387     {
1388      "SEED.rss" =>
1389       {
1390            title           => "The SEED",
1391            description     => "Latest news from the SEED",
1392            link            => "Html/rss/SEED.rss",
1393       },
1394    
1395      "SEEDsubsystems.rss" =>
1396      {
1397            title           => "SEED Subsystems",
1398            description     => "Recently updated SEED subsystems",
1399            link            => "Html/rss/SEEDsubsystems.rss",
1400      },
1401    
1402      "SEEDsubsystems.rss" =>
1403      {
1404            title           => "SEED Genomes",
1405            description     => "Genomes recently added to the SEED",
1406            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1407      },
1408    
1409     };
1410    
1411    
1412     # build the new xml
1413     my $xml = "\t<item>\n";
1414     foreach my $qw ("title", "description", "link") {
1415      unless ($args->{$qw}) {
1416       print STDERR "You need to include a $qw tag in your RSS description\n";
1417       return(0);
1418      }
1419      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1420      # so we are going to pull out the links and uri_escape just the part after the .cgi
1421      if ($qw eq "link")
1422      {
1423       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1424       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1425      }
1426    
1427      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1428      delete $args->{$qw};
1429     }
1430    
1431     foreach my $tag (grep {!/type/i} keys %$args)
1432     {
1433      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1434     }
1435    
1436     $xml .= "\t</item>\n";
1437    
1438    
1439     my @files=("SEED.rss");
1440     if ($args->{"type"}) {push @files, "SEED.$type.rss"}
1441    
1442     foreach my $file ("SEED.rss", @$files)
1443     {
1444      if (-e "$filepath/$file")
1445      {
1446       my @out; # the new content of the file
1447       my $itemcount=0; # how many <item> </item>'s are we keeping
1448       my $initem; # are we in an item?
1449       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1450       while (<IN>)
1451       {
1452        if (/\<item\>/) {
1453         push @out, $xml, unless ($itemcount);
1454         $itemcount++;
1455         $initem=1;
1456        }
1457        if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1458        next if ($initem && $itemcount > $max_entries);
1459        push @out, $_;
1460       }
1461       close IN;
1462       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1463       print OUT @out;
1464      }
1465      else
1466      {
1467       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1468       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1469       if ($info->{$file})
1470       {
1471         # we're going to sanity check each of the three options we output, just to be sure
1472         foreach my $qw ("title", "description", "link")
1473         {
1474           if ($info->{$file}->{$qw})
1475           {
1476              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1477           } else {
1478              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1479           }
1480         }
1481       }
1482       else {
1483        print STDERR "Please define title, link, and description information for $file\n";
1484        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1485       }
1486       print OUT "\n", $xml;
1487       print OUT "\n", "</channel>\n</rss>\n"
1488      }
1489     }
1490    }
1491    
1492    
1493    
1494    1;
1495    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3