[Bio] / FigWebServices / protein.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.193 - (view) (download)

1 : redwards 1.94 # -*- perl -*-
2 : olson 1.170 #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 : overbeek 1.117 use InterfaceRoutines;
20 :    
21 : efrank 1.1 use FIG;
22 : olson 1.56
23 :     my $sproutAvail = eval {
24 :     require SproutFIG;
25 :     require PageBuilder;
26 :     };
27 :    
28 : olson 1.92 #if (!$sproutAvail) {
29 :     # warn "Sprout library not available: $@\n";
30 :     #}
31 : olson 1.56
32 : heiko 1.45 use FIGGenDB;
33 : olson 1.48 use FIGjs;
34 : efrank 1.1
35 : golsen 1.107 use URI::Escape; # uri_escape
36 : efrank 1.1 use HTML;
37 : olson 1.48 use Data::Dumper;
38 :    
39 : efrank 1.1 use strict;
40 :     use GenoGraphics;
41 :     use CGI;
42 : parrello 1.60 use Tracer;
43 : overbeek 1.184 use BasicLocation;
44 : parrello 1.60
45 : efrank 1.1 my $cgi = new CGI;
46 :    
47 : olson 1.57 use Carp 'cluck';
48 : parrello 1.60 my $traceData = $cgi->param('trace');
49 :     if ($traceData) {
50 : parrello 1.120 TSetup($traceData, "QUEUE");
51 : parrello 1.60 $traceData = 1;
52 :     } else {
53 :     TSetup(0, "NONE");
54 :     $traceData = 0;
55 :     }
56 : olson 1.57
57 : overbeek 1.66 if (0) {
58 : overbeek 1.40 my $VAR1;
59 :     eval(join("",`cat /tmp/protein_parms`));
60 :     $cgi = $VAR1;
61 :     # print STDERR &Dumper($cgi);
62 :     }
63 :    
64 : parrello 1.60 if (0) {
65 : efrank 1.1 print $cgi->header;
66 :     my @params = $cgi->param;
67 :     print "<pre>\n";
68 : parrello 1.60 foreach $_ (@params) {
69 :     print "$_\t:",join(",",$cgi->param($_)),":\n";
70 : efrank 1.1 }
71 : overbeek 1.40
72 : parrello 1.60 if (0) {
73 :     if (open(TMP,">/tmp/protein_parms")) {
74 :     print TMP &Dumper($cgi);
75 :     close(TMP);
76 :     }
77 : overbeek 1.40 }
78 : efrank 1.1 exit;
79 :     }
80 :    
81 : overbeek 1.53 my($fig_or_sprout);
82 : olson 1.83
83 :     my $is_sprout;
84 :    
85 :     my $html = [];
86 :    
87 : parrello 1.60 if ($cgi->param('SPROUT')) {
88 : olson 1.83 $is_sprout = 1;
89 : olson 1.56 $fig_or_sprout = new SproutFIG($FIG_Config::sproutDB, $FIG_Config::sproutData);
90 : olson 1.83 unshift @$html, "<TITLE>The NMPDR Protein Page</TITLE>\n";
91 : parrello 1.60 } else {
92 : olson 1.83 $is_sprout = 0;
93 : overbeek 1.53 $fig_or_sprout = new FIG;
94 : olson 1.83 unshift @$html, "<TITLE>The SEED Protein Page</TITLE>\n";
95 : overbeek 1.53 }
96 :    
97 : efrank 1.1
98 :     my $prot = $cgi->param('prot');
99 : parrello 1.60 if (! $prot) {
100 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Protein Page</TITLE>\n";
101 : efrank 1.1 push(@$html,"<h1>Sorry, you need to specify a protein</h1>\n");
102 : overbeek 1.53 &display_page($fig_or_sprout,$cgi,$html);
103 : efrank 1.1 exit;
104 :     }
105 : golsen 1.34
106 : parrello 1.60 if ($prot !~ /^fig\|/) {
107 : overbeek 1.53 my @poss = &by_alias($fig_or_sprout,$prot);
108 :    
109 : parrello 1.60 if (@poss > 0) {
110 :     $prot = $poss[0];
111 :     } else {
112 :     unshift @$html, "<TITLE>The SEED: Protein Page</TITLE>\n";
113 :     push(@$html,"<h1>Sorry, $prot appears not to have a FIG id at this point</h1>\n");
114 :     &display_page($fig_or_sprout,$cgi,$html);
115 :     exit;
116 : overbeek 1.16 }
117 :     }
118 : efrank 1.1
119 : overbeek 1.53
120 : golsen 1.34 #
121 :     # Allow previous and next actions in calls to the script -- GJO
122 :     #
123 :    
124 :     my $adjust = $cgi->param('previous PEG') ? -1 : $cgi->param('next PEG') ? 1 : 0;
125 :     if ( $adjust ) {
126 :     my ( $prefix, $protnum ) = $prot =~ /^(.*\.)(\d+)$/;
127 :     if ( $prefix && $protnum ) {
128 :     my $prot2 = $prefix . ($protnum + $adjust);
129 : overbeek 1.53 if ( &translatable($fig_or_sprout, $prot2 ) ) {
130 : golsen 1.34 $prot = $prot2;
131 :     $cgi->delete('prot');
132 :     $cgi->param(-name => 'prot', -value => $prot);
133 :     }
134 :     }
135 :     ( $adjust < 0 ) && $cgi->delete('previous PEG');
136 :     ( $adjust > 0 ) && $cgi->delete('next PEG');
137 :     }
138 :    
139 :     my $request = $cgi->param("request") || "";
140 : overbeek 1.63 #my $compute_ok = eval {
141 :    
142 : olson 1.58
143 : overbeek 1.68 if ($request eq "use_protein_tool") { &use_protein_tool($fig_or_sprout,$cgi,$html,$prot); }
144 : parrello 1.60 elsif ($request eq "view_annotations") { &view_annotations($fig_or_sprout,$cgi,$html,$prot); }
145 :     elsif ($request eq "view_all_annotations") { &view_all_annotations($fig_or_sprout,$cgi,$html,$prot); }
146 : overbeek 1.68 elsif ($request eq "aa_sequence") { &aa_sequence($fig_or_sprout,$cgi,$html,$prot); }
147 : parrello 1.60 elsif ($request eq "dna_sequence") { &dna_sequence($fig_or_sprout,$cgi,$html,$prot); }
148 : overbeek 1.173 elsif ($request eq "dna_sequence_adjacent") { &dna_sequence_adjacent($fig_or_sprout,$cgi,$html,$prot); }
149 : parrello 1.60 elsif ($request eq "fast_assign") { $html = &make_assignment($fig_or_sprout,$cgi,$html,$prot); }
150 :     elsif ($request eq "show_coupling_evidence") { &show_coupling_evidence($fig_or_sprout,$cgi,$html,$prot); }
151 : overbeek 1.171 elsif ($request eq "abstract_coupling") { &show_abstract_coupling_evidence($fig_or_sprout,$cgi,$html,$prot); }
152 : parrello 1.60 elsif ($request eq "ec_to_maps") { &show_ec_to_maps($fig_or_sprout,$cgi,$html); }
153 :     elsif ($request eq "link_to_map") { &link_to_map($fig_or_sprout,$cgi,$html); }
154 :     elsif ($request eq "fusions") { &show_fusions($fig_or_sprout,$cgi,$html,$prot); }
155 :     else {
156 :     $html = &show_html_followed_by_initial($fig_or_sprout,$cgi,$html,$prot);
157 :     }
158 : overbeek 1.68
159 :     if ($cgi->param('SPROUT') && (ref($html) eq "ARRAY"))
160 :     {
161 :     $_ = {};
162 :     $_->{kv_pairs} = $html;
163 :     $html = $_;
164 :     }
165 : overbeek 1.63 #};
166 : olson 1.58
167 : overbeek 1.63 #if (!$compute_ok) {
168 :     # Trace($@);
169 :     #}
170 : overbeek 1.68
171 : overbeek 1.53 &display_page($fig_or_sprout,$cgi,$html);
172 : overbeek 1.11 exit;
173 :    
174 :     #==============================================================================
175 :     # use_protein_tool
176 :     #==============================================================================
177 : efrank 1.1
178 :     sub use_protein_tool {
179 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
180 : efrank 1.1 my($url,$method,@args,$line,$name,$val);
181 :    
182 : overbeek 1.53 my $seq = &get_translation($fig_or_sprout,$prot);
183 : parrello 1.60 if (! $seq) {
184 :     unshift @$html, "<TITLE>The SEED: Protein Page</TITLE>\n";
185 :     push(@$html,$cgi->h1("Sorry, $prot does not have a translation"));
186 :     return;
187 : efrank 1.1 }
188 :     my $protQ = quotemeta $prot;
189 :    
190 :     my $tool = $cgi->param('tool');
191 :     $/ = "\n//\n";
192 :     my @tools = grep { $_ =~ /^$tool\n/ } `cat $FIG_Config::global/LinksToTools`;
193 : parrello 1.60 if (@tools == 1) {
194 :     chomp $tools[0];
195 :     (undef,undef,$url,$method,@args) = split(/\n/,$tools[0]);
196 :     my $args = [];
197 :     foreach $line (@args) {
198 :     ($name,$val) = split(/\t/,$line);
199 :     $val =~ s/FIGID/$prot/;
200 :     $val =~ s/FIGSEQ/$seq/;
201 :     $val =~ s/\\n/\n/g;
202 :     push(@$args,[$name,$val]);
203 :     }
204 :     unshift @$html, "<TITLE>The SEED: Protein Tool</TITLE>\n";
205 : overbeek 1.72 #$url='http://localhost/cgi-bin/extract_params.cgi'; in case I forget to delete this, it is just a script that grabs params from cgis RAE
206 : overbeek 1.190
207 :     my @result = &HTML::get_html($url,$method,$args);
208 :    
209 :     #
210 :     # The extra form in the Sprout header causes some problems with javascript-containing
211 :     # pages. So if we're in sprout, and there's javascript in the page, just show the
212 :     # output and exit.
213 :     #
214 :    
215 :     if ($is_sprout)
216 :     {
217 :     for my $rl (@result)
218 :     {
219 :     if ($rl =~ /javascript/i)
220 :     {
221 :     print $cgi->header;
222 :     print join("", @result);
223 :     exit 0;
224 :     }
225 :     }
226 :     }
227 :    
228 :     push(@$html, @result);
229 : efrank 1.1 }
230 :     }
231 :    
232 : overbeek 1.11 #==============================================================================
233 :     # make_assignment
234 :     #==============================================================================
235 :    
236 : efrank 1.1 sub make_assignment {
237 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
238 : efrank 1.1 my($userR);
239 :    
240 :     my $function = $cgi->param('func');
241 :     my $user = $cgi->param('user');
242 :    
243 : parrello 1.60 if ($function && $user && $prot) {
244 :     if ($user =~ /master:(.*)/) {
245 :     $userR = $1;
246 :     &assign_function($fig_or_sprout,$prot,"master",$function,"");
247 : overbeek 1.68 &add_annotation($fig_or_sprout,$cgi,$prot,$userR,"Set master function to\n$function\n");
248 : parrello 1.60 } else {
249 : overbeek 1.68 &assign_function($fig_or_sprout,$prot,$user,$function,"");
250 :     &add_annotation($fig_or_sprout,$cgi,$prot,$user,"Set function to\n$function\n");
251 :     }
252 : efrank 1.1 }
253 :     $cgi->delete("request");
254 :     $cgi->delete("func");
255 : overbeek 1.53 $html = &show_html_followed_by_initial($fig_or_sprout,$cgi,$html,$prot);
256 :     return $html;
257 : efrank 1.1 }
258 :    
259 : overbeek 1.11 #==============================================================================
260 :     # view_annotations
261 :     #==============================================================================
262 :    
263 : efrank 1.1 sub view_annotations {
264 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
265 : efrank 1.1
266 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Protein Annotations</TITLE>\n";
267 : efrank 1.1 my $col_hdrs = ["who","when","annotation"];
268 : overbeek 1.69
269 : overbeek 1.68 my $tab = [ map { [$_->[2],$_->[1],"<pre>" . $_->[3] . "<\/pre>"] } &feature_annotations($fig_or_sprout,$cgi,$prot) ];
270 : parrello 1.60 if (@$tab > 0) {
271 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Annotations for $prot"));
272 :     } else {
273 :     push(@$html,"<h1>No Annotations for $prot</h1>\n");
274 : efrank 1.1 }
275 :     }
276 :    
277 : overbeek 1.15 sub view_all_annotations {
278 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
279 : overbeek 1.15 my($ann);
280 :    
281 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Protein Annotations</TITLE>\n";
282 : parrello 1.60 if (&is_real_feature($fig_or_sprout,$peg)) {
283 :     my $col_hdrs = ["who","when","PEG","genome","annotation"];
284 : overbeek 1.68 my @related = &related_by_func_sim($fig_or_sprout,$cgi,$peg,$cgi->param('user'));
285 : parrello 1.60 push(@related,$peg);
286 :    
287 :     my @annotations = &merged_related_annotations($fig_or_sprout,\@related);
288 :    
289 :     my $tab = [ map { $ann = $_;
290 :     [$ann->[2],$ann->[1],&HTML::fid_link($cgi,$ann->[0]),
291 :     &genus_species($fig_or_sprout,&genome_of($ann->[0])),
292 :     "<pre>" . $ann->[3] . "</pre>"
293 :     ] } @annotations];
294 :     if (@$tab > 0) {
295 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"All Related Annotations for $peg"));
296 :     } else {
297 :     push(@$html,"<h1>No Annotations for $peg</h1>\n");
298 :     }
299 : overbeek 1.15 }
300 :     }
301 :    
302 : overbeek 1.11 #==============================================================================
303 :     # show_coupling_evidence
304 :     #==============================================================================
305 :    
306 : overbeek 1.171 sub show_abstract_coupling_evidence {
307 :     my($fig_or_sprout,$cgi,$html,$prot) = @_;
308 :    
309 :     my @coupling = $fig_or_sprout->abstract_coupled_to($prot);
310 :     if (@coupling > 0)
311 :     {
312 : overbeek 1.172 push(@$html,&HTML::abstract_coupling_table($cgi,$prot,\@coupling));
313 : overbeek 1.171 }
314 :     else
315 :     {
316 :     push(@$html,$cgi->h1("sorry, no abstract coupling data for $prot"));
317 :     }
318 :     }
319 :    
320 : efrank 1.1 sub show_coupling_evidence {
321 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
322 : efrank 1.1 my($pair,$peg1,$peg2,$link1,$link2);
323 :    
324 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Functional Coupling</TITLE>\n";
325 : efrank 1.1 my $user = $cgi->param('user');
326 :     my $to = $cgi->param('to');
327 : overbeek 1.115 my @coup = grep { $_->[1] eq $to } &coupling_and_evidence($fig_or_sprout,$peg,5000,1.0e-10,4,1);
328 : efrank 1.1
329 : parrello 1.60 if (@coup != 1) {
330 :     push(@$html,"<h1>Sorry, no evidence that $peg is coupled to $to</h1>\n");
331 :     } else {
332 : overbeek 1.91 my $col_hdrs = ["Peg1","Function1","Peg2","Function2","Organism"];
333 : parrello 1.60 my $tab = [];
334 :     foreach $pair (@{$coup[0]->[2]}) {
335 :     ($peg1,$peg2) = @$pair;
336 :     $link1 = &HTML::fid_link($cgi,$peg1);
337 :     $link2 = &HTML::fid_link($cgi,$peg2);
338 :     push( @$tab, [ $link1,
339 : overbeek 1.91 scalar &function_ofS($fig_or_sprout,$peg1,$user),
340 :     $link2,
341 :     scalar &function_ofS($fig_or_sprout,$peg2,$user),
342 :     &org_of($fig_or_sprout,$peg1)
343 : parrello 1.60 ]
344 : overbeek 1.11 );
345 : parrello 1.60 }
346 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Evidence that $peg Is Coupled To $to"));
347 : efrank 1.1 }
348 :     }
349 :    
350 : overbeek 1.11 #==============================================================================
351 :     # psi_blast_prot_sequence
352 :     #==============================================================================
353 :    
354 : efrank 1.1 sub psi_blast_prot_sequence {
355 : overbeek 1.53 my($fig_or_sprout,$cgi,$prot_id) = @_;
356 : efrank 1.1 }
357 :    
358 : overbeek 1.11 #==============================================================================
359 :     # show_initial
360 :     #==============================================================================
361 :    
362 : efrank 1.1 sub show_initial {
363 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
364 :    
365 :     unshift @{$html->{general}}, "<TITLE>The SEED: Protein Page</TITLE>\n";
366 : efrank 1.1
367 : overbeek 1.53 my $gs = &org_of($fig_or_sprout,$prot);
368 : parrello 1.60 Trace("got gs=$gs prot=$prot $fig_or_sprout\n") if T(2);
369 :     if ($prot =~ /^fig\|\d+\.\d+\.peg/) {
370 :     if (! &is_real_feature($fig_or_sprout,$prot)) {
371 :     push(@{$html->{general}},"<h1>Sorry, $prot is an unknown identifier</h1>\n");
372 :     } else {
373 :     push(@{$html->{general}},"<h1>Protein $prot: $gs</h1>\n");
374 : efrank 1.187
375 :     # caBIG insists on explicitly displaying the taxon ID rather
376 :     # than learning how to read the figID, so display it.
377 :     # ...please don't delete this without consulting with Ed
378 :    
379 :     my $taxon;
380 :     if ($prot =~ /^fig\|(\d+)\.(\d+)/) {
381 :     push(@{$html->{general}},"<h2>Taxon=$1 (NCBI TaxonId, if one exists)</h2>\n");
382 :     }
383 :    
384 : parrello 1.60 &translation_piece($fig_or_sprout,$cgi,$html->{translate_status});
385 :     &display_peg($fig_or_sprout,$cgi,$html,$prot);
386 :     }
387 :     } else {
388 :     # &display_external($fig_or_sprout,$cgi,$html,$prot);
389 : efrank 1.1 }
390 :     }
391 :    
392 : overbeek 1.11 #==============================================================================
393 :     # display_peg
394 :     #==============================================================================
395 :    
396 : efrank 1.1 sub display_peg {
397 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
398 : efrank 1.1 my $loc;
399 : overbeek 1.104
400 : overbeek 1.53 my $user = $cgi->param('user');
401 : overbeek 1.104 my $org = &genome_of($peg);
402 : overbeek 1.116 my $domain = &genome_domain($fig_or_sprout,$org);
403 : overbeek 1.104
404 :     #...set default minimum size for euk or non-euk display region...
405 :     my $half_sz = ($domain =~ m/^euk/i) ? 50000 : 5000;
406 :    
407 : overbeek 1.10 my $fc = $cgi->param('fc');
408 :     my @fc_data;
409 : parrello 1.60 if ($fc) {
410 : redwards 1.49 # RAE Added the following lines so that you can define this in the URL
411 : parrello 1.60 # but the default behavior remains unchanged. I doubt anyone will ever
412 :     # see this, but I use it sometimes to see what happens
413 :     my ($bound,$sim_cutoff,$coupling_cutoff)=(5000, 1.0e-10, 4);
414 :     if ($cgi->param('fcbound')) {$bound=$cgi->param('fcbound')}
415 :     if ($cgi->param('fcsim')) {$sim_cutoff=$cgi->param('fcsim')}
416 :     if ($cgi->param('fccoup')) {$coupling_cutoff=$cgi->param('fccoup')}
417 : overbeek 1.104
418 : overbeek 1.115 @fc_data = &coupling_and_evidence($fig_or_sprout,$peg,$bound,$sim_cutoff,$coupling_cutoff,1);
419 : parrello 1.60 } else {
420 :     @fc_data = ();
421 :     }
422 : overbeek 1.104
423 : parrello 1.60 if ($loc = &feature_locationS($fig_or_sprout,$peg)) {
424 : overbeek 1.146 if ($loc =~ /^(\d+\.\d+:(\S+)) \2$/)
425 :     {
426 :     #
427 :     # REMOVE ME.
428 :     #
429 :     # Patch a sprout bug that returns spurious gunk in feature locations.
430 :     #
431 :    
432 :     $loc = $1;
433 :     }
434 :    
435 : parrello 1.60 my($contig,$beg,$end) = &boundaries_of($fig_or_sprout,$loc);
436 : overbeek 1.104
437 :     my $len = abs($end-$beg) + 1;
438 : overbeek 1.112 if ($len > $half_sz)
439 :     {
440 :     $half_sz = $len;
441 :     }
442 :     else
443 :     {
444 :     $half_sz = $half_sz * (1 + 3*int($len/$half_sz)); #...set scale of region...
445 :     }
446 : overbeek 1.104 # print STDERR "half_sz = $half_sz\n";
447 :    
448 :     my $min = &max(0,&min($beg,$end) - $half_sz);
449 :     my $max = &max($beg,$end) + $half_sz;
450 : parrello 1.60 Trace("display_peg: min=$min max=$max beg=$beg end=$end") if T(2);
451 : overbeek 1.104
452 : mkubal 1.166 my $feat;
453 :     ($feat,$min,$max) = &genes_in_region($fig_or_sprout,$cgi,&genome_of($peg),$contig,$min,$max);
454 :    
455 : parrello 1.60 Trace("beg=$beg end=$end New min = $min, max = $max, features = " . join(", ", @{$feat})) if T(3);
456 :    
457 :     my ($beg,$end,$genes) = &print_context($fig_or_sprout,$cgi,$html->{contig_context},$peg,$feat,$min,$max);
458 :     Trace("Print context returned: beg=$beg, end=$end, genes = " . join(", ", @{$genes})) if T(3);
459 :     &print_graphics_context($beg,$end,$genes,$html->{context_graphic});
460 :    
461 : overbeek 1.68 &print_assignments($fig_or_sprout,$cgi,$html->{assign_for_equiv_prots},$peg);
462 : redwards 1.99 &print_kv_pairs($is_sprout, $fig_or_sprout,$cgi,$html->{kv_pairs},$peg);
463 : redwards 1.125 &print_protein_fams($is_sprout, $fig_or_sprout,$cgi,$html->{kv_pairs},$peg,$user);
464 : parrello 1.60 &print_subsys_connections($fig_or_sprout,$cgi,$html->{subsys_connections},$peg,$user);
465 :     &print_links($fig_or_sprout,$cgi,$html->{links},$peg);
466 :    
467 :    
468 :     my $has_translation = &translatable($fig_or_sprout,$peg);
469 :     &print_services($fig_or_sprout,$cgi,$html->{services},$peg,$has_translation,\@fc_data);
470 : overbeek 1.63
471 : parrello 1.60 &print_sims_block($fig_or_sprout,$cgi,$html->{similarities},$peg,$user,$has_translation);
472 :    
473 :     if ($has_translation) {
474 :     &show_tools($fig_or_sprout,$cgi,$html->{tools},$peg);
475 :     }
476 : efrank 1.1 }
477 :     }
478 :    
479 :     ################# Table-Driven Show Tools ############################
480 :    
481 :     sub show_tools {
482 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
483 : efrank 1.1
484 : redwards 1.80 # generate the link to turn tools on or off
485 : overbeek 1.161 my $toollink = $cgi->url(-relative => 1, -query => 1, -path_info => 1);
486 :    
487 : redwards 1.80 $toollink =~ s/[\&\;]fulltools.*[^\;\&]/\&/;
488 : redwards 1.125 my $fulltoolbutton = $cgi->a({href=> $toollink . "&fulltools='1'"}, "> Show tool descriptions"); # define this here before we mess with ourself!
489 :     my $brieftoolbutton = $cgi->a({href=> $toollink}, "< Hide tool descriptions");
490 : parrello 1.108
491 : efrank 1.1 $cgi->param(-name => "request",
492 :     -value => "use_protein_tool");
493 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1);
494 : efrank 1.1
495 : parrello 1.60 if (open(TMP,"<$FIG_Config::global/LinksToTools")) {
496 :     my $col_hdrs = ["Tool","Description"];
497 :     my $tab = [];
498 :    
499 :     $/ = "\n//\n";
500 : redwards 1.80 my $brieftools; # in case we don't want descriptions and whatnot
501 : parrello 1.60 while (defined($_ = <TMP>)) {
502 : overbeek 1.72 # allow comment lines in the file
503 :     next if (/^#/);
504 : parrello 1.60 my($tool,$desc) = split(/\n/,$_);
505 : overbeek 1.72 # RAE modified this so we can include column headers.
506 :     undef($desc) if ($desc eq "//"); # it is a separator
507 : redwards 1.80 # RAE modified again so that we only get a short tool list instead of the big table if that is what we want.
508 :     if ($cgi->param('fulltools')) {
509 :     if ($desc) {push(@$tab,["<a href=\"$url\&tool=$tool\">$tool</a>",$desc])}
510 : parrello 1.108 else {push(@$tab, [["<strong>$tool</strong>", "td colspan=2 align=center"]])}
511 : redwards 1.80 }
512 :     else {
513 :     # Why doesn't this work $brieftools .= "<span class=\"tool\" style=\"border: 0 1px solid gray\"><a href=\"$url\&tool=$tool\">$tool</a></span>";
514 :     if ($desc) {$brieftools .= " &nbsp; <a href=\"$url\&tool=$tool\">$tool</a> &nbsp;|"}
515 :     }
516 : parrello 1.60 }
517 :     close(TMP);
518 :     $/ = "\n";
519 : redwards 1.80 if ($brieftools) {push(@$html, $cgi->p("|" . $brieftools), $fulltoolbutton)}
520 :     else {push(@$html,&HTML::make_table($col_hdrs,$tab,"Tools to Analyze Protein Sequences"), $brieftoolbutton)}
521 : efrank 1.1 }
522 :     $cgi->delete('request');
523 :     }
524 :    
525 :     ################# Functional Coupling ############################
526 :    
527 :     sub print_fc {
528 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg,$fc_data) = @_;
529 : efrank 1.1 my($sc,$neigh);
530 : parrello 1.60
531 : efrank 1.1 my $user = $cgi->param('user');
532 :     my @tab = map { ($sc,$neigh) = @$_;
533 : parrello 1.60 [&ev_link($cgi,$neigh,$sc),$neigh,scalar &function_ofS($fig_or_sprout,$neigh,$user)]
534 :     } @$fc_data;
535 :     if (@tab > 0) {
536 :     push(@$html,"<hr>\n");
537 :     my $col_hdrs = ["Score","Peg","Function"];
538 :     push(@$html,&HTML::make_table($col_hdrs,\@tab,"Functional Coupling"));
539 : efrank 1.1 }
540 :     }
541 :    
542 :     sub ev_link {
543 :     my($cgi,$neigh,$sc) = @_;
544 :    
545 :     my $prot = $cgi->param('prot');
546 : overbeek 1.121 my $sprout = $cgi->param('SPROUT');
547 : overbeek 1.161 my $link = $cgi->url(-relative => 1) . "?request=show_coupling_evidence&prot=$prot&to=$neigh&SPROUT=$sprout";
548 : efrank 1.1 return "<a href=$link>$sc</a>";
549 :     }
550 :    
551 :     ################# Assignments ############################
552 :    
553 :     sub trans_function_of {
554 : overbeek 1.53 my($cgi,$fig_or_sprout,$peg,$user) = @_;
555 : efrank 1.1
556 : parrello 1.60 if (wantarray()) {
557 :     my $x;
558 : overbeek 1.68 my @funcs = &function_ofL($fig_or_sprout,$peg,$user);
559 :    
560 : parrello 1.60 if ($cgi->param('translate')) {
561 :     @funcs = map { $x = $_; $x->[1] = &translate_function($fig_or_sprout,$x->[1]); $x } @funcs;
562 :     }
563 :     return @funcs;
564 :     } else {
565 :     my $func = &function_ofS($fig_or_sprout,$peg,$user);
566 :     if ($cgi->param('translate')) {
567 :     $func = &translate_function($fig_or_sprout,$func);
568 :     }
569 :     return $func;
570 : efrank 1.1 }
571 :     }
572 :    
573 : overbeek 1.53 ########################## Routines that build pieces of HTML ######################
574 :    
575 :    
576 :     sub print_sims_block {
577 :     my($fig_or_sprout,$cgi,$html,$peg,$user,$has_translation) = @_;
578 :    
579 :     my $sims = $cgi->param('sims');
580 : overbeek 1.122 if ( (! $sims ) && $has_translation)
581 : golsen 1.76 {
582 :     my $short_form = 1;
583 :     sims_request_form( $fig_or_sprout, $cgi, $html, $peg, $user, $short_form );
584 :     }
585 : overbeek 1.53
586 : golsen 1.76 # Added test $has_translation && (...) -- GJO
587 : overbeek 1.122 elsif ( $has_translation && $sims)
588 : golsen 1.76 {
589 : golsen 1.100 print_similarities( $fig_or_sprout, $cgi, $html, $peg );
590 : overbeek 1.53 }
591 :     }
592 :    
593 :    
594 :     sub print_services {
595 :     my($fig_or_sprout,$cgi,$html,$peg,$has_translation,$fc_data) = @_;
596 :    
597 : overbeek 1.161 # my $baseurl=$FIG_Config::cgi_base;
598 :     # Old base my $base = $cgi->self_url();
599 :    
600 :     my $baseurl = ".";
601 :    
602 :     my $base = $cgi->url(-relative => 1, -query => 1, -path_info => 1);
603 :     my $link1 = "$base&request=view_annotations";
604 :     my $link2 = "$base&request=view_all_annotations";
605 : overbeek 1.150
606 :     #
607 :     # Since one cannot annotate in SPROUT, don't show this help.
608 :     #
609 :    
610 :     if (not $is_sprout)
611 :     {
612 :     push(@$html, "<a href='$baseurl/Html/seedtips.html#gene_names' class='help' target='help'>Help on Annotations</a><br>\n");
613 :     }
614 :    
615 : mkubal 1.166
616 : redwards 1.134 push(@$html,"<a href=$link1>To View Annotations</a> / <a href=$link2>To View All Related Annotations</a>\n");
617 : mkubal 1.166 my $user = $cgi->param('user');
618 : overbeek 1.181
619 :     #
620 :     # Controlled vocabulary is SEED-only
621 :     #
622 :     if (not $is_sprout)
623 :     {
624 :     my $cv_link = "cv.cgi?prot=$peg&user=$user";
625 :     push(@$html,"<br><a href=$cv_link>Edit Controlled Vocabulary</a>\n");
626 :     }
627 : mkubal 1.166
628 : overbeek 1.116 if ((! $cgi->param('SPROUT')) && &peg_in_gendb($fig_or_sprout,$cgi,$peg))
629 : overbeek 1.63 {
630 :     push(@$html, "<br/>".&FIGGenDB::linkPEGGenDB($peg));
631 :     push(@$html, "<br/>".&FIGGenDB::importOrganismGenDB($peg));
632 :     }
633 : overbeek 1.53
634 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=aa_sequence";
635 : overbeek 1.53 push(@$html,"<br><a href=$link>Protein Sequence</a>\n");
636 :    
637 : overbeek 1.161 $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=dna_sequence";
638 : overbeek 1.173 push(@$html,"<br><a href=$link>DNA Sequence</a>\n");
639 :     $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=dna_sequence_adjacent";
640 :     push(@$html," [<a href=$link>with flanking sequence</a>]<br>\n");
641 : overbeek 1.53
642 : overbeek 1.161 $link = $cgi->url(-relative => 1);
643 : overbeek 1.53 $link =~ s/protein.cgi/fid_checked.cgi/;
644 :     my $sprout = $cgi->param('SPROUT') ? 1 : "";
645 :     my $user = $cgi->param('user');
646 : parrello 1.60 if (! $user) {
647 :     $user = "";
648 :     } else {
649 :     $link = $link . "?SPROUT=$sprout&fid=$prot&user=$user&checked=$prot&assign/annotate=assign/annotate";
650 : redwards 1.133 push(@$html,"<a href=$link target=checked_window>To Make an Annotation</a>\n");
651 : overbeek 1.53 }
652 :    
653 : overbeek 1.146 if (! $sprout)
654 : overbeek 1.145 {
655 : overbeek 1.146 my($cid,@fams);
656 : overbeek 1.145
657 : overbeek 1.63 my $fc = $cgi->param('fc');
658 :     if ((! $fc) && (&feature_locationS($fig_or_sprout,$peg))) {
659 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&fc=1";
660 : overbeek 1.63 push(@$html,"<br><a href=$link>To Get Detailed Functional Coupling Data</a>\n");
661 :     } elsif ($fc) {
662 :     &print_fc($fig_or_sprout,$cgi,$html,$peg,$fc_data);
663 :     }
664 : overbeek 1.53
665 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=fusions";
666 : overbeek 1.63 push(@$html,"<br><a href=$link>To Get Fusion Data</a>\n");
667 : overbeek 1.53
668 : overbeek 1.63 my $link = &cgi_url . "/homologs_in_clusters.cgi?prot=$peg&user=$user\n";
669 :     push(@$html,"<br><a href=$link>To Find Homologs in Clusters</a>\n");
670 : overbeek 1.171
671 :     my @coup = $fig_or_sprout->abstract_coupled_to($peg);
672 :     if (@coup > 0)
673 :     {
674 :     my $link = &cgi_url . "/protein.cgi?prot=$peg&user=$user&request=abstract_coupling\n";
675 : overbeek 1.172 push(@$html,"<br><a href=$link>Show Abstract Coupling Data</a>\n");
676 : overbeek 1.171 }
677 : overbeek 1.63 }
678 : overbeek 1.53
679 : parrello 1.60 if ((! $cgi->param('compare_region')) && $has_translation) {
680 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&compare_region=1";
681 : overbeek 1.165 push(@$html,"<A href=\"Html/compare_regions.html\" class='help' target=\"SEED_or_SPROUT_help\">Help on compare regions</A>\n");
682 : overbeek 1.168 push(@$html,"<a href=$link>To Compare Region</a> &nbsp;\n<br>");
683 :     push(@$html, "<a href='proteinfamilies.cgi?user=$user&prot=$peg&equivalence=1'>Explore Protein Families for $peg</a></br>\n");
684 : parrello 1.60 } elsif ($cgi->param('compare_region')) {
685 :     &print_compared_regions($fig_or_sprout,$cgi,$html,$peg);
686 : overbeek 1.53 }
687 :     }
688 :    
689 : efrank 1.1 sub print_assignments {
690 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
691 : efrank 1.1 my($who,$func,$ec,@ecs,@tmp,$id,$i,$master_func,$user_func,$x);
692 :    
693 :     my $user = $cgi->param('user');
694 : overbeek 1.68 $user = defined($user) ? $user : "";
695 :    
696 : overbeek 1.53 my @funcs = map { [$peg,@$_] } &trans_function_of($cgi,$fig_or_sprout,$peg);
697 : overbeek 1.68 $user_func = &trans_function_of($cgi,$fig_or_sprout,$peg);
698 :    
699 :     push(@$html,$cgi->h2("Current Assignment: $peg: $user_func"));
700 : parrello 1.108
701 : overbeek 1.163 my @maps_to = grep { $_ ne $peg and $_ !~ /^xxx/ } map { $_->[0] } &mapped_prot_ids($fig_or_sprout,$cgi,$peg);
702 : efrank 1.1
703 : parrello 1.60 foreach $id (@maps_to) {
704 : overbeek 1.68 my $tmp;
705 :     if (($id ne $peg) && ($tmp = &trans_function_of($cgi,$fig_or_sprout,$id)))
706 :     {
707 :     push(@funcs, [$id,&who($id),$tmp]);
708 : parrello 1.60 }
709 : efrank 1.1 }
710 :     @funcs = map { ($_->[1] eq "master") ? [$_->[0],"",$_->[2]] : $_ } @funcs;
711 : overbeek 1.68
712 :    
713 : efrank 1.1 push(@$html,"<hr>\n");
714 :    
715 : parrello 1.60 if ((@funcs == 0) && (! $user_func)) {
716 :     push(@$html,$cgi->h1("No function has been assigned"));
717 : efrank 1.1 }
718 : overbeek 1.25
719 : parrello 1.108 my $tab = [ map { ($id,$who,$func) = @$_;
720 : overbeek 1.68 [ &HTML::set_prot_links($cgi,$id),
721 :     &org_of($fig_or_sprout,$id),
722 : overbeek 1.75 $who ? $who : "&nbsp;",
723 : parrello 1.108 ($user ? &assign_link($cgi,$func,$user_func) : "&nbsp;"),
724 : golsen 1.169 &set_ec_and_tc_links($fig_or_sprout,$cgi,&genome_of($peg),$func)] } @funcs ];
725 : parrello 1.60 if (@$tab > 0) {
726 :     my $col_hdrs = ["Id","Organism","Who","ASSIGN","Assignment"];
727 :     my $title = "Assignments for Essentially Identical Proteins";
728 : overbeek 1.180 push @$html, "<a href=\"javascript:toggleOffLayer('identicalproteins');\" title=\"Show Identicals\">Show/Hide Assignments for Essentially Identical Proteins</a>";
729 : redwards 1.134 push(@$html,$cgi->div({id=>"identicalproteins"}, &HTML::make_table($col_hdrs,$tab,$title)));
730 : efrank 1.1 }
731 : overbeek 1.53 }
732 : parrello 1.60
733 : overbeek 1.53 sub print_kv_pairs {
734 : redwards 1.99 my($is_sprout, $fig_or_sprout,$cgi,$html,$peg) = @_;
735 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
736 : overbeek 1.161 $baseurl = "./"; # Relative url fix
737 : parrello 1.108
738 : redwards 1.99 # we don't want to do this for SPROUT
739 : olson 1.129 if ($is_sprout)
740 :     {
741 :     return print_kv_pairs_sprout($fig_or_sprout,$cgi,$html,$peg);
742 :     }
743 : parrello 1.108
744 : redwards 1.94 # RAE: modified this to allow the users to edit the key/value pairs.
745 :     # there will be two choices: when the "Edit Attributes" button is pressed
746 :     # we will redraw the table with input fields and what not.
747 :    
748 :     # If the Add Changes button is pressed we will save the changes
749 :     # we will do this first before displaying the results
750 : parrello 1.108
751 : overbeek 1.141 my @attr = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
752 : redwards 1.94 if ($cgi->param('Add Changes')) {
753 :     my ($deleted, $added, $changed)=(undef, undef, undef);
754 : parrello 1.108
755 : redwards 1.94 foreach my $key (@attr) {
756 : redwards 1.105 unless ($cgi->param("key.".$key->[1])) {
757 : redwards 1.138 if (&delete_attribute($fig_or_sprout, $peg, $key->[1], $cgi->param("value.".$key->[1]), $cgi->param("url.".$key->[1]))) {
758 : redwards 1.99 push @$deleted, [@$key, ["deleted", "td colspan=2 style=\"text-align: center\""]];
759 :     }
760 : redwards 1.94 }
761 : redwards 1.105 if (($cgi->param("value.".$key->[1]) ne $key->[2]) || ($cgi->param("url.".$key->[1]) ne $key->[3])) {
762 : redwards 1.138 if (&change_attribute($fig_or_sprout,$peg, $key->[1], $key->[2], $key->[3], $cgi->param("value.".$key->[1]), $cgi->param("url.".$key->[1]))) {
763 : redwards 1.105 push @$changed, [@$key, $cgi->param("value.".$key->[1]), $cgi->param("url.".$key->[1])];
764 : redwards 1.99 }
765 : redwards 1.94 }
766 :     }
767 :     for (my $i=0; $i<=5; $i++) {
768 :     if ($cgi->param("key.$i")) {
769 : redwards 1.99 if (&add_attribute($fig_or_sprout,$peg, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"))) {
770 : redwards 1.138 push @$added, [$cgi->param("key.$i"), ["added", "td colspan=3 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
771 : redwards 1.99 }
772 :     else {
773 :     print STDERR $peg, " and ", $cgi->param("key.$i"), " not added\n";
774 :     }
775 : redwards 1.134 }
776 : redwards 1.94 }
777 : parrello 1.108
778 : redwards 1.134 if ($changed || $deleted || $added) {
779 :     my $tab = [];
780 :     my $col_hdrs=["Peg", "Attribute", "Original Value", "Original URL", "New Value", "New URL"];
781 : redwards 1.138 if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$changed}
782 :     if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$deleted}
783 :     if ($added) {push @$tab, [["<strong>Added Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$added}
784 : redwards 1.94
785 : redwards 1.134 push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
786 : overbeek 1.141 @attr = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
787 : redwards 1.134 }
788 :     # now get the explanations and save those
789 :     my $explanations;
790 :     foreach my $key (@attr) {
791 :     if ($cgi->param("explanation.".$key->[1])) {
792 : overbeek 1.162 if (&key_info($fig_or_sprout, $key->[1], {"description"=>$cgi->param("explanation.".$key->[1])})) {
793 : redwards 1.134 push @$explanations, [@$key, $cgi->param("explanation.".$key->[1])];
794 :     }
795 :     }
796 :     }
797 :     for (my $i=0; $i<=5; $i++) {
798 :     if ($cgi->param("key.$i") && $cgi->param("value.$i") && $cgi->param("explanation.".$i)) {
799 : overbeek 1.162 if (&key_info($fig_or_sprout, $cgi->param("key.$i"), {"description"=>$cgi->param("explanation.".$i)})) {
800 : redwards 1.134 push @$explanations, [$cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"), $cgi->param("explanation.".$i)];
801 :     }
802 :     }
803 :     }
804 : redwards 1.138 if ($explanations) {
805 : redwards 1.134 my $col_hdrs=["Peg", "Attribute", "Value", "URL", "Explanation"];
806 :     push(@$html,&HTML::make_table($col_hdrs,$explanations,"Explanations"));
807 :     }
808 : redwards 1.94 }
809 :    
810 : redwards 1.134 my $col_hdrs=["Key<br><span style='font-size: smaller'>Link Explains Key</span>","Value"];
811 : redwards 1.94
812 : redwards 1.95 my $tab = [];
813 :     if ($cgi->param('Edit Attributes') && $cgi->param('user')) {
814 : redwards 1.134 push @$col_hdrs, "URL", "Explanation";
815 : redwards 1.105 foreach my $key (sort {$a->[1] cmp $b->[1]} @attr) {
816 : mkubal 1.166 my $data=$fig_or_sprout->key_info($key->[1]);
817 :     if ($data->{"is_cv"} == 1){next}
818 : redwards 1.95 push @$tab,
819 :     [
820 : redwards 1.105 $cgi->textfield(-name=>"key.".$key->[1], -default=>$key->[1], -size=>30),
821 :     $cgi->textfield(-name=>"value.".$key->[1], -default=>$key->[2], -size=>30),
822 :     $cgi->textfield(-name=>"url.".$key->[1], -default=>$key->[3], -size=>30),
823 : overbeek 1.162 $cgi->textfield(-name=>"explanation.".$key->[1], -default=>$data->{"description"}, -size=>30),
824 : redwards 1.95 ];
825 :     }
826 :     for (my $i=0; $i<=5; $i++) {
827 :     push @$tab,
828 :     [
829 :     $cgi->textfield(-name=>"key.$i", -size=>30),
830 :     $cgi->textfield(-name=>"value.$i", -size=>30),
831 :     $cgi->textfield(-name=>"url.$i", -size=>30),
832 : redwards 1.134 $cgi->textfield(-name=>"explanation.$i", -default=>'', -size=>30),
833 : redwards 1.95 ];
834 :     }
835 :     }
836 : redwards 1.99 #RAE we need to check that this is a scalar
837 :     elsif (ref($attr[0]) eq "ARRAY") {
838 : overbeek 1.161 my $link=$cgi->url(-relative => 1, -query => 1, -path_info => 1);
839 : redwards 1.95 foreach $_ (sort {$a->[0] cmp $b->[0]} @attr) {
840 : redwards 1.105 my($peg,$tag,$val,$url) = @$_;
841 : mkubal 1.166 push(@$tab,["<a href='$link&showtag=$tag'>$tag</a>",$url ? "<a href=\"$url\">$val</a>" : $val]);
842 : redwards 1.134 if ($cgi->param("showtag") && $cgi->param("showtag") eq $tag) {
843 :     my $data=&key_info($fig_or_sprout, $tag);
844 :     my $info="No Information Known about $tag";
845 : overbeek 1.162 if ($data->{"description"}) {$info=$data->{"description"}}
846 : redwards 1.134 push(@$tab, [["Key", "th"], ["Explanation", "th"]], [$tag, $info]);
847 :     }
848 : redwards 1.95 }
849 :     }
850 : parrello 1.108
851 : redwards 1.95 # Add the appropriate submit button to the table
852 :     if ($cgi->param('user') && $cgi->param('Edit Attributes')) {
853 :     # we want a Add button
854 :     push @$tab, [[$cgi->submit('Add Changes'), "td colspan=3 style=\"text-align: center\""]];
855 :     }
856 :     elsif ($cgi->param('user')) {
857 : overbeek 1.168 # RAE:
858 :     # I have turned off editing attributes at the moment. I think it is debateable that it has any value
859 :     # I am not aware of anyone editing attributes on a per-protein basis, although I know that people have
860 :     # edited them in bulk. The code is not working properly, and should be rewritten, so for now
861 :     # I have disabled them.
862 :    
863 :     #push @$tab, [[$cgi->submit('Edit Attributes'), "td colspan=2 style=\"text-align: center\""]];
864 : overbeek 1.38 }
865 : redwards 1.95 push(@$html,$cgi->start_form(-action=>"protein.cgi"), $cgi->hidden("prot"), $cgi->hidden("user"));
866 : redwards 1.134 if (($cgi->param('user') && $cgi->param('Edit Attributes')) || $cgi->param("showtag")) {
867 :     # these are the cases where we automatically want this shown
868 :     push(@$html,$cgi->br,$cgi->hr,&HTML::make_table($col_hdrs, $tab,"Attributes"),$cgi->hr);
869 :     }
870 :     else {
871 :     # otherwise we set the javascript section to hide this.
872 :     push @$html, "<a href=\"javascript:toggleLayer('attributes');\" title=\"Show Attributes\">Show/Hide Attributes</a>",
873 : overbeek 1.140 "\n<div id='attributes'>\n<a href='$baseurl/Html/Attributes.html' class='help' target='help'>Help on Attributes</a>\n",
874 : redwards 1.134 &HTML::make_table($col_hdrs, $tab,"Attributes"), "</div>";
875 :     }
876 : golsen 1.100 # Add end of form -- GJO
877 : redwards 1.105 # RAE: sorry about that Gary.
878 : golsen 1.100 push( @$html, $cgi->end_form );
879 : overbeek 1.53 }
880 :    
881 : olson 1.129 sub print_kv_pairs_sprout
882 :     {
883 :     my($fig_or_sprout, $cgi, $html, $peg) = @_;
884 :    
885 : overbeek 1.141 my @props = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
886 : olson 1.129
887 :     my @col_hdrs = ("Key", "Value");
888 :    
889 :     my @tab;
890 :    
891 :     for my $prop (@props)
892 :     {
893 : overbeek 1.146 my($fid, $name, $value, $evidence) = @$prop;
894 : olson 1.129 my $txt;
895 :     if ($evidence =~ /^http/)
896 :     {
897 :     $txt = qq(<a href="$evidence">$value</a>);
898 :     }
899 :     else
900 :     {
901 :     $txt = $value;
902 :     }
903 :     push(@tab, [$name, $txt]);
904 :     }
905 :    
906 :     push(@$html, &HTML::make_table(\@col_hdrs, \@tab, "Attributes"), $cgi->hr);
907 :    
908 :     print STDERR Dumper($html);
909 :     }
910 :    
911 :    
912 : redwards 1.125 sub print_protein_fams {
913 : redwards 1.126
914 :     ############## RAE
915 :     # This code adds the protein family table to the page. This can be shown/hidden at the discretion of the viewer. Hopefully.
916 :    
917 :     my($is_sprout, $fig_or_sprout,$cgi,$html,$peg,$user) = @_;
918 :     # we don't want to do this for SPROUT
919 :     return if ($is_sprout);
920 :    
921 :     # get the families and other information
922 :     my $tab=[];
923 :     my @families=&families_for_protein($fig_or_sprout,$peg);
924 : redwards 1.128 unless (scalar @families) {
925 :     push @$html, "No protein families found\n";
926 :     return;
927 :     }
928 : redwards 1.136
929 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
930 : overbeek 1.161
931 : overbeek 1.168 push @$html, "<a href=\"javascript:toggleLayer('proteinfamilies');\" title=\"Show Protein Families\">Show/Hide Protein Families</a>";
932 : redwards 1.126 foreach my $fam (@families)
933 :     {
934 : overbeek 1.164 my $link="<a href='proteinfamilies.cgi?user=$user&family=$fam'>$fam</a>";
935 : redwards 1.126 push @$tab, [$link, &family_function($fig_or_sprout, $fam), &sz_family($fig_or_sprout, $fam)];
936 :     }
937 :     my $col_hdrs=["Family ID<br><small>Link Investigates Family</small>", "Family Function", "Family Size"];
938 : redwards 1.136 push @$html, $cgi->br, $cgi->div({id=>"proteinfamilies"},
939 : overbeek 1.165 "\n<a href='Html/ProteinFamilies.html' class='help' target='help'>Help on Protein Families</a>\n",
940 : redwards 1.136 &HTML::make_table($col_hdrs, $tab, "Protein Families")
941 :     );
942 : redwards 1.126 }
943 :    
944 :    
945 :     sub old_print_protein_fams {
946 :    
947 :     ############## RAE
948 :     # This is functional code that displays the protein families, but I want to try it using
949 :     # the CSS method. Therefore, I am keeping this code just for now, rather than munging it and being
950 :     # stuck with nothing working. Just rename this method and it will be fine!
951 :    
952 : redwards 1.125 my($is_sprout, $fig_or_sprout,$cgi,$html,$peg,$user) = @_;
953 :    
954 :     # we don't want to do this for SPROUT
955 :     return if ($is_sprout);
956 :    
957 :     # generate the link to turn protein fams on or off
958 : overbeek 1.161 my $link=$cgi->url(-relative => 1, -query => 1, -path_info => 1);
959 : redwards 1.125 if ($link =~ /showproteinfams/) {
960 :     $link =~ s/[\&\;]showproteinfams.*[^\;\&]/\&/;
961 :     push @$html, "< &nbsp; " . $cgi->a({href=> $link}, "Hide Protein Families");
962 :    
963 :     # get the families and other information
964 :     my $tab=[];
965 :     my @families=&families_for_protein($fig_or_sprout,$peg);
966 :     return unless (scalar @families);
967 :     foreach my $fam (@families)
968 :     {
969 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
970 : overbeek 1.161 $baseurl = './'; # Relative url fix
971 : overbeek 1.140 my $link="<a href='$baseurl/proteinfamilies.cgi?user=$user&family=$fam'>$fam</a>";
972 : redwards 1.125 push @$tab, [$link, &family_function($fig_or_sprout, $fam), &sz_family($fig_or_sprout, $fam)];
973 :     }
974 :     my $col_hdrs=["Family ID<br><small>Link Investigates Family</small>", "Family Function", "Family Size"];
975 :     push @$html, $cgi->br, &HTML::make_table($col_hdrs, $tab, "Protein Families"), $cgi->hr;
976 :     }
977 :     else
978 :     {
979 :     push @$html, "> &nbsp; " . $cgi->a({href=> $link . "&showproteinfams='1'"}, "Show Protein Families"); # define this here before we mess with ourself!
980 :     }
981 :     }
982 :    
983 : overbeek 1.68 sub who {
984 :     my($id) = @_;
985 :    
986 :     if ($id =~ /^fig\|/) { return "FIG" }
987 :     if ($id =~ /^gi\|/) { return "" }
988 :     if ($id =~ /^^[NXYZA]P_/) { return "RefSeq" }
989 :     if ($id =~ /^sp\|/) { return "SwissProt" }
990 :     if ($id =~ /^uni\|/) { return "UniProt" }
991 : overbeek 1.123 if ($id =~ /^tigr\|/) { return "TIGR" }
992 : overbeek 1.68 if ($id =~ /^pir\|/) { return "PIR" }
993 :     if ($id =~ /^kegg\|/) { return "KEGG" }
994 :     }
995 :    
996 : overbeek 1.53 sub print_subsys_connections {
997 :     my($fig_or_sprout,$cgi,$html,$peg,$user) = @_;
998 : overbeek 1.38
999 : olson 1.28 #
1000 :     # Show the subsystems in which this protein participates.
1001 :     #
1002 :    
1003 : parrello 1.60 if (my @subsystems = &subsystems_for_peg($fig_or_sprout,$peg)) {
1004 :     push(@$html,
1005 :     $cgi->h2("Subsystems in which this peg is present"));
1006 :    
1007 :     my(@hdrs);
1008 :     my(@table);
1009 :    
1010 : overbeek 1.147 @hdrs = ("Subsystem", "Curator", "Role");
1011 : parrello 1.60
1012 : overbeek 1.122 my $sprout = $cgi->param('SPROUT') ? 1 : "";
1013 : parrello 1.60
1014 :     for my $ent (@subsystems) {
1015 :     my($sub, $role) = @$ent;
1016 : overbeek 1.147 my $curator = &subsystem_curator($fig_or_sprout,$sub);
1017 : overbeek 1.149 my $can_alter;
1018 :    
1019 : golsen 1.107 my $esc_sub = uri_escape($sub); # in URI::Escape
1020 : overbeek 1.156 my $genome = &FIG::genome_of($peg);
1021 : overbeek 1.149 my %opts = (SPROUT => $sprout,
1022 :     user => $user,
1023 :     ssa_name => $esc_sub,
1024 : overbeek 1.156 focus => $genome,
1025 :     request => 'show_ssa',
1026 :     show_clusters => 1,
1027 : overbeek 1.149 sort => 'by_phylo'
1028 :     );
1029 :    
1030 :     if (($user = $cgi->param('user')) && ($user eq $curator))
1031 :     {
1032 :     $opts{can_alter} = 1;
1033 :     }
1034 :    
1035 :     my $opts = join("&", map { "$_=$opts{$_}" } keys(%opts));
1036 :    
1037 :     # my $url = $cgi->a({href => "subsys.cgi?${can_alter}SPROUT=$sprout&user=$user&ssa_name=$esc_sub&request=show_ssa&show_clusters=1&sort=by_phylo"}, $sub);
1038 : overbeek 1.155 my $url = $cgi->a({href => "display_subsys.cgi?$opts"}, $sub);
1039 : overbeek 1.89
1040 : overbeek 1.147 push(@table, [$url, $curator, $role]);
1041 : parrello 1.60 }
1042 :     push(@$html, &HTML::make_table(\@hdrs, \@table));
1043 : olson 1.28 }
1044 : overbeek 1.53 }
1045 :    
1046 :     sub print_links {
1047 :     my($fig_or_sprout,$cgi,$html,$peg) = @_;
1048 : overbeek 1.31
1049 : parrello 1.60 my @links = &peg_links($fig_or_sprout,$peg);
1050 :     if (@links > 0) {
1051 :     my $col_hdrs = [1,2,3,4,5];
1052 :     my $title = "Links to Related Entries in Other Sites";
1053 :     my $tab = [];
1054 :     my ($n,$i);
1055 :     for ($i=0; ($i < @links); $i += 5) {
1056 :     $n = (($i + (5-1)) < @links) ? $i+(5-1) : $i+(@links - $i);
1057 :     push(@$tab,[@links[$i..$n]]);
1058 :     }
1059 : redwards 1.134 push @$html, "<a href=\"javascript:toggleLayer('linkselsewhere');\" title=\"Show Links\">Show/Hide Links to Related Entries in Other Sites</a>";
1060 : overbeek 1.188 push(@$html,$cgi->div({id=>"linkselsewhere"}, &HTML::make_table($col_hdrs,$tab,$title)));
1061 :     }
1062 :     if (! $cgi->param('SPROUT'))
1063 :     {
1064 :     my $url = &cgi_url . "/add_links.cgi?peg=$peg";
1065 :     push @$html, $cgi->br("<a href=$url>To Add New Links to this Gene</a>\n");
1066 : overbeek 1.53 }
1067 : efrank 1.1 }
1068 :    
1069 :    
1070 :    
1071 :     ################# Similarities ############################
1072 :    
1073 :    
1074 :     sub print_similarities {
1075 : overbeek 1.53 my( $fig_or_sprout, $cgi, $html, $peg ) = @_;
1076 : overbeek 1.63
1077 :     if ($cgi->param('SPROUT'))
1078 :     {
1079 :     &print_similarities_SPROUT($fig_or_sprout, $cgi, $html, $peg );
1080 :     }
1081 :     else
1082 :     {
1083 :     &print_similarities_SEED($fig_or_sprout, $cgi, $html, $peg );
1084 :     }
1085 :     }
1086 :    
1087 : golsen 1.76
1088 : overbeek 1.63 sub print_similarities_SPROUT {
1089 :     my($fig_or_sprout, $cgi, $html, $peg ) = @_;
1090 :    
1091 : overbeek 1.122 $cgi->delete('sims');
1092 :    
1093 : overbeek 1.63 my $user = $cgi->param('user') || "";
1094 : overbeek 1.122
1095 : overbeek 1.63 my $current_func = &trans_function_of($cgi,$fig_or_sprout,$peg,$user);
1096 :    
1097 :     push( @$html, $cgi->hr,
1098 :     "<a name=Similarities>",
1099 : overbeek 1.68 $cgi->h1(''),
1100 : overbeek 1.63 "</a>\n"
1101 :     );
1102 :    
1103 : overbeek 1.116 my @sims = sort { $a->[1] <=> $b->[1] } &bbhs($fig_or_sprout,$peg,1.0e-10);
1104 : overbeek 1.63
1105 :     my @from = $cgi->radio_group(-name => 'from',
1106 :     -nolabels => 1,
1107 :     -override => 1,
1108 : overbeek 1.65 -values => ["",$peg,map { $_->[0] } @sims]);
1109 : overbeek 1.63
1110 :     my $target = "window$$";
1111 :     # RAE: added a name to the form so tha the javascript works
1112 :     push( @$html, $cgi->start_form( -method => 'post',
1113 :     -target => $target,
1114 :     -action => 'fid_checked.cgi',
1115 :     -name => 'fid_checked'
1116 :     ),
1117 :     $cgi->hidden(-name => 'SPROUT', -value => 1),
1118 :     $cgi->hidden(-name => 'fid', -value => $peg),
1119 :     $cgi->hidden(-name => 'user', -value => $user),
1120 :     $cgi->br,
1121 :     "For Selected (checked) sequences: ",
1122 :     $cgi->submit('align'),
1123 :     );
1124 :    
1125 :     if ($user) {
1126 :     my $help_url = "Html/help_for_assignments_and_rules.html";
1127 : golsen 1.100 push ( @$html, $cgi->br, $cgi->br,
1128 :     "<a href=$help_url target=\"SEED_or_SPROUT_help\">Help on Assignments, Rules, and Checkboxes</a>",
1129 : overbeek 1.63 $cgi->br, $cgi->br,
1130 :     $cgi->submit('assign/annotate')
1131 :     );
1132 :    
1133 :     if ($cgi->param('translate')) {
1134 :     push( @$html, $cgi->submit('add rules'),
1135 :     $cgi->submit('check rules'),
1136 :     $cgi->br
1137 :     );
1138 :     }
1139 :     }
1140 :    
1141 :     push( @$html, $cgi->br,
1142 :     $cgi->checkbox( -name => 'checked',
1143 :     -value => $peg,
1144 :     -override => 1,
1145 :     -checked => 1,
1146 :     -label => ""
1147 :     )
1148 :     );
1149 :    
1150 :     my $col_hdrs;
1151 :     if ($user && $cgi->param('translate')) {
1152 :     push( @$html, " ASSIGN to/Translate from/SELECT current PEG", $cgi->br,
1153 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1154 :     "ASSIGN from/Translate to current PEG: ", shift @from
1155 :     );
1156 :     $col_hdrs = [ "ASSIGN to<hr>Translate from",
1157 :     "Similar sequence",
1158 :     "E-val",
1159 : overbeek 1.65 "In Sub",
1160 : overbeek 1.63 "ASSIGN from<hr>Translate to",
1161 :     "Function",
1162 :     "Organism",
1163 :     "Aliases"
1164 :     ];
1165 :     } elsif ($user) {
1166 :     push( @$html, " ASSIGN to/SELECT current PEG", $cgi->br,
1167 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1168 :     "ASSIGN from current PEG: ", shift @from
1169 :     );
1170 :     $col_hdrs = [ "ASSIGN to<hr>SELECT",
1171 :     "Similar sequence",
1172 :     "E-val",
1173 : overbeek 1.65 "In Sub",
1174 : overbeek 1.63 "ASSIGN from",
1175 :     "Function",
1176 :     "Organism",
1177 :     "Aliases"
1178 :     ];
1179 :     } else {
1180 :     push(@$html, " SELECT current PEG", $cgi->br );
1181 :     $col_hdrs = [ "SELECT",
1182 :     "Similar sequence",
1183 :     "E-val",
1184 :     "In Sub",
1185 :     "Function",
1186 :     "Organism",
1187 :     "Aliases"
1188 :     ];
1189 :     }
1190 :    
1191 :     my $ncol = @$col_hdrs;
1192 :     push( @$html, "<TABLE border cols=$ncol>\n",
1193 : overbeek 1.68 "\t<Caption><h2>Bidirectional Best Hits</h2></Caption>\n",
1194 : overbeek 1.63 "\t<TR>\n\t\t<TH>",
1195 :     join( "</TH>\n\t\t<TH>", @$col_hdrs ),
1196 :     "</TH>\n\t</TR>\n"
1197 :     );
1198 :    
1199 :     # Add the table data, row-by-row
1200 :    
1201 :     my $sim;
1202 :     foreach $sim ( @sims ) {
1203 :     my($id2,$psc) = @$sim;
1204 :     my $cbox = &translatable($fig_or_sprout,$id2) ?
1205 :     qq(<input type=checkbox name=checked value="$id2">) : "";
1206 :     my $id2_link = &HTML::set_prot_links($cgi,$id2);
1207 :     chomp $id2_link;
1208 :    
1209 :     my @in_sub = &peg_to_subsystems($fig_or_sprout,$id2);
1210 :     my $in_sub;
1211 :     if (@in_sub > 0) {
1212 :     $in_sub = @in_sub;
1213 :     } else {
1214 : overbeek 1.74 $in_sub = "&nbsp;";
1215 : overbeek 1.63 }
1216 :    
1217 :     my $radio = $user ? shift @from : undef;
1218 :     my $func2 = html_enc( scalar &trans_function_of( $cgi, $fig_or_sprout, $id2, $user ) );
1219 :     ## RAE Added color3. This will color function tables that do not match the original
1220 :     ## annotation. This makes is a lot easier to see what is different (e.g. caps/spaces, etc)
1221 :     my $color3="#FFFFFF";
1222 :     unless ($func2 eq $current_func) {$color3="#FFDEAD"}
1223 :    
1224 :     #
1225 :     # Colorize organisms:
1226 :     #
1227 :     # my $org = html_enc( &org_of($fig_or_sprout, $id2 ) );
1228 :     my ($org,$oc) = &org_and_color_of($fig_or_sprout, $id2 );
1229 :     $org = html_enc( $org );
1230 :    
1231 :     my $aliases = html_enc( join( ", ", &feature_aliasesL($fig_or_sprout,$id2) ) );
1232 : overbeek 1.68
1233 : overbeek 1.64 $aliases = &HTML::set_prot_links($cgi,$aliases);
1234 : overbeek 1.63
1235 :     # Okay, everything is calculated, let's "print" the row datum-by-datum:
1236 :    
1237 : overbeek 1.74 $func2 = $func2 ? $func2 : "&nbsp;";
1238 :     $aliases = $aliases ? $aliases : "&nbsp;";
1239 : overbeek 1.63 push( @$html, "\t<TR>\n",
1240 :     #
1241 :     # Colorize check box by Domain
1242 :     #
1243 :     "\t\t<TD Align=center Bgcolor=$oc>$cbox</TD>\n",
1244 :     "\t\t<TD Nowrap>$id2_link</TD>\n",
1245 :     "\t\t<TD Nowrap>$psc</TD>\n",
1246 : overbeek 1.65 "\t\t<TD>$in_sub</TD>",
1247 : overbeek 1.63 $user ? "\t\t<TD Align=center>$radio</TD>\n" : (),
1248 :     "\t\t<TD Bgcolor=$color3>$func2</TD>\n",
1249 :     #
1250 :     # Colorize organism by Domain
1251 :     #
1252 :     # "\t\t<TD>$org</TD>\n",
1253 :     "\t\t<TD Bgcolor=$oc>$org</TD>\n",
1254 :     "\t\t<TD>$aliases</TD>\n",
1255 :     "\t</TR>\n"
1256 :     );
1257 :     }
1258 :     push( @$html, "</TABLE>\n" );
1259 :     push( @$html, $cgi->end_form );
1260 :     }
1261 :    
1262 :    
1263 :     sub print_similarities_SEED {
1264 :     my( $fig_or_sprout, $cgi, $html, $peg ) = @_;
1265 : efrank 1.1
1266 : golsen 1.18 my $user = $cgi->param('user') || "";
1267 : golsen 1.76 my $current_func = &trans_function_of( $cgi, $fig_or_sprout, $peg, $user );
1268 : efrank 1.1
1269 : golsen 1.100 push @$html, $cgi->hr,
1270 :     "<a name=Similarities>", # Put an anchor on the heading
1271 :     $cgi->h2('Similarities'),
1272 :     "</a>\n";
1273 : golsen 1.34
1274 : golsen 1.76 # Generate the request form, and return current option values in hash
1275 : efrank 1.1
1276 : golsen 1.76 my $short_form = 0;
1277 : golsen 1.98 my $SimParams = sims_request_form( $fig_or_sprout, $cgi, $html, $peg, $user, $short_form );
1278 : overbeek 1.51
1279 : golsen 1.76 my $maxN = $SimParams->{ maxN };
1280 :     my $maxP = $SimParams->{ maxP };
1281 :     my $max_expand = $SimParams->{ max_expand };
1282 : golsen 1.98 my $select = $SimParams->{ select };
1283 : golsen 1.76 my $show_env = $SimParams->{ show_env };
1284 :     my $hide_alias = $SimParams->{ hide_alias };
1285 : overbeek 1.90 my $group_by_genome = $SimParams->{ group_by_genome };
1286 : golsen 1.98
1287 :     # These are active, but the values are only used in sims()
1288 :     # my $extra_opt = $SimParams->{ extra_opt };
1289 :     # my $min_q_cov = $SimParams->{ min_q_cov };
1290 :     # my $min_s_cov = $SimParams->{ min_s_cov };
1291 :     # my $min_sim = $SimParams->{ min_sim };
1292 :     # my $sim_meas = $SimParams->{ sim_meas };
1293 :     # my $sort_by = $SimParams->{ sort_by };
1294 :    
1295 : golsen 1.76 # None of these are currently active: -- GJO
1296 : golsen 1.98 # my $show_rep = $SimParams->{ show_rep };
1297 :     # my $max_sim = $SimParams->{ max_sim };
1298 :     # my $dyn_thrsh = $SimParams->{ dyn_thrsh };
1299 :     # my $save_dist = $SimParams->{ save_dist };
1300 :     # my $chk_which = $SimParams->{ chk_which };
1301 : efrank 1.1
1302 : golsen 1.76 # There is currently no control to turn this on! -- GJO
1303 : parrello 1.108 my $expand_groups = $SimParams->{ expand_groups };
1304 : efrank 1.1
1305 : golsen 1.76 # Move filtering of sims list out of display loop. Avoids many problems,
1306 :     # including display of table with no entries. Anticipate more filters.
1307 :     # -- GJO
1308 : golsen 1.97 #
1309 : golsen 1.98 # All the filtering is now done in get_raw_sims and expand_raw_sims. -- GJO
1310 : golsen 1.76
1311 : golsen 1.98 my @sims = sims( $fig_or_sprout,
1312 :     $peg,
1313 :     $maxN,
1314 :     $maxP,
1315 :     $select,
1316 :     $max_expand,
1317 :     $group_by_genome,
1318 :     $SimParams
1319 :     );
1320 : golsen 1.77
1321 : golsen 1.76 if ( @sims ) {
1322 :     push( @$html, $cgi->hr );
1323 :     my @from = $cgi->radio_group( -name => 'from',
1324 :     -nolabels => 1,
1325 :     -override => 1,
1326 :     -values => [ "", $peg, map { $_->id2 } @sims ]
1327 :     );
1328 : parrello 1.60
1329 :     my $target = "window$$";
1330 :     # RAE: added a name to the form so tha the javascript works
1331 :     push( @$html, $cgi->start_form( -method => 'post',
1332 : golsen 1.76 -target => $target,
1333 :     -action => 'fid_checked.cgi',
1334 :     -name => 'fid_checked'
1335 : parrello 1.60 ),
1336 :     $cgi->hidden(-name => 'fid', -value => $peg),
1337 :     $cgi->hidden(-name => 'user', -value => $user),
1338 :     $cgi->br,
1339 :     "For Selected (checked) sequences: ",
1340 :     $cgi->submit('align'),
1341 :     $cgi->submit('view annotations'),
1342 : golsen 1.106 $cgi->submit('get sequences'),
1343 : parrello 1.60 $cgi->submit('show regions')
1344 :     );
1345 :    
1346 :     if ($user) {
1347 :     my $help_url = "Html/help_for_assignments_and_rules.html";
1348 :     push ( @$html, $cgi->br, $cgi->br,
1349 : golsen 1.100 "<a href=$help_url target=\"SEED_or_SPROUT_help\">Help on Assignments, Rules, and Checkboxes</a>",
1350 : parrello 1.60 $cgi->br, $cgi->br,
1351 :     $cgi->submit('assign/annotate')
1352 :     );
1353 :    
1354 :     if ($cgi->param('translate')) {
1355 :     push( @$html, $cgi->submit('add rules'),
1356 :     $cgi->submit('check rules'),
1357 :     $cgi->br
1358 :     );
1359 :     }
1360 :     }
1361 : efrank 1.1
1362 : parrello 1.60 push( @$html, $cgi->br,
1363 :     $cgi->checkbox( -name => 'checked',
1364 :     -value => $peg,
1365 :     -override => 1,
1366 :     -checked => 1,
1367 :     -label => ""
1368 :     )
1369 :     );
1370 :    
1371 :     my $col_hdrs;
1372 : overbeek 1.176 my $color_help = "(<A href=\"Html/similarity_region_colors.html\" target=\"SEED_or_SPROUT_help\">colors</A>)";
1373 :     my $func_clr_help = "(<A href=\"Html/function_colors.html\" target=\"SEED_or_SPROUT_help\">function colors</A>)";
1374 : golsen 1.97
1375 : parrello 1.60 if ($user && $cgi->param('translate')) {
1376 :     push( @$html, " ASSIGN to/Translate from/SELECT current PEG", $cgi->br,
1377 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1378 : golsen 1.97 "ASSIGN from/Translate to current PEG: ", shift @from
1379 : parrello 1.60 );
1380 :     $col_hdrs = [ "ASSIGN to<hr>Translate from",
1381 :     $expand_groups ? "family" : (),
1382 :     $expand_groups ? "size" : (),
1383 :     "Similar sequence",
1384 :     "E-val<br>% iden",
1385 : overbeek 1.177 "region in<br>sim seq<br>$color_help",
1386 :     "region in<br>peg<br>$color_help",
1387 : parrello 1.60 "ASSIGN from<hr>Translate to",
1388 : overbeek 1.90 "In Sub",
1389 : overbeek 1.143 &evidence_codes_link($cgi),
1390 : golsen 1.97 "Function<br>$func_clr_help",
1391 : parrello 1.60 "Organism",
1392 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1393 : parrello 1.60 ];
1394 :     } elsif ($user) {
1395 :     push( @$html, " ASSIGN to/SELECT current PEG", $cgi->br,
1396 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1397 : golsen 1.97 "ASSIGN from current PEG: ", shift @from
1398 : parrello 1.60 );
1399 :     $col_hdrs = [ "ASSIGN to<hr>SELECT",
1400 :     $expand_groups ? "family" : (),
1401 :     $expand_groups ? "size" : (),
1402 :     "Similar sequence",
1403 :     "E-val<br>% iden",
1404 : overbeek 1.178 "region in<br>sim seq<br>$color_help",
1405 :     "region in<br>peg<br>$color_help",
1406 : overbeek 1.179 "Assign from",
1407 : parrello 1.60 "In Sub",
1408 : overbeek 1.143 &evidence_codes_link($cgi),
1409 : golsen 1.97 "Function<br>$func_clr_help",
1410 : parrello 1.60 "Organism",
1411 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1412 : parrello 1.60 ];
1413 :     } else {
1414 :     push(@$html, " SELECT current PEG", $cgi->br );
1415 :     $col_hdrs = [ "SELECT",
1416 :     $expand_groups ? "family" : (),
1417 :     $expand_groups ? "size" : (),
1418 :     "Similar sequence",
1419 :     "E-val<br>% iden",
1420 :     "region in<br>similar sequence<br>$color_help",
1421 :     "region in<br>$peg<br>$color_help",
1422 : golsen 1.97 "In Sub",
1423 : overbeek 1.143 &evidence_codes_link($cgi),
1424 : golsen 1.97 "Function<br>$func_clr_help",
1425 : parrello 1.60 "Organism",
1426 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1427 : parrello 1.60 ];
1428 :     }
1429 : efrank 1.1
1430 : redwards 1.37 # RAE Add the check all/uncheck all boxes.
1431 :     push (@$html, $cgi->br, &HTML::java_buttons("fid_checked", "checked"), $cgi->br);
1432 :    
1433 : parrello 1.60 #
1434 :     # Total rewrite of sim table code: cleaner program flow; omitting
1435 :     # empty columns; colorizing region-of-similarity cells -- GJO
1436 :     #
1437 :     # Start the similarity table with "Caption" and header row
1438 :    
1439 :     my $ncol = @$col_hdrs;
1440 :     push( @$html, "<TABLE border cols=$ncol>\n",
1441 :     "\t<Caption><h2>Similarities</h2></Caption>\n",
1442 :     "\t<TR>\n\t\t<TH>",
1443 :     join( "</TH>\n\t\t<TH>", @$col_hdrs ),
1444 :     "</TH>\n\t</TR>\n"
1445 :     );
1446 :    
1447 : golsen 1.97 #
1448 : golsen 1.93 # Grouping by genome is hard to see. This is an attempt to make it more obvious
1449 :     # by consolidating the "Organism" for all rows in which it is repeated. -- GJO
1450 : golsen 1.97 #
1451 :     # Let's figure out the function here too. This will allow color to be
1452 :     # specific for more than one function. For example, we can color:
1453 :     #
1454 :     # Identical function white
1455 :     # Most common alternative brown
1456 :     # Next most common alternatives red, orange, yellow, green, blue, and violet
1457 :     # Any additional alternatives gray
1458 :     #
1459 : golsen 1.93
1460 :     my $sim;
1461 : golsen 1.97 my ( $id2, $func, $genome, $org, $color, $info, $prev_genome, $prev_sim );
1462 :     my %func_cnt = ();
1463 :    
1464 : golsen 1.93 foreach $sim ( @sims ) {
1465 :     $id2 = $sim->id2;
1466 : golsen 1.97
1467 :     $func = html_enc( scalar trans_function_of( $cgi, $fig_or_sprout, $id2, $user ) );
1468 :     $func && $func_cnt{ $func }++;
1469 :    
1470 : golsen 1.93 if ( $group_by_genome && ( ( $genome ) = $id2 =~ /fig\|(\d+\.\d+)\./ )
1471 :     && ( $genome eq $prev_genome ) )
1472 :     {
1473 : golsen 1.97 $prev_sim->[-1]->[3]++; # Increase row span of org
1474 :     push @$sim, [ $func, "", $color, 0 ]; # No org name, prev_color, no row span
1475 : golsen 1.93 }
1476 :     else
1477 :     {
1478 :     ( $org, $color ) = org_and_color_of( $fig_or_sprout, $id2 );
1479 : golsen 1.97 push @$sim, [ $func, html_enc( $org ), $color, 1 ];
1480 : golsen 1.93 $prev_genome = $genome || "";
1481 :     $prev_sim = $sim;
1482 :     }
1483 :     }
1484 :    
1485 : golsen 1.97 # Build a function to color translation table based on frequence of function.
1486 :     # Reserve white for the current function.
1487 :    
1488 :     my %func_color;
1489 :     $func_cnt{ $current_func } && delete $func_cnt{ $current_func };
1490 :     $func_color{ $current_func } = "#FFFFFF";
1491 : parrello 1.108
1492 : golsen 1.97 # Assign other colors until we run out:
1493 :    
1494 :     my @colors = qw( #EECCAA #FFAAAA #FFCC66 #FFFF00 #AAFFAA #BBBBFF #FFAAFF );
1495 :     for ( sort { $func_cnt{ $b } <=> $func_cnt{ $a } } keys %func_cnt )
1496 :     {
1497 :     $func_color{ $_ } = ( shift @colors ) || "#DDDDDD";
1498 :     }
1499 :    
1500 : parrello 1.60 # Add the table data, row-by-row
1501 :    
1502 : overbeek 1.90 my $alia = (! $hide_alias);
1503 : parrello 1.60 foreach $sim ( @sims ) {
1504 :     my $id2 = $sim->id2;
1505 : golsen 1.76
1506 : parrello 1.60 my $cbox = &translatable($fig_or_sprout,$id2) ?
1507 :     qq(<input type=checkbox name=checked value="$id2">) : "";
1508 :    
1509 :     my( $family, $sz, $funcF, $fam_link );
1510 : overbeek 1.118 $family = $sz = $funcF = $fam_link = "";
1511 : parrello 1.60
1512 :     my $id2_link = &HTML::set_prot_links($cgi,$id2);
1513 :     chomp $id2_link;
1514 :    
1515 :     my @in_sub = &peg_to_subsystems($fig_or_sprout,$id2);
1516 :     my $in_sub;
1517 : overbeek 1.141
1518 : parrello 1.60 if (@in_sub > 0) {
1519 :     $in_sub = @in_sub;
1520 : overbeek 1.158 # RAE: add a javascript popup with all the subsystems
1521 :     my $ss_list=join "<br>", map { my $g = $_; $g =~ s/\_/ /g; $_ = $g } sort {$a cmp $b} @in_sub;
1522 :     $in_sub = $cgi->a(
1523 : redwards 1.160 {id=>"subsystems", onMouseover=>"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Subsystems', '$ss_list', ''); this.tooltip.addHandler(); return false;"}, $in_sub);
1524 : parrello 1.60 } else {
1525 : overbeek 1.74 $in_sub = "&nbsp;";
1526 : parrello 1.60 }
1527 :    
1528 : redwards 1.160 # evidence codes moved here so I can add a tool tip for them
1529 :     my $ev_codes=" &nbsp; ";
1530 :     my @ev_codes=&evidence_codes($fig_or_sprout,$id2);
1531 :     if (scalar(@ev_codes) && $ev_codes[0])
1532 :     {
1533 :     my $ev_code_help=join("<br />", map {&evidence_codes_explain($_)} @ev_codes);
1534 :     $ev_codes = $cgi->a(
1535 :     {id=>"evidence_codes", onMouseover=>"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Evidence Codes', '$ev_code_help', ''); this.tooltip.addHandler(); return false;"}, join("<br />", @ev_codes));
1536 :     }
1537 :    
1538 : parrello 1.60 my $psc = $sim->psc;
1539 :     my $iden = $sim->iden;
1540 :     my $ln1 = $sim->ln1;
1541 :     my $ln2 = $sim->ln2;
1542 :     my $b1 = $sim->b1;
1543 :     my $e1 = $sim->e1;
1544 :     my $b2 = $sim->b2;
1545 :     my $e2 = $sim->e2;
1546 :     my $d1 = abs($e1 - $b1) + 1;
1547 :     my $d2 = abs($e2 - $b2) + 1;
1548 :     my $reg1 = "$b1-$e1 (<b>$d1/$ln1</b>)";
1549 :     my $color1 = match_color( $b1, $e1, $ln1 );
1550 :     my $reg2 = "$b2-$e2 (<b>$d2/$ln2</b>)";
1551 :     my $color2 = match_color( $b2, $e2, $ln2 );
1552 :     my $radio = $user ? shift @from : undef;
1553 : golsen 1.97
1554 :     # Retrieve the Function and Organism data that was pushed on the end of the sim:
1555 :    
1556 :     my ( $func2, $org, $oc, $rowspan ) = @{$sim->[-1]};
1557 : golsen 1.93
1558 :     ## RAE Added color3. This will color function cells that do not match the original
1559 : parrello 1.60 ## annotation. This makes is a lot easier to see what is different (e.g. caps/spaces, etc)
1560 : golsen 1.97
1561 :     my $color3 = $func2 && $func_color{ $func2 } || "#DDDDDD";
1562 : parrello 1.60
1563 : golsen 1.93 if ( $funcF && ( $funcF ne $func2 ) ) { $func2 = "$funcF<br>$func2" }
1564 : golsen 1.97 $func2 ||= "&nbsp;";
1565 : parrello 1.60
1566 : golsen 1.97 my $aliases = undef;
1567 :     if ( $alia )
1568 :     {
1569 :     $aliases = html_enc( join( ", ", &feature_aliasesL($fig_or_sprout,$id2) ) );
1570 :     $aliases = &HTML::set_prot_links( $cgi, $aliases );
1571 :     $aliases ||= "&nbsp;";
1572 :     }
1573 : parrello 1.60
1574 :     # Okay, everything is calculated, let's "print" the row datum-by-datum:
1575 :    
1576 :     push( @$html, "\t<TR>\n",
1577 :     #
1578 :     # Colorize check box by Domain
1579 :     #
1580 :     "\t\t<TD Align=center Bgcolor=$oc>$cbox</TD>\n",
1581 :     $expand_groups ? "\t\t<TD>$fam_link</TD>/n" : (),
1582 :     $expand_groups ? "\t\t<TD>$sz</TD>\n" : (),
1583 :     "\t\t<TD Nowrap>$id2_link</TD>\n",
1584 :     "\t\t<TD Nowrap>$psc<br>$iden\%</TD>\n",
1585 :     "\t\t<TD Nowrap Bgcolor=$color2>$reg2</TD>\n",
1586 :     "\t\t<TD Nowrap Bgcolor=$color1>$reg1</TD>\n",
1587 :     $user ? "\t\t<TD Align=center>$radio</TD>\n" : (),
1588 : golsen 1.100 "\t\t<TD Align=center>$in_sub</TD>",
1589 : redwards 1.160 "\t\t<TD Align=center>$ev_codes</TD>",
1590 : parrello 1.60 "\t\t<TD Bgcolor=$color3>$func2</TD>\n",
1591 :     #
1592 :     # Colorize organism by Domain
1593 :     #
1594 : golsen 1.93 $rowspan ? "\t\t<TD Rowspan=$rowspan Bgcolor=$oc>$org</TD>\n" : (),
1595 : parrello 1.60 $alia ? "\t\t<TD>$aliases</TD>\n" : (),
1596 :     "\t</TR>\n"
1597 :     );
1598 :     }
1599 : overbeek 1.11
1600 : parrello 1.60 push( @$html, "</TABLE>\n" );
1601 :     push( @$html, $cgi->end_form );
1602 : efrank 1.1 }
1603 :     }
1604 :    
1605 : golsen 1.18 #
1606 :     # Support functions for writing the similarities
1607 :     #
1608 :     # This is a sufficient set of escaping for text in HTML:
1609 :     #
1610 :    
1611 :     sub html_enc { $_ = $_[0]; s/\&/&amp;/g; s/\>/&gt;/g; s/\</&lt;/g; $_ }
1612 :    
1613 :     #
1614 :     # Make a background color that reflects the position and extent of a
1615 :     # matching region.
1616 :     #
1617 :     # Left side is red; right side is blue.
1618 :     # Long match is white or pastel; short match is saturated color.
1619 :     #
1620 :    
1621 :     sub match_color {
1622 :     my ( $b, $e, $n ) = @_;
1623 :     my ( $l, $r ) = ( $e > $b ) ? ( $b, $e ) : ( $e, $b );
1624 :     # my $hue = 3/4 * 0.5*($l+$r)/$n - 1/24;
1625 :     my $hue = 5/6 * 0.5*($l+$r)/$n - 1/12;
1626 :     my $cov = ( $r - $l + 1 ) / $n;
1627 :     my $sat = 1 - 10 * $cov / 9;
1628 :     my $br = 1;
1629 :     rgb2html( hsb2rgb( $hue, $sat, $br ) );
1630 :     }
1631 :    
1632 :     #
1633 :     # Convert HSB to RGB. Hue is taken to be in range 0 - 1 (red to red);
1634 :     #
1635 :    
1636 :     sub hsb2rgb {
1637 :     my ( $h, $s, $br ) = @_;
1638 :     $h = 6 * ($h - floor($h)); # Hue is made cyclic modulo 1
1639 :     if ( $s > 1 ) { $s = 1 } elsif ( $s < 0 ) { $s = 0 }
1640 :     if ( $br > 1 ) { $br = 1 } elsif ( $br < 0 ) { $br = 0 }
1641 :     my ( $r, $g, $b ) = ( $h <= 3 ) ? ( ( $h <= 1 ) ? ( 1, $h, 0 )
1642 :     : ( $h <= 2 ) ? ( 2 - $h, 1, 0 )
1643 :     : ( 0, 1, $h - 2 )
1644 :     )
1645 :     : ( ( $h <= 4 ) ? ( 0, 4 - $h, 1 )
1646 :     : ( $h <= 5 ) ? ( $h - 4, 0, 1 )
1647 :     : ( 1, 0, 6 - $h )
1648 :     );
1649 :     ( ( $r * $s + 1 - $s ) * $br,
1650 :     ( $g * $s + 1 - $s ) * $br,
1651 :     ( $b * $s + 1 - $s ) * $br
1652 :     )
1653 :     }
1654 :    
1655 :     #
1656 :     # Convert an RGB value to an HTML color string:
1657 :     #
1658 :    
1659 :     sub rgb2html {
1660 :     my ( $r, $g, $b ) = @_;
1661 :     if ( $r > 1 ) { $r = 1 } elsif ( $r < 0 ) { $r = 0 }
1662 :     if ( $g > 1 ) { $g = 1 } elsif ( $g < 0 ) { $g = 0 }
1663 :     if ( $b > 1 ) { $b = 1 } elsif ( $b < 0 ) { $b = 0 }
1664 :     sprintf("\"#%02x%02x%02x\"", int(255.999*$r), int(255.999*$g), int(255.999*$b) )
1665 :     }
1666 :    
1667 :     #
1668 :     # floor could be gotten from POSIX::, but why bother?
1669 :     #
1670 :    
1671 :     sub floor {
1672 :     my $x = $_[0];
1673 :     defined( $x ) || return undef;
1674 :     ( $x >= 0 ) || ( int($x) == $x ) ? int( $x ) : -1 - int( - $x )
1675 :     }
1676 :    
1677 :    
1678 : golsen 1.76 #------------------------------------------------------------------------
1679 :     # Generate similarity query forms for the SEED. Consolidates things like
1680 :     # style and defaults in one place.
1681 :     #
1682 :     # my $user = $cgi->param('user') || "";
1683 :     # my $short_form = 0;
1684 :     # my $SimParam = sims_request_form( $fig, $cgi, $html, $peg, $user, $short_form );
1685 :     #------------------------------------------------------------------------
1686 :    
1687 :     sub sims_request_form {
1688 :     my ( $fig, $cgi, $html, $peg, $user, $short_form ) = @_;
1689 :    
1690 : overbeek 1.122 my $trans_role = $cgi->param('translate') || 0;
1691 :    
1692 :     if ($cgi->param('SPROUT'))
1693 :     {
1694 :     &sprout_sims_request_form($cgi,$html,$peg,$trans_role,$user);
1695 :     return;
1696 :     }
1697 :    
1698 : golsen 1.76 # Read available parameters, and fill in defaults:
1699 :    
1700 :     my $maxN = defined( $cgi->param('maxN') ) ? $cgi->param('maxN') : 50;
1701 :     my $max_expand = defined( $cgi->param('max_expand') ) ? $cgi->param('max_expand') : 5;
1702 :     my $maxP = defined( $cgi->param('maxP') ) ? $cgi->param('maxP') : 1.0e-5;
1703 : golsen 1.98 my $select = $cgi->param('select') || 'all';
1704 :     my $show_env = $cgi->param('show_env') || 0;
1705 :     my $hide_alias = $cgi->param('hide_alias') || 0;
1706 : golsen 1.100 my $sort_by = $cgi->param('sort_by') || 'bits';
1707 : golsen 1.98 my $group_by_genome = $cgi->param('group_by_genome') || 0;
1708 :     my $expand_groups = $cgi->param('expand_groups') || 0;
1709 : golsen 1.76
1710 : golsen 1.77 # New similarity options
1711 :    
1712 :     # Act on request for more or fewer sim options
1713 : golsen 1.76
1714 :     my $extra_opt = defined( $cgi->param('extra_opt') ) ? $cgi->param('extra_opt') : 0;
1715 : golsen 1.77 if ( $cgi->param('more sim options') ) {
1716 :     $extra_opt = 1;
1717 :     $cgi->delete('more sim options');
1718 :     }
1719 :     if ( $cgi->param('fewer sim options') ) {
1720 :     $extra_opt = 0;
1721 :     $cgi->delete('fewer sim options');
1722 :     }
1723 :    
1724 :     # Make defaults completely open (match original behavior)
1725 :    
1726 :     my $min_sim = $extra_opt && defined( $cgi->param('min_sim') ) ? $cgi->param('min_sim') : 0;
1727 : golsen 1.100 my $sim_meas = $extra_opt && defined( $cgi->param('sim_meas') ) ? $cgi->param('sim_meas') : 'id';
1728 : golsen 1.77 my $min_q_cov = $extra_opt && defined( $cgi->param('min_q_cov') ) ? $cgi->param('min_q_cov') : 0;
1729 :     my $min_s_cov = $extra_opt && defined( $cgi->param('min_s_cov') ) ? $cgi->param('min_s_cov') : 0;
1730 : golsen 1.76
1731 : golsen 1.77 # New parameters. Not yet implimented.
1732 : golsen 1.76 # The defaults for representative sequences might be tuned:
1733 :    
1734 : golsen 1.77 my $show_rep = $extra_opt && defined( $cgi->param('show_rep') ) ? $cgi->param('show_rep') : 0;
1735 :     my $max_sim = $extra_opt && defined( $cgi->param('max_sim') ) ? $cgi->param('max_sim') : 0.70;
1736 :     my $dyn_thrsh = $extra_opt && defined( $cgi->param('dyn_thrsh') ) ? $cgi->param('dyn_thrsh') : 0;
1737 :     my $save_dist = $extra_opt && defined( $cgi->param('save_dist') ) ? $cgi->param('save_dist') : 0.80;
1738 : golsen 1.76
1739 :     # Mark some of the sequences automatically?
1740 :    
1741 : golsen 1.77 my $chk_which = $extra_opt && defined( $cgi->param('chk_which') ) ? $cgi->param('chk_which') : 'none';
1742 :    
1743 : golsen 1.76 # Use $cgi->param('more similarities') to drive increase in maxN and max_expand
1744 :    
1745 :     if ( $cgi->param('more similarities') ) {
1746 :     $maxN *= 2;
1747 :     $max_expand *= 2;
1748 :     $cgi->delete('more similarities');
1749 :     }
1750 :    
1751 : golsen 1.100 # Sanity checks on fixed vocabulary parameter values:
1752 : golsen 1.76
1753 : golsen 1.102 my %select_opts = map { ( $_, 1 ) } qw( all fig figx fig_pref figx_pref );
1754 :     my %sort_opts = map { ( $_, 1 ) } qw( bits id id2 bpp bpp2 );
1755 :     my %sim_meas_opts = map { ( $_, 1 ) } qw( id bpp );
1756 :     my %chk_which_opts = map { ( $_, 1 ) } qw( none all rep );
1757 :    
1758 :     $select = 'all' unless $select_opts{ $select };
1759 :     $sort_by = 'bits' unless $sort_opts{ $sort_by };
1760 :     $sim_meas = 'id' unless $sim_meas_opts{ $sim_meas };
1761 :     $chk_which = 'none' unless $chk_which_opts{ $chk_which };
1762 : golsen 1.76
1763 : golsen 1.100 # We have processed all options. Use them to build forms.
1764 : golsen 1.76
1765 :     # Checkmarks for input tags
1766 :    
1767 : golsen 1.102 my $chk_select_all = select_if( $select eq 'all' );
1768 :     my $chk_select_figp = select_if( $select eq 'fig_pref' );
1769 :     my $chk_select_figxp = select_if( $select eq 'figx_pref' );
1770 :     my $chk_select_fig = select_if( $select eq 'fig' );
1771 :     my $chk_select_figx = select_if( $select eq 'figx' );
1772 :     my $chk_show_env = chked_if( $show_env );
1773 :     my $chk_hide_alias = chked_if( $hide_alias );
1774 : overbeek 1.90 my $chk_group_by_genome = chked_if( $group_by_genome );
1775 : golsen 1.102 my $chk_sort_by_id = select_if( $sort_by eq 'id' );
1776 :     my $chk_sort_by_id2 = select_if( $sort_by eq 'id2' );
1777 :     my $chk_sort_by_bits = select_if( $sort_by eq 'bits' );
1778 :     my $chk_sort_by_bpp = select_if( $sort_by eq 'bpp' );
1779 :     my $chk_sort_by_bpp2 = select_if( $sort_by eq 'bpp2' );
1780 : golsen 1.76
1781 :     # Features unique to the long form:
1782 :    
1783 :     if ( $short_form )
1784 :     {
1785 :     # Use a here document to push the short version of the similarities form
1786 :     # on @$html (many values are passed as hidden inputs).
1787 :    
1788 :     push @$html, <<"End_Short_Form";
1789 :    
1790 :     <FORM Action=\"protein.cgi#Similarities\">
1791 :     <input type=hidden name=prot value=\"$peg\">
1792 :     <input type=hidden name=sims value=1>
1793 :     <input type=hidden name=fid value=\"$peg\">
1794 :     <input type=hidden name=user value=\"$user\">
1795 :     <input type=hidden name=translate value=$trans_role>
1796 :    
1797 : golsen 1.103 &nbsp;&nbsp;&nbsp; Max sims:<input type=text name=maxN size=5 value=$maxN> &nbsp;&nbsp;
1798 : golsen 1.100 Max expand:<input type=text name=max_expand size=5 value=$max_expand> &nbsp;&nbsp;
1799 :     Max E-val:<input type=text name=maxP size=8 value=$maxP> &nbsp;&nbsp;
1800 : golsen 1.98 <select name=select>
1801 : golsen 1.102 <option value=all $chk_select_all>Show all databases</option>
1802 :     <option value=fig_pref $chk_select_figp>Prefer FIG IDs (to max exp)</option>
1803 :     <option value=figx_pref $chk_select_figxp>Prefer FIG IDs (all)</option>
1804 :     <option value=fig $chk_select_fig>Just FIG IDs (to max exp)</option>
1805 :     <option value=figx $chk_select_figx>Just FIG IDs (all)</option>
1806 : golsen 1.100 </select> &nbsp;&nbsp;
1807 :     Show Env. samples:<input type=checkbox name=show_env value=1 $chk_show_env> &nbsp;&nbsp;
1808 : golsen 1.98 Hide aliases:<input type=checkbox name=hide_alias value=1 $chk_hide_alias><br />
1809 :    
1810 : golsen 1.103 <input type=submit name=Similarities value=Similarities> &nbsp;&nbsp;
1811 : golsen 1.98 Sort by
1812 :     <select name=sort_by>
1813 : golsen 1.101 <option value=bits $chk_sort_by_bits>score</option>
1814 :     <option value=id2 $chk_sort_by_id2>percent identity*</option>
1815 :     <option value=bpp2 $chk_sort_by_bpp2>score per position*</option>
1816 : golsen 1.98 <option value=id $chk_sort_by_id>percent identity</option>
1817 :     <option value=bpp $chk_sort_by_bpp>score per position</option>
1818 : golsen 1.100 </select> &nbsp;&nbsp;
1819 :     Group by genome:<input type=checkbox name=group_by_genome value=1 $chk_group_by_genome>
1820 :     &nbsp;&nbsp;&nbsp;
1821 : overbeek 1.168 <A href=\"Html/similarities_options.html\" target=\"SEED_or_SPROUT_help\" class=\"help\">Help with SEED similarities options</A><BR />
1822 : golsen 1.76 </FORM>
1823 : golsen 1.100
1824 : golsen 1.76 End_Short_Form
1825 :    
1826 :     }
1827 :     else
1828 :     {
1829 :     # Navigation buttons
1830 :    
1831 :     my ( $prev_peg_btn, $next_peg_btn ) = ( "", "" );
1832 :     my ( $prefix, $protnum ) = $peg =~ /^(.*\.)(\d+)$/;
1833 :     if ( $prefix && $protnum ) {
1834 :     if ( ( $protnum > 1 ) && &translatable( $fig_or_sprout, $prefix . ($protnum-1) ) )
1835 :     {
1836 :     $prev_peg_btn = $cgi->submit('previous PEG');
1837 :     }
1838 :     if ( &translatable( $fig_or_sprout, $prefix . ($protnum+1) ) )
1839 :     {
1840 :     $next_peg_btn = $cgi->submit('next PEG');
1841 :     }
1842 :     }
1843 :    
1844 :     # Add/remove extra options button
1845 :    
1846 :     my $extra_opt_btn = $extra_opt ? $cgi->submit('fewer sim options')
1847 :     : $cgi->submit('more sim options');
1848 :    
1849 :     # Checkmarks for input tags
1850 :    
1851 :     my $chk_sim_meas_id = select_if( $sim_meas eq 'id' );
1852 :     my $chk_sim_meas_bpp = select_if( $sim_meas eq 'bpp' );
1853 :     my $chk_show_rep = chked_if( $show_rep );
1854 :     my $chk_dyn_thrsh = chked_if( $dyn_thrsh );
1855 :     my $chk_chk_none = select_if( $chk_which eq 'none' );
1856 :     my $chk_chk_all = select_if( $chk_which eq 'all' );
1857 :     my $chk_chk_rep = select_if( $chk_which eq 'rep' );
1858 :    
1859 : golsen 1.77 # Finally time to write some HTML
1860 :     #
1861 : golsen 1.76 # Default options
1862 :    
1863 :     push @$html, <<"End_Default_Options";
1864 : golsen 1.98
1865 : golsen 1.76 <FORM Action=\"protein.cgi#Similarities\">
1866 :     <input type=hidden name=prot value=\"$peg\">
1867 :     <input type=hidden name=sims value=1>
1868 :     <input type=hidden name=fid value=\"$peg\">
1869 :     <input type=hidden name=user value=\"$user\">
1870 :     <input type=hidden name=translate value=$trans_role>
1871 :    
1872 : golsen 1.100 Max sims:<input type=text name=maxN size=5 value=$maxN> &nbsp;&nbsp;
1873 :     Max expand:<input type=text name=max_expand size=5 value=$max_expand> &nbsp;&nbsp;
1874 :     Max E-val:<input type=text name=maxP size=8 value=$maxP> &nbsp;&nbsp;
1875 : golsen 1.98 <select name=select>
1876 : golsen 1.102 <option value=all $chk_select_all>Show all databases</option>
1877 :     <option value=fig_pref $chk_select_figp>Prefer FIG IDs (to max exp)</option>
1878 :     <option value=figx_pref $chk_select_figxp>Prefer FIG IDs (all)</option>
1879 :     <option value=fig $chk_select_fig>Just FIG IDs (to max exp)</option>
1880 :     <option value=figx $chk_select_figx>Just FIG IDs (all)</option>
1881 : golsen 1.100 </select> &nbsp;&nbsp;
1882 :     Show Env. samples:<input type=checkbox name=show_env value=1 $chk_show_env> &nbsp;&nbsp;
1883 : golsen 1.98 Hide aliases:<input type=checkbox name=hide_alias value=1 $chk_hide_alias><br />
1884 :    
1885 :     Sort by
1886 :     <select name=sort_by>
1887 : golsen 1.101 <option value=bits $chk_sort_by_bits>score</option>
1888 :     <option value=id2 $chk_sort_by_id2>percent identity*</option>
1889 :     <option value=bpp2 $chk_sort_by_bpp2>score per position*</option>
1890 : golsen 1.98 <option value=id $chk_sort_by_id>percent identity</option>
1891 :     <option value=bpp $chk_sort_by_bpp>score per position</option>
1892 : golsen 1.100 </select> &nbsp;&nbsp;
1893 :     Group by genome:<input type=checkbox name=group_by_genome value=1 $chk_group_by_genome> &nbsp;&nbsp;&nbsp;
1894 : overbeek 1.168 <A href=\"Html/similarities_options.html\" target=\"SEED_or_SPROUT_help\" class=\"help\">Help with SEED similarities options</A><br />
1895 : golsen 1.76 End_Default_Options
1896 :    
1897 :     # Extra options
1898 :    
1899 :     push @$html, <<"End_Extra_Options" if $extra_opt;
1900 : golsen 1.77 <input type=hidden name=extra_opt value=\"$extra_opt\">
1901 :    
1902 : golsen 1.76 Min similarity:<input type=text name=min_sim size=5 value=$min_sim>
1903 : golsen 1.98 defined by
1904 : golsen 1.76 <select name=sim_meas>
1905 : golsen 1.98 <option value=id $chk_sim_meas_id>identities (0-100%)</option>
1906 :     <option value=bpp $chk_sim_meas_bpp>score per position (0-2 bits)</option>
1907 : golsen 1.100 </select> &nbsp;&nbsp;
1908 :     Min query cover (%):<input type=text name=min_q_cov size=5 value=$min_q_cov> &nbsp;&nbsp;
1909 : golsen 1.98 Min subject cover (%):<input type=text name=min_s_cov size=5 value=$min_s_cov><br />
1910 : golsen 1.76
1911 : golsen 1.77 <!-- Hide unimplimented options
1912 : golsen 1.76 <TABLE Cols=2>
1913 :     <TR>
1914 :     <TD Valign=top><input type=checkbox name=show_rep $chk_show_rep></TD>
1915 :     <TD> Show only representative sequences whose similarities to one another
1916 :     are less than <input type=text size=5 name=max_sim value=$max_sim>
1917 :     <br />
1918 :     <input type=checkbox name=dyn_thrsh value=1 $chk_dyn_thrsh> But keep sequences
1919 :     that are at least <input type=text size=5 name=save_dist value=$save_dist>
1920 :     times as distant from one another as from the query</TD>
1921 :     </TR>
1922 :     </TABLE>
1923 :    
1924 : golsen 1.77 <input type=hidden name=chk_which value=\"$chk_which\">
1925 :    
1926 : golsen 1.76 Automatically Select (check) which sequences:<select name=chk_which>
1927 :     <option value=none $chk_chk_none>none</option>
1928 :     <option value=all $chk_chk_all>all shown</option>
1929 :     <option value=rep $chk_chk_rep>representative set</option>
1930 :     </select><br />
1931 : golsen 1.77 -->
1932 : golsen 1.76 End_Extra_Options
1933 :    
1934 :     # Submit buttons
1935 :    
1936 :     push @$html, <<"End_of_Buttons";
1937 :     <input type=submit name='resubmit' value='resubmit'>
1938 :     <input type=submit name='more similarities' value='more similarities'>
1939 :     $prev_peg_btn
1940 :     $next_peg_btn
1941 : golsen 1.77 $extra_opt_btn
1942 : golsen 1.76 </FORM>
1943 : golsen 1.100
1944 : golsen 1.76 End_of_Buttons
1945 :    
1946 :     }
1947 :    
1948 :     # Return the current parameter values in a hash
1949 :    
1950 :     { maxN => $maxN,
1951 :     maxP => $maxP,
1952 :     max_expand => $max_expand,
1953 : golsen 1.98 select => $select,
1954 : golsen 1.76 show_env => $show_env,
1955 :     hide_alias => $hide_alias,
1956 : overbeek 1.90 group_by_genome => $group_by_genome,
1957 : golsen 1.76 trans_role => $trans_role,
1958 :     extra_opt => $extra_opt,
1959 :     min_sim => $min_sim,
1960 :     min_q_cov => $min_q_cov,
1961 :     min_s_cov => $min_s_cov,
1962 :     sim_meas => $sim_meas,
1963 : golsen 1.98 sort_by => $sort_by,
1964 : golsen 1.76 show_rep => $show_rep,
1965 :     max_sim => $max_sim,
1966 :     dyn_thrsh => $dyn_thrsh,
1967 :     save_dist => $save_dist,
1968 :     chk_which => $chk_which,
1969 :     expand_groups => $expand_groups
1970 :     }
1971 :     }
1972 :    
1973 : overbeek 1.122 sub sprout_sims_request_form {
1974 :     my($cgi,$html,$peg,$trans_role,$user) = @_;
1975 :    
1976 :     push @$html, <<"End_Short_Form";
1977 :    
1978 :     <FORM Action=\"protein.cgi\">
1979 :     <input type=hidden name=prot value=\"$peg\">
1980 :     <input type=hidden name=sims value=1>
1981 :     <input type=hidden name=SPROUT value=1>
1982 :     <input type=hidden name=user value=\"$user\">
1983 :     <input type=hidden name=translate value=$trans_role>
1984 :     <input type=submit name='Bidirectional Best Hits' value='Bidirectional Best Hits'>
1985 :    
1986 :     </FORM>
1987 :    
1988 :     End_Short_Form
1989 :     }
1990 :    
1991 : golsen 1.76
1992 :     #------------------------------------------------------------------------
1993 :     # Auxilliary function to acivate checkmark for input fields
1994 :     #------------------------------------------------------------------------
1995 :     sub chked_if { $_[0] ? 'checked ' : '' }
1996 :    
1997 :     sub select_if { $_[0] ? 'selected ' : '' }
1998 :    
1999 :    
2000 :    
2001 : efrank 1.1 ################# Context on the Chromosome ############################
2002 :    
2003 :     sub print_context {
2004 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg,$feat,$beg,$end) = @_;
2005 : olson 1.56
2006 : olson 1.57 if ($beg eq $end) { cluck "Have zero len"; }
2007 : efrank 1.1 my($contig1,$beg1,$end1,$strand,$max_so_far,$gap,$comment,$fc,$aliases);
2008 : overbeek 1.81 my($fid1,$sz,$color,$map,$gg,$n,$link,$in_neighborhood);
2009 : efrank 1.1
2010 : overbeek 1.41
2011 :     my $user = $cgi->param('user');
2012 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2013 :     push(@$html,$cgi->start_form(-action => &cgi_url . "/chromosomal_clusters.cgi"),
2014 :     $cgi->hidden(-name => 'SPROUT', -value => $sprout),
2015 : overbeek 1.41 $cgi->hidden(-name => "prot", -value => $peg),
2016 : overbeek 1.44 $cgi->hidden(-name => "uni", -value => 1),
2017 : overbeek 1.41 $cgi->hidden(-name => "user", -value => $user));
2018 :    
2019 : overbeek 1.109 my $in_cluster = &in_cluster_with($fig_or_sprout,$cgi,$peg);
2020 : overbeek 1.73 my $col_hdrs;
2021 : overbeek 1.112
2022 : redwards 1.130 # RAE Added Subsys col headers
2023 : overbeek 1.73 if ($cgi->param('SPROUT'))
2024 :     {
2025 : overbeek 1.143 $col_hdrs = ["fid","starts","ends","size","","gap","find<br>best<br>clusters","pins","fc-sc","SS",&evidence_codes_link($cgi),"comment","","","aliases"];
2026 : overbeek 1.73 }
2027 :     else
2028 :     {
2029 : overbeek 1.143 $col_hdrs = ["fid","starts","ends","size","","gap","find<br>best<br>clusters","pins","fc-sc","SS",&evidence_codes_link($cgi),"comment","aliases"];
2030 : overbeek 1.73 }
2031 :    
2032 : efrank 1.1 my($tab) = [];
2033 :     my $genes = [];
2034 : parrello 1.60
2035 : overbeek 1.109 my %coupled;
2036 : olson 1.148
2037 :     #
2038 :     # Make a pass over the features, determining what subsystems they appear in. Assign
2039 :     # unique numbers (names?) for them.
2040 :     #
2041 :    
2042 :     my %fid_to_subs;
2043 :     my %subs;
2044 :     for my $fid (@$feat)
2045 :     {
2046 :     my $subs = [&peg_to_subsystems($fig_or_sprout, $fid)];
2047 :     map { $subs{$_}++ } @$subs;
2048 :     $fid_to_subs{$fid} = $subs;
2049 :     }
2050 :    
2051 :     my $sub_idx = 1;
2052 :     my %sub_names;
2053 :     for my $sub (sort { $subs{$b} <=> $subs{$a} } keys %subs)
2054 :     {
2055 :     $sub_names{$sub} = $sub_idx++;
2056 :     }
2057 : overbeek 1.109
2058 :     my $fc_sc;
2059 : parrello 1.60 foreach $fid1 (@$feat) {
2060 : overbeek 1.119 my $best_clusters_link = "<a href=" . &cgi_url . "/homologs_in_clusters.cgi?prot=$fid1&user=$user&SPROUT=$sprout><img src=\"Html/button-cl.png\" border=\"0\"></a>";
2061 : overbeek 1.110 if (defined($fc_sc = $in_cluster->{$fid1}))
2062 : overbeek 1.109 {
2063 :     $fc = &pin_link($cgi,$fid1);
2064 :     }
2065 :     else
2066 :     {
2067 :     $fc = "";
2068 :     $fc_sc = "";
2069 :     }
2070 : efrank 1.1
2071 : parrello 1.60 my $aliases = join( ', ', &feature_aliasesL($fig_or_sprout,$fid1) );
2072 : olson 1.48 my $uniprot;
2073 :     if ($aliases =~ /(uni[^,]+)/) {
2074 :     # print STDERR "$1\n";
2075 :     $uniprot = $1;
2076 :     }
2077 : overbeek 1.68 $aliases = &HTML::set_prot_links($cgi,$aliases),
2078 :     $aliases =~ s/SPROUT=1/SPROUT=0/g;
2079 :     $aliases =~ s/[&;]user=[^&;]+[;&]/;/g;
2080 : overbeek 1.74 $aliases = $aliases ? $aliases : "&nbsp;";
2081 : overbeek 1.68
2082 : overbeek 1.73 my($to_seed,$to_gbrowse);
2083 :     $to_seed = $to_gbrowse = "";
2084 :     if ($cgi->param('SPROUT') && ($fid1 =~ /peg/))
2085 :     {
2086 :     $to_seed = &cgi_url . "/protein.cgi?prot=$fid1";
2087 :     $to_gbrowse = &cgi_url . $fig_or_sprout->get_gbrowse_feature_link($fid1);
2088 :     }
2089 :    
2090 :    
2091 : overbeek 1.68 ($contig1,$beg1,$end1) = &boundaries_of($fig_or_sprout,&feature_locationS($fig_or_sprout,$fid1));;
2092 :     $strand = ($beg1 < $end1) ? "+" : "-";
2093 :    
2094 :     my $function = &function_ofS($fig_or_sprout,$fid1);
2095 : olson 1.48 my $info = join ('<br/>', "<b>PEG:</b> ".$fid1, "<b>Contig:</b> ".$contig1, "<b>Begin:</b> ".$beg1, "<b>End:</b> ".$end1,$function ? "<b>Function:</b> ".$function : '', $uniprot ? "<b>Uniprot ID:</b> ".$uniprot : '');
2096 :    
2097 : parrello 1.60 if ($fid1 eq $peg) { $color = "green" }
2098 :     elsif ($fc) { $color = "blue" }
2099 :     else { $color = "red" }
2100 :    
2101 :     if ($fid1 =~ /peg\.(\d+)$/) {
2102 :     $n = $1;
2103 : overbeek 1.63 my $sprout = $cgi->param('SPROUT');
2104 :     $sprout = $sprout ? $sprout : "";
2105 : overbeek 1.161 $link = $cgi->url(-relative => 1) . "?prot=$fid1&user=$user&SPROUT=$sprout";
2106 : parrello 1.60 } elsif ($fid1 =~ /\.([a-z]+)\.\d+$/) {
2107 :     $n = uc $1;
2108 :     $link = "";
2109 :     } else {
2110 :     $n ="";
2111 :     $link = "";
2112 :     }
2113 :    
2114 :     push(@$genes,[&min($beg1,$end1),&max($beg1,$end1),($strand eq "+") ? "rightArrow" : "leftArrow", $color,$n,$link,$info]);
2115 :     if ($max_so_far) {
2116 :     $gap = (&min($beg1,$end1) - $max_so_far) - 1;
2117 :     } else {
2118 :     $gap = "";
2119 :     }
2120 :     $max_so_far = &max($beg1,$end1);
2121 : olson 1.48
2122 : efrank 1.1
2123 : parrello 1.60 if (&ftype($fid1) eq "peg") {
2124 :     $comment = &trans_function_of($cgi,$fig_or_sprout,$fid1,$user);
2125 :     } else {
2126 :     $comment = "";
2127 :     }
2128 : golsen 1.169 $comment = &set_ec_and_tc_links($fig_or_sprout,$cgi,&genome_of($fid1),$comment);
2129 : parrello 1.60 if ($fid1 eq $peg) {
2130 :     $comment = "\@bgcolor=\"#00FF00\":$comment";
2131 :     }
2132 :     $sz = abs($end1-$beg1)+1;
2133 :    
2134 : overbeek 1.74 $comment = $comment ? $comment : "&nbsp;";
2135 : redwards 1.130 # RAE Count the number of subsystems. This is just copied from elsewhere
2136 : olson 1.148 #my @in_sub = &peg_to_subsystems($fig_or_sprout,$fid1);
2137 :     my @in_sub = @{$fid_to_subs{$fid1}};
2138 : overbeek 1.154
2139 : redwards 1.130 my $in_sub;
2140 :     if (@in_sub > 0) {
2141 : overbeek 1.154 if ($is_sprout)
2142 :     {
2143 :     $in_sub = @in_sub;
2144 :     }
2145 :     else
2146 :     {
2147 :     $in_sub = @in_sub;
2148 : overbeek 1.158 $in_sub .= ": " . join(" ", map { $sub_names{$_} } sort {$b cmp $a} @in_sub);
2149 :     # RAE: add a javascript popup with all the subsystems
2150 :     # RAE: unless you assign $_ to $g,the map operates on the result of s///, i.e. the number of substitutions made. I think there is a cleaner
2151 :     # way to do this, eh Gary?
2152 :     my $ss_list=join "<br>", map { my $g = "$sub_names{$_} : $_"; $g =~ s/_/ /g; $_=$g } sort {$b cmp $a} @in_sub;
2153 :     $in_sub = $cgi->a(
2154 :     {id=>"subsystems", onMouseover=>"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Subsystems', '$ss_list', ''); this.tooltip.addHandler(); return false;"}, $in_sub),
2155 : overbeek 1.154 }
2156 : redwards 1.130 } else {
2157 :     $in_sub = "&nbsp;";
2158 :     }
2159 : redwards 1.160
2160 :     # Generate the text for the evidence codes so we can have the popup tool tips
2161 :     my $ev_codes=" &nbsp; ";
2162 :     my @ev_codes=&evidence_codes($fig_or_sprout,$fid1);
2163 :     if (scalar(@ev_codes) && $ev_codes[0])
2164 :     {
2165 :     my $ev_code_help=join("<br />", map {&evidence_codes_explain($_)} @ev_codes);
2166 :     $ev_codes = $cgi->a(
2167 :     {id=>"evidence_codes", onMouseover=>"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Evidence Codes', '$ev_code_help', ''); this.tooltip.addHandler(); return false;"}, join("<br />", @ev_codes));
2168 :     }
2169 :    
2170 :    
2171 : redwards 1.130
2172 : overbeek 1.73 if ($cgi->param('SPROUT'))
2173 :     {
2174 : olson 1.83 my($s_link, $g_link);
2175 :     if (0)
2176 :     {
2177 :     $s_link = "<a href=$to_seed>S</a>";
2178 :     $g_link = "<a href=$to_gbrowse>G</a>";
2179 :     }
2180 :     else
2181 :     {
2182 :     $s_link = "<a href=$to_seed><img src=\"Html/button-s.png\" border=\"0\"></a>";
2183 :     $g_link = "<a href=$to_gbrowse><img src=\"Html/button-g.png\" border=\"0\"></a>";
2184 :     }
2185 : overbeek 1.73 push(@$tab,[&HTML::fid_link($cgi,$fid1,"local"),$beg1,$end1,$sz,$strand,$gap,
2186 : overbeek 1.112 $best_clusters_link,
2187 : overbeek 1.124 $fc ? $fc : "&nbsp;",
2188 :     $fc_sc ? $fc_sc : "&nbsp;",
2189 : redwards 1.130 $in_sub,
2190 : overbeek 1.141 join("<br>",&evidence_codes($fig_or_sprout,$fid1)),
2191 : overbeek 1.73 $comment,
2192 : olson 1.83 $s_link,
2193 :     $g_link,
2194 : overbeek 1.81 $aliases]);
2195 : overbeek 1.73 }
2196 :     else
2197 :     {
2198 :     push(@$tab,[&HTML::fid_link($cgi,$fid1,"local"),$beg1,$end1,$sz,$strand,$gap,
2199 : overbeek 1.112 $best_clusters_link,
2200 : overbeek 1.109 $fc,$fc_sc,
2201 : redwards 1.130 $in_sub,
2202 : redwards 1.160 $ev_codes,
2203 : overbeek 1.73 $comment,
2204 : overbeek 1.81 $aliases]);
2205 : overbeek 1.73 }
2206 : efrank 1.1 }
2207 : overbeek 1.104 push(@$html,&HTML::make_table($col_hdrs,$tab,"Context on contig $contig1 from base $beg to $end (".(abs($end-$beg)+1)." bp)"));
2208 : overbeek 1.113 push(@$html,$cgi->end_form);
2209 : overbeek 1.53 return ($beg,$end,$genes);
2210 :     }
2211 :    
2212 :     sub print_graphics_context {
2213 :     my($beg,$end,$genes,$html) = @_;
2214 :    
2215 :     my $map = ["",$beg,$end,$genes];
2216 :     my $gg = [$map];
2217 : overbeek 1.2 push(@$html,@{ &GenoGraphics::render($gg,700,4,0,1) });
2218 : efrank 1.1 return;
2219 :     }
2220 :    
2221 :     sub assign_link {
2222 :     my($cgi,$func,$existing_func) = @_;
2223 :     my($assign_url,$assign_link);
2224 :    
2225 : parrello 1.60 if ($func && ((! $existing_func) || ($existing_func ne $func))) {
2226 :     $cgi->delete('request');
2227 : overbeek 1.161 $assign_url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=fast_assign&func=$func"; ## must encode
2228 : parrello 1.60 $assign_link = "<a href=\"$assign_url\">&nbsp;<=&nbsp;</a>";
2229 :     } else {
2230 :     $assign_link = "";
2231 : efrank 1.1 }
2232 :     return $assign_link;
2233 :     }
2234 :    
2235 :     sub pin_link {
2236 :     my($cgi,$peg) = @_;
2237 :     my $user = $cgi->param('user');
2238 :     $user = defined($user) ? $user : "";
2239 :    
2240 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2241 : overbeek 1.119 my $cluster_url = "chromosomal_clusters.cgi?prot=$peg&user=$user&uni=1&SPROUT=$sprout";
2242 : olson 1.83
2243 : overbeek 1.112 my $cluster_img = 0 ? "*" : '<img src="Html/button-pins-1.png" border="0">';
2244 : overbeek 1.114 my $cluster_link = "<a href=\"$cluster_url\" target=pinned_region.$$>$cluster_img</a>";
2245 : efrank 1.1 return $cluster_link;
2246 :     }
2247 :    
2248 : overbeek 1.84 sub set_ec_and_tc_links {
2249 : golsen 1.169 my($fig_or_sprout,$cgi,$org,$func) = @_;
2250 : parrello 1.167 Trace("Incoming functional assignment is \"$func\".") if T(EClink => 4);
2251 : parrello 1.60 if ($func =~ /^(.*)(\d+\.\d+\.\d+\.\d+)(.*)$/) {
2252 :     my $before = $1;
2253 :     my $ec = $2;
2254 :     my $after = $3;
2255 : parrello 1.167 Trace("Matched EC case: ID = $ec.") if T(EClink => 4);
2256 : golsen 1.169 return &set_ec_and_tc_links($fig_or_sprout,$cgi,$org,$before) . &set_ec_to_maps($fig_or_sprout,$cgi,$org,$ec) . &set_ec_and_tc_links($fig_or_sprout,$cgi,$org,$after);
2257 : overbeek 1.84 }
2258 :     elsif ($func =~ /^(.*)(TC \d+(\.[0-9A-Z]+){3,6})(.*)$/) {
2259 :     my $before = $1;
2260 :     my $tc = $2;
2261 :     my $after = $4;
2262 : parrello 1.167 Trace("Matched TC case: ID = $tc.") if T(EClink => 4);
2263 : golsen 1.169 return &set_ec_and_tc_links($fig_or_sprout,$cgi,$org,$before) . &set_tc_link($fig_or_sprout,$org,$tc) . &set_ec_and_tc_links($fig_or_sprout,$cgi,$org,$after);
2264 : efrank 1.1 }
2265 :     return $func;
2266 :     }
2267 :    
2268 : overbeek 1.84 sub set_tc_link {
2269 :     my($fig_or_sprout,$org,$tc) = @_;
2270 :    
2271 :     if ($tc =~ /^TC\s+(\S+)$/)
2272 :     {
2273 : olson 1.159 return "<a href=http://www.tcdb.org/tcdb/index.php?tc=$1&Submit=Lookup>$tc</a>";
2274 : overbeek 1.84 }
2275 :     return $tc;
2276 :     }
2277 : parrello 1.108
2278 : overbeek 1.84
2279 : efrank 1.1 sub set_ec_to_maps {
2280 : golsen 1.169 my($fig_or_sprout,$cgi,$org,$ec) = @_;
2281 : efrank 1.1
2282 : overbeek 1.53 my @maps = &ec_to_maps($fig_or_sprout,$ec);
2283 : parrello 1.60 if (@maps > 0) {
2284 :     $cgi->delete('request');
2285 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=ec_to_maps&ec=$ec&org=$org";
2286 : parrello 1.60 my $link = "<a href=\"$url\">$ec</a>";
2287 :     return $link;
2288 : efrank 1.1 }
2289 :     return $ec;
2290 :     }
2291 :    
2292 :     sub show_ec_to_maps {
2293 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$ec) = @_;
2294 : efrank 1.1
2295 :     my $ec = $cgi->param('ec');
2296 : parrello 1.60 if (! $ec) {
2297 :     push(@$html,$cgi->h1("Missing EC number"));
2298 :     return;
2299 : efrank 1.1 }
2300 :    
2301 : overbeek 1.53 my @maps = &ec_to_maps($fig_or_sprout,$ec);
2302 : parrello 1.60 if (@maps > 0) {
2303 :     my $col_hdrs = ["map","metabolic topic"];
2304 :     my $map;
2305 :     my $tab = [map { $map = $_; [&map_link($cgi,$map),&map_name($fig_or_sprout,$map)] } @maps];
2306 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$ec: " . &ec_name($fig_or_sprout,$ec)));
2307 : efrank 1.1 }
2308 :     }
2309 :    
2310 :     sub map_link {
2311 :     my($cgi,$map) = @_;
2312 :    
2313 :     $cgi->delete('request');
2314 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=link_to_map&map=$map";
2315 : efrank 1.1 my $link = "<a href=\"$url\">$map</a>";
2316 :     return $link;
2317 :     }
2318 :    
2319 :     sub link_to_map {
2320 : overbeek 1.53 my($fig_or_sprout,$cgi,$html) = @_;
2321 : efrank 1.1
2322 :     my $map = $cgi->param('map');
2323 : parrello 1.60 if (! $map) {
2324 :     push(@$html,$cgi->h1("Missing Map"));
2325 :     return;
2326 : efrank 1.1 }
2327 :    
2328 :     my $org = $cgi->param('org');
2329 : parrello 1.60 if (! $org) {
2330 :     push(@$html,$cgi->h1("Missing Org Parameter"));
2331 :     return;
2332 : efrank 1.1 }
2333 :     my$user = $cgi->param('user');
2334 :     $user = $user ? $user : "";
2335 :    
2336 :     $ENV{"REQUEST_METHOD"} = "GET";
2337 :     $ENV{"QUERY_STRING"} = "user=$user&map=$map&org=$org";
2338 :     my @out = `./show_kegg_map.cgi`;
2339 :     &HTML::trim_output(\@out);
2340 :     push(@$html,@out);
2341 :     }
2342 : parrello 1.60
2343 : efrank 1.1 sub aa_sequence {
2344 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
2345 : efrank 1.1 my($seq,$func,$i);
2346 :    
2347 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Protein Sequence</TITLE>\n";
2348 : parrello 1.60 if ($seq = &get_translation($fig_or_sprout,$prot)) {
2349 :     $func = &function_ofS($fig_or_sprout,$prot,$cgi->param('user'));
2350 :     push(@$html,$cgi->pre,">$prot $func\n");
2351 :     for ($i=0; ($i < length($seq)); $i += 60) {
2352 :     if ($i > (length($seq) - 60)) {
2353 :     push(@$html,substr($seq,$i) . "\n");
2354 :     } else {
2355 :     push(@$html,substr($seq,$i,60) . "\n");
2356 :     }
2357 :     }
2358 :     push(@$html,$cgi->end_pre);
2359 :     } else {
2360 :     push(@$html,$cgi->h1("No translation available for $prot"));
2361 : efrank 1.1 }
2362 :     }
2363 :    
2364 :     sub dna_sequence {
2365 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$fid) = @_;
2366 : efrank 1.1 my($seq,$func,$i);
2367 :    
2368 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Nucleotide Sequence</TITLE>\n";
2369 : parrello 1.60 if ($seq = &dna_seq($fig_or_sprout,&genome_of($fid),&feature_locationS($fig_or_sprout,$fid))) {
2370 :     $func = &function_ofS($fig_or_sprout,$prot,$cgi->param('user'));
2371 :     push(@$html,$cgi->pre,">$fid $func\n");
2372 :     for ($i=0; ($i < length($seq)); $i += 60) {
2373 :     if ($i > (length($seq) - 60)) {
2374 :     push(@$html,substr($seq,$i) . "\n");
2375 :     } else {
2376 :     push(@$html,substr($seq,$i,60) . "\n");
2377 :     }
2378 :     }
2379 :     push(@$html,$cgi->end_pre);
2380 :     } else {
2381 :     push(@$html,$cgi->h1("No DNA sequence available for $fid"));
2382 : efrank 1.1 }
2383 :     }
2384 : parrello 1.60
2385 : overbeek 1.173 # RAE: Added this routine to get the adjacent sequence. The default is to get 500 bp on either side of the
2386 :     # gene, but you can (secretly) change this to get more or less sequence by setting additional_sequence
2387 :     # in the URL. Also, I changed the way that the display is generated above so that I can used the s///
2388 :     # to add the color and new lines.
2389 : golsen 1.175 #
2390 :     # Fixed off-by-one errors in the end of coloring (which started this all).
2391 :     # Modified to detect end of contig (otherwise it fails when it runs off an end).
2392 :     # Modified to handle multisegment locations. -- GJO
2393 : overbeek 1.173
2394 :     sub dna_sequence_adjacent {
2395 : golsen 1.175 my( $fig_or_sprout,$cgi, $html, $fid ) = @_;
2396 :     my( $contig, $beg, $end, $seq, $func, $i );
2397 : overbeek 1.173
2398 :     unshift @$html, "<TITLE>The SEED: Nucleotide Sequence</TITLE>\n";
2399 : golsen 1.175 my $additional = $cgi->param("additional_sequence");
2400 :     defined( $additional ) or ( $additional = 500 );
2401 :    
2402 :     # Now handles segmented location and running off an end. -- GJO
2403 :    
2404 : overbeek 1.184 my $genome = &genome_of( $fid );
2405 :     my $loc = &feature_locationS($fig_or_sprout,$fid);
2406 :     # my $loc = $fig_or_sprout->feature_location( $fid );
2407 : golsen 1.175 my @loc = split /,/, $loc;
2408 :    
2409 : overbeek 1.184
2410 : golsen 1.175 # Add to beginning of the first segment:
2411 :    
2412 : overbeek 1.182 # NOTE the difference
2413 :     # Sprout returns locations in the form contig_start-stop
2414 :    
2415 : overbeek 1.184 # ( $contig, $beg, $end ) = $loc[0] =~ /^(.*)_(\d+)\D(\d+)$/;
2416 :    
2417 :     ($contig, $beg, $end) = BasicLocation::Parse($loc[0]);
2418 : overbeek 1.182
2419 : golsen 1.175 if ( ! ( $contig && $beg && $end ) )
2420 :     {
2421 :     push @$html, $cgi->h2( "Bad location information for $fid" );
2422 :     print STDERR "SEED Error: Bad location information ($loc) for $fid in dna_sequence_adjacent\n";
2423 :     return;
2424 :     }
2425 :     my ( $n1, $npre );
2426 :     if ( $beg < $end )
2427 :     {
2428 :     $n1 = $beg - $additional;
2429 :     $n1 = 1 if $n1 < 1;
2430 :     $npre = $beg - $n1;
2431 :     }
2432 :     else
2433 :     {
2434 :     $n1 = $beg + $additional;
2435 :     my $clen = $fig_or_sprout->contig_ln( $genome, $contig );
2436 :     $n1 = $clen if $n1 > $clen;
2437 :     $npre = $n1 - $beg;
2438 :     }
2439 :     $loc[0] = join( '_', $contig, $n1, $end );
2440 :    
2441 :     # Add to the end of the last segment:
2442 :    
2443 : overbeek 1.186 ( $contig, $beg, $end ) = BasicLocation::Parse($loc[-1]);
2444 :    
2445 : golsen 1.175 if ( ! ( $contig && $beg && $end ) )
2446 :     {
2447 :     push @$html, $cgi->h2( "Bad location information for $fid" );
2448 :     print STDERR "SEED Error: Bad location information ($loc) for $fid in dna_sequence_adjacent\n";
2449 :     return;
2450 :     }
2451 :     my ( $n2, $npost );
2452 :     if ( $beg < $end )
2453 :     {
2454 :     $n2 = $end + $additional;
2455 :     my $clen = $fig_or_sprout->contig_ln( $genome, $contig );
2456 :     $n2 = $clen if $n2 > $clen;
2457 :     $npost = $n2 - $end;
2458 :     }
2459 :     else
2460 :     {
2461 :     $n2 = $end - $additional;
2462 :     $n2 = 1 if $n2 < 1;
2463 :     $npost = $end - $n2;
2464 :     }
2465 :     $loc[-1] = join( '_', $contig, $beg, $n2 );
2466 :    
2467 :     $seq = $fig_or_sprout->dna_seq( $genome, join( ',', @loc ) );
2468 :     if ( ! $seq )
2469 :     {
2470 :     push @$html, $cgi->h2( "No DNA sequence available for $fid" );
2471 :     return;
2472 : overbeek 1.173 }
2473 : golsen 1.175
2474 :     my $len = length( $seq ); # Get length before adding newlines
2475 :     $seq =~ s/(.{60})/$1\n/g; # Cleaver way to wrap the sequence
2476 :     my $p1 = $npre + int( $npre/60 ); # End of prefix, adjusted for newlines
2477 :     my $p2 = $len - $npost; # End of data,
2478 :     $p2 += int( $p2/60 ); # adjusted for newlines
2479 :     my $diff = $p2 - $p1; # Characters of data
2480 :     # Integrate the HTML codes
2481 :     $seq =~ s/^(.{$p1})(.{$diff})(.*)$/$1<SPAN Style="color:red">$2<\/SPAN>$3/s;
2482 :    
2483 :     $func = $fig_or_sprout->function_of( $fid, $cgi->param('user') );
2484 :    
2485 :     push @$html, $cgi->pre, ">$fid $func\n$seq\n", $cgi->end_pre;
2486 : overbeek 1.173 }
2487 :    
2488 : golsen 1.175
2489 : efrank 1.1 sub show_fusions {
2490 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
2491 : efrank 1.1
2492 : overbeek 1.22 my $user = $cgi->param('user');
2493 :     $user = $user ? $user : "";
2494 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2495 :    
2496 : efrank 1.1 $ENV{"REQUEST_METHOD"} = "GET";
2497 : overbeek 1.53 $ENV{"QUERY_STRING"} = "peg=$prot&user=$user&SPROUT=$sprout";
2498 : efrank 1.1 my @out = `./fusions.cgi`;
2499 :     print join("",@out);
2500 :     exit;
2501 : overbeek 1.2 }
2502 :    
2503 : overbeek 1.53 ###########################################################################
2504 : overbeek 1.2 sub print_compared_regions {
2505 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
2506 :    
2507 :     my $sz_region = $cgi->param('sz_region');
2508 :     $sz_region = $sz_region ? $sz_region : 16000;
2509 :    
2510 :     my $num_close = $cgi->param('num_close');
2511 :     $num_close = $num_close ? $num_close : 5;
2512 : overbeek 1.153
2513 : overbeek 1.189 my $user = $cgi->param('user');
2514 : overbeek 1.65 my @closest_pegs = &closest_pegs($fig_or_sprout,$cgi,$peg,$num_close);
2515 : overbeek 1.40
2516 : parrello 1.60 if (@closest_pegs > 0) {
2517 :     if (&possibly_truncated($fig_or_sprout,$peg)) {
2518 :     push(@closest_pegs,&possible_extensions($peg,\@closest_pegs));
2519 :     }
2520 :     @closest_pegs = &sort_fids_by_taxonomy($fig_or_sprout,@closest_pegs);
2521 :     unshift(@closest_pegs,$peg);
2522 :     my @all_pegs = ();
2523 : overbeek 1.119
2524 : parrello 1.60 my $gg = &build_maps($fig_or_sprout,\@closest_pegs,\@all_pegs,$sz_region);
2525 :     #warn Dumper($gg);
2526 : overbeek 1.68 my $color_sets = &cluster_genes($fig_or_sprout,$cgi,\@all_pegs,$peg);
2527 : parrello 1.60 &set_colors_text_and_links($gg,\@all_pegs,$color_sets);
2528 :     ################################### add commentary capability
2529 :     my $sprout = $cgi->param('SPROUT') ? 1 : "";
2530 :    
2531 :     my($gene,$n,%how_many,$val,@vals,$x);
2532 :     my($i,$map);
2533 :     @vals = ();
2534 :     for ($i=(@$gg - 1); ($i >= 0); $i--) {
2535 :     my @vals1 = ();
2536 :     $map = $gg->[$i];
2537 :     my $found = 0;
2538 :     my $got_red = 0;
2539 :     undef %how_many;
2540 :     foreach $gene (@{$map->[3]}) {
2541 :     if (($x = $gene->[3]) ne "grey") {
2542 :     $n = $gene->[4];
2543 :     if ($n == 1) { $got_red = 1 }
2544 :     $how_many{$n}++;
2545 :     $gene->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/;
2546 :     $val = join("@",($n,$i,$1,$map->[0],$how_many{$n}));
2547 :     push(@vals1,$val);
2548 :     $found++;
2549 :     }
2550 :     }
2551 :    
2552 :     if (! $got_red) {
2553 :     splice(@$gg,$i,1);
2554 :     } else {
2555 :     push(@vals,@vals1);
2556 :     }
2557 :     }
2558 : overbeek 1.35
2559 : overbeek 1.151 if (@$gg < 2) {
2560 :     push(@$html,$cgi->h3("No alignable regions in close genomes"));
2561 : overbeek 1.189 &add_previous_next($html,undef,undef,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2562 : parrello 1.60 } else {
2563 : overbeek 1.151
2564 :     my @parm_reset_form = ($cgi->hr);
2565 :     push(@parm_reset_form,$cgi->start_form(-action => &cgi_url . "/protein.cgi" ));
2566 :     my $param;
2567 :     foreach $param ($cgi->param()) {
2568 :     next if (($param eq "sz_region") || ($param eq "num_close"));
2569 :     push(@parm_reset_form,$cgi->hidden(-name => $param, -value => $cgi->param($param)));
2570 :     }
2571 :     push(@parm_reset_form,
2572 :     "size region: ",
2573 :     $cgi->textfield(-name => 'sz_region', -size => 10, -value => $sz_region, -override => 1),
2574 :     "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ",
2575 :     "Number genomes: ",
2576 :     $cgi->textfield(-name => 'num_close', -size => 4, -value => $num_close, -override => 1),
2577 :     $cgi->br,
2578 :     $cgi->submit('Resubmit')
2579 :     );
2580 :     push(@parm_reset_form,$cgi->end_form);
2581 :     push(@$html,@parm_reset_form);
2582 : overbeek 1.189
2583 : overbeek 1.151 my @commentary_form = ();
2584 :     my $ctarget = "window$$";
2585 :     push(@commentary_form,$cgi->start_form(-target => $ctarget,
2586 :     -action => &cgi_url . "/chromosomal_clusters.cgi"
2587 :     ));
2588 :    
2589 :     push(@commentary_form,$cgi->hidden(-name => 'SPROUT', -value => $sprout),
2590 :     $cgi->hidden(-name => "request", -value => "show_commentary"));
2591 :     push(@commentary_form,$cgi->hidden(-name => "prot", -value => $peg));
2592 :     push(@commentary_form,$cgi->hidden(-name => "uni", -value => 1));
2593 :     push(@commentary_form,$cgi->hidden(-name => "user", -value => $user));
2594 : parrello 1.60 push(@commentary_form,$cgi->hidden(-name => "show", -value => [@vals]));
2595 :     push(@commentary_form,$cgi->submit('commentary'));
2596 :     push(@commentary_form,$cgi->end_form());
2597 :     push(@$html,@commentary_form);
2598 : overbeek 1.151 push(@$html,@{ &GenoGraphics::render($gg,700,4,0,2) });
2599 : overbeek 1.189
2600 :     my($prev,$next);
2601 :     my $map1 = $gg->[0]->[3];
2602 :     if (($map1->[0]->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/) && ($1 ne $peg))
2603 :     {
2604 :     $prev = $1;
2605 :     }
2606 :     if (($map1->[$#{$map1}]->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/) && ($1 ne $peg))
2607 :     {
2608 :     $next = $1;
2609 :     }
2610 :     &add_previous_next($html,$prev,$next,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2611 : parrello 1.60 }
2612 : overbeek 1.151
2613 : parrello 1.120 if (! $cgi->param('SPROUT'))
2614 :     {
2615 :     push @$html, &FIGGenDB::linkClusterGenDB($peg);
2616 :     }
2617 : overbeek 1.2 }
2618 : overbeek 1.151 else
2619 :     {
2620 :     push(@$html,$cgi->h3("No alignable regions in close genomes"));
2621 : overbeek 1.189 &add_previous_next($html,undef,undef,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2622 :     }
2623 :     }
2624 :    
2625 :     sub add_previous_next {
2626 :     my($html,$prev,$next,$fig_or_sprout,$peg,$user,$sz_region,$num_close) = @_;
2627 :    
2628 :     push(@$html,$cgi->br);
2629 :     if ($prev)
2630 :     {
2631 :     push(@$html,"<a href=protein.cgi?prot=$prev&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>previous</a>");
2632 :     }
2633 :     else
2634 :     {
2635 :     my $genome = &FIG::genome_of($peg);
2636 :     my @contigs = $fig_or_sprout->contigs_of($genome);
2637 :     my @loc = $fig_or_sprout->feature_location($peg);
2638 :     my $contig;
2639 :     if ((@loc > 0) && ($loc[0] =~ /^(\S+)_\d+_\d+$/))
2640 :     {
2641 :     $contig = $1;
2642 :     }
2643 :     my $i;
2644 :     for ($i=0; ($i < @contigs) && ($contig ne $contigs[$i]); $i++) {}
2645 :     if (($i > 0) && ($i < @contigs))
2646 :     {
2647 :     $contig = $contigs[$i-1];
2648 :     my($genes,undef,undef) = $fig_or_sprout->genes_in_region($genome,$contig,1,10000);
2649 :     my @genes = grep { $fig_or_sprout->ftype($_) eq "peg" } @$genes;
2650 :    
2651 :     if (@genes > 0)
2652 :     {
2653 :     my $gene = $genes[0];
2654 :     push(@$html,"<a href=protein.cgi?prot=$gene&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>previous</a>");
2655 :     }
2656 :     }
2657 :     }
2658 :    
2659 :    
2660 :     if ($next)
2661 :     {
2662 :     push(@$html,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=protein.cgi?prot=$next&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>next</a>");
2663 :     }
2664 :     else
2665 :     {
2666 :     my $genome = &FIG::genome_of($peg);
2667 :     my @contigs = $fig_or_sprout->contigs_of($genome);
2668 :     my @loc = $fig_or_sprout->feature_location($peg);
2669 :     my $contig;
2670 :     if ((@loc > 0) && ($loc[0] =~ /^(\S+)_\d+_\d+$/))
2671 :     {
2672 :     $contig = $1;
2673 :     }
2674 :     my $i;
2675 :     for ($i=0; ($i < @contigs) && ($contig ne $contigs[$i]); $i++) {}
2676 :     if (($i >= 0) && ($i < $#contigs))
2677 :     {
2678 :     $contig = $contigs[$i+1];
2679 :     my($genes,undef,undef) = $fig_or_sprout->genes_in_region($genome,$contig,1,10000);
2680 :     my @genes = grep { $fig_or_sprout->ftype($_) eq "peg" } @$genes;
2681 :    
2682 :     if (@genes > 0)
2683 :     {
2684 :     my $gene = $genes[0];
2685 :     push(@$html,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href=protein.cgi?prot=$gene&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>next</a>");
2686 :     }
2687 :     }
2688 : overbeek 1.151 }
2689 : overbeek 1.2 }
2690 :    
2691 : overbeek 1.189
2692 : overbeek 1.2 sub closest_pegs {
2693 : overbeek 1.65 my($fig_or_sprout,$cgi,$peg,$n) = @_;
2694 : overbeek 1.2 my($id2,$d,$peg2,$i);
2695 :    
2696 : overbeek 1.65 my @closest;
2697 :     if ($cgi->param('SPROUT'))
2698 :     {
2699 : parrello 1.120 @closest = map { $_->[0] } sort { $a->[1] <=> $b->[1] } &bbhs($fig_or_sprout,$peg, 1.0e-10);
2700 : overbeek 1.65 }
2701 :     else
2702 :     {
2703 : parrello 1.120 @closest = map { $id2 = $_->id2; ($id2 =~ /^fig\|/) ? $id2 : () } &sims($fig_or_sprout,$peg,&FIG::max(20,$n*4),1.0e-20,"fig",&FIG::max(20,$n*4));
2704 : overbeek 1.65 }
2705 : overbeek 1.152
2706 : overbeek 1.151 if (@closest >= ($n-1))
2707 :     {
2708 :     $#closest = $n-2 ;
2709 :     }
2710 : overbeek 1.152 my %closest = map { $_ => 1 } @closest;
2711 : overbeek 1.2
2712 : overbeek 1.152 my @pinned_to = grep { ($_ ne $peg) && (! $closest{$_}) } &in_pch_pin_with($fig_or_sprout,$peg);
2713 :     my $g1 = &genome_of($peg);
2714 :     @pinned_to = map {$_->[1] }
2715 :     sort { $a->[0] <=> $b->[0] }
2716 :     map { $peg2 = $_; $d = &crude_estimate_of_distance($fig_or_sprout,$g1,&genome_of($peg2)); [$d,$peg2] }
2717 :     @pinned_to;
2718 : overbeek 1.2
2719 : overbeek 1.152 if (@closest == ($n-1))
2720 :     {
2721 :     $#closest = ($n - 2) - &FIG::min(scalar @pinned_to,int($n/2));
2722 :     for ($i=0; ($i < @pinned_to) && (@closest < ($n-1)); $i++)
2723 :     {
2724 : overbeek 1.151 if (! $closest{$pinned_to[$i]})
2725 :     {
2726 :     $closest{$pinned_to[$i]} = 1;
2727 :     push(@closest,$pinned_to[$i]);
2728 :     }
2729 :     }
2730 : overbeek 1.2 }
2731 : overbeek 1.151 return @closest;
2732 : overbeek 1.2 }
2733 :    
2734 :     sub build_maps {
2735 : overbeek 1.53 my($fig_or_sprout,$pinned_pegs,$all_pegs,$sz_region) = @_;
2736 : overbeek 1.2 my($gg,$loc,$contig,$beg,$end,$mid,$min,$max,$genes,$feat,$fid);
2737 :     my($contig1,$beg1,$end1,$map,$peg);
2738 :    
2739 :     $gg = [];
2740 : parrello 1.60 foreach $peg (@$pinned_pegs) {
2741 :     $loc = &feature_locationS($fig_or_sprout,$peg);
2742 :     ($contig,$beg,$end) = &boundaries_of($fig_or_sprout,$loc);
2743 :     if ($contig && $beg && $end) {
2744 :     $mid = int(($beg + $end) / 2);
2745 :     $min = int($mid - ($sz_region / 2));
2746 :     $max = int($mid + ($sz_region / 2));
2747 :     $genes = [];
2748 : overbeek 1.81 ($feat,undef,undef) = &genes_in_region($fig_or_sprout,$cgi,&genome_of($peg),$contig,$min,$max);
2749 : parrello 1.60 foreach $fid (@$feat) {
2750 :     ($contig1,$beg1,$end1) = &boundaries_of($fig_or_sprout,&feature_locationS($fig_or_sprout,$fid));
2751 :     $beg1 = &in_bounds($min,$max,$beg1);
2752 :     $end1 = &in_bounds($min,$max,$end1);
2753 :     my $aliases = join( ', ', &feature_aliasesL($fig_or_sprout,$fid) );
2754 :     my $function = &function_ofS($fig_or_sprout,$fid);
2755 : golsen 1.192 my ( $uniprot ) = $aliases =~ /(uni\|[^,]+)/;
2756 :     my $user = $cgi->param('user');
2757 :     my $info = join('<br/>', "<b>PEG:</b> $fid",
2758 :     "<b>Contig:</b> $contig1",
2759 :     "<b>Begin:</b> $beg1",
2760 :     "<b>End:</b> $end1",
2761 :     $function ? "<b>Function:</b> $function" : (),
2762 :     $uniprot ? "<b>Uniprot ID:</b> $uniprot" : ()
2763 :     );
2764 : parrello 1.60
2765 :     my $sprout = $cgi->param('SPROUT') ? 1 : "";
2766 : parrello 1.120 my $fmg;
2767 :     if ($sprout)
2768 :     {
2769 : redwards 1.137 $fmg = "<a href=\&quot;protein.cgi?SPROUT=$sprout&compare_region=1\&prot=$fid\&user=$user\&quot>show</a>";
2770 : parrello 1.120 }
2771 :     else
2772 :     {
2773 : redwards 1.137 $fmg = join ('<br/>', "<a href=\&quot;protein.cgi?SPROUT=$sprout&compare_region=1\&prot=$fid\&user=$user\&quot>show</a>",
2774 : parrello 1.60 "<a onClick=\&quot;setValue('bound1', '$fid'); return false;\&quot;>set bound 1</a>",
2775 :     "<a onClick=\&quot;setValue('bound2', '$fid'); return false;\&quot;>set bound 2</a>",
2776 :     "<a onClick=\&quot;setValue('candidates', '$fid'); return false;\&quot;>set candidate</a>");
2777 : parrello 1.120 }
2778 : parrello 1.60 push(@$genes,[&min($beg1,$end1),
2779 :     &max($beg1,$end1),
2780 :     ($beg1 < $end1) ? "rightArrow" : "leftArrow",
2781 :     "grey",
2782 :     "",
2783 :     $fid,
2784 :     $info, $fmg]);
2785 :    
2786 :     if ($fid =~ /peg/) {
2787 :     push(@$all_pegs,$fid);
2788 :     }
2789 :     }
2790 : golsen 1.192
2791 :     # Sequence title can be replaced by [ title, url, popup_text, menu, popup_title ]
2792 :    
2793 :     my $org = org_of( $fig_or_sprout, $peg );
2794 : golsen 1.193 my $desc = "Genome: $org<br />Contig: $contig";
2795 :     $map = [ [ FIG::abbrev( $org ), undef, $desc, undef, 'Contig' ],
2796 : golsen 1.192 0,
2797 :     $max+1 - $min,
2798 :     ($beg < $end) ? &decr_coords($genes,$min) : &flip_map($genes,$min,$max)
2799 :     ];
2800 : parrello 1.60 push(@$gg,$map);
2801 :     }
2802 : overbeek 1.2 }
2803 : overbeek 1.55 &GenoGraphics::disambiguate_maps($gg);
2804 : overbeek 1.2 return $gg;
2805 :     }
2806 :    
2807 :     sub in {
2808 :     my($x,$xL) = @_;
2809 :     my($i);
2810 :    
2811 :     for ($i=0; ($i < @$xL) && ($x != $xL->[$i]); $i++) {}
2812 :     return ($i < @$xL);
2813 :     }
2814 :    
2815 :     sub in_bounds {
2816 :     my($min,$max,$x) = @_;
2817 :    
2818 :     if ($x < $min) { return $min }
2819 :     elsif ($x > $max) { return $max }
2820 :     else { return $x }
2821 :     }
2822 :    
2823 :     sub decr_coords {
2824 :     my($genes,$min) = @_;
2825 :     my($gene);
2826 :    
2827 : parrello 1.60 foreach $gene (@$genes) {
2828 :     $gene->[0] -= $min;
2829 :     $gene->[1] -= $min;
2830 : overbeek 1.2 }
2831 :     return $genes;
2832 :     }
2833 :    
2834 :     sub flip_map {
2835 :     my($genes,$min,$max) = @_;
2836 :     my($gene);
2837 : parrello 1.60
2838 :     foreach $gene (@$genes) {
2839 :     ($gene->[0],$gene->[1]) = ($max - $gene->[1],$max - $gene->[0]);
2840 :     $gene->[2] = ($gene->[2] eq "rightArrow") ? "leftArrow" : "rightArrow";
2841 : overbeek 1.2 }
2842 :     return $genes;
2843 :     }
2844 :    
2845 :     sub cluster_genes {
2846 : overbeek 1.68 my($fig_or_sprout,$cgi,$all_pegs,$peg) = @_;
2847 : overbeek 1.2 my(%seen,$i,$j,$k,$x,$cluster,$conn,$pegI,$red_set);
2848 :    
2849 :     my @color_sets = ();
2850 :    
2851 : overbeek 1.68 $conn = &get_connections_by_similarity($fig_or_sprout,$cgi,$all_pegs);
2852 :    
2853 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2854 :     if ($all_pegs->[$i] eq $peg) { $pegI = $i }
2855 :     if (! $seen{$i}) {
2856 :     $cluster = [$i];
2857 :     $seen{$i} = 1;
2858 :     for ($j=0; ($j < @$cluster); $j++) {
2859 :     $x = $conn->{$cluster->[$j]};
2860 :     foreach $k (@$x) {
2861 :     if (! $seen{$k}) {
2862 :     push(@$cluster,$k);
2863 :     $seen{$k} = 1;
2864 :     }
2865 :     }
2866 :     }
2867 :    
2868 :     if ((@$cluster > 1) || ($cluster->[0] eq $pegI)) {
2869 :     push(@color_sets,$cluster);
2870 :     }
2871 :     }
2872 : overbeek 1.2 }
2873 :     for ($i=0; ($i < @color_sets) && (! &in($pegI,$color_sets[$i])); $i++) {}
2874 :     $red_set = $color_sets[$i];
2875 :     splice(@color_sets,$i,1);
2876 :     @color_sets = sort { @$b <=> @$a } @color_sets;
2877 :     unshift(@color_sets,$red_set);
2878 :    
2879 :     my $color_sets = {};
2880 : parrello 1.60 for ($i=0; ($i < @color_sets); $i++) {
2881 :     foreach $x (@{$color_sets[$i]}) {
2882 :     $color_sets->{$all_pegs->[$x]} = $i;
2883 :     }
2884 : overbeek 1.2 }
2885 :     return $color_sets;
2886 :     }
2887 :    
2888 :     sub get_connections_by_similarity {
2889 : overbeek 1.68 my($fig_or_sprout,$cgi,$all_pegs) = @_;
2890 : parrello 1.108
2891 : overbeek 1.68 if ($cgi->param('SPROUT'))
2892 :     {
2893 :     return &get_connections_by_similarity_SPROUT($fig_or_sprout,$all_pegs);
2894 :     }
2895 :     else
2896 :     {
2897 :     return &get_connections_by_similarity_SEED($fig_or_sprout,$all_pegs);
2898 :     }
2899 :     }
2900 :    
2901 :     sub get_connections_by_similarity_SPROUT {
2902 :     my($fig_or_sprout,$all_pegs) = @_;
2903 :     my(%in,$i,$j,$peg1,$peg2);
2904 :    
2905 :     my $conn = {};
2906 :    
2907 :     for ($i=0; $i < @$all_pegs; $i++)
2908 :     {
2909 :     $in{$all_pegs->[$i]} = $i;
2910 :     }
2911 : parrello 1.108
2912 : overbeek 1.68 foreach $peg1 (@$all_pegs)
2913 :     {
2914 :     $i = $in{$peg1};
2915 : overbeek 1.116 foreach $peg2 (map { $_->[0] } bbhs($fig_or_sprout,$peg1,1.0e-10))
2916 : overbeek 1.68 {
2917 :     $j = $in{$peg2};
2918 :     if (defined($i) && defined($j))
2919 :     {
2920 :     push(@{$conn->{$i}},$j);
2921 :     }
2922 :     }
2923 :     }
2924 :     return $conn;
2925 :     }
2926 :    
2927 :     sub get_connections_by_similarity_SEED {
2928 :     my($fig_or_sprout,$all_pegs) = @_;
2929 : overbeek 1.40 my($i,$j,$tmp,$peg,%pos_of);
2930 :     my($sim,%conn,$x,$y);
2931 : overbeek 1.2
2932 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2933 :     $tmp = &maps_to_id($fig_or_sprout,$all_pegs->[$i]);
2934 :     push(@{$pos_of{$tmp}},$i); # map the representative in nr to subscript in all_pegs
2935 :     if ($tmp ne $all_pegs->[$i]) {
2936 :     push(@{$pos_of{$all_pegs->[$i]}},$i);
2937 :     }
2938 : overbeek 1.2 }
2939 :    
2940 : parrello 1.60 foreach $y (keys(%pos_of)) {
2941 :     $x = $pos_of{$y};
2942 :     for ($i=0; ($i < @$x); $i++) {
2943 :     for ($j=$i+1; ($j < @$x); $j++) {
2944 :     push(@{$conn{$x->[$i]}},$x->[$j]);
2945 :     push(@{$conn{$x->[$j]}},$x->[$i]);
2946 :     }
2947 :     }
2948 : overbeek 1.40 }
2949 :    
2950 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2951 :     foreach $sim (&sims($fig_or_sprout,$all_pegs->[$i],500,1.0e-5,"raw")) {
2952 :     if (defined($x = $pos_of{$sim->id2})) {
2953 :     foreach $y (@$x) {
2954 :     push(@{$conn{$i}},$y);
2955 :     }
2956 :     }
2957 :     }
2958 : overbeek 1.2 }
2959 :     return \%conn;
2960 :     }
2961 :    
2962 :     sub set_colors_text_and_links {
2963 :     my($gg,$all_pegs,$color_sets) = @_;
2964 :     my($map,$gene,$peg,$color);
2965 :    
2966 : parrello 1.60 foreach $map (@$gg) {
2967 :     foreach $gene (@{$map->[3]}) {
2968 :     $peg = $gene->[5];
2969 :     if (defined($color = $color_sets->{$peg})) {
2970 :     $gene->[3] = ($color == 0) ? "red" : "color$color";
2971 :     $gene->[4] = $color + 1;
2972 :     }
2973 :     $gene->[5] = &peg_url($cgi,$peg);
2974 :     }
2975 : overbeek 1.2 }
2976 :     }
2977 :    
2978 :     sub peg_url {
2979 :     my($cgi,$peg) = @_;
2980 :    
2981 :     my $prot = $cgi->param('prot');
2982 :     $cgi->delete('prot');
2983 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&prot=$peg&compare_region=1";
2984 : overbeek 1.2 $cgi->delete('prot');
2985 :     $cgi->param(-name => 'prot', -value => $prot);
2986 :    
2987 :     return $url;
2988 : parrello 1.60 }
2989 : overbeek 1.2
2990 :     sub possible_extensions {
2991 :     my($peg,$closest_pegs) = @_;
2992 :     my($g,$sim,$id2,$peg1,%poss);
2993 :    
2994 : overbeek 1.53 $g = &genome_of($peg);
2995 : overbeek 1.2
2996 : parrello 1.60 foreach $peg1 (@$closest_pegs) {
2997 :     if ($g ne &genome_of($peg1)) {
2998 :     foreach $sim (&sims($fig_or_sprout,$peg1,500,1.0e-5,"all")) {
2999 :     $id2 = $sim->id2;
3000 :     if (($id2 ne $peg) && ($id2 =~ /^fig\|$g\./) && &possibly_truncated($fig_or_sprout,$id2)) {
3001 :     $poss{$id2} = 1;
3002 :     }
3003 :     }
3004 :     }
3005 : overbeek 1.2 }
3006 :     return keys(%poss);
3007 : efrank 1.1 }
3008 : overbeek 1.53
3009 :     sub display_page {
3010 :     my($fig_or_sprout,$cgi,$html) = @_;
3011 :    
3012 : parrello 1.60 if (ref($html) eq "ARRAY") {
3013 :     if ($traceData) {
3014 :     push @$html, QTrace('html');
3015 :     }
3016 :     &HTML::show_page($cgi,$html);
3017 :     } else {
3018 :     Trace(Dumper($html)) if T(2);
3019 :     if ($cgi->param('SPROUT')) {
3020 :     if ($traceData) {
3021 :     $html->{tracings} = "<h3>Trace Messages</h3>\n" . QTrace('html');
3022 :     } else {
3023 :     $html->{tracings} = "\n";
3024 :     }
3025 :     print "Content-Type: text/html\n";
3026 :     print "\n";
3027 :     my $templ = "$FIG_Config::fig/CGI/Html/Protein_tmpl.html";
3028 : parrello 1.108 print PageBuilder::Build("<$templ", $html,"Html");
3029 : parrello 1.60 } else {
3030 :     my $gathered = [];
3031 :    
3032 :     my $section;
3033 :     foreach $section (qw( javascript
3034 :     general
3035 :     translate_status
3036 :     contig_context
3037 :     context_graphic
3038 :     subsys_connections
3039 : overbeek 1.68 assign_for_equiv_prots
3040 : parrello 1.60 links
3041 :     services
3042 :     kv_pairs
3043 :     compare_region
3044 :     similarities
3045 :     tools
3046 :     ) ) {
3047 :     if (@{$html->{$section}} > 0) {
3048 :     push(@$gathered,@{$html->{$section}});
3049 :     push(@$gathered,$cgi->hr);
3050 :     }
3051 :     }
3052 :     pop @$gathered;
3053 :     &HTML::show_page($cgi,$gathered);
3054 :     }
3055 : overbeek 1.53 }
3056 :     }
3057 :    
3058 :     sub show_html_followed_by_initial {
3059 :     my($fig_or_sprout,$cgi,$html,$prot) = @_;
3060 :    
3061 : overbeek 1.191 my $loc_url = $cgi->url(-absolute => 1, -full => 1, -query => 1, -path_info => 1);
3062 :    
3063 :     #
3064 :     # Truncate it in case the url is humongous (like it will be for the pins commentary page).
3065 :     #
3066 :    
3067 :     $loc_url = substr($loc_url, 0, 100);
3068 :    
3069 : overbeek 1.53 my %html = ( general => [],
3070 :     contig_context => [],
3071 :     context_graphic => [],
3072 :     subsys_connections => [],
3073 :     links => [],
3074 :     services => [],
3075 :     translate_status => [],
3076 :     tools => [],
3077 :     kv_pairs => [],
3078 :     similarities => [],
3079 : overbeek 1.68 assign_for_equiv_prots => [],
3080 : overbeek 1.53 javascript => [],
3081 : overbeek 1.157 compare_region => [],
3082 : overbeek 1.191 location_tag => [uri_escape($loc_url)],
3083 : overbeek 1.53 );
3084 :    
3085 :     push(@{$html{general}},@$html);
3086 :     $html = \%html;
3087 : parrello 1.60 &show_initial($fig_or_sprout,$cgi,$html,$prot);
3088 : overbeek 1.53 return $html;
3089 :     }
3090 :    
3091 :     sub translation_piece {
3092 :     my($fig_or_sprout,$cgi,$html) = @_;
3093 :    
3094 :     my $msg;
3095 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1);
3096 : overbeek 1.53 if ($cgi->param('translate')) {
3097 : parrello 1.60 $url =~ s/[;&]translate(=[^;&])?//i or $url =~ s/translate(=[^;&])?[;&]//i;
3098 :     $msg = "Turn Off Function Translation";
3099 :     } else {
3100 : golsen 1.169 $url .= "&translate=1";
3101 : parrello 1.60 $msg = "Translate Function Assignments";
3102 : overbeek 1.53 }
3103 :     push(@$html, "<a href=\"$url\">$msg</a><br>\n");
3104 :     }
3105 :    
3106 :    
3107 :     #######################################################################################
3108 : overbeek 1.119 sub sims {
3109 :     my( $fig_or_sprout, $peg, $max, $cutoff, $select, $expand, $group_by_genome, $filters ) = @_;
3110 :     my( @tmp, $id, $genome, @genomes, %sims, $sim );
3111 :    
3112 :     @tmp = $fig_or_sprout->sims( $peg, $max, $cutoff, $select, $expand, $filters );
3113 :     if (! $group_by_genome) { return @tmp };
3114 :    
3115 :     # Collect all sims from genome with the first occurance of the genome:
3116 :    
3117 :     foreach $sim ( @tmp )
3118 :     {
3119 :     $id = $sim->id2;
3120 :     $genome = ($id =~ /^fig\|(\d+\.\d+)\.peg\.\d+/) ? $1 : $id;
3121 :     if (! defined( $sims{ $genome } ) ) { push @genomes, $genome }
3122 :     push @{ $sims{ $genome } }, $sim;
3123 :     }
3124 :     return map { @{ $sims{$_} } } @genomes;
3125 :     }
3126 : overbeek 1.121
3127 :     sub in_cluster_with {
3128 :     my($fig_or_sprout,$cgi,$peg) = @_;
3129 :     my %in_cluster;
3130 :    
3131 :     if ($fig_or_sprout->table_exists('fc_pegs') && $fig_or_sprout->is_complete(&FIG::genome_of($peg)))
3132 :     {
3133 :     %in_cluster = map { $_->[0] => &ev_link($cgi,$_->[0],$_->[1]) } $fig_or_sprout->coupled_to($peg);
3134 :     if (keys(%in_cluster) > 0)
3135 :     {
3136 :     $in_cluster{$peg} = "";
3137 :     }
3138 :     elsif ($cgi->param('fc'))
3139 :     {
3140 :     %in_cluster = map { $_ => "" } $fig_or_sprout->in_cluster_with($peg);
3141 : overbeek 1.127 if (keys(%in_cluster) == 1)
3142 :     {
3143 :     my @tmp = keys(%in_cluster);
3144 :     delete $in_cluster{$tmp[0]};
3145 :     }
3146 : overbeek 1.121 }
3147 :     }
3148 :     return \%in_cluster;
3149 :     }
3150 :    
3151 : overbeek 1.141 sub evidence_codes {
3152 :     my($fig_or_sprout,$peg) = @_;
3153 :    
3154 :     if ($peg !~ /^fig\|\d+\.\d+\.peg\.\d+$/) { return "" }
3155 :    
3156 : overbeek 1.142 my @codes = grep { $_->[1] =~ /^evidence_code/i } $fig_or_sprout->get_attributes($peg);
3157 : overbeek 1.141 return (@codes > 0) ? map { $_->[2] } @codes : ();
3158 :     }
3159 :    
3160 : overbeek 1.143 sub evidence_codes_link {
3161 : redwards 1.160 my($cgi) = @_;
3162 :     return "<A href=\"Html/evidence_codes.html\" target=\"SEED_or_SPROUT_help\">Ev</A>";
3163 :     }
3164 :    
3165 : overbeek 1.141
3166 : redwards 1.160 sub evidence_codes_explain {
3167 :     my($ec)=@_;
3168 :     return unless ($ec);
3169 :    
3170 :     $ec=uc($ec);
3171 :     return "IDA: Inferred from Direct Assay" if ($ec eq "IDA");
3172 :     return "IGI: Inferred from Genetic Interaction" if ($ec eq "IGI");
3173 :     return "TAS: Traceable Author Statement" if ($ec eq "TAS");
3174 :     return "ISU: in subsystem unique" if ($ec eq "ISU");
3175 :     return "$ec: in subsystem duplicates" if ($ec =~ /IDU/);
3176 :     return "$ec: in cluster with" if ($ec =~ /ICW/);
3177 :     return "$ec: unknown!";
3178 : overbeek 1.141 }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3