[Bio] / FigKernelPackages / HTML.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3