[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.102, Thu Sep 28 22:59:05 2006 UTC
# Line 1  Line 1 
1    #
2    # Copyright (c) 2003-2006 University of Chicago and Fellowship
3    # for Interpretations of Genomes. All Rights Reserved.
4    #
5    # This file is part of the SEED Toolkit.
6    #
7    # The SEED Toolkit is free software. You can redistribute
8    # it and/or modify it under the terms of the SEED Toolkit
9    # Public License.
10    #
11    # You should have received a copy of the SEED Toolkit Public License
12    # along with this program; if not write to the University of Chicago
13    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14    # Genomes at veronika@thefig.info or download a copy from
15    # http://www.theseed.org/LICENSE.TXT.
16    #
17    
18  package HTML;  package HTML;
19    
20    use strict;
21    use Tracer;
22  use FIG;  use FIG;
23  use Carp;  use Carp;
24  use Data::Dumper;  use Data::Dumper;
# Line 10  Line 29 
29  use HTTP::Request::Common;  use HTTP::Request::Common;
30  use POSIX;  use POSIX;
31    
32    #use raelib; # now used for the excel function, that should eventually end up in here. Way too experimental!
33    my $raelib;
34    
35    
36    my $top_link_cache;
37    
38    
39  sub new  sub new
40  {  {
41      my($class) = @_;      my($class) = @_;
# Line 19  Line 45 
45      return bless $self, $class;      return bless $self, $class;
46  }  }
47    
48    sub top_link
49    {
50    
51        #
52        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
53        # just /p2p).
54        #
55    
56        return $top_link_cache if ($top_link_cache);
57    
58        my @parts = split(/\//, $ENV{SCRIPT_NAME});
59        my $top;
60        if ($parts[-2] eq 'FIG')
61        {
62            $top = '.';
63    #       warn "toplevel @parts\n";
64        }
65        elsif ($parts[-3] eq 'FIG')
66        {
67            $top = '..';
68    #       warn "subdir @parts\n";
69        }
70        else
71        {
72            $top = $FIG_Config::cgi_base;
73    #       warn "other @parts\n";
74        }
75    
76        $top_link_cache = $top;
77        return $top;
78    }
79    
80  sub compute_html_header  sub compute_html_header
81  {  {
82      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
83      my($additional_insert,$user) = @_;      my($additional_insert, $user, %options ) = @_;
84      my $html_hdr_file = "./Html/html.hdr";  
85        local $/ = "\n";
86    
87        my $header_name = $options{header_name} ? $options{header_name} : "html.hdr";
88        my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
89    
90        my $html_hdr_file = "./Html/$header_name";
91      if (! -f $html_hdr_file)      if (! -f $html_hdr_file)
92      {      {
93          $html_hdr_file = "$FIG_Config::fig/CGI/Html/html.hdr";          $html_hdr_file = "$FIG_Config::fig/CGI/Html/$header_name";
94      }      }
95      my @html_hdr = &FIG::file_read($html_hdr_file);      my @html_hdr = &FIG::file_read($html_hdr_file);
96      push( @html_hdr, "<br><a href=\"index.cgi?user=$user\">FIG search</a>\n" );  
97        # for my $k (sort keys %ENV) { warn "$k = $ENV{$k}\n"; }
98    
99        #
100        # Determine if this is a toplevel cgi or one in one of the subdirs (currently
101        # just /p2p).
102        #
103    
104        my @parts = split(/\//, $ENV{SCRIPT_NAME});
105        my $top;
106        if ($parts[-2] eq 'FIG')
107        {
108            $top = '.';
109    #       warn "toplevel @parts\n";
110        }
111        elsif ($parts[-3] eq 'FIG')
112        {
113            $top = '..';
114    #       warn "subdir @parts\n";
115        }
116        else
117        {
118            $top = $FIG_Config::cgi_base;
119    #       warn "other @parts\n";
120        }
121    
122        $options{no_fig_search} or push( @html_hdr, "<br><a href=\"$top/index.cgi?user=$user\">FIG search</a>\n" );
123    
124      if (@html_hdr)      if (@html_hdr)
125      {      {
126          my $insert_stuff;          my $insert_stuff;
127    
128            if (not $options{no_release_info})
129            {
130          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);          my @ver = &FIG::file_head("$FIG_Config::fig_disk/CURRENT_RELEASE", 1);
131          my $ver = $ver[0];          my $ver = $ver[0];
132          chomp $ver;          chomp $ver;
# Line 45  Line 138 
138          }          }
139          my $host = &FIG::get_local_hostname();          my $host = &FIG::get_local_hostname();
140          $insert_stuff = "SEED version <b>$ver</b> on $host";          $insert_stuff = "SEED version <b>$ver</b> on $host";
141            }
142    
143          if ($additional_insert)          if ($additional_insert)
144          {          {
145              $insert_stuff .= "<br>" . $additional_insert;              $insert_stuff .= "<br>" . $additional_insert;
# Line 52  Line 147 
147    
148          for $_ (@html_hdr)          for $_ (@html_hdr)
149          {          {
150              s,(href|img\s+src)="/FIG/,\1="$FIG_Config::cgi_base,g;              s,(href|img\s+src)="/FIG/,$1="$top/,g;
151                    s,(\?user\=)\",$1$user",;
152              if ($_ eq "<!-- HEADER_INSERT -->\n")              if ($_ eq "<!-- HEADER_INSERT -->\n")
153              {              {
154                  $_ = $insert_stuff;                  $_ = $insert_stuff;
# Line 66  Line 162 
162  sub show_page {  sub show_page {
163      #warn "SHOWPAGE: cgi=", Dumper(@_);      #warn "SHOWPAGE: cgi=", Dumper(@_);
164      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
165      my($cgi,$html,$no_home, $alt_header, $css, $javasrc) = @_;      my($cgi,$html,$no_home, $alt_header, $css, $javasrc, $cookie, $options) = @_;
166      my $i;      my $i;
167    
168        my $top = top_link();
169    
170      # ARGUMENTS:      # ARGUMENTS:
171      #     $cgi is the CGI method      #     $cgi is the CGI method
# Line 78  Line 175 
175      #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls      #     $css is a reference to a hash. The key is the name of the CSS sheet and the value is the URL of that sheet. Note the usual rules about relative css urls
176      #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css      #               the sheet named "Default" is considered to be the default style sheet, and if this is not set it points at $FIG_Config::HTML/css/default.css
177      #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css      #               the sheet named "Sans Serif" is considered to the the first alternate, and if this is not set it points at $FIG_Config::HTML/css/sanserif.css
178      #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "/FIG/Html/css/styleswitcher.js")      #     $javasrc is a reference to an array of URLs to javascripts to be included (e.g. "FIG/Html/css/styleswitcher.js")
179        #     $cookie is the name and value of the cookie to set. Note that you should probably use raelib->cookie to get/set your cookies
180        #     $options is a reference to a hash of options that you can pass around the pages
181      #      #
182      # Find the HTML header      # Find the HTML header
183      #      #
184    
185      my $html_tail_file = "./Html/html.tail";      my $tail_name = $options->{tail_name} ? $options->{tail_name} : "html.tail";
186        my $html_tail_file = "./Html/$tail_name";
187      if (! -f $html_tail_file)      if (! -f $html_tail_file)
188      {      {
189          $html_tail_file = "$FIG_Config::fig/CGI/Html/html.tail";          $html_tail_file = "$FIG_Config::fig/CGI/Html/$tail_name";
190      }      }
191    
192      my $user = $cgi->param('user') || "";      my $user = $cgi->param('user') || "";
# Line 97  Line 197 
197      }      }
198      else      else
199      {      {
200          @html_hdr = compute_html_header(undef,$user);          @html_hdr = compute_html_header(undef,$user,%$options);
201      }      }
202    
203        # RAE: I am offloading the handling of cookies to CGI.pm since I don't know how they are set up.
204        # This modification adds the cookies if necessary
205    
206      print $cgi->header;      # Note: 3/10/05 commented this line out pending the discussion of adding cookies into the seed that we are waiting to see about
207        # to add cookies back in replace these two header lines with each other
208    
209        #print $cgi->header(-cookie=>$cookie);
210        print $cgi->header();
211    
212      #      #
213      #  The SEED header file goes immediately after <BODY>.  Figure out      #  The SEED header file goes immediately after <BODY>.  Figure out
# Line 119  Line 225 
225                       meta     => 1,                       meta     => 1,
226                       nextid   => 1,                       nextid   => 1,
227                       style    => 1,                       style    => 1,
228                       title    => 1                       title    => 1,
229                     );                     );
230    
231      #      #
# Line 162  Line 268 
268          if ( $html->[$i] =~ /\<body[^0-9a-z]/i )          if ( $html->[$i] =~ /\<body[^0-9a-z]/i )
269          {          {
270              $body_line = $i;              $body_line = $i;
271              $last;              last;
272          }          }
273    
274          #  Now the general case.          #  Now the general case.
# Line 222  Line 328 
328      #  Added the javascript for the buttons immediately after body.      #  Added the javascript for the buttons immediately after body.
329      #  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,
330      #  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!
331        #  RAE: This is now deprecated because everything is in an external file, FIG.js, included later
332    
333      if ( $body_line < 0 )      if ( $body_line < 0 )
334      {      {
         my $js=&javascript;  
335          $body_line = $last_head_line + 1;          $body_line = $last_head_line + 1;
336          splice( @$html, $body_line, 0, "<BODY>\n$js\n" );          splice( @$html, $body_line, 0, "<BODY>\n" );
337      }      }
338    
339      #      #
# Line 261  Line 367 
367    
368      if (!$css || !$css->{'Default'})      if (!$css || !$css->{'Default'})
369      {      {
370         $css->{'Default'}="/FIG/Html/css/default.css";         $css->{'Default'} = "Html/css/default.css";
371      }      }
372      if (!$css->{"Sans Serif"})      if (!$css->{"Sans Serif"})
373      {      {
374         $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";         $css->{'Sans Serif'} = "Html/css/sanserif.css";
375      }      }
376    
377      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";
378      $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";
379    
# Line 276  Line 383 
383         $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";
384      }      }
385    
386        $csstext   .= "<link rel='alternate'  title='SEED RSS feeds' href='Html/rss/SEED.rss' type='application/rss+xml'>\n";
387    
388      # RAE: also added support for external javascripts here.      # RAE: also added support for external javascripts here.
389      # we are cluttering the HTML code with all the javascripts when they could easily be in external files      # we are cluttering the HTML code with all the javascripts when they could easily be in external files
390      # this solution allows us to source other files      # this solution allows us to source other files
391    
392        # the file FIG.js contains most of the java script we use routinely. Every browser will just cache this and so
393        # it will reduce our overhead.
394    
395      # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts      # $javasrc must be a ref to an array with urls (absolute or relative) to the javascripts
396      if ($javasrc && ref($javasrc) eq "ARRAY") {      push @$javasrc, "Html/css/FIG.js";
397       foreach my $script (@$javasrc) {       foreach my $script (@$javasrc) {
398        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";        $csstext .= "<script src=\"$script\" type=\"text/javascript\"></script>\n";
399       }       }
     }  
400    
401    
402    
# Line 307  Line 417 
417          # BASE href needs to be absolute. RDO.          # BASE href needs to be absolute. RDO.
418          #          #
419          #          #
420          $base_url = &FIG::cgi_url;  #        $base_url = &FIG::cgi_url;
421  #       my $base_url = $FIG_Config::cgi_base;  #       my $base_url = $FIG_Config::cgi_base;
422  #       if ( ! $base_url )                      # if cgi_base was not defined  #       if ( ! $base_url )                      # if cgi_base was not defined
423  #       {  #       {
# Line 317  Line 427 
427  #       }  #       }
428    
429          $base_line = $head_end_line;          $base_line = $head_end_line;
430          splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );          #
431            # RDO 2005-1006. Remove this so proxying works better.
432            #
433    #        splice( @$html, $base_line, 0, "<BASE href=\"$base_url/\">\n" );
434      }      }
435    
436      #      #
# Line 367  Line 480 
480      #  Figure out where to insert The SEED tail.  Before </body>,      #  Figure out where to insert The SEED tail.  Before </body>,
481      #  or before </html>, or at end of page.      #  or before </html>, or at end of page.
482      #      #
   
483      my @tags = ();      my @tags = ();
484        # Check for a tracing queue.
485        my $traceString = QTrace("HTML");
486        if ($traceString) {
487            push @tags, $traceString;
488        }
489      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}      for ($i=0; ($i < @$html) && ($html->[$i] !~ /\<\/body\>/i); $i++) {}
490      if ($i >= @$html)        # </body> not found; look for </html>      if ($i >= @$html)        # </body> not found; look for </html>
491      {      {
# Line 400  Line 516 
516      #      #
517      # Apparently the above still breaks things. This is the correct code:      # Apparently the above still breaks things. This is the correct code:
518    
519      print @$html;      foreach $_ (@$html)
520        {
521            print $_;
522  }  }
523    
524    }
525    
526    
527    =head1 make_table
528    
529    The main method to convert an array into a table.
530    
531    The col_hdrs are set to the <th> headers, the $tab is an array of arrays. The first is the rows, and the second is the columns. The title is the title of the table.
532    
533    The options define the settings for the table such as border, width, and class for css formatting. If the option "excelfile" is set to a filename that will be created in FIG_Config::temp, and the link included that allows the user to download the file as an excel file.
534    
535    =cut
536    
537  sub make_table {  sub make_table {
538      my($col_hdrs,$tab,$title, %options ) = @_;      my($col_hdrs,$tab,$title, %options ) = @_;
539      my(@tab);      my(@tab);
540    
541      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";      my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
542      push( @tab, "\n<table $border>\n",      my $width = defined $options{width} ? "width=\"$options{width}\"" : undef;
543        my $class = defined $options{class} ? "class=\"$options{class}\"" : undef;
544        push( @tab, "\n<table $border $width $class>\n",
545                  "\t<caption><b>$title</b></caption>\n",                  "\t<caption><b>$title</b></caption>\n",
546                  "\t<tr>\n\t\t"                  "\t<tr>\n\t\t"
547                . join( "\n", map { &expand($_, "th") } @$col_hdrs )                . join( "\n", map { &expand($_, "th") } @$col_hdrs )
# Line 425  Line 558 
558              );              );
559      }      }
560      push(@tab,"</table>\n");      push(@tab,"</table>\n");
561    
562        # excelfile should be appropriate for a filename (no spaces/special characters)
563        if (defined $options{"excelfile"}) {
564            if (! defined($raelib)) {
565                require raelib;
566                $raelib = new raelib;
567            }
568            push @tab, $raelib->tab2excel($col_hdrs,$tab,$title,\%options,$options{"excelfile"})}
569    
570      return join("",@tab);      return join("",@tab);
571  }  }
572    
573    sub abstract_coupling_table {
574        my($cgi,$prot,$coupling) = @_;
575        my %fc;
576    
577        my $col_hdrs = ["coupled to","Score","Type of Coupling", "Type-specific Data"];
578        my $tab = [];
579        my %by_peg;
580        foreach my $x (@$coupling)
581        {
582            my($peg2,$psc,$type,$extra) = @$x;
583            if (($type !~ /^[ID]FC$/) || (! $fc{$peg2}))
584            {
585                if ($type =~  /^[ID]FC$/)
586                {
587                    $fc{$peg2} = 1;
588                }
589    
590                $by_peg{$peg2} += $psc;
591            }
592        }
593    
594        foreach my $x (sort { ($by_peg{$b->[0]} <=> $by_peg{$a->[0]})
595                              or ($a->[0] cmp $b->[0])
596                              or ($b->[1] <=> $a->[1])
597                              or ($a->[2] cmp $b->[2]) } @$coupling)
598        {
599            my($peg2,$psc,$type,$extra) = @$x;
600            push(@$tab,[&fid_link($cgi,$peg2,1),$psc,$type,&set_prot_links($cgi,join(", ",@$extra))]);
601        }
602    
603    
604         my $help = "<a href=\"Html/abstract_coupling.html\" target=\"SEED_or_SPROUT_help\">for help</a>";
605    #    my @html = &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot");
606    #    push(@html,"<hr>\n",$cgi->h3($help),"<br>");
607    #    return @html;
608    
609        return &make_table($col_hdrs,$tab,"Abstract Coupling Data for $prot [$help]");
610    }
611    
612  sub expand {  sub expand {
613      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
614      my( $x, $tag ) = @_;      my( $x, $tag ) = @_;
# Line 440  Line 621 
621      # 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
622      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
623    
624      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.
625        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
626    
627      if ( $x =~ /^\@([^:]+)\:(.*)$/ )      if ( $x =~ /^\@([^:]+)\:(.*)$/ )
628      {      {
# Line 452  Line 634 
634      }      }
635  }  }
636    
637    
638    =head2 merge_table_rows()
639    
640    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
641    
642    Something like this:
643    
644        -----------------------
645        |    1     |    a     |
646        -----------------------
647        |    1     |    b     |
648        -----------------------
649        |    2     |    c     |
650        -----------------------
651        |    3     |    d     |
652        -----------------------
653        |    4     |    d     |
654        -----------------------
655        |    5     |    d     |
656        -----------------------
657    
658    Will become:
659    
660        -----------------------
661        |          |    a     |
662        |    1     |-----------
663        |          |    b     |
664        -----------------------
665        |    2     |    c     |
666        -----------------------
667        |    3     |          |
668        ------------          |
669        |    4     |    5     |
670        ------------          |
671        |    5     |          |
672        -----------------------
673    
674    
675    The method takes two arguments. The reference to the array that is the table ($tab). This is the standard table that is created for HTML.pm to draw, and a reference to a hash of columns that you don't want to merge together. The reference to the hash is optional, and if not included, everything will be merged.
676    
677     $tab=&HTML::merge_table_rows($tab);
678    
679     or
680    
681     $skip=(1=>1, 3=>1, 5=>1);
682     $tab=&HTML::merge_table_rows($tab, $skip);  # will merge all columns except 1, 3 and 5. Note the first column in the table is #0
683    
684    
685    =cut
686    
687    
688    
689    
690    sub merge_table_rows {
691     # RAE:
692     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
693     # this block should merge adjacent rows that have the same text in them.
694     # use like this:
695     #      $tab=&HTML::merge_table_rows($tab);
696     # before you do a make_table call
697    
698     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
699     my ($tab, $skip)=@_;
700    
701     my $newtable;
702     my $lastrow;
703     my $rowspan;
704     my $refs;
705    
706     for (my $y=0; $y <= $#$tab; $y++) {
707     #$y is the row in the table;
708      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
709       # this is the user definable columns not to merge
710       if ($skip->{$x})
711       {
712        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
713        next;
714       }
715    
716       #$x is the column in the table
717       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
718       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
719    
720       # handle cells that are references to arrays
721       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
722    
723       # now we go back through the table looking where to draw the merge line:
724       my $lasty=$y;
725       while ($lasty >= 0 && $tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
726       $lasty++; # this is the last identical cell. If lasty==y it is the current cell, so we just save the data. Otherwise we increment the rowspan
727       if ($lasty == $y) {
728        # we always want to have something in rows that may otherwise be empty but should be there (see below)
729        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
730        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
731       }
732       else {$rowspan->[$lasty]->[$x]++}
733      }
734     }
735    
736     # now just join everything back together
737     for (my $y=0; $y <= $#$tab; $y++) {
738      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
739       if ($rowspan->[$y]->[$x]) {
740        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
741        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
742        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
743       }
744       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
745        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
746       }
747      }
748     }
749    
750    
751     # finally we have to remove any completely empty cells that have been added by the array mechanism
752     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
753     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
754     # I am sure that Gary can do this in one line, but I am hacking.
755     my @trimmed;
756     foreach my $a (@$newtable) {
757      my @row;
758      foreach my $b (@$a) {
759       push @row, $b if ($b);
760      }
761      push @trimmed, \@row;
762     }
763    
764     return \@trimmed;
765    }
766    
767    
768    
769    
770  sub set_ec_links {  sub set_ec_links {
771      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
772      my($cgi,$x) = @_;      my($cgi,$x) = @_;
# Line 493  Line 808 
808      return "<a href=$link>$role</a>";      return "<a href=$link>$role</a>";
809  }  }
810    
811  #  =head2 fid_link
812  # Local means to eliminate the fig|org.peg from the  
813  # text of the link.  Get a link to a fid.
814  #  
815    use: my $html=&HTML::fid_link($cgi, $fid, Local, Just_URL, Full_Path);
816    
817    Local is a boolean means to eliminate the fig|org.peg from the text of the link.
818    
819    Just_URL will only return the URL and not the HTML code. The default is to return the full code.
820    
821    Full_Path is a boolean that will get the full path to the URL not just a relative path. This is required in pages where the base href changes (e.g. if an image is imported like on the metabolic pages).
822    
823    =cut
824    
825    
826  sub fid_link {  sub fid_link {
827      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
828      my($cgi,$fid,$local,$just_url) = @_;      my($cgi,$fid,$local,$just_url,$fullpath) = @_;
829    
830        my $err=join(" ", $cgi,$fid,$local,$just_url,$fullpath);
831        print STDERR "Creating link : $err\n";
832    
833      my($n);      my($n);
834    
835        my $top = top_link();
836        if ($fullpath) {$top=$FIG_Config::cgi_url}
837    
838        print STDERR "Top is $top because full path is $fullpath\n";
839    
840      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)      if ($fid =~ /^fig\|\d+\.\d+\.([a-z]+)\.(\d+)/)
841      {      {
842          if ($local)          if ($local)
# Line 519  Line 854 
854          {          {
855              $n = $fid;              $n = $fid;
856          }          }
857          if ($1 ne "peg") { return $n }  
858            my $link;
859            my $new_framework = $cgi->param('new_framework') ? 1 : 0;
860            #added to format prophage and path island links to feature.cgi
861            my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
862            if ($1 ne "peg" && ! $sprout)
863            {
864               my $user = $cgi->param('user');
865               if (! $user) { $user = "" }
866               $link = "$top/feature.cgi?feature=$fid&user=$user$sprout";
867               $link =~ s/[a-z_A-Z0-9]+\.cgi\?/feature.cgi?/;
868            }
869            else
870            {
871          my $user = $cgi->param('user');          my $user = $cgi->param('user');
872          if (! $user) { $user = "" }          if (! $user) { $user = "" }
873          my $trans = $cgi->param('translate') ? "&translate=1" : "";          my $trans = $cgi->param('translate') ? "&translate=1" : "";
874          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";          my $sprout = $cgi->param('SPROUT') ? "&SPROUT=1" : "";
875          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,;  
876    
877    ### This used to be
878    ###     my $link = &FIG::cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
879    ###
880    ### The cost became prohibitive in the subsystem spreadsheets.  Hence, we cache the value
881    ###
882    ### RAO
883    
884                #if (! $cgi_url) { $cgi_url = &FIG::cgi_url }
885                #$link = $cgi_url . "/protein.cgi?prot=$fid&user=$user$trans$sprout";
886                $link = "$top/protein.cgi?prot=$fid&user=$user$trans$sprout\&new_framework=$new_framework";
887                $link =~ s/[a-z_A-Z0-9]+\.cgi\?/protein.cgi?/;
888            }
889          if ($just_url)          if ($just_url)
890          {          {
891              return $link;              return $link;
892          }          }
893          else          else
894          {          {
895              return "<a href=$link>$n</a>";              return "<a href='$link'>$n</a>";
896          }          }
897      }      }
898      return $fid;      return $fid;
# Line 569  Line 924 
924          my $response = $ua->request($request);          my $response = $ua->request($request);
925          $out = $response->content;          $out = $response->content;
926      }      }
927      else  
928        if ($type =~/get/i)
929      {      {
930          @args = ();          @args = ();
931          foreach $x (@$kv_pairs)          foreach $x (@$kv_pairs)
# Line 581  Line 937 
937          {          {
938              $url .= "?" . join("&",@args);              $url .= "?" . join("&",@args);
939          }          }
940          $request = new HTTP::Request('GET', $url);          my $request = new HTTP::Request('GET', $url);
941          my $response = $ua->request($request);          my $response = $ua->request($request);
942    
943          if ($response->is_success)          if ($response->is_success)
# Line 599  Line 955 
955    
956  #   Now splice in a line of the form <base href=URL> to cause all relative links to work  #   Now splice in a line of the form <base href=URL> to cause all relative links to work
957  #   properly.  Remove the header.  #   properly.  Remove the header.
958        my $i;
959      for ($i=0; ($i < @output) && ($output[$i] !~ /^\s*\</); $i++) {}      for ($i=0; ($i < @output) && ($output[$i] !~ /^\s*\</); $i++) {}
960      if ($i < @output)      if ($i < @output) {
     {  
   
961          splice(@output,0,$i);          splice(@output,0,$i);
962      }      }
963    
# Line 619  Line 973 
973  sub trim_output {  sub trim_output {
974      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
975      my($out) = @_;      my($out) = @_;
976      my $i;      my ($i, $j);
977    
978      for ($i=0; ($i < @$out) && ($out->[$i] !~ /^\</); $i++) {}      for ($i=0; ($i < @$out) && ($out->[$i] !~ /^\</); $i++) {}
979      splice(@$out,0,$i);      splice(@$out,0,$i);
# Line 648  Line 1002 
1002      for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}      for ($j=$i-1; ($j > 0) && ($out->[$j] !~ /FIG search/); $j--) {}
1003      if ($j > 0)      if ($j > 0)
1004      {      {
1005            #
1006            # Hm. We would have tried using the options here:
1007            # my $tail_name = $options{tail_name} ? $options{tail_name} : "html.tail";
1008            # but they're not passed in. So use the default html.tail.
1009            #
1010            my $html_tail_file = "./Html/html.tail";
1011          my @tmp = `cat $html_tail_file`;          my @tmp = `cat $html_tail_file`;
1012          my $n = @tmp;          my $n = @tmp;
1013          splice(@$out,$j-$n,$n+1);          splice(@$out,$j-$n,$n+1);
# Line 666  Line 1026 
1026          $after = $3;          $after = $3;
1027          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);
1028      }      }
1029      elsif ($x =~ /^(.*)\b([NXYZA]P_[0-9\.]+)\b(.*)/s)      elsif ($x =~ /^(.*)\b([NXYZA][PM]_[0-9\.]+)\b(.*)/s)
1030      {      {
1031          $before = $1;          $before = $1;
1032          $match = $2;          $match = $2;
# Line 680  Line 1040 
1040          $after = $3;          $after = $3;
1041          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);
1042      }      }
1043        elsif ($x =~ /^(.*)(tigr\|\w+)(.*)/s)
1044        {
1045            $before = $1;
1046            $match = $2;
1047            $after = $3;
1048            return &set_prot_links($cgi,$before) . &HTML::tigr_link($cgi,$match) . &set_prot_links($cgi,$after);
1049        }
1050        elsif ($x =~ /^(.*)\b(eric\|\S+)\b(.*)/s)
1051        {
1052            $before = $1;
1053            $match = $2;
1054            $after = $3;
1055            return &set_prot_links($cgi,$before) . &HTML::eric_link($cgi,$match) . &set_prot_links($cgi,$after);
1056        }
1057    
1058        elsif ($x =~ /^(.*)\b(bhb\|.*?)\b(.*)/s)
1059        {
1060            $before = $1;
1061            $match = $2;
1062            $after = $3;
1063            return &set_prot_links($cgi,$before) . &HTML::bhb_link($cgi,$match) . &set_prot_links($cgi,$after);
1064        }
1065    
1066        elsif ($x =~ /^(.*)\b(apidb\|[0-9\.a-z_]+)\b(.*)/s)
1067        {
1068            $before = $1;
1069            $match = $2;
1070            $after = $3;
1071            return &set_prot_links($cgi,$before) . &HTML::apidb_link($cgi,$match) . &set_prot_links($cgi,$after);
1072        }
1073    
1074        elsif ($x =~ /^(.*)\b(patric\|.*?)\b(.*)/s)
1075        {
1076            $before = $1;
1077            $match = $2;
1078            $after = $3;
1079            return &set_prot_links($cgi,$before) . &HTML::patric_link($cgi,$match) . &set_prot_links($cgi,$after);
1080        }
1081    
1082        elsif ($x =~ /^(.*)\b(vbrc\|.*?)\b(.*)/s)
1083        {
1084            $before = $1;
1085            $match = $2;
1086            $after = $3;
1087            return &set_prot_links($cgi,$before) . &HTML::vbrc_link($cgi,$match) . &set_prot_links($cgi,$after);
1088        }
1089    
1090        elsif ($x =~ /^(.*)\b(vectorbase\|.*?)\b(.*)/s)
1091        {
1092            $before = $1;
1093            $match = $2;
1094            $after = $3;
1095            return &set_prot_links($cgi,$before) . &HTML::vectorbase_link($cgi,$match) . &set_prot_links($cgi,$after);
1096        }
1097      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)      elsif ($x =~  /^(.*)(uni\|[A-Z0-9]{6})(.*)/s)
1098      {      {
1099          $before = $1;          $before = $1;
# Line 708  Line 1122 
1122          $after = $3;          $after = $3;
1123          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);
1124      }      }
1125        elsif ($x =~ /^(.*)(Ensembl[a-zA-Z]+:[a-zA-Z_0-9\.]+)(.*)/s)
1126        {
1127            $before = $1;
1128            $match = $2;
1129            $after = $3;
1130            return &set_prot_links($cgi,$before) . &HTML::ensembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1131        }
1132        elsif ($x =~ /^(.*)(EntrezGene:[a-zA-Z_0-9\.]+)(.*)/s)
1133        {
1134            $before = $1;
1135            $match = $2;
1136            $after = $3;
1137            return &set_prot_links($cgi,$before) . &HTML::entrezgene_link($cgi,$match) . &set_prot_links($cgi,$after);
1138        }
1139        elsif ($x =~ /^(.*)(MIM:[a-zA-Z_0-9\.]+)(.*)/s)
1140        {
1141            $before = $1;
1142            $match = $2;
1143            $after = $3;
1144            return &set_prot_links($cgi,$before) . &HTML::mim_link($cgi,$match) . &set_prot_links($cgi,$after);
1145        }
1146        elsif ($x =~ /^(.*)(HGNC:[a-zA-Z_0-9\.]+)(.*)/s)
1147        {
1148            $before = $1;
1149            $match = $2;
1150            $after = $3;
1151            return &set_prot_links($cgi,$before) . &HTML::hgnc_link($cgi,$match) . &set_prot_links($cgi,$after);
1152        }
1153        elsif ($x =~ /^(.*)(UniGene:[a-zA-Z_0-9\.]+)(.*)/s)
1154        {
1155            $before = $1;
1156            $match = $2;
1157            $after = $3;
1158            return &set_prot_links($cgi,$before) . &HTML::unigene_link($cgi,$match) . &set_prot_links($cgi,$after);
1159        }
1160    # IPI stopped working. turn off for now.
1161    #    elsif ($x =~ /^(.*)(IPI:[a-zA-Z_0-9\.]+)(.*)/s)
1162    #    {
1163    #        $before = $1;
1164    #        $match = $2;
1165    #        $after = $3;
1166    #        return &set_prot_links($cgi,$before) . &HTML::ipi_link($cgi,$match) . &set_prot_links($cgi,$after);
1167    #    }
1168        elsif ($x =~ /^(.*)(WP:[a-zA-Z_0-9\.]+)(.*)/s)
1169        {
1170            #wormbase
1171    
1172            $before = $1;
1173            $match = $2;
1174            $after = $3;
1175            return &set_prot_links($cgi,$before) . &HTML::wp_link($cgi,$match) . &set_prot_links($cgi,$after);
1176        }
1177        elsif ($x =~ /^(.*)(FB:[a-zA-Z_0-9\.]+)(.*)/s)
1178        {
1179            #flybase
1180    
1181            $before = $1;
1182            $match = $2;
1183            $after = $3;
1184            return &set_prot_links($cgi,$before) . &HTML::fb_link($cgi,$match) . &set_prot_links($cgi,$after);
1185        }
1186        elsif ($x =~ /^(.*)(FlyBaseORFNames:[a-zA-Z_0-9\.]+)(.*)/s)
1187        {
1188            #flybase
1189    
1190            $before = $1;
1191            $match = $2;
1192            $after = $3;
1193            return &set_prot_links($cgi,$before) . &HTML::fborf_link($cgi,$match) . &set_prot_links($cgi,$after);
1194        }
1195        elsif ($x =~ /^(.*)(SGD_LOCUS:[a-zA-Z_0-9\.]+)(.*)/s)
1196        {
1197            #flybase
1198    
1199            $before = $1;
1200            $match = $2;
1201            $after = $3;
1202            return &set_prot_links($cgi,$before) . &HTML::sgd_link($cgi,$match) . &set_prot_links($cgi,$after);
1203        }
1204        elsif ($x =~ /^(.*)(tr\|[a-zA-Z0-9]+)(.*)/s)
1205        {
1206    
1207          $before = $1;
1208          $match = $2;
1209          $after = $3;
1210    
1211          return &set_prot_links($cgi,$before) .  &HTML::trembl_link($cgi,$match) . &set_prot_links($cgi,$after);
1212        }
1213      return $x;      return $x;
1214  }  }
1215    
1216    sub trembl_link {
1217        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1218        my($cgi,$id) = @_;
1219    
1220        if ($id =~ /^tr\|(.*)/) {
1221          return "<a href='http://ca.expasy.org/uniprot/$1' target=_blank>$id</a>";
1222        } else {
1223          return "invalid call to trembl link";
1224        }
1225    }
1226    
1227  sub refseq_link {  sub refseq_link {
1228      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1229      my($cgi,$id) = @_;      my($cgi,$id) = @_;
1230    
1231      if ($id =~ /^[NXYZA]P_/)      if ($id =~ /^[NXYZA]P_/)
1232      {      {
1233          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' target=_blank>$id</a>";
1234        }
1235        elsif ($id =~ /^[NXYZA]M_/)
1236        {
1237            return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nuccore&cmd=search&term=$id' target=_blank>$id</a>";
1238      }      }
1239  }  }
1240    
# Line 727  Line 1244 
1244    
1245      if ($gi =~ /^gi\|(\d+)$/)      if ($gi =~ /^gi\|(\d+)$/)
1246      {      {
1247          return "<a href=http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=Protein&list_uids=$1&dopt=GenPept>$gi</a>";          return "<a href='http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=Protein&list_uids=$1&dopt=GenPept' target=_blank>$gi</a>";
1248      }      }
1249      return $gi;      return $gi;
1250  }  }
1251    
1252    sub tigr_link {
1253        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1254        my($cgi,$tigr) = @_;
1255    
1256        if ($tigr =~ /^tigr\|(NT|ntbp|ntbpA|BA|BMAA|BXB|GBA)(\w+)$/)
1257        {
1258            my $id=$1.$2;
1259            return "<a href=\"http://pathema.tigr.org/tigr-scripts/pathema/shared/GenePage.cgi?locus=$id\" target=_blank>$tigr</a> (Pathema)";
1260        }
1261        elsif ($tigr =~ /^tigr\|(\S+)$/)
1262        {
1263            return "<a href=\"http://www.tigr.org/tigr-scripts/CMR2/GenePage.spl?locus=$1\" target=_blank>$tigr</a>";
1264        }
1265        return $tigr;
1266    }
1267    
1268    sub eric_link {
1269        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1270        my($cgi,$eric) = @_;
1271    
1272        if ($eric =~ /^eric\|(\S+)/)
1273        {
1274            return "<a href=\"https://asap.ahabs.wisc.edu/asap/feature_info.php?FeatureID=$1\" target=_blank>$eric</a>";
1275        }
1276        return $eric;
1277    }
1278    
1279    sub bhb_link {
1280        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1281        my($cgi,$bhb) = @_;
1282    
1283        return "<a href=\"http://www.biohealthbase.org\" target=_blank>$bhb</a>";
1284    }
1285    
1286    sub apidb_link {
1287        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1288        my($cgi,$api) = @_;
1289    
1290        if ($api =~ /apidb\|(.*?)\.(.*)$/)
1291        {
1292            return "<a href=\"http://www.apidb.org/cgi-bin/redirect.cgi?taxon_id=$1&source_id=$2\" target=_blank>$api</a>";
1293        }
1294        return $api;
1295    }
1296    
1297    sub patric_link {
1298        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1299        my($cgi,$patric) = @_;
1300    
1301        if ($patric =~ /patric\|(.*)/)
1302        {
1303            return "<a href=\"https://patric.vbi.vt.edu/software/curationTool/gep/pgiCuration.php?locus_name=$1\" target=_blank>$patric</a>";
1304        }
1305        return $patric;
1306    }
1307    
1308    sub vbrc_link {
1309        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1310        my($cgi,$vbrc) = @_;
1311    
1312        if ($vbrc =~ /vbrc\|(.*)/)
1313        {
1314            return "<a href=\"http://www.biovirus.org/gene_detail.asp?name=$1\" target=_blank>$vbrc</a>";
1315        }
1316        return $vbrc;
1317    }
1318    
1319    sub vectorbase_link {
1320        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1321        my($cgi,$vec) = @_;
1322        return "<a href=\"http://www.vectorbase.org\" target=_blank>$vec</a>";
1323    }
1324    
1325    
1326  sub uni_link {  sub uni_link {
1327      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1328      my($cgi,$uni) = @_;      my($cgi,$uni) = @_;
1329    
1330      if ($uni =~ /^uni\|(\S+)$/)      if ($uni =~ /^uni\|(\S+)$/)
1331      {      {
1332          return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";          #return "<a href=http://www.pir.uniprot.org/cgi-bin/upEntry?id=$1>$uni</a>";
1333            return "<a href='http://www.ebi.uniprot.org/uniprot-srv/uniProtView.do?proteinAc=$1' target=_blank>$uni</a>";
1334      }      }
1335      return $uni;      return $uni;
1336  }  }
# Line 749  Line 1341 
1341    
1342      if ($sp =~ /^sp\|(\S+)$/)      if ($sp =~ /^sp\|(\S+)$/)
1343      {      {
1344          return "<a href=http://us.expasy.org/cgi-bin/get-sprot-entry?$1>$sp</a>";          return "<a href='http://us.expasy.org/cgi-bin/get-sprot-entry?$1' target=_blank>$sp</a>";
1345      }      }
1346      return $sp;      return $sp;
1347  }  }
# Line 760  Line 1352 
1352    
1353      if ($pir =~ /^pirnr\|(NF\d+)$/)      if ($pir =~ /^pirnr\|(NF\d+)$/)
1354      {      {
1355          return "<a href=http://pir.georgetown.edu/cgi-bin/nfEntry.pl?id=$1>$pir</a>";          return "<a href='http://pir.georgetown.edu/cgi-bin/nfEntry.pl?id=$1' target=_blank>$pir</a>";
1356      }      }
1357      return $pir;      return $pir;
1358  }  }
# Line 771  Line 1363 
1363    
1364      if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)      if ($kegg =~ /^kegg\|([^:]+):(\S+)$/)
1365      {      {
1366          return "<a href=http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2>$kegg</a>";          return "<a href='http://www.genome.ad.jp/dbget-bin/www_bget?$1+$2' target=_blank>$kegg</a>";
1367      }      }
1368      return $kegg;      return $kegg;
1369  }  }
1370    
1371  sub set_map_links {  sub ensembl_link {
1372      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1373      my($cgi,$x) = @_;      my($cgi,$ensembl) = @_;
     my($before,$match,$after);  
1374    
1375      my $org = ($cgi->param('org') || $cgi->param('genome') || "");      if ($ensembl =~ /^(\S+):(\S+)$/)
1376        {
1377            my $what=$1;
1378            my $key=$2;
1379            my $idx="All";
1380            if ($what eq "EnsemblGene") { $idx = "Gene" }
1381            if ($what eq "EnsemblTranscript") { $idx = "All" }
1382            if ($what eq "EnsemblProtein") { $idx = "All" }
1383    
1384      if ($x =~ /^(.*)(MAP\d+)(.*)/s)          #I really want to get right to the transcript and peptide pages, but
1385            #can't see how to do that without knowing the org name too, which
1386            #I don't know at this point. (ensembl org name, not real org name)
1387    
1388            return "<a href='http://www.ensembl.org/Homo_sapiens/searchview?species=all&idx=$idx&q=$key' target=_blank>$ensembl</a>";
1389        }
1390        return $ensembl;
1391    }
1392    
1393    sub entrezgene_link {
1394        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1395        my($cgi,$entrezgene) = @_;
1396    
1397        if ($entrezgene =~ /^EntrezGene:(\S+)$/)
1398      {      {
1399          $before = $1;          return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=full_report&list_uids=$1' target=_blank>$entrezgene</a>";
         $match = $2;  
         $after = $3;  
         return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);  
1400      }      }
1401      return $x;      return $entrezgene;
1402  }  }
1403    
1404  sub map_link {  sub mim_link {
1405      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1406      my($cgi,$map,$org) = @_;      my($cgi,$mim) = @_;
1407    
1408      $user = $cgi->param('user');      if ($mim =~ /^MIM:(\S+)$/)
1409      $user = $user ? $user : "";      {
1410      $org = $org ? $org : "";          return "<a href='http://www3.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=$1' target=_blank>$mim</a>";
1411      my $url = "$FIG_Config::cgi_url/show_kegg_map.cgi?user=$user&map=$map&org=$org";      }
1412      my $link = "<a href=\"$url\">$map</a>";      return $mim;
     return $link;  
1413  }  }
1414    
1415  sub javascript {  sub hgnc_link {
1416      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1417          #### MODIFIED BY RAE TO ADD JAVA SUPPORT FOR CHECK ALL/UNCHECK ALL      my($cgi,$hgnc) = @_;
         # 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.  
1418    
1419          # Note that the other change is I added a -name=>'fig_checked' to the start_form      if ($hgnc =~ /^HGNC:(\S+)$/)
1420          # field. The name is needed for the java script.      {
1421          #          return "<a href='http://www.gene.ucl.ac.uk/cgi-bin/nomenclature/searchgenes.pl?field=symbol&anchor=equals&match=$1&symbol_search=Search&number=50&format=html&sortby=symbol' target=_blank>$hgnc</a>";
1422        }
1423    
1424        return $hgnc;
1425    }
1426    
1427            $java_script=<<EOF;  sub unigene_link {
1428    <SCRIPT LANGUAGE="JavaScript">      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1429    <!-- Begin      my($cgi,$unigene) = @_;
1430    function checkAll(field)  
1431        if ($unigene =~ /^UniGene:(\S+)$/)
1432    {    {
1433     for (i = 0; i < field.length; i++)          return "<a href='http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=unigene&cmd=search&term=$1' target=_blank>$unigene</a>";
1434     field[i].checked = true ;      }
1435        return $unigene;
1436    }    }
1437    
1438    function checkFirst(field)  sub ipi_link {
1439        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1440        my($cgi,$ipi) = @_;
1441    
1442        if ($ipi =~ /^IPI:(\S+)$/)
1443    {    {
1444     for (i = 0; i < field.length/2; i++)          return "<a href='http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-id+AEoS1R8Jnn+-e+[IPI:\'$1\']+-qnum+1+-enum+1' target=_blank>$ipi</a>";
1445     field[i].checked = true;      }
1446        return $ipi;
1447    }    }
1448    
1449    function checkSecond(field)  sub wp_link {
1450        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1451        my($cgi,$wp) = @_;
1452    
1453        #wormbase
1454    
1455        if ($wp =~ /^WP:(\S+)$/)
1456    {    {
1457     for (i=Math.round(field.length/2); i < field.length; i++)          return "<a href='http://www.wormbase.org/db/searches/basic?class=Any&query=$1&Search=Search' target=_blank>$wp</a>";
1458     field[i].checked = true ;      }
1459        return $wp;
1460    }    }
1461    
1462    function uncheckAll(field)  sub fb_link {
1463        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1464        my($cgi,$fb) = @_;
1465    
1466        #flybase
1467    
1468        if ($fb =~ /^FB:(\S+)$/)
1469    {    {
1470     for (i = 0; i < field.length; i++)          return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
    field[i].checked = false ;  
1471    }    }
1472    //  End -->      return $fb;
1473    </script>  }
1474  EOF  
1475          return $java_script;  sub fborf_link {
1476        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1477        my($cgi,$fb) = @_;
1478    
1479        #flybase
1480    
1481        if ($fb =~ /^FlyBaseORFNames:(\S+)$/)
1482        {
1483            return "<a href='http://flybase.bio.indiana.edu/.bin/fbidq.html?$1' target=_blank>$fb</a>";
1484        }
1485        return $fb;
1486    }
1487    
1488    sub sgd_link {
1489        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1490        my($cgi,$sgd) = @_;
1491    
1492        #yeast
1493    
1494        if ($sgd =~ /^SGD_LOCUS:(\S+)$/)
1495        {
1496            return "<a href='http://db.yeastgenome.org/cgi-bin/locus.pl?locus=$1' target=_blank>$sgd</a>";
1497        }
1498        return $sgd;
1499    }
1500    
1501    
1502    
1503    
1504    sub set_map_links {
1505        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1506        my($cgi,$x) = @_;
1507        my($before,$match,$after);
1508    
1509        my $org = ($cgi->param('org') || $cgi->param('genome') || "");
1510    
1511        if ($x =~ /^(.*)(MAP\d+)(.*)/s)
1512        {
1513            $before = $1;
1514            $match = $2;
1515            $after = $3;
1516            return &set_map_links($cgi,$before) . &map_link($cgi,$match,$org) . &set_map_links($cgi,$after);
1517        }
1518        return $x;
1519    }
1520    
1521    
1522    
1523    sub map_link {
1524        shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1525        my($cgi,$map,$org) = @_;
1526    
1527        my $user = $cgi->param('user');
1528        $user = $user ? $user : "";
1529        $org = $org ? $org : "";
1530    
1531        my $url = "show_kegg_map.cgi?user=$user&map=$map&org=$org";
1532    #rel    my $url = &FIG::cgi_url() . "/show_kegg_map.cgi?user=$user&map=$map&org=$org";
1533        my $link = "<a href=\"$url\">$map</a>";
1534        return $link;
1535  }  }
1536    
1537  sub java_buttons {  sub java_buttons {
# Line 864  Line 1542 
1542    # -name => field and the checkbox name    # -name => field and the checkbox name
1543    my ($form, $button)=@_;    my ($form, $button)=@_;
1544    
1545    $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";    my $java_script="<input type=\"button\" name=\"CheckAll\" value=\"Check All\"\nonClick=\"checkAll(document.$form.$button)\">\n";
1546    $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";    $java_script.="<input type=\"button\" name=\"CheckFirst\" value=\"Check First Half\"\nonClick=\"checkFirst(document.$form.$button)\">\n";
1547    $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";    $java_script.="<input type=\"button\" name=\"CheckSecond\" value=\"Check Second Half\"\nonClick=\"checkSecond(document.$form.$button)\">\n";
1548    $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";    $java_script.="<input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\"\nonClick=\"uncheckAll(document.$form.$button)\">\n";
# Line 878  Line 1556 
1556      my($sub_link);      my($sub_link);
1557    
1558      my $user = $cgi->param('user');      my $user = $cgi->param('user');
1559        my $esc_sub = uri_escape( $sub );
1560        $sub =~ s/\_/ /g;
1561      if ($user)      if ($user)
1562      {      {
         my $esc_sub = uri_escape( $sub );  
1563          $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";          $sub_link = "<a href=./subsys.cgi?ssa_name=$esc_sub&request=show_ssa&user=$user>$sub</a>";
1564      }      }
1565      else      else
1566      {      {
1567          $sub_link = $sub;          $sub_link = "<a href=\"display_subsys.cgi?ssa_name=$esc_sub&request=show_ssa&sort=by_phylo\">$sub</a>";
1568      }      }
1569      return $sub_link;      return $sub_link;
1570  }  }
1571    
1572  1  sub reaction_link {
1573        my($reaction) = @_;
1574        if ($reaction =~ /^(\*)?(R\d+)/)
1575        {
1576            return "<a href=\"http://www.genome.ad.jp/dbget-bin/www_bget?rn+$2\" target=reaction$$>$reaction</a>";
1577        }
1578        return $reaction;
1579    }
1580    
1581    
1582    sub html_for_assignments {
1583        my($fig,$user,$peg_sets) = @_;
1584        my $i;
1585    
1586        my @vals = ();
1587        my $set = 1;
1588        foreach my $peg_set (@$peg_sets)
1589        {
1590            for ($i=0; ($i < @$peg_set); $i++)
1591            {
1592                my $peg = $peg_set->[$i];
1593                push(@vals,'show=' . join("@",($set,$i+1,$peg,&FIG::abbrev($fig->org_of($peg)),"")));
1594            }
1595            $set++;
1596        }
1597    
1598        $ENV{'REQUEST_METHOD'} = 'GET';
1599        $ENV{'QUERY_STRING'} = join('&',('request=show_commentary',"uni=1","user=$user",@vals));
1600        my $out = join("",`$FIG_Config::fig/CGI/chromosomal_clusters.cgi`);
1601        $out =~ s/^.*?<form/<form/si;
1602        $out =~ s/^(.*)<table.*/$1/si;
1603        return $out;
1604    }
1605    
1606    =head1 rss_feed
1607    
1608    Add something to the RSS feed. The rss feeds are stored in the Html directory, and there are several RSS feeds:
1609            SEED.rss                - everything gets written here
1610            SEEDgenomes.rss                 - whenever a genome is added to the SEED
1611            SEEDsubsystems.rss      - whenever a subsystem is edited (or should this be added?)
1612    
1613    
1614    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.
1615    
1616    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.
1617    
1618    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.
1619    
1620    The has can have these keys:
1621    
1622    REQUIRED:
1623    title       : the title. This is usually what is seen by the user in the pull down menu
1624    description : a more complete description that is often seen is rss viewers but not always
1625    link        : link to the item that was added/edited
1626    All other keys are treated as optional RSS arguments and written to the file.
1627    
1628    At most, $max_entries recent entries are stored in the rss file, and this is currently 50.
1629    
1630    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.
1631    
1632    
1633    =cut
1634    
1635    sub rss_feed {
1636     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
1637     my ($files, $args)=@_;
1638    
1639     # how many entries to store in the file
1640     my $max_entries=50;
1641    
1642     foreach my $a (keys %$args) {if ($a =~ /^-(.*)/) {my $b=$1; $args->{$b}=$args->{$a}; delete $args->{$a}}}
1643    
1644     my $filepath=$FIG_Config::fig."/CGI/Html/rss";
1645     # check for the directory and if not, make it
1646     mkdir $filepath unless (-d $filepath);
1647    
1648     # note that $info is a hash of references to hashes that are written out as headers in the file
1649     my $info=
1650     {
1651      "SEED.rss" =>
1652       {
1653            title           => "The SEED",
1654            description     => "Latest news from the SEED",
1655            link            => "Html/rss/SEED.rss",
1656       },
1657    
1658      "SEEDsubsystems.rss" =>
1659      {
1660            title           => "SEED Subsystems",
1661            description     => "Recently updated SEED subsystems",
1662            link            => "Html/rss/SEEDsubsystems.rss",
1663      },
1664    
1665      "SEEDsubsystems.rss" =>
1666      {
1667            title           => "SEED Genomes",
1668            description     => "Genomes recently added to the SEED",
1669            link            => &FIG::cgi_url()."/Html/rss/SEEDsubsystems.rss",
1670      },
1671    
1672     };
1673    
1674    
1675     # build the new xml
1676     my $xml = "\t<item>\n";
1677     foreach my $qw ("title", "description", "link") {
1678      unless ($args->{$qw}) {
1679       print STDERR "You need to include a $qw tag in your RSS description\n";
1680       return(0);
1681      }
1682      # we need to do something a bit funky with the link. We can't have ampersands in the <link> </link> in valid html
1683      # so we are going to pull out the links and uri_escape just the part after the .cgi
1684      if ($qw eq "link")
1685      {
1686       $args->{$qw} =~ /^(.*?\.cgi.)(.*)$/;
1687       $args->{$qw} = $1.uri_escape($2) if ($1 && $2);
1688      }
1689    
1690      $xml .= "\t\t<$qw>".$args->{$qw}."</$qw>\n";
1691      delete $args->{$qw};
1692     }
1693    
1694     foreach my $tag (grep {!/type/i} keys %$args)
1695     {
1696      $xml .= "\t\t<$tag>".$args->{$tag}."</$tag>\n";
1697     }
1698    
1699     $xml .= "\t</item>\n";
1700    
1701    
1702     my @files=("SEED.rss");
1703     if ($args->{"type"}) {
1704        my $type = $args->{type};
1705        push @files, "SEED.$type.rss"
1706    }
1707    
1708     foreach my $file ("SEED.rss", @$files)
1709     {
1710      if (-e "$filepath/$file")
1711      {
1712       my @out; # the new content of the file
1713       my $itemcount=0; # how many <item> </item>'s are we keeping
1714       my $initem; # are we in an item?
1715       open(IN, "$filepath/$file") || die "Can't open $filepath/$file";
1716       while (<IN>)
1717       {
1718        if (/\<item\>/) {
1719         push @out, $xml, unless ($itemcount);
1720         $itemcount++;
1721         $initem=1;
1722        }
1723        if (/\<\/item\>/) {$initem=0; next if ($itemcount > $max_entries)}
1724        next if ($initem && $itemcount > $max_entries);
1725        push @out, $_;
1726       }
1727       close IN;
1728       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1729       print OUT @out;
1730      }
1731      else
1732      {
1733       open(OUT, ">$filepath/$file") || die "Can't open $filepath/$file for writing";
1734       print OUT "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n<channel>\n";
1735       if ($info->{$file})
1736       {
1737         # we're going to sanity check each of the three options we output, just to be sure
1738         foreach my $qw ("title", "description", "link")
1739         {
1740           if ($info->{$file}->{$qw})
1741           {
1742              print OUT "<$qw>", $info->{$file}->{$qw}, "</$qw>\n";
1743           } else {
1744              print STDERR "Please add a $qw for $file\n"; print OUT "<$qw>$file</$qw>\n";
1745           }
1746         }
1747       }
1748       else {
1749        print STDERR "Please define title, link, and description information for $file\n";
1750        print OUT "<title>$file</title>\n<description>An RSS feed</description>\n<link>", &FIG::cgi_url, "</link>\n";
1751       }
1752       print OUT "\n", $xml;
1753       print OUT "\n", "</channel>\n</rss>\n"
1754      }
1755     }
1756    }
1757    
1758    
1759    
1760    1;
1761    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3