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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3