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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.198 - (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 : overbeek 1.195 if (not $is_sprout)
650 :     {
651 :     push(@$html, "<a href='$baseurl/Html/seedtips.html#gene_names' class='help' target='help'>Help on Annotations</a><br>\n");
652 :     }
653 :     my $nlink = $link . "?SPROUT=$sprout&fid=$prot&user=$user&checked=$prot&assign/annotate=assign/annotate";
654 :     my $notlink = $link . "?SPROUT=$sprout&fid=$prot&user=$user&checked=$prot&assign/annotate=assign/annotate&negate=1";
655 :     push(@$html,"<a href='$nlink' target='checked_window'>To Make an Annotation</a> [<a href='$notlink' target='checked_window'>Negate annotation</a>]\n");
656 : overbeek 1.53 }
657 :    
658 : overbeek 1.146 if (! $sprout)
659 : overbeek 1.145 {
660 : overbeek 1.146 my($cid,@fams);
661 : overbeek 1.145
662 : overbeek 1.63 my $fc = $cgi->param('fc');
663 :     if ((! $fc) && (&feature_locationS($fig_or_sprout,$peg))) {
664 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&fc=1";
665 : overbeek 1.63 push(@$html,"<br><a href=$link>To Get Detailed Functional Coupling Data</a>\n");
666 :     } elsif ($fc) {
667 :     &print_fc($fig_or_sprout,$cgi,$html,$peg,$fc_data);
668 :     }
669 : overbeek 1.53
670 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=fusions";
671 : overbeek 1.63 push(@$html,"<br><a href=$link>To Get Fusion Data</a>\n");
672 : overbeek 1.53
673 : overbeek 1.63 my $link = &cgi_url . "/homologs_in_clusters.cgi?prot=$peg&user=$user\n";
674 :     push(@$html,"<br><a href=$link>To Find Homologs in Clusters</a>\n");
675 : overbeek 1.171
676 :     my @coup = $fig_or_sprout->abstract_coupled_to($peg);
677 :     if (@coup > 0)
678 :     {
679 :     my $link = &cgi_url . "/protein.cgi?prot=$peg&user=$user&request=abstract_coupling\n";
680 : overbeek 1.172 push(@$html,"<br><a href=$link>Show Abstract Coupling Data</a>\n");
681 : overbeek 1.171 }
682 : overbeek 1.63 }
683 : overbeek 1.53
684 : parrello 1.60 if ((! $cgi->param('compare_region')) && $has_translation) {
685 : overbeek 1.161 my $link = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&compare_region=1";
686 : overbeek 1.165 push(@$html,"<A href=\"Html/compare_regions.html\" class='help' target=\"SEED_or_SPROUT_help\">Help on compare regions</A>\n");
687 : overbeek 1.168 push(@$html,"<a href=$link>To Compare Region</a> &nbsp;\n<br>");
688 :     push(@$html, "<a href='proteinfamilies.cgi?user=$user&prot=$peg&equivalence=1'>Explore Protein Families for $peg</a></br>\n");
689 : parrello 1.60 } elsif ($cgi->param('compare_region')) {
690 :     &print_compared_regions($fig_or_sprout,$cgi,$html,$peg);
691 : overbeek 1.53 }
692 :     }
693 :    
694 : efrank 1.1 sub print_assignments {
695 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
696 : efrank 1.1 my($who,$func,$ec,@ecs,@tmp,$id,$i,$master_func,$user_func,$x);
697 :    
698 :     my $user = $cgi->param('user');
699 : overbeek 1.68 $user = defined($user) ? $user : "";
700 :    
701 : overbeek 1.53 my @funcs = map { [$peg,@$_] } &trans_function_of($cgi,$fig_or_sprout,$peg);
702 : overbeek 1.68 $user_func = &trans_function_of($cgi,$fig_or_sprout,$peg);
703 :    
704 :     push(@$html,$cgi->h2("Current Assignment: $peg: $user_func"));
705 : parrello 1.108
706 : overbeek 1.163 my @maps_to = grep { $_ ne $peg and $_ !~ /^xxx/ } map { $_->[0] } &mapped_prot_ids($fig_or_sprout,$cgi,$peg);
707 : efrank 1.1
708 : parrello 1.60 foreach $id (@maps_to) {
709 : overbeek 1.68 my $tmp;
710 :     if (($id ne $peg) && ($tmp = &trans_function_of($cgi,$fig_or_sprout,$id)))
711 :     {
712 :     push(@funcs, [$id,&who($id),$tmp]);
713 : parrello 1.60 }
714 : efrank 1.1 }
715 :     @funcs = map { ($_->[1] eq "master") ? [$_->[0],"",$_->[2]] : $_ } @funcs;
716 : overbeek 1.68
717 :    
718 : efrank 1.1 push(@$html,"<hr>\n");
719 :    
720 : parrello 1.60 if ((@funcs == 0) && (! $user_func)) {
721 :     push(@$html,$cgi->h1("No function has been assigned"));
722 : efrank 1.1 }
723 : overbeek 1.25
724 : parrello 1.108 my $tab = [ map { ($id,$who,$func) = @$_;
725 : overbeek 1.68 [ &HTML::set_prot_links($cgi,$id),
726 :     &org_of($fig_or_sprout,$id),
727 : overbeek 1.75 $who ? $who : "&nbsp;",
728 : parrello 1.108 ($user ? &assign_link($cgi,$func,$user_func) : "&nbsp;"),
729 : golsen 1.169 &set_ec_and_tc_links($fig_or_sprout,$cgi,&genome_of($peg),$func)] } @funcs ];
730 : parrello 1.60 if (@$tab > 0) {
731 :     my $col_hdrs = ["Id","Organism","Who","ASSIGN","Assignment"];
732 :     my $title = "Assignments for Essentially Identical Proteins";
733 : overbeek 1.180 push @$html, "<a href=\"javascript:toggleOffLayer('identicalproteins');\" title=\"Show Identicals\">Show/Hide Assignments for Essentially Identical Proteins</a>";
734 : redwards 1.134 push(@$html,$cgi->div({id=>"identicalproteins"}, &HTML::make_table($col_hdrs,$tab,$title)));
735 : efrank 1.1 }
736 : overbeek 1.53 }
737 : parrello 1.60
738 : overbeek 1.53 sub print_kv_pairs {
739 : redwards 1.99 my($is_sprout, $fig_or_sprout,$cgi,$html,$peg) = @_;
740 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
741 : overbeek 1.161 $baseurl = "./"; # Relative url fix
742 : parrello 1.108
743 : redwards 1.99 # we don't want to do this for SPROUT
744 : olson 1.129 if ($is_sprout)
745 :     {
746 :     return print_kv_pairs_sprout($fig_or_sprout,$cgi,$html,$peg);
747 :     }
748 : parrello 1.108
749 : redwards 1.94 # RAE: modified this to allow the users to edit the key/value pairs.
750 :     # there will be two choices: when the "Edit Attributes" button is pressed
751 :     # we will redraw the table with input fields and what not.
752 :    
753 :     # If the Add Changes button is pressed we will save the changes
754 :     # we will do this first before displaying the results
755 : parrello 1.108
756 : overbeek 1.141 my @attr = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
757 : redwards 1.94 if ($cgi->param('Add Changes')) {
758 :     my ($deleted, $added, $changed)=(undef, undef, undef);
759 : parrello 1.108
760 : redwards 1.94 foreach my $key (@attr) {
761 : redwards 1.105 unless ($cgi->param("key.".$key->[1])) {
762 : redwards 1.138 if (&delete_attribute($fig_or_sprout, $peg, $key->[1], $cgi->param("value.".$key->[1]), $cgi->param("url.".$key->[1]))) {
763 : redwards 1.99 push @$deleted, [@$key, ["deleted", "td colspan=2 style=\"text-align: center\""]];
764 :     }
765 : redwards 1.94 }
766 : redwards 1.105 if (($cgi->param("value.".$key->[1]) ne $key->[2]) || ($cgi->param("url.".$key->[1]) ne $key->[3])) {
767 : 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]))) {
768 : redwards 1.105 push @$changed, [@$key, $cgi->param("value.".$key->[1]), $cgi->param("url.".$key->[1])];
769 : redwards 1.99 }
770 : redwards 1.94 }
771 :     }
772 :     for (my $i=0; $i<=5; $i++) {
773 :     if ($cgi->param("key.$i")) {
774 : redwards 1.99 if (&add_attribute($fig_or_sprout,$peg, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"))) {
775 : 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")];
776 : redwards 1.99 }
777 :     else {
778 :     print STDERR $peg, " and ", $cgi->param("key.$i"), " not added\n";
779 :     }
780 : redwards 1.134 }
781 : redwards 1.94 }
782 : parrello 1.108
783 : redwards 1.134 if ($changed || $deleted || $added) {
784 :     my $tab = [];
785 :     my $col_hdrs=["Peg", "Attribute", "Original Value", "Original URL", "New Value", "New URL"];
786 : redwards 1.138 if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$changed}
787 :     if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$deleted}
788 :     if ($added) {push @$tab, [["<strong>Added Attributes", "td colspan=6 bgcolor=gray style=\"text-align: center\""]], @$added}
789 : redwards 1.94
790 : redwards 1.134 push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
791 : overbeek 1.141 @attr = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
792 : redwards 1.134 }
793 :     # now get the explanations and save those
794 :     my $explanations;
795 :     foreach my $key (@attr) {
796 :     if ($cgi->param("explanation.".$key->[1])) {
797 : overbeek 1.162 if (&key_info($fig_or_sprout, $key->[1], {"description"=>$cgi->param("explanation.".$key->[1])})) {
798 : redwards 1.134 push @$explanations, [@$key, $cgi->param("explanation.".$key->[1])];
799 :     }
800 :     }
801 :     }
802 :     for (my $i=0; $i<=5; $i++) {
803 :     if ($cgi->param("key.$i") && $cgi->param("value.$i") && $cgi->param("explanation.".$i)) {
804 : overbeek 1.162 if (&key_info($fig_or_sprout, $cgi->param("key.$i"), {"description"=>$cgi->param("explanation.".$i)})) {
805 : redwards 1.134 push @$explanations, [$cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"), $cgi->param("explanation.".$i)];
806 :     }
807 :     }
808 :     }
809 : redwards 1.138 if ($explanations) {
810 : redwards 1.134 my $col_hdrs=["Peg", "Attribute", "Value", "URL", "Explanation"];
811 :     push(@$html,&HTML::make_table($col_hdrs,$explanations,"Explanations"));
812 :     }
813 : redwards 1.94 }
814 :    
815 : redwards 1.134 my $col_hdrs=["Key<br><span style='font-size: smaller'>Link Explains Key</span>","Value"];
816 : redwards 1.94
817 : redwards 1.95 my $tab = [];
818 :     if ($cgi->param('Edit Attributes') && $cgi->param('user')) {
819 : redwards 1.134 push @$col_hdrs, "URL", "Explanation";
820 : redwards 1.105 foreach my $key (sort {$a->[1] cmp $b->[1]} @attr) {
821 : mkubal 1.166 my $data=$fig_or_sprout->key_info($key->[1]);
822 :     if ($data->{"is_cv"} == 1){next}
823 : redwards 1.95 push @$tab,
824 :     [
825 : redwards 1.105 $cgi->textfield(-name=>"key.".$key->[1], -default=>$key->[1], -size=>30),
826 :     $cgi->textfield(-name=>"value.".$key->[1], -default=>$key->[2], -size=>30),
827 :     $cgi->textfield(-name=>"url.".$key->[1], -default=>$key->[3], -size=>30),
828 : overbeek 1.162 $cgi->textfield(-name=>"explanation.".$key->[1], -default=>$data->{"description"}, -size=>30),
829 : redwards 1.95 ];
830 :     }
831 :     for (my $i=0; $i<=5; $i++) {
832 :     push @$tab,
833 :     [
834 :     $cgi->textfield(-name=>"key.$i", -size=>30),
835 :     $cgi->textfield(-name=>"value.$i", -size=>30),
836 :     $cgi->textfield(-name=>"url.$i", -size=>30),
837 : redwards 1.134 $cgi->textfield(-name=>"explanation.$i", -default=>'', -size=>30),
838 : redwards 1.95 ];
839 :     }
840 :     }
841 : redwards 1.99 #RAE we need to check that this is a scalar
842 :     elsif (ref($attr[0]) eq "ARRAY") {
843 : overbeek 1.161 my $link=$cgi->url(-relative => 1, -query => 1, -path_info => 1);
844 : redwards 1.95 foreach $_ (sort {$a->[0] cmp $b->[0]} @attr) {
845 : redwards 1.105 my($peg,$tag,$val,$url) = @$_;
846 : mkubal 1.166 push(@$tab,["<a href='$link&showtag=$tag'>$tag</a>",$url ? "<a href=\"$url\">$val</a>" : $val]);
847 : redwards 1.134 if ($cgi->param("showtag") && $cgi->param("showtag") eq $tag) {
848 :     my $data=&key_info($fig_or_sprout, $tag);
849 :     my $info="No Information Known about $tag";
850 : overbeek 1.162 if ($data->{"description"}) {$info=$data->{"description"}}
851 : redwards 1.134 push(@$tab, [["Key", "th"], ["Explanation", "th"]], [$tag, $info]);
852 :     }
853 : redwards 1.95 }
854 :     }
855 : parrello 1.108
856 : redwards 1.95 # Add the appropriate submit button to the table
857 :     if ($cgi->param('user') && $cgi->param('Edit Attributes')) {
858 :     # we want a Add button
859 :     push @$tab, [[$cgi->submit('Add Changes'), "td colspan=3 style=\"text-align: center\""]];
860 :     }
861 :     elsif ($cgi->param('user')) {
862 : overbeek 1.168 # RAE:
863 :     # I have turned off editing attributes at the moment. I think it is debateable that it has any value
864 :     # I am not aware of anyone editing attributes on a per-protein basis, although I know that people have
865 :     # edited them in bulk. The code is not working properly, and should be rewritten, so for now
866 :     # I have disabled them.
867 :    
868 :     #push @$tab, [[$cgi->submit('Edit Attributes'), "td colspan=2 style=\"text-align: center\""]];
869 : overbeek 1.38 }
870 : redwards 1.95 push(@$html,$cgi->start_form(-action=>"protein.cgi"), $cgi->hidden("prot"), $cgi->hidden("user"));
871 : redwards 1.134 if (($cgi->param('user') && $cgi->param('Edit Attributes')) || $cgi->param("showtag")) {
872 :     # these are the cases where we automatically want this shown
873 :     push(@$html,$cgi->br,$cgi->hr,&HTML::make_table($col_hdrs, $tab,"Attributes"),$cgi->hr);
874 :     }
875 :     else {
876 :     # otherwise we set the javascript section to hide this.
877 :     push @$html, "<a href=\"javascript:toggleLayer('attributes');\" title=\"Show Attributes\">Show/Hide Attributes</a>",
878 : overbeek 1.140 "\n<div id='attributes'>\n<a href='$baseurl/Html/Attributes.html' class='help' target='help'>Help on Attributes</a>\n",
879 : redwards 1.134 &HTML::make_table($col_hdrs, $tab,"Attributes"), "</div>";
880 :     }
881 : golsen 1.100 # Add end of form -- GJO
882 : redwards 1.105 # RAE: sorry about that Gary.
883 : golsen 1.100 push( @$html, $cgi->end_form );
884 : overbeek 1.53 }
885 :    
886 : olson 1.129 sub print_kv_pairs_sprout
887 :     {
888 :     my($fig_or_sprout, $cgi, $html, $peg) = @_;
889 :    
890 : overbeek 1.141 my @props = sort { ($a->[1] cmp $b->[1]) or ($a->[2] cmp $b->[2]) } $fig_or_sprout->get_attributes($peg);
891 : olson 1.129
892 :     my @col_hdrs = ("Key", "Value");
893 :    
894 :     my @tab;
895 :    
896 :     for my $prop (@props)
897 :     {
898 : overbeek 1.146 my($fid, $name, $value, $evidence) = @$prop;
899 : olson 1.129 my $txt;
900 :     if ($evidence =~ /^http/)
901 :     {
902 :     $txt = qq(<a href="$evidence">$value</a>);
903 :     }
904 :     else
905 :     {
906 :     $txt = $value;
907 :     }
908 :     push(@tab, [$name, $txt]);
909 :     }
910 :    
911 :     push(@$html, &HTML::make_table(\@col_hdrs, \@tab, "Attributes"), $cgi->hr);
912 :    
913 :     print STDERR Dumper($html);
914 :     }
915 :    
916 :    
917 : redwards 1.125 sub print_protein_fams {
918 : redwards 1.126
919 :     ############## RAE
920 :     # This code adds the protein family table to the page. This can be shown/hidden at the discretion of the viewer. Hopefully.
921 :    
922 :     my($is_sprout, $fig_or_sprout,$cgi,$html,$peg,$user) = @_;
923 :     # we don't want to do this for SPROUT
924 :     return if ($is_sprout);
925 :    
926 :     # get the families and other information
927 :     my $tab=[];
928 :     my @families=&families_for_protein($fig_or_sprout,$peg);
929 : redwards 1.128 unless (scalar @families) {
930 :     push @$html, "No protein families found\n";
931 :     return;
932 :     }
933 : redwards 1.136
934 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
935 : overbeek 1.161
936 : overbeek 1.168 push @$html, "<a href=\"javascript:toggleLayer('proteinfamilies');\" title=\"Show Protein Families\">Show/Hide Protein Families</a>";
937 : redwards 1.126 foreach my $fam (@families)
938 :     {
939 : overbeek 1.164 my $link="<a href='proteinfamilies.cgi?user=$user&family=$fam'>$fam</a>";
940 : redwards 1.126 push @$tab, [$link, &family_function($fig_or_sprout, $fam), &sz_family($fig_or_sprout, $fam)];
941 :     }
942 :     my $col_hdrs=["Family ID<br><small>Link Investigates Family</small>", "Family Function", "Family Size"];
943 : redwards 1.136 push @$html, $cgi->br, $cgi->div({id=>"proteinfamilies"},
944 : overbeek 1.165 "\n<a href='Html/ProteinFamilies.html' class='help' target='help'>Help on Protein Families</a>\n",
945 : redwards 1.136 &HTML::make_table($col_hdrs, $tab, "Protein Families")
946 :     );
947 : redwards 1.126 }
948 :    
949 :    
950 :     sub old_print_protein_fams {
951 :    
952 :     ############## RAE
953 :     # This is functional code that displays the protein families, but I want to try it using
954 :     # the CSS method. Therefore, I am keeping this code just for now, rather than munging it and being
955 :     # stuck with nothing working. Just rename this method and it will be fine!
956 :    
957 : redwards 1.125 my($is_sprout, $fig_or_sprout,$cgi,$html,$peg,$user) = @_;
958 :    
959 :     # we don't want to do this for SPROUT
960 :     return if ($is_sprout);
961 :    
962 :     # generate the link to turn protein fams on or off
963 : overbeek 1.161 my $link=$cgi->url(-relative => 1, -query => 1, -path_info => 1);
964 : redwards 1.125 if ($link =~ /showproteinfams/) {
965 :     $link =~ s/[\&\;]showproteinfams.*[^\;\&]/\&/;
966 :     push @$html, "< &nbsp; " . $cgi->a({href=> $link}, "Hide Protein Families");
967 :    
968 :     # get the families and other information
969 :     my $tab=[];
970 :     my @families=&families_for_protein($fig_or_sprout,$peg);
971 :     return unless (scalar @families);
972 :     foreach my $fam (@families)
973 :     {
974 : overbeek 1.140 my $baseurl=$FIG_Config::cgi_base;
975 : overbeek 1.161 $baseurl = './'; # Relative url fix
976 : overbeek 1.140 my $link="<a href='$baseurl/proteinfamilies.cgi?user=$user&family=$fam'>$fam</a>";
977 : redwards 1.125 push @$tab, [$link, &family_function($fig_or_sprout, $fam), &sz_family($fig_or_sprout, $fam)];
978 :     }
979 :     my $col_hdrs=["Family ID<br><small>Link Investigates Family</small>", "Family Function", "Family Size"];
980 :     push @$html, $cgi->br, &HTML::make_table($col_hdrs, $tab, "Protein Families"), $cgi->hr;
981 :     }
982 :     else
983 :     {
984 :     push @$html, "> &nbsp; " . $cgi->a({href=> $link . "&showproteinfams='1'"}, "Show Protein Families"); # define this here before we mess with ourself!
985 :     }
986 :     }
987 :    
988 : overbeek 1.68 sub who {
989 :     my($id) = @_;
990 :    
991 :     if ($id =~ /^fig\|/) { return "FIG" }
992 :     if ($id =~ /^gi\|/) { return "" }
993 :     if ($id =~ /^^[NXYZA]P_/) { return "RefSeq" }
994 :     if ($id =~ /^sp\|/) { return "SwissProt" }
995 :     if ($id =~ /^uni\|/) { return "UniProt" }
996 : overbeek 1.123 if ($id =~ /^tigr\|/) { return "TIGR" }
997 : overbeek 1.68 if ($id =~ /^pir\|/) { return "PIR" }
998 :     if ($id =~ /^kegg\|/) { return "KEGG" }
999 :     }
1000 :    
1001 : overbeek 1.53 sub print_subsys_connections {
1002 :     my($fig_or_sprout,$cgi,$html,$peg,$user) = @_;
1003 : overbeek 1.38
1004 : olson 1.28 #
1005 :     # Show the subsystems in which this protein participates.
1006 :     #
1007 :    
1008 : parrello 1.60 if (my @subsystems = &subsystems_for_peg($fig_or_sprout,$peg)) {
1009 :     push(@$html,
1010 :     $cgi->h2("Subsystems in which this peg is present"));
1011 :    
1012 :     my(@hdrs);
1013 :     my(@table);
1014 :    
1015 : overbeek 1.147 @hdrs = ("Subsystem", "Curator", "Role");
1016 : parrello 1.60
1017 : overbeek 1.122 my $sprout = $cgi->param('SPROUT') ? 1 : "";
1018 : parrello 1.60
1019 :     for my $ent (@subsystems) {
1020 :     my($sub, $role) = @$ent;
1021 : overbeek 1.147 my $curator = &subsystem_curator($fig_or_sprout,$sub);
1022 : overbeek 1.149 my $can_alter;
1023 :    
1024 : golsen 1.107 my $esc_sub = uri_escape($sub); # in URI::Escape
1025 : overbeek 1.156 my $genome = &FIG::genome_of($peg);
1026 : overbeek 1.149 my %opts = (SPROUT => $sprout,
1027 :     user => $user,
1028 :     ssa_name => $esc_sub,
1029 : overbeek 1.156 focus => $genome,
1030 :     request => 'show_ssa',
1031 :     show_clusters => 1,
1032 : overbeek 1.149 sort => 'by_phylo'
1033 :     );
1034 :    
1035 :     my $opts = join("&", map { "$_=$opts{$_}" } keys(%opts));
1036 : overbeek 1.155 my $url = $cgi->a({href => "display_subsys.cgi?$opts"}, $sub);
1037 : overbeek 1.89
1038 : overbeek 1.147 push(@table, [$url, $curator, $role]);
1039 : parrello 1.60 }
1040 :     push(@$html, &HTML::make_table(\@hdrs, \@table));
1041 : olson 1.28 }
1042 : overbeek 1.53 }
1043 :    
1044 :     sub print_links {
1045 :     my($fig_or_sprout,$cgi,$html,$peg) = @_;
1046 : overbeek 1.31
1047 : parrello 1.60 my @links = &peg_links($fig_or_sprout,$peg);
1048 :     if (@links > 0) {
1049 :     my $col_hdrs = [1,2,3,4,5];
1050 :     my $title = "Links to Related Entries in Other Sites";
1051 :     my $tab = [];
1052 :     my ($n,$i);
1053 :     for ($i=0; ($i < @links); $i += 5) {
1054 :     $n = (($i + (5-1)) < @links) ? $i+(5-1) : $i+(@links - $i);
1055 :     push(@$tab,[@links[$i..$n]]);
1056 :     }
1057 : redwards 1.134 push @$html, "<a href=\"javascript:toggleLayer('linkselsewhere');\" title=\"Show Links\">Show/Hide Links to Related Entries in Other Sites</a>";
1058 : overbeek 1.188 push(@$html,$cgi->div({id=>"linkselsewhere"}, &HTML::make_table($col_hdrs,$tab,$title)));
1059 :     }
1060 :     if (! $cgi->param('SPROUT'))
1061 :     {
1062 :     my $url = &cgi_url . "/add_links.cgi?peg=$peg";
1063 :     push @$html, $cgi->br("<a href=$url>To Add New Links to this Gene</a>\n");
1064 : overbeek 1.53 }
1065 : efrank 1.1 }
1066 :    
1067 :    
1068 :    
1069 :     ################# Similarities ############################
1070 :    
1071 :    
1072 :     sub print_similarities {
1073 : overbeek 1.53 my( $fig_or_sprout, $cgi, $html, $peg ) = @_;
1074 : overbeek 1.63
1075 :     if ($cgi->param('SPROUT'))
1076 :     {
1077 :     &print_similarities_SPROUT($fig_or_sprout, $cgi, $html, $peg );
1078 :     }
1079 :     else
1080 :     {
1081 :     &print_similarities_SEED($fig_or_sprout, $cgi, $html, $peg );
1082 :     }
1083 :     }
1084 :    
1085 : golsen 1.76
1086 : overbeek 1.63 sub print_similarities_SPROUT {
1087 :     my($fig_or_sprout, $cgi, $html, $peg ) = @_;
1088 :    
1089 : overbeek 1.122 $cgi->delete('sims');
1090 :    
1091 : overbeek 1.63 my $user = $cgi->param('user') || "";
1092 : overbeek 1.122
1093 : overbeek 1.63 my $current_func = &trans_function_of($cgi,$fig_or_sprout,$peg,$user);
1094 :    
1095 :     push( @$html, $cgi->hr,
1096 :     "<a name=Similarities>",
1097 : overbeek 1.68 $cgi->h1(''),
1098 : overbeek 1.63 "</a>\n"
1099 :     );
1100 :    
1101 : overbeek 1.116 my @sims = sort { $a->[1] <=> $b->[1] } &bbhs($fig_or_sprout,$peg,1.0e-10);
1102 : overbeek 1.63
1103 :     my @from = $cgi->radio_group(-name => 'from',
1104 :     -nolabels => 1,
1105 :     -override => 1,
1106 : overbeek 1.65 -values => ["",$peg,map { $_->[0] } @sims]);
1107 : overbeek 1.63
1108 :     my $target = "window$$";
1109 :     # RAE: added a name to the form so tha the javascript works
1110 :     push( @$html, $cgi->start_form( -method => 'post',
1111 :     -target => $target,
1112 :     -action => 'fid_checked.cgi',
1113 :     -name => 'fid_checked'
1114 :     ),
1115 :     $cgi->hidden(-name => 'SPROUT', -value => 1),
1116 :     $cgi->hidden(-name => 'fid', -value => $peg),
1117 :     $cgi->hidden(-name => 'user', -value => $user),
1118 :     $cgi->br,
1119 :     "For Selected (checked) sequences: ",
1120 :     $cgi->submit('align'),
1121 :     );
1122 :    
1123 :     if ($user) {
1124 :     my $help_url = "Html/help_for_assignments_and_rules.html";
1125 : golsen 1.100 push ( @$html, $cgi->br, $cgi->br,
1126 :     "<a href=$help_url target=\"SEED_or_SPROUT_help\">Help on Assignments, Rules, and Checkboxes</a>",
1127 : overbeek 1.63 $cgi->br, $cgi->br,
1128 :     $cgi->submit('assign/annotate')
1129 :     );
1130 :    
1131 :     if ($cgi->param('translate')) {
1132 :     push( @$html, $cgi->submit('add rules'),
1133 :     $cgi->submit('check rules'),
1134 :     $cgi->br
1135 :     );
1136 :     }
1137 :     }
1138 :    
1139 :     push( @$html, $cgi->br,
1140 :     $cgi->checkbox( -name => 'checked',
1141 :     -value => $peg,
1142 :     -override => 1,
1143 :     -checked => 1,
1144 :     -label => ""
1145 :     )
1146 :     );
1147 :    
1148 :     my $col_hdrs;
1149 :     if ($user && $cgi->param('translate')) {
1150 :     push( @$html, " ASSIGN to/Translate from/SELECT current PEG", $cgi->br,
1151 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1152 :     "ASSIGN from/Translate to current PEG: ", shift @from
1153 :     );
1154 :     $col_hdrs = [ "ASSIGN to<hr>Translate from",
1155 :     "Similar sequence",
1156 :     "E-val",
1157 : overbeek 1.65 "In Sub",
1158 : overbeek 1.63 "ASSIGN from<hr>Translate to",
1159 :     "Function",
1160 :     "Organism",
1161 :     "Aliases"
1162 :     ];
1163 :     } elsif ($user) {
1164 :     push( @$html, " ASSIGN to/SELECT current PEG", $cgi->br,
1165 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1166 :     "ASSIGN from current PEG: ", shift @from
1167 :     );
1168 :     $col_hdrs = [ "ASSIGN to<hr>SELECT",
1169 :     "Similar sequence",
1170 :     "E-val",
1171 : overbeek 1.65 "In Sub",
1172 : overbeek 1.63 "ASSIGN from",
1173 :     "Function",
1174 :     "Organism",
1175 :     "Aliases"
1176 :     ];
1177 :     } else {
1178 :     push(@$html, " SELECT current PEG", $cgi->br );
1179 :     $col_hdrs = [ "SELECT",
1180 :     "Similar sequence",
1181 :     "E-val",
1182 :     "In Sub",
1183 :     "Function",
1184 :     "Organism",
1185 :     "Aliases"
1186 :     ];
1187 :     }
1188 :    
1189 :     my $ncol = @$col_hdrs;
1190 :     push( @$html, "<TABLE border cols=$ncol>\n",
1191 : overbeek 1.68 "\t<Caption><h2>Bidirectional Best Hits</h2></Caption>\n",
1192 : overbeek 1.63 "\t<TR>\n\t\t<TH>",
1193 :     join( "</TH>\n\t\t<TH>", @$col_hdrs ),
1194 :     "</TH>\n\t</TR>\n"
1195 :     );
1196 :    
1197 :     # Add the table data, row-by-row
1198 :    
1199 :     my $sim;
1200 :     foreach $sim ( @sims ) {
1201 :     my($id2,$psc) = @$sim;
1202 :     my $cbox = &translatable($fig_or_sprout,$id2) ?
1203 :     qq(<input type=checkbox name=checked value="$id2">) : "";
1204 :     my $id2_link = &HTML::set_prot_links($cgi,$id2);
1205 :     chomp $id2_link;
1206 :    
1207 :     my @in_sub = &peg_to_subsystems($fig_or_sprout,$id2);
1208 :     my $in_sub;
1209 :     if (@in_sub > 0) {
1210 :     $in_sub = @in_sub;
1211 :     } else {
1212 : overbeek 1.74 $in_sub = "&nbsp;";
1213 : overbeek 1.63 }
1214 :    
1215 :     my $radio = $user ? shift @from : undef;
1216 :     my $func2 = html_enc( scalar &trans_function_of( $cgi, $fig_or_sprout, $id2, $user ) );
1217 :     ## RAE Added color3. This will color function tables that do not match the original
1218 :     ## annotation. This makes is a lot easier to see what is different (e.g. caps/spaces, etc)
1219 :     my $color3="#FFFFFF";
1220 :     unless ($func2 eq $current_func) {$color3="#FFDEAD"}
1221 :    
1222 :     #
1223 :     # Colorize organisms:
1224 :     #
1225 :     # my $org = html_enc( &org_of($fig_or_sprout, $id2 ) );
1226 :     my ($org,$oc) = &org_and_color_of($fig_or_sprout, $id2 );
1227 :     $org = html_enc( $org );
1228 :    
1229 :     my $aliases = html_enc( join( ", ", &feature_aliasesL($fig_or_sprout,$id2) ) );
1230 : overbeek 1.68
1231 : overbeek 1.64 $aliases = &HTML::set_prot_links($cgi,$aliases);
1232 : overbeek 1.63
1233 :     # Okay, everything is calculated, let's "print" the row datum-by-datum:
1234 :    
1235 : overbeek 1.74 $func2 = $func2 ? $func2 : "&nbsp;";
1236 :     $aliases = $aliases ? $aliases : "&nbsp;";
1237 : overbeek 1.63 push( @$html, "\t<TR>\n",
1238 :     #
1239 :     # Colorize check box by Domain
1240 :     #
1241 :     "\t\t<TD Align=center Bgcolor=$oc>$cbox</TD>\n",
1242 :     "\t\t<TD Nowrap>$id2_link</TD>\n",
1243 :     "\t\t<TD Nowrap>$psc</TD>\n",
1244 : overbeek 1.65 "\t\t<TD>$in_sub</TD>",
1245 : overbeek 1.63 $user ? "\t\t<TD Align=center>$radio</TD>\n" : (),
1246 :     "\t\t<TD Bgcolor=$color3>$func2</TD>\n",
1247 :     #
1248 :     # Colorize organism by Domain
1249 :     #
1250 :     # "\t\t<TD>$org</TD>\n",
1251 :     "\t\t<TD Bgcolor=$oc>$org</TD>\n",
1252 :     "\t\t<TD>$aliases</TD>\n",
1253 :     "\t</TR>\n"
1254 :     );
1255 :     }
1256 :     push( @$html, "</TABLE>\n" );
1257 :     push( @$html, $cgi->end_form );
1258 :     }
1259 :    
1260 :    
1261 :     sub print_similarities_SEED {
1262 :     my( $fig_or_sprout, $cgi, $html, $peg ) = @_;
1263 : efrank 1.1
1264 : golsen 1.18 my $user = $cgi->param('user') || "";
1265 : golsen 1.76 my $current_func = &trans_function_of( $cgi, $fig_or_sprout, $peg, $user );
1266 : efrank 1.1
1267 : golsen 1.100 push @$html, $cgi->hr,
1268 :     "<a name=Similarities>", # Put an anchor on the heading
1269 :     $cgi->h2('Similarities'),
1270 :     "</a>\n";
1271 : golsen 1.34
1272 : golsen 1.76 # Generate the request form, and return current option values in hash
1273 : efrank 1.1
1274 : golsen 1.76 my $short_form = 0;
1275 : golsen 1.98 my $SimParams = sims_request_form( $fig_or_sprout, $cgi, $html, $peg, $user, $short_form );
1276 : overbeek 1.51
1277 : golsen 1.76 my $maxN = $SimParams->{ maxN };
1278 :     my $maxP = $SimParams->{ maxP };
1279 :     my $max_expand = $SimParams->{ max_expand };
1280 : golsen 1.98 my $select = $SimParams->{ select };
1281 : golsen 1.76 my $show_env = $SimParams->{ show_env };
1282 :     my $hide_alias = $SimParams->{ hide_alias };
1283 : overbeek 1.90 my $group_by_genome = $SimParams->{ group_by_genome };
1284 : golsen 1.98
1285 :     # These are active, but the values are only used in sims()
1286 :     # my $extra_opt = $SimParams->{ extra_opt };
1287 :     # my $min_q_cov = $SimParams->{ min_q_cov };
1288 :     # my $min_s_cov = $SimParams->{ min_s_cov };
1289 :     # my $min_sim = $SimParams->{ min_sim };
1290 :     # my $sim_meas = $SimParams->{ sim_meas };
1291 :     # my $sort_by = $SimParams->{ sort_by };
1292 :    
1293 : golsen 1.76 # None of these are currently active: -- GJO
1294 : golsen 1.98 # my $show_rep = $SimParams->{ show_rep };
1295 :     # my $max_sim = $SimParams->{ max_sim };
1296 :     # my $dyn_thrsh = $SimParams->{ dyn_thrsh };
1297 :     # my $save_dist = $SimParams->{ save_dist };
1298 :     # my $chk_which = $SimParams->{ chk_which };
1299 : efrank 1.1
1300 : golsen 1.76 # There is currently no control to turn this on! -- GJO
1301 : parrello 1.108 my $expand_groups = $SimParams->{ expand_groups };
1302 : efrank 1.1
1303 : golsen 1.76 # Move filtering of sims list out of display loop. Avoids many problems,
1304 :     # including display of table with no entries. Anticipate more filters.
1305 :     # -- GJO
1306 : golsen 1.97 #
1307 : golsen 1.98 # All the filtering is now done in get_raw_sims and expand_raw_sims. -- GJO
1308 : golsen 1.76
1309 : golsen 1.98 my @sims = sims( $fig_or_sprout,
1310 :     $peg,
1311 :     $maxN,
1312 :     $maxP,
1313 :     $select,
1314 :     $max_expand,
1315 :     $group_by_genome,
1316 :     $SimParams
1317 :     );
1318 : golsen 1.77
1319 : golsen 1.76 if ( @sims ) {
1320 :     push( @$html, $cgi->hr );
1321 :     my @from = $cgi->radio_group( -name => 'from',
1322 :     -nolabels => 1,
1323 :     -override => 1,
1324 :     -values => [ "", $peg, map { $_->id2 } @sims ]
1325 :     );
1326 : parrello 1.60
1327 :     my $target = "window$$";
1328 :     # RAE: added a name to the form so tha the javascript works
1329 :     push( @$html, $cgi->start_form( -method => 'post',
1330 : golsen 1.76 -target => $target,
1331 :     -action => 'fid_checked.cgi',
1332 :     -name => 'fid_checked'
1333 : parrello 1.60 ),
1334 :     $cgi->hidden(-name => 'fid', -value => $peg),
1335 :     $cgi->hidden(-name => 'user', -value => $user),
1336 :     $cgi->br,
1337 :     "For Selected (checked) sequences: ",
1338 :     $cgi->submit('align'),
1339 :     $cgi->submit('view annotations'),
1340 : golsen 1.106 $cgi->submit('get sequences'),
1341 : parrello 1.60 $cgi->submit('show regions')
1342 :     );
1343 :    
1344 :     if ($user) {
1345 :     my $help_url = "Html/help_for_assignments_and_rules.html";
1346 :     push ( @$html, $cgi->br, $cgi->br,
1347 : golsen 1.100 "<a href=$help_url target=\"SEED_or_SPROUT_help\">Help on Assignments, Rules, and Checkboxes</a>",
1348 : parrello 1.60 $cgi->br, $cgi->br,
1349 :     $cgi->submit('assign/annotate')
1350 :     );
1351 :    
1352 :     if ($cgi->param('translate')) {
1353 :     push( @$html, $cgi->submit('add rules'),
1354 :     $cgi->submit('check rules'),
1355 :     $cgi->br
1356 :     );
1357 :     }
1358 :     }
1359 : efrank 1.1
1360 : parrello 1.60 push( @$html, $cgi->br,
1361 :     $cgi->checkbox( -name => 'checked',
1362 :     -value => $peg,
1363 :     -override => 1,
1364 :     -checked => 1,
1365 :     -label => ""
1366 :     )
1367 :     );
1368 :    
1369 :     my $col_hdrs;
1370 : overbeek 1.176 my $color_help = "(<A href=\"Html/similarity_region_colors.html\" target=\"SEED_or_SPROUT_help\">colors</A>)";
1371 :     my $func_clr_help = "(<A href=\"Html/function_colors.html\" target=\"SEED_or_SPROUT_help\">function colors</A>)";
1372 : golsen 1.97
1373 : parrello 1.60 if ($user && $cgi->param('translate')) {
1374 :     push( @$html, " ASSIGN to/Translate from/SELECT current PEG", $cgi->br,
1375 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1376 : golsen 1.97 "ASSIGN from/Translate to current PEG: ", shift @from
1377 : parrello 1.60 );
1378 :     $col_hdrs = [ "ASSIGN to<hr>Translate from",
1379 :     $expand_groups ? "family" : (),
1380 :     $expand_groups ? "size" : (),
1381 :     "Similar sequence",
1382 :     "E-val<br>% iden",
1383 : overbeek 1.177 "region in<br>sim seq<br>$color_help",
1384 :     "region in<br>peg<br>$color_help",
1385 : parrello 1.60 "ASSIGN from<hr>Translate to",
1386 : overbeek 1.90 "In Sub",
1387 : overbeek 1.143 &evidence_codes_link($cgi),
1388 : golsen 1.97 "Function<br>$func_clr_help",
1389 : parrello 1.60 "Organism",
1390 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1391 : parrello 1.60 ];
1392 :     } elsif ($user) {
1393 :     push( @$html, " ASSIGN to/SELECT current PEG", $cgi->br,
1394 :     "ASSIGN/annotate with form: ", shift @from, $cgi->br,
1395 : golsen 1.97 "ASSIGN from current PEG: ", shift @from
1396 : parrello 1.60 );
1397 :     $col_hdrs = [ "ASSIGN to<hr>SELECT",
1398 :     $expand_groups ? "family" : (),
1399 :     $expand_groups ? "size" : (),
1400 :     "Similar sequence",
1401 :     "E-val<br>% iden",
1402 : overbeek 1.178 "region in<br>sim seq<br>$color_help",
1403 :     "region in<br>peg<br>$color_help",
1404 : overbeek 1.179 "Assign from",
1405 : parrello 1.60 "In Sub",
1406 : overbeek 1.143 &evidence_codes_link($cgi),
1407 : golsen 1.97 "Function<br>$func_clr_help",
1408 : parrello 1.60 "Organism",
1409 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1410 : parrello 1.60 ];
1411 :     } else {
1412 :     push(@$html, " SELECT current PEG", $cgi->br );
1413 :     $col_hdrs = [ "SELECT",
1414 :     $expand_groups ? "family" : (),
1415 :     $expand_groups ? "size" : (),
1416 :     "Similar sequence",
1417 :     "E-val<br>% iden",
1418 :     "region in<br>similar sequence<br>$color_help",
1419 :     "region in<br>$peg<br>$color_help",
1420 : golsen 1.97 "In Sub",
1421 : overbeek 1.143 &evidence_codes_link($cgi),
1422 : golsen 1.97 "Function<br>$func_clr_help",
1423 : parrello 1.60 "Organism",
1424 : overbeek 1.90 (! $hide_alias) ? "Aliases" : ()
1425 : parrello 1.60 ];
1426 :     }
1427 : efrank 1.1
1428 : redwards 1.37 # RAE Add the check all/uncheck all boxes.
1429 :     push (@$html, $cgi->br, &HTML::java_buttons("fid_checked", "checked"), $cgi->br);
1430 :    
1431 : parrello 1.60 #
1432 :     # Total rewrite of sim table code: cleaner program flow; omitting
1433 :     # empty columns; colorizing region-of-similarity cells -- GJO
1434 :     #
1435 :     # Start the similarity table with "Caption" and header row
1436 :    
1437 :     my $ncol = @$col_hdrs;
1438 :     push( @$html, "<TABLE border cols=$ncol>\n",
1439 :     "\t<Caption><h2>Similarities</h2></Caption>\n",
1440 :     "\t<TR>\n\t\t<TH>",
1441 :     join( "</TH>\n\t\t<TH>", @$col_hdrs ),
1442 :     "</TH>\n\t</TR>\n"
1443 :     );
1444 :    
1445 : golsen 1.97 #
1446 : golsen 1.93 # Grouping by genome is hard to see. This is an attempt to make it more obvious
1447 :     # by consolidating the "Organism" for all rows in which it is repeated. -- GJO
1448 : golsen 1.97 #
1449 :     # Let's figure out the function here too. This will allow color to be
1450 :     # specific for more than one function. For example, we can color:
1451 :     #
1452 :     # Identical function white
1453 :     # Most common alternative brown
1454 :     # Next most common alternatives red, orange, yellow, green, blue, and violet
1455 :     # Any additional alternatives gray
1456 :     #
1457 : golsen 1.93
1458 :     my $sim;
1459 : golsen 1.97 my ( $id2, $func, $genome, $org, $color, $info, $prev_genome, $prev_sim );
1460 :     my %func_cnt = ();
1461 :    
1462 : golsen 1.93 foreach $sim ( @sims ) {
1463 :     $id2 = $sim->id2;
1464 : golsen 1.97
1465 :     $func = html_enc( scalar trans_function_of( $cgi, $fig_or_sprout, $id2, $user ) );
1466 :     $func && $func_cnt{ $func }++;
1467 :    
1468 : golsen 1.93 if ( $group_by_genome && ( ( $genome ) = $id2 =~ /fig\|(\d+\.\d+)\./ )
1469 :     && ( $genome eq $prev_genome ) )
1470 :     {
1471 : golsen 1.97 $prev_sim->[-1]->[3]++; # Increase row span of org
1472 :     push @$sim, [ $func, "", $color, 0 ]; # No org name, prev_color, no row span
1473 : golsen 1.93 }
1474 :     else
1475 :     {
1476 :     ( $org, $color ) = org_and_color_of( $fig_or_sprout, $id2 );
1477 : golsen 1.97 push @$sim, [ $func, html_enc( $org ), $color, 1 ];
1478 : golsen 1.93 $prev_genome = $genome || "";
1479 :     $prev_sim = $sim;
1480 :     }
1481 :     }
1482 :    
1483 : golsen 1.97 # Build a function to color translation table based on frequence of function.
1484 :     # Reserve white for the current function.
1485 :    
1486 :     my %func_color;
1487 :     $func_cnt{ $current_func } && delete $func_cnt{ $current_func };
1488 :     $func_color{ $current_func } = "#FFFFFF";
1489 : parrello 1.108
1490 : golsen 1.97 # Assign other colors until we run out:
1491 :    
1492 :     my @colors = qw( #EECCAA #FFAAAA #FFCC66 #FFFF00 #AAFFAA #BBBBFF #FFAAFF );
1493 :     for ( sort { $func_cnt{ $b } <=> $func_cnt{ $a } } keys %func_cnt )
1494 :     {
1495 :     $func_color{ $_ } = ( shift @colors ) || "#DDDDDD";
1496 :     }
1497 :    
1498 : parrello 1.60 # Add the table data, row-by-row
1499 :    
1500 : overbeek 1.90 my $alia = (! $hide_alias);
1501 : parrello 1.60 foreach $sim ( @sims ) {
1502 :     my $id2 = $sim->id2;
1503 : golsen 1.76
1504 : parrello 1.60 my $cbox = &translatable($fig_or_sprout,$id2) ?
1505 :     qq(<input type=checkbox name=checked value="$id2">) : "";
1506 :    
1507 :     my( $family, $sz, $funcF, $fam_link );
1508 : overbeek 1.118 $family = $sz = $funcF = $fam_link = "";
1509 : parrello 1.60
1510 :     my $id2_link = &HTML::set_prot_links($cgi,$id2);
1511 :     chomp $id2_link;
1512 :    
1513 :     my @in_sub = &peg_to_subsystems($fig_or_sprout,$id2);
1514 :     my $in_sub;
1515 : overbeek 1.141
1516 : parrello 1.60 if (@in_sub > 0) {
1517 :     $in_sub = @in_sub;
1518 : overbeek 1.158 # RAE: add a javascript popup with all the subsystems
1519 :     my $ss_list=join "<br>", map { my $g = $_; $g =~ s/\_/ /g; $_ = $g } sort {$a cmp $b} @in_sub;
1520 :     $in_sub = $cgi->a(
1521 : 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);
1522 : parrello 1.60 } else {
1523 : overbeek 1.74 $in_sub = "&nbsp;";
1524 : parrello 1.60 }
1525 :    
1526 : redwards 1.160 # evidence codes moved here so I can add a tool tip for them
1527 :     my $ev_codes=" &nbsp; ";
1528 :     my @ev_codes=&evidence_codes($fig_or_sprout,$id2);
1529 :     if (scalar(@ev_codes) && $ev_codes[0])
1530 :     {
1531 :     my $ev_code_help=join("<br />", map {&evidence_codes_explain($_)} @ev_codes);
1532 :     $ev_codes = $cgi->a(
1533 :     {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));
1534 :     }
1535 :    
1536 : parrello 1.60 my $psc = $sim->psc;
1537 :     my $iden = $sim->iden;
1538 :     my $ln1 = $sim->ln1;
1539 :     my $ln2 = $sim->ln2;
1540 :     my $b1 = $sim->b1;
1541 :     my $e1 = $sim->e1;
1542 :     my $b2 = $sim->b2;
1543 :     my $e2 = $sim->e2;
1544 :     my $d1 = abs($e1 - $b1) + 1;
1545 :     my $d2 = abs($e2 - $b2) + 1;
1546 :     my $reg1 = "$b1-$e1 (<b>$d1/$ln1</b>)";
1547 :     my $color1 = match_color( $b1, $e1, $ln1 );
1548 :     my $reg2 = "$b2-$e2 (<b>$d2/$ln2</b>)";
1549 :     my $color2 = match_color( $b2, $e2, $ln2 );
1550 :     my $radio = $user ? shift @from : undef;
1551 : golsen 1.97
1552 :     # Retrieve the Function and Organism data that was pushed on the end of the sim:
1553 :    
1554 :     my ( $func2, $org, $oc, $rowspan ) = @{$sim->[-1]};
1555 : golsen 1.93
1556 :     ## RAE Added color3. This will color function cells that do not match the original
1557 : parrello 1.60 ## annotation. This makes is a lot easier to see what is different (e.g. caps/spaces, etc)
1558 : golsen 1.97
1559 :     my $color3 = $func2 && $func_color{ $func2 } || "#DDDDDD";
1560 : parrello 1.60
1561 : golsen 1.93 if ( $funcF && ( $funcF ne $func2 ) ) { $func2 = "$funcF<br>$func2" }
1562 : golsen 1.97 $func2 ||= "&nbsp;";
1563 : parrello 1.60
1564 : golsen 1.97 my $aliases = undef;
1565 :     if ( $alia )
1566 :     {
1567 :     $aliases = html_enc( join( ", ", &feature_aliasesL($fig_or_sprout,$id2) ) );
1568 :     $aliases = &HTML::set_prot_links( $cgi, $aliases );
1569 :     $aliases ||= "&nbsp;";
1570 :     }
1571 : parrello 1.60
1572 :     # Okay, everything is calculated, let's "print" the row datum-by-datum:
1573 :    
1574 :     push( @$html, "\t<TR>\n",
1575 :     #
1576 :     # Colorize check box by Domain
1577 :     #
1578 :     "\t\t<TD Align=center Bgcolor=$oc>$cbox</TD>\n",
1579 :     $expand_groups ? "\t\t<TD>$fam_link</TD>/n" : (),
1580 :     $expand_groups ? "\t\t<TD>$sz</TD>\n" : (),
1581 :     "\t\t<TD Nowrap>$id2_link</TD>\n",
1582 :     "\t\t<TD Nowrap>$psc<br>$iden\%</TD>\n",
1583 :     "\t\t<TD Nowrap Bgcolor=$color2>$reg2</TD>\n",
1584 :     "\t\t<TD Nowrap Bgcolor=$color1>$reg1</TD>\n",
1585 :     $user ? "\t\t<TD Align=center>$radio</TD>\n" : (),
1586 : golsen 1.100 "\t\t<TD Align=center>$in_sub</TD>",
1587 : redwards 1.160 "\t\t<TD Align=center>$ev_codes</TD>",
1588 : parrello 1.60 "\t\t<TD Bgcolor=$color3>$func2</TD>\n",
1589 :     #
1590 :     # Colorize organism by Domain
1591 :     #
1592 : golsen 1.93 $rowspan ? "\t\t<TD Rowspan=$rowspan Bgcolor=$oc>$org</TD>\n" : (),
1593 : parrello 1.60 $alia ? "\t\t<TD>$aliases</TD>\n" : (),
1594 :     "\t</TR>\n"
1595 :     );
1596 :     }
1597 : overbeek 1.11
1598 : parrello 1.60 push( @$html, "</TABLE>\n" );
1599 :     push( @$html, $cgi->end_form );
1600 : efrank 1.1 }
1601 :     }
1602 :    
1603 : golsen 1.18 #
1604 :     # Support functions for writing the similarities
1605 :     #
1606 :     # This is a sufficient set of escaping for text in HTML:
1607 :     #
1608 :    
1609 :     sub html_enc { $_ = $_[0]; s/\&/&amp;/g; s/\>/&gt;/g; s/\</&lt;/g; $_ }
1610 :    
1611 :     #
1612 :     # Make a background color that reflects the position and extent of a
1613 :     # matching region.
1614 :     #
1615 :     # Left side is red; right side is blue.
1616 :     # Long match is white or pastel; short match is saturated color.
1617 :     #
1618 :    
1619 :     sub match_color {
1620 :     my ( $b, $e, $n ) = @_;
1621 :     my ( $l, $r ) = ( $e > $b ) ? ( $b, $e ) : ( $e, $b );
1622 :     # my $hue = 3/4 * 0.5*($l+$r)/$n - 1/24;
1623 :     my $hue = 5/6 * 0.5*($l+$r)/$n - 1/12;
1624 :     my $cov = ( $r - $l + 1 ) / $n;
1625 :     my $sat = 1 - 10 * $cov / 9;
1626 :     my $br = 1;
1627 :     rgb2html( hsb2rgb( $hue, $sat, $br ) );
1628 :     }
1629 :    
1630 :     #
1631 :     # Convert HSB to RGB. Hue is taken to be in range 0 - 1 (red to red);
1632 :     #
1633 :    
1634 :     sub hsb2rgb {
1635 :     my ( $h, $s, $br ) = @_;
1636 :     $h = 6 * ($h - floor($h)); # Hue is made cyclic modulo 1
1637 :     if ( $s > 1 ) { $s = 1 } elsif ( $s < 0 ) { $s = 0 }
1638 :     if ( $br > 1 ) { $br = 1 } elsif ( $br < 0 ) { $br = 0 }
1639 :     my ( $r, $g, $b ) = ( $h <= 3 ) ? ( ( $h <= 1 ) ? ( 1, $h, 0 )
1640 :     : ( $h <= 2 ) ? ( 2 - $h, 1, 0 )
1641 :     : ( 0, 1, $h - 2 )
1642 :     )
1643 :     : ( ( $h <= 4 ) ? ( 0, 4 - $h, 1 )
1644 :     : ( $h <= 5 ) ? ( $h - 4, 0, 1 )
1645 :     : ( 1, 0, 6 - $h )
1646 :     );
1647 :     ( ( $r * $s + 1 - $s ) * $br,
1648 :     ( $g * $s + 1 - $s ) * $br,
1649 :     ( $b * $s + 1 - $s ) * $br
1650 :     )
1651 :     }
1652 :    
1653 :     #
1654 :     # Convert an RGB value to an HTML color string:
1655 :     #
1656 :    
1657 :     sub rgb2html {
1658 :     my ( $r, $g, $b ) = @_;
1659 :     if ( $r > 1 ) { $r = 1 } elsif ( $r < 0 ) { $r = 0 }
1660 :     if ( $g > 1 ) { $g = 1 } elsif ( $g < 0 ) { $g = 0 }
1661 :     if ( $b > 1 ) { $b = 1 } elsif ( $b < 0 ) { $b = 0 }
1662 :     sprintf("\"#%02x%02x%02x\"", int(255.999*$r), int(255.999*$g), int(255.999*$b) )
1663 :     }
1664 :    
1665 :     #
1666 :     # floor could be gotten from POSIX::, but why bother?
1667 :     #
1668 :    
1669 :     sub floor {
1670 :     my $x = $_[0];
1671 :     defined( $x ) || return undef;
1672 :     ( $x >= 0 ) || ( int($x) == $x ) ? int( $x ) : -1 - int( - $x )
1673 :     }
1674 :    
1675 :    
1676 : golsen 1.76 #------------------------------------------------------------------------
1677 :     # Generate similarity query forms for the SEED. Consolidates things like
1678 :     # style and defaults in one place.
1679 :     #
1680 :     # my $user = $cgi->param('user') || "";
1681 :     # my $short_form = 0;
1682 :     # my $SimParam = sims_request_form( $fig, $cgi, $html, $peg, $user, $short_form );
1683 :     #------------------------------------------------------------------------
1684 :    
1685 :     sub sims_request_form {
1686 :     my ( $fig, $cgi, $html, $peg, $user, $short_form ) = @_;
1687 :    
1688 : overbeek 1.122 my $trans_role = $cgi->param('translate') || 0;
1689 :    
1690 :     if ($cgi->param('SPROUT'))
1691 :     {
1692 :     &sprout_sims_request_form($cgi,$html,$peg,$trans_role,$user);
1693 :     return;
1694 :     }
1695 :    
1696 : golsen 1.76 # Read available parameters, and fill in defaults:
1697 :    
1698 :     my $maxN = defined( $cgi->param('maxN') ) ? $cgi->param('maxN') : 50;
1699 :     my $max_expand = defined( $cgi->param('max_expand') ) ? $cgi->param('max_expand') : 5;
1700 :     my $maxP = defined( $cgi->param('maxP') ) ? $cgi->param('maxP') : 1.0e-5;
1701 : golsen 1.98 my $select = $cgi->param('select') || 'all';
1702 :     my $show_env = $cgi->param('show_env') || 0;
1703 :     my $hide_alias = $cgi->param('hide_alias') || 0;
1704 : golsen 1.100 my $sort_by = $cgi->param('sort_by') || 'bits';
1705 : golsen 1.98 my $group_by_genome = $cgi->param('group_by_genome') || 0;
1706 :     my $expand_groups = $cgi->param('expand_groups') || 0;
1707 : golsen 1.76
1708 : golsen 1.77 # New similarity options
1709 :    
1710 :     # Act on request for more or fewer sim options
1711 : golsen 1.76
1712 :     my $extra_opt = defined( $cgi->param('extra_opt') ) ? $cgi->param('extra_opt') : 0;
1713 : golsen 1.77 if ( $cgi->param('more sim options') ) {
1714 :     $extra_opt = 1;
1715 :     $cgi->delete('more sim options');
1716 :     }
1717 :     if ( $cgi->param('fewer sim options') ) {
1718 :     $extra_opt = 0;
1719 :     $cgi->delete('fewer sim options');
1720 :     }
1721 :    
1722 :     # Make defaults completely open (match original behavior)
1723 :    
1724 :     my $min_sim = $extra_opt && defined( $cgi->param('min_sim') ) ? $cgi->param('min_sim') : 0;
1725 : golsen 1.100 my $sim_meas = $extra_opt && defined( $cgi->param('sim_meas') ) ? $cgi->param('sim_meas') : 'id';
1726 : golsen 1.77 my $min_q_cov = $extra_opt && defined( $cgi->param('min_q_cov') ) ? $cgi->param('min_q_cov') : 0;
1727 :     my $min_s_cov = $extra_opt && defined( $cgi->param('min_s_cov') ) ? $cgi->param('min_s_cov') : 0;
1728 : golsen 1.76
1729 : golsen 1.77 # New parameters. Not yet implimented.
1730 : golsen 1.76 # The defaults for representative sequences might be tuned:
1731 :    
1732 : golsen 1.77 my $show_rep = $extra_opt && defined( $cgi->param('show_rep') ) ? $cgi->param('show_rep') : 0;
1733 :     my $max_sim = $extra_opt && defined( $cgi->param('max_sim') ) ? $cgi->param('max_sim') : 0.70;
1734 :     my $dyn_thrsh = $extra_opt && defined( $cgi->param('dyn_thrsh') ) ? $cgi->param('dyn_thrsh') : 0;
1735 :     my $save_dist = $extra_opt && defined( $cgi->param('save_dist') ) ? $cgi->param('save_dist') : 0.80;
1736 : golsen 1.76
1737 :     # Mark some of the sequences automatically?
1738 :    
1739 : golsen 1.77 my $chk_which = $extra_opt && defined( $cgi->param('chk_which') ) ? $cgi->param('chk_which') : 'none';
1740 :    
1741 : golsen 1.76 # Use $cgi->param('more similarities') to drive increase in maxN and max_expand
1742 :    
1743 :     if ( $cgi->param('more similarities') ) {
1744 :     $maxN *= 2;
1745 :     $max_expand *= 2;
1746 :     $cgi->delete('more similarities');
1747 :     }
1748 :    
1749 : golsen 1.100 # Sanity checks on fixed vocabulary parameter values:
1750 : golsen 1.76
1751 : golsen 1.102 my %select_opts = map { ( $_, 1 ) } qw( all fig figx fig_pref figx_pref );
1752 :     my %sort_opts = map { ( $_, 1 ) } qw( bits id id2 bpp bpp2 );
1753 :     my %sim_meas_opts = map { ( $_, 1 ) } qw( id bpp );
1754 :     my %chk_which_opts = map { ( $_, 1 ) } qw( none all rep );
1755 :    
1756 :     $select = 'all' unless $select_opts{ $select };
1757 :     $sort_by = 'bits' unless $sort_opts{ $sort_by };
1758 :     $sim_meas = 'id' unless $sim_meas_opts{ $sim_meas };
1759 :     $chk_which = 'none' unless $chk_which_opts{ $chk_which };
1760 : golsen 1.76
1761 : golsen 1.100 # We have processed all options. Use them to build forms.
1762 : golsen 1.76
1763 :     # Checkmarks for input tags
1764 :    
1765 : golsen 1.102 my $chk_select_all = select_if( $select eq 'all' );
1766 :     my $chk_select_figp = select_if( $select eq 'fig_pref' );
1767 :     my $chk_select_figxp = select_if( $select eq 'figx_pref' );
1768 :     my $chk_select_fig = select_if( $select eq 'fig' );
1769 :     my $chk_select_figx = select_if( $select eq 'figx' );
1770 :     my $chk_show_env = chked_if( $show_env );
1771 :     my $chk_hide_alias = chked_if( $hide_alias );
1772 : overbeek 1.90 my $chk_group_by_genome = chked_if( $group_by_genome );
1773 : golsen 1.102 my $chk_sort_by_id = select_if( $sort_by eq 'id' );
1774 :     my $chk_sort_by_id2 = select_if( $sort_by eq 'id2' );
1775 :     my $chk_sort_by_bits = select_if( $sort_by eq 'bits' );
1776 :     my $chk_sort_by_bpp = select_if( $sort_by eq 'bpp' );
1777 :     my $chk_sort_by_bpp2 = select_if( $sort_by eq 'bpp2' );
1778 : golsen 1.76
1779 :     # Features unique to the long form:
1780 :    
1781 :     if ( $short_form )
1782 :     {
1783 :     # Use a here document to push the short version of the similarities form
1784 :     # on @$html (many values are passed as hidden inputs).
1785 :    
1786 :     push @$html, <<"End_Short_Form";
1787 :    
1788 :     <FORM Action=\"protein.cgi#Similarities\">
1789 :     <input type=hidden name=prot value=\"$peg\">
1790 :     <input type=hidden name=sims value=1>
1791 :     <input type=hidden name=fid value=\"$peg\">
1792 :     <input type=hidden name=user value=\"$user\">
1793 :     <input type=hidden name=translate value=$trans_role>
1794 :    
1795 : golsen 1.103 &nbsp;&nbsp;&nbsp; Max sims:<input type=text name=maxN size=5 value=$maxN> &nbsp;&nbsp;
1796 : golsen 1.100 Max expand:<input type=text name=max_expand size=5 value=$max_expand> &nbsp;&nbsp;
1797 :     Max E-val:<input type=text name=maxP size=8 value=$maxP> &nbsp;&nbsp;
1798 : golsen 1.98 <select name=select>
1799 : golsen 1.102 <option value=all $chk_select_all>Show all databases</option>
1800 :     <option value=fig_pref $chk_select_figp>Prefer FIG IDs (to max exp)</option>
1801 :     <option value=figx_pref $chk_select_figxp>Prefer FIG IDs (all)</option>
1802 :     <option value=fig $chk_select_fig>Just FIG IDs (to max exp)</option>
1803 :     <option value=figx $chk_select_figx>Just FIG IDs (all)</option>
1804 : golsen 1.100 </select> &nbsp;&nbsp;
1805 :     Show Env. samples:<input type=checkbox name=show_env value=1 $chk_show_env> &nbsp;&nbsp;
1806 : golsen 1.98 Hide aliases:<input type=checkbox name=hide_alias value=1 $chk_hide_alias><br />
1807 :    
1808 : golsen 1.103 <input type=submit name=Similarities value=Similarities> &nbsp;&nbsp;
1809 : golsen 1.98 Sort by
1810 :     <select name=sort_by>
1811 : golsen 1.101 <option value=bits $chk_sort_by_bits>score</option>
1812 :     <option value=id2 $chk_sort_by_id2>percent identity*</option>
1813 :     <option value=bpp2 $chk_sort_by_bpp2>score per position*</option>
1814 : golsen 1.98 <option value=id $chk_sort_by_id>percent identity</option>
1815 :     <option value=bpp $chk_sort_by_bpp>score per position</option>
1816 : golsen 1.100 </select> &nbsp;&nbsp;
1817 :     Group by genome:<input type=checkbox name=group_by_genome value=1 $chk_group_by_genome>
1818 :     &nbsp;&nbsp;&nbsp;
1819 : overbeek 1.168 <A href=\"Html/similarities_options.html\" target=\"SEED_or_SPROUT_help\" class=\"help\">Help with SEED similarities options</A><BR />
1820 : golsen 1.76 </FORM>
1821 : golsen 1.100
1822 : golsen 1.76 End_Short_Form
1823 :    
1824 :     }
1825 :     else
1826 :     {
1827 :     # Navigation buttons
1828 :    
1829 :     my ( $prev_peg_btn, $next_peg_btn ) = ( "", "" );
1830 :     my ( $prefix, $protnum ) = $peg =~ /^(.*\.)(\d+)$/;
1831 :     if ( $prefix && $protnum ) {
1832 :     if ( ( $protnum > 1 ) && &translatable( $fig_or_sprout, $prefix . ($protnum-1) ) )
1833 :     {
1834 :     $prev_peg_btn = $cgi->submit('previous PEG');
1835 :     }
1836 :     if ( &translatable( $fig_or_sprout, $prefix . ($protnum+1) ) )
1837 :     {
1838 :     $next_peg_btn = $cgi->submit('next PEG');
1839 :     }
1840 :     }
1841 :    
1842 :     # Add/remove extra options button
1843 :    
1844 :     my $extra_opt_btn = $extra_opt ? $cgi->submit('fewer sim options')
1845 :     : $cgi->submit('more sim options');
1846 :    
1847 :     # Checkmarks for input tags
1848 :    
1849 :     my $chk_sim_meas_id = select_if( $sim_meas eq 'id' );
1850 :     my $chk_sim_meas_bpp = select_if( $sim_meas eq 'bpp' );
1851 :     my $chk_show_rep = chked_if( $show_rep );
1852 :     my $chk_dyn_thrsh = chked_if( $dyn_thrsh );
1853 :     my $chk_chk_none = select_if( $chk_which eq 'none' );
1854 :     my $chk_chk_all = select_if( $chk_which eq 'all' );
1855 :     my $chk_chk_rep = select_if( $chk_which eq 'rep' );
1856 :    
1857 : golsen 1.77 # Finally time to write some HTML
1858 :     #
1859 : golsen 1.76 # Default options
1860 :    
1861 :     push @$html, <<"End_Default_Options";
1862 : golsen 1.98
1863 : golsen 1.76 <FORM Action=\"protein.cgi#Similarities\">
1864 :     <input type=hidden name=prot value=\"$peg\">
1865 :     <input type=hidden name=sims value=1>
1866 :     <input type=hidden name=fid value=\"$peg\">
1867 :     <input type=hidden name=user value=\"$user\">
1868 :     <input type=hidden name=translate value=$trans_role>
1869 :    
1870 : golsen 1.100 Max sims:<input type=text name=maxN size=5 value=$maxN> &nbsp;&nbsp;
1871 :     Max expand:<input type=text name=max_expand size=5 value=$max_expand> &nbsp;&nbsp;
1872 :     Max E-val:<input type=text name=maxP size=8 value=$maxP> &nbsp;&nbsp;
1873 : golsen 1.98 <select name=select>
1874 : golsen 1.102 <option value=all $chk_select_all>Show all databases</option>
1875 :     <option value=fig_pref $chk_select_figp>Prefer FIG IDs (to max exp)</option>
1876 :     <option value=figx_pref $chk_select_figxp>Prefer FIG IDs (all)</option>
1877 :     <option value=fig $chk_select_fig>Just FIG IDs (to max exp)</option>
1878 :     <option value=figx $chk_select_figx>Just FIG IDs (all)</option>
1879 : golsen 1.100 </select> &nbsp;&nbsp;
1880 :     Show Env. samples:<input type=checkbox name=show_env value=1 $chk_show_env> &nbsp;&nbsp;
1881 : golsen 1.98 Hide aliases:<input type=checkbox name=hide_alias value=1 $chk_hide_alias><br />
1882 :    
1883 :     Sort by
1884 :     <select name=sort_by>
1885 : golsen 1.101 <option value=bits $chk_sort_by_bits>score</option>
1886 :     <option value=id2 $chk_sort_by_id2>percent identity*</option>
1887 :     <option value=bpp2 $chk_sort_by_bpp2>score per position*</option>
1888 : golsen 1.98 <option value=id $chk_sort_by_id>percent identity</option>
1889 :     <option value=bpp $chk_sort_by_bpp>score per position</option>
1890 : golsen 1.100 </select> &nbsp;&nbsp;
1891 :     Group by genome:<input type=checkbox name=group_by_genome value=1 $chk_group_by_genome> &nbsp;&nbsp;&nbsp;
1892 : overbeek 1.168 <A href=\"Html/similarities_options.html\" target=\"SEED_or_SPROUT_help\" class=\"help\">Help with SEED similarities options</A><br />
1893 : golsen 1.76 End_Default_Options
1894 :    
1895 :     # Extra options
1896 :    
1897 :     push @$html, <<"End_Extra_Options" if $extra_opt;
1898 : golsen 1.77 <input type=hidden name=extra_opt value=\"$extra_opt\">
1899 :    
1900 : golsen 1.76 Min similarity:<input type=text name=min_sim size=5 value=$min_sim>
1901 : golsen 1.98 defined by
1902 : golsen 1.76 <select name=sim_meas>
1903 : golsen 1.98 <option value=id $chk_sim_meas_id>identities (0-100%)</option>
1904 :     <option value=bpp $chk_sim_meas_bpp>score per position (0-2 bits)</option>
1905 : golsen 1.100 </select> &nbsp;&nbsp;
1906 :     Min query cover (%):<input type=text name=min_q_cov size=5 value=$min_q_cov> &nbsp;&nbsp;
1907 : golsen 1.98 Min subject cover (%):<input type=text name=min_s_cov size=5 value=$min_s_cov><br />
1908 : golsen 1.76
1909 : golsen 1.77 <!-- Hide unimplimented options
1910 : golsen 1.76 <TABLE Cols=2>
1911 :     <TR>
1912 :     <TD Valign=top><input type=checkbox name=show_rep $chk_show_rep></TD>
1913 :     <TD> Show only representative sequences whose similarities to one another
1914 :     are less than <input type=text size=5 name=max_sim value=$max_sim>
1915 :     <br />
1916 :     <input type=checkbox name=dyn_thrsh value=1 $chk_dyn_thrsh> But keep sequences
1917 :     that are at least <input type=text size=5 name=save_dist value=$save_dist>
1918 :     times as distant from one another as from the query</TD>
1919 :     </TR>
1920 :     </TABLE>
1921 :    
1922 : golsen 1.77 <input type=hidden name=chk_which value=\"$chk_which\">
1923 :    
1924 : golsen 1.76 Automatically Select (check) which sequences:<select name=chk_which>
1925 :     <option value=none $chk_chk_none>none</option>
1926 :     <option value=all $chk_chk_all>all shown</option>
1927 :     <option value=rep $chk_chk_rep>representative set</option>
1928 :     </select><br />
1929 : golsen 1.77 -->
1930 : golsen 1.76 End_Extra_Options
1931 :    
1932 :     # Submit buttons
1933 :    
1934 :     push @$html, <<"End_of_Buttons";
1935 :     <input type=submit name='resubmit' value='resubmit'>
1936 :     <input type=submit name='more similarities' value='more similarities'>
1937 :     $prev_peg_btn
1938 :     $next_peg_btn
1939 : golsen 1.77 $extra_opt_btn
1940 : golsen 1.76 </FORM>
1941 : golsen 1.100
1942 : golsen 1.76 End_of_Buttons
1943 :    
1944 :     }
1945 :    
1946 :     # Return the current parameter values in a hash
1947 :    
1948 :     { maxN => $maxN,
1949 :     maxP => $maxP,
1950 :     max_expand => $max_expand,
1951 : golsen 1.98 select => $select,
1952 : golsen 1.76 show_env => $show_env,
1953 :     hide_alias => $hide_alias,
1954 : overbeek 1.90 group_by_genome => $group_by_genome,
1955 : golsen 1.76 trans_role => $trans_role,
1956 :     extra_opt => $extra_opt,
1957 :     min_sim => $min_sim,
1958 :     min_q_cov => $min_q_cov,
1959 :     min_s_cov => $min_s_cov,
1960 :     sim_meas => $sim_meas,
1961 : golsen 1.98 sort_by => $sort_by,
1962 : golsen 1.76 show_rep => $show_rep,
1963 :     max_sim => $max_sim,
1964 :     dyn_thrsh => $dyn_thrsh,
1965 :     save_dist => $save_dist,
1966 :     chk_which => $chk_which,
1967 :     expand_groups => $expand_groups
1968 :     }
1969 :     }
1970 :    
1971 : overbeek 1.122 sub sprout_sims_request_form {
1972 :     my($cgi,$html,$peg,$trans_role,$user) = @_;
1973 :    
1974 :     push @$html, <<"End_Short_Form";
1975 :    
1976 :     <FORM Action=\"protein.cgi\">
1977 :     <input type=hidden name=prot value=\"$peg\">
1978 :     <input type=hidden name=sims value=1>
1979 :     <input type=hidden name=SPROUT value=1>
1980 :     <input type=hidden name=user value=\"$user\">
1981 :     <input type=hidden name=translate value=$trans_role>
1982 :     <input type=submit name='Bidirectional Best Hits' value='Bidirectional Best Hits'>
1983 :    
1984 :     </FORM>
1985 :    
1986 :     End_Short_Form
1987 :     }
1988 :    
1989 : golsen 1.76
1990 :     #------------------------------------------------------------------------
1991 :     # Auxilliary function to acivate checkmark for input fields
1992 :     #------------------------------------------------------------------------
1993 :     sub chked_if { $_[0] ? 'checked ' : '' }
1994 :    
1995 :     sub select_if { $_[0] ? 'selected ' : '' }
1996 :    
1997 :    
1998 :    
1999 : efrank 1.1 ################# Context on the Chromosome ############################
2000 :    
2001 :     sub print_context {
2002 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg,$feat,$beg,$end) = @_;
2003 : olson 1.56
2004 : olson 1.57 if ($beg eq $end) { cluck "Have zero len"; }
2005 : efrank 1.1 my($contig1,$beg1,$end1,$strand,$max_so_far,$gap,$comment,$fc,$aliases);
2006 : overbeek 1.81 my($fid1,$sz,$color,$map,$gg,$n,$link,$in_neighborhood);
2007 : efrank 1.1
2008 : overbeek 1.41
2009 :     my $user = $cgi->param('user');
2010 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2011 :     push(@$html,$cgi->start_form(-action => &cgi_url . "/chromosomal_clusters.cgi"),
2012 :     $cgi->hidden(-name => 'SPROUT', -value => $sprout),
2013 : overbeek 1.41 $cgi->hidden(-name => "prot", -value => $peg),
2014 : overbeek 1.44 $cgi->hidden(-name => "uni", -value => 1),
2015 : overbeek 1.41 $cgi->hidden(-name => "user", -value => $user));
2016 :    
2017 : overbeek 1.109 my $in_cluster = &in_cluster_with($fig_or_sprout,$cgi,$peg);
2018 : overbeek 1.73 my $col_hdrs;
2019 : overbeek 1.112
2020 : redwards 1.130 # RAE Added Subsys col headers
2021 : parrello 1.197 # BDP removed extra button columns per request by LKM
2022 :     # if ($cgi->param('SPROUT'))
2023 :     # {
2024 :     # $col_hdrs = ["fid","starts","ends","size","","gap","find<br>best<br>clusters","pins","fc-sc","SS",&evidence_codes_link($cgi),"comment","","","aliases"];
2025 :     # }
2026 :     # else
2027 :     # {
2028 : 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"];
2029 : parrello 1.197 # }
2030 : overbeek 1.73
2031 : efrank 1.1 my($tab) = [];
2032 :     my $genes = [];
2033 : parrello 1.60
2034 : overbeek 1.109 my %coupled;
2035 : olson 1.148
2036 :     #
2037 :     # Make a pass over the features, determining what subsystems they appear in. Assign
2038 :     # unique numbers (names?) for them.
2039 :     #
2040 :    
2041 :     my %fid_to_subs;
2042 :     my %subs;
2043 :     for my $fid (@$feat)
2044 :     {
2045 :     my $subs = [&peg_to_subsystems($fig_or_sprout, $fid)];
2046 :     map { $subs{$_}++ } @$subs;
2047 :     $fid_to_subs{$fid} = $subs;
2048 :     }
2049 :    
2050 :     my $sub_idx = 1;
2051 :     my %sub_names;
2052 :     for my $sub (sort { $subs{$b} <=> $subs{$a} } keys %subs)
2053 :     {
2054 :     $sub_names{$sub} = $sub_idx++;
2055 :     }
2056 : overbeek 1.109
2057 :     my $fc_sc;
2058 : parrello 1.60 foreach $fid1 (@$feat) {
2059 : 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>";
2060 : overbeek 1.110 if (defined($fc_sc = $in_cluster->{$fid1}))
2061 : overbeek 1.109 {
2062 :     $fc = &pin_link($cgi,$fid1);
2063 :     }
2064 :     else
2065 :     {
2066 :     $fc = "";
2067 :     $fc_sc = "";
2068 :     }
2069 : efrank 1.1
2070 : parrello 1.60 my $aliases = join( ', ', &feature_aliasesL($fig_or_sprout,$fid1) );
2071 : olson 1.48 my $uniprot;
2072 :     if ($aliases =~ /(uni[^,]+)/) {
2073 :     # print STDERR "$1\n";
2074 :     $uniprot = $1;
2075 :     }
2076 : overbeek 1.68 $aliases = &HTML::set_prot_links($cgi,$aliases),
2077 :     $aliases =~ s/SPROUT=1/SPROUT=0/g;
2078 :     $aliases =~ s/[&;]user=[^&;]+[;&]/;/g;
2079 : overbeek 1.74 $aliases = $aliases ? $aliases : "&nbsp;";
2080 : overbeek 1.68
2081 : overbeek 1.73 my($to_seed,$to_gbrowse);
2082 :     $to_seed = $to_gbrowse = "";
2083 : parrello 1.197 # BDP: removed extra columns per request by LKM
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 : overbeek 1.73
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 : parrello 1.198 # BDP: removed Sprout and GBrowse columns
2175 :     # my($s_link, $g_link);
2176 :     # if (0)
2177 :     # {
2178 :     # $s_link = "<a href=$to_seed>S</a>";
2179 :     # $g_link = "<a href=$to_gbrowse>G</a>";
2180 :     # }
2181 :     # else
2182 :     # {
2183 :     # $s_link = "<a href=$to_seed><img src=\"Html/button-s.png\" border=\"0\"></a>";
2184 :     # $g_link = "<a href=$to_gbrowse><img src=\"Html/button-g.png\" border=\"0\"></a>";
2185 :     # }
2186 : overbeek 1.73 push(@$tab,[&HTML::fid_link($cgi,$fid1,"local"),$beg1,$end1,$sz,$strand,$gap,
2187 : overbeek 1.112 $best_clusters_link,
2188 : overbeek 1.124 $fc ? $fc : "&nbsp;",
2189 :     $fc_sc ? $fc_sc : "&nbsp;",
2190 : redwards 1.130 $in_sub,
2191 : overbeek 1.141 join("<br>",&evidence_codes($fig_or_sprout,$fid1)),
2192 : overbeek 1.73 $comment,
2193 : parrello 1.198 # $s_link,
2194 :     # $g_link,
2195 : overbeek 1.81 $aliases]);
2196 : overbeek 1.73 }
2197 :     else
2198 :     {
2199 :     push(@$tab,[&HTML::fid_link($cgi,$fid1,"local"),$beg1,$end1,$sz,$strand,$gap,
2200 : overbeek 1.112 $best_clusters_link,
2201 : overbeek 1.109 $fc,$fc_sc,
2202 : redwards 1.130 $in_sub,
2203 : redwards 1.160 $ev_codes,
2204 : overbeek 1.73 $comment,
2205 : overbeek 1.81 $aliases]);
2206 : overbeek 1.73 }
2207 : efrank 1.1 }
2208 : 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)"));
2209 : overbeek 1.113 push(@$html,$cgi->end_form);
2210 : overbeek 1.53 return ($beg,$end,$genes);
2211 :     }
2212 :    
2213 :     sub print_graphics_context {
2214 :     my($beg,$end,$genes,$html) = @_;
2215 :    
2216 :     my $map = ["",$beg,$end,$genes];
2217 :     my $gg = [$map];
2218 : overbeek 1.2 push(@$html,@{ &GenoGraphics::render($gg,700,4,0,1) });
2219 : efrank 1.1 return;
2220 :     }
2221 :    
2222 :     sub assign_link {
2223 :     my($cgi,$func,$existing_func) = @_;
2224 :     my($assign_url,$assign_link);
2225 :    
2226 : parrello 1.60 if ($func && ((! $existing_func) || ($existing_func ne $func))) {
2227 :     $cgi->delete('request');
2228 : overbeek 1.161 $assign_url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=fast_assign&func=$func"; ## must encode
2229 : parrello 1.60 $assign_link = "<a href=\"$assign_url\">&nbsp;<=&nbsp;</a>";
2230 :     } else {
2231 :     $assign_link = "";
2232 : efrank 1.1 }
2233 :     return $assign_link;
2234 :     }
2235 :    
2236 :     sub pin_link {
2237 :     my($cgi,$peg) = @_;
2238 :     my $user = $cgi->param('user');
2239 :     $user = defined($user) ? $user : "";
2240 :    
2241 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2242 : overbeek 1.119 my $cluster_url = "chromosomal_clusters.cgi?prot=$peg&user=$user&uni=1&SPROUT=$sprout";
2243 : olson 1.83
2244 : overbeek 1.112 my $cluster_img = 0 ? "*" : '<img src="Html/button-pins-1.png" border="0">';
2245 : overbeek 1.114 my $cluster_link = "<a href=\"$cluster_url\" target=pinned_region.$$>$cluster_img</a>";
2246 : efrank 1.1 return $cluster_link;
2247 :     }
2248 :    
2249 : overbeek 1.84 sub set_ec_and_tc_links {
2250 : golsen 1.169 my($fig_or_sprout,$cgi,$org,$func) = @_;
2251 : parrello 1.167 Trace("Incoming functional assignment is \"$func\".") if T(EClink => 4);
2252 : parrello 1.60 if ($func =~ /^(.*)(\d+\.\d+\.\d+\.\d+)(.*)$/) {
2253 :     my $before = $1;
2254 :     my $ec = $2;
2255 :     my $after = $3;
2256 : parrello 1.167 Trace("Matched EC case: ID = $ec.") if T(EClink => 4);
2257 : 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);
2258 : overbeek 1.84 }
2259 :     elsif ($func =~ /^(.*)(TC \d+(\.[0-9A-Z]+){3,6})(.*)$/) {
2260 :     my $before = $1;
2261 :     my $tc = $2;
2262 :     my $after = $4;
2263 : parrello 1.167 Trace("Matched TC case: ID = $tc.") if T(EClink => 4);
2264 : 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);
2265 : efrank 1.1 }
2266 :     return $func;
2267 :     }
2268 :    
2269 : overbeek 1.84 sub set_tc_link {
2270 :     my($fig_or_sprout,$org,$tc) = @_;
2271 :    
2272 :     if ($tc =~ /^TC\s+(\S+)$/)
2273 :     {
2274 : olson 1.159 return "<a href=http://www.tcdb.org/tcdb/index.php?tc=$1&Submit=Lookup>$tc</a>";
2275 : overbeek 1.84 }
2276 :     return $tc;
2277 :     }
2278 : parrello 1.108
2279 : overbeek 1.84
2280 : efrank 1.1 sub set_ec_to_maps {
2281 : golsen 1.169 my($fig_or_sprout,$cgi,$org,$ec) = @_;
2282 : efrank 1.1
2283 : overbeek 1.53 my @maps = &ec_to_maps($fig_or_sprout,$ec);
2284 : parrello 1.60 if (@maps > 0) {
2285 :     $cgi->delete('request');
2286 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=ec_to_maps&ec=$ec&org=$org";
2287 : parrello 1.60 my $link = "<a href=\"$url\">$ec</a>";
2288 :     return $link;
2289 : efrank 1.1 }
2290 :     return $ec;
2291 :     }
2292 :    
2293 :     sub show_ec_to_maps {
2294 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$ec) = @_;
2295 : efrank 1.1
2296 :     my $ec = $cgi->param('ec');
2297 : parrello 1.60 if (! $ec) {
2298 :     push(@$html,$cgi->h1("Missing EC number"));
2299 :     return;
2300 : efrank 1.1 }
2301 :    
2302 : overbeek 1.53 my @maps = &ec_to_maps($fig_or_sprout,$ec);
2303 : parrello 1.60 if (@maps > 0) {
2304 :     my $col_hdrs = ["map","metabolic topic"];
2305 :     my $map;
2306 :     my $tab = [map { $map = $_; [&map_link($cgi,$map),&map_name($fig_or_sprout,$map)] } @maps];
2307 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"$ec: " . &ec_name($fig_or_sprout,$ec)));
2308 : efrank 1.1 }
2309 :     }
2310 :    
2311 :     sub map_link {
2312 :     my($cgi,$map) = @_;
2313 :    
2314 :     $cgi->delete('request');
2315 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&request=link_to_map&map=$map";
2316 : efrank 1.1 my $link = "<a href=\"$url\">$map</a>";
2317 :     return $link;
2318 :     }
2319 :    
2320 :     sub link_to_map {
2321 : overbeek 1.53 my($fig_or_sprout,$cgi,$html) = @_;
2322 : efrank 1.1
2323 :     my $map = $cgi->param('map');
2324 : parrello 1.60 if (! $map) {
2325 :     push(@$html,$cgi->h1("Missing Map"));
2326 :     return;
2327 : efrank 1.1 }
2328 :    
2329 :     my $org = $cgi->param('org');
2330 : parrello 1.60 if (! $org) {
2331 :     push(@$html,$cgi->h1("Missing Org Parameter"));
2332 :     return;
2333 : efrank 1.1 }
2334 :     my$user = $cgi->param('user');
2335 :     $user = $user ? $user : "";
2336 :    
2337 :     $ENV{"REQUEST_METHOD"} = "GET";
2338 :     $ENV{"QUERY_STRING"} = "user=$user&map=$map&org=$org";
2339 :     my @out = `./show_kegg_map.cgi`;
2340 :     &HTML::trim_output(\@out);
2341 :     push(@$html,@out);
2342 :     }
2343 : parrello 1.60
2344 : efrank 1.1 sub aa_sequence {
2345 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
2346 : efrank 1.1 my($seq,$func,$i);
2347 :    
2348 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Protein Sequence</TITLE>\n";
2349 : parrello 1.60 if ($seq = &get_translation($fig_or_sprout,$prot)) {
2350 :     $func = &function_ofS($fig_or_sprout,$prot,$cgi->param('user'));
2351 :     push(@$html,$cgi->pre,">$prot $func\n");
2352 :     for ($i=0; ($i < length($seq)); $i += 60) {
2353 :     if ($i > (length($seq) - 60)) {
2354 :     push(@$html,substr($seq,$i) . "\n");
2355 :     } else {
2356 :     push(@$html,substr($seq,$i,60) . "\n");
2357 :     }
2358 :     }
2359 :     push(@$html,$cgi->end_pre);
2360 :     } else {
2361 :     push(@$html,$cgi->h1("No translation available for $prot"));
2362 : efrank 1.1 }
2363 :     }
2364 :    
2365 :     sub dna_sequence {
2366 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$fid) = @_;
2367 : efrank 1.1 my($seq,$func,$i);
2368 :    
2369 : golsen 1.19 unshift @$html, "<TITLE>The SEED: Nucleotide Sequence</TITLE>\n";
2370 : parrello 1.60 if ($seq = &dna_seq($fig_or_sprout,&genome_of($fid),&feature_locationS($fig_or_sprout,$fid))) {
2371 :     $func = &function_ofS($fig_or_sprout,$prot,$cgi->param('user'));
2372 :     push(@$html,$cgi->pre,">$fid $func\n");
2373 :     for ($i=0; ($i < length($seq)); $i += 60) {
2374 :     if ($i > (length($seq) - 60)) {
2375 :     push(@$html,substr($seq,$i) . "\n");
2376 :     } else {
2377 :     push(@$html,substr($seq,$i,60) . "\n");
2378 :     }
2379 :     }
2380 :     push(@$html,$cgi->end_pre);
2381 :     } else {
2382 :     push(@$html,$cgi->h1("No DNA sequence available for $fid"));
2383 : efrank 1.1 }
2384 :     }
2385 : parrello 1.60
2386 : overbeek 1.173 # RAE: Added this routine to get the adjacent sequence. The default is to get 500 bp on either side of the
2387 :     # gene, but you can (secretly) change this to get more or less sequence by setting additional_sequence
2388 :     # in the URL. Also, I changed the way that the display is generated above so that I can used the s///
2389 :     # to add the color and new lines.
2390 : golsen 1.175 #
2391 :     # Fixed off-by-one errors in the end of coloring (which started this all).
2392 :     # Modified to detect end of contig (otherwise it fails when it runs off an end).
2393 :     # Modified to handle multisegment locations. -- GJO
2394 : overbeek 1.173
2395 :     sub dna_sequence_adjacent {
2396 : golsen 1.175 my( $fig_or_sprout,$cgi, $html, $fid ) = @_;
2397 :     my( $contig, $beg, $end, $seq, $func, $i );
2398 : overbeek 1.173
2399 :     unshift @$html, "<TITLE>The SEED: Nucleotide Sequence</TITLE>\n";
2400 : golsen 1.175 my $additional = $cgi->param("additional_sequence");
2401 :     defined( $additional ) or ( $additional = 500 );
2402 :    
2403 :     # Now handles segmented location and running off an end. -- GJO
2404 :    
2405 : overbeek 1.184 my $genome = &genome_of( $fid );
2406 :     my $loc = &feature_locationS($fig_or_sprout,$fid);
2407 :     # my $loc = $fig_or_sprout->feature_location( $fid );
2408 : golsen 1.175 my @loc = split /,/, $loc;
2409 :    
2410 : overbeek 1.184
2411 : golsen 1.175 # Add to beginning of the first segment:
2412 :    
2413 : overbeek 1.182 # NOTE the difference
2414 :     # Sprout returns locations in the form contig_start-stop
2415 :    
2416 : overbeek 1.184 # ( $contig, $beg, $end ) = $loc[0] =~ /^(.*)_(\d+)\D(\d+)$/;
2417 :    
2418 :     ($contig, $beg, $end) = BasicLocation::Parse($loc[0]);
2419 : overbeek 1.182
2420 : golsen 1.175 if ( ! ( $contig && $beg && $end ) )
2421 :     {
2422 :     push @$html, $cgi->h2( "Bad location information for $fid" );
2423 :     print STDERR "SEED Error: Bad location information ($loc) for $fid in dna_sequence_adjacent\n";
2424 :     return;
2425 :     }
2426 :     my ( $n1, $npre );
2427 :     if ( $beg < $end )
2428 :     {
2429 :     $n1 = $beg - $additional;
2430 :     $n1 = 1 if $n1 < 1;
2431 :     $npre = $beg - $n1;
2432 :     }
2433 :     else
2434 :     {
2435 :     $n1 = $beg + $additional;
2436 :     my $clen = $fig_or_sprout->contig_ln( $genome, $contig );
2437 :     $n1 = $clen if $n1 > $clen;
2438 :     $npre = $n1 - $beg;
2439 :     }
2440 :     $loc[0] = join( '_', $contig, $n1, $end );
2441 :    
2442 :     # Add to the end of the last segment:
2443 :    
2444 : overbeek 1.186 ( $contig, $beg, $end ) = BasicLocation::Parse($loc[-1]);
2445 :    
2446 : golsen 1.175 if ( ! ( $contig && $beg && $end ) )
2447 :     {
2448 :     push @$html, $cgi->h2( "Bad location information for $fid" );
2449 :     print STDERR "SEED Error: Bad location information ($loc) for $fid in dna_sequence_adjacent\n";
2450 :     return;
2451 :     }
2452 :     my ( $n2, $npost );
2453 :     if ( $beg < $end )
2454 :     {
2455 :     $n2 = $end + $additional;
2456 :     my $clen = $fig_or_sprout->contig_ln( $genome, $contig );
2457 :     $n2 = $clen if $n2 > $clen;
2458 :     $npost = $n2 - $end;
2459 :     }
2460 :     else
2461 :     {
2462 :     $n2 = $end - $additional;
2463 :     $n2 = 1 if $n2 < 1;
2464 :     $npost = $end - $n2;
2465 :     }
2466 :     $loc[-1] = join( '_', $contig, $beg, $n2 );
2467 :    
2468 :     $seq = $fig_or_sprout->dna_seq( $genome, join( ',', @loc ) );
2469 :     if ( ! $seq )
2470 :     {
2471 :     push @$html, $cgi->h2( "No DNA sequence available for $fid" );
2472 :     return;
2473 : overbeek 1.173 }
2474 : golsen 1.175
2475 :     my $len = length( $seq ); # Get length before adding newlines
2476 :     $seq =~ s/(.{60})/$1\n/g; # Cleaver way to wrap the sequence
2477 :     my $p1 = $npre + int( $npre/60 ); # End of prefix, adjusted for newlines
2478 :     my $p2 = $len - $npost; # End of data,
2479 :     $p2 += int( $p2/60 ); # adjusted for newlines
2480 :     my $diff = $p2 - $p1; # Characters of data
2481 :     # Integrate the HTML codes
2482 :     $seq =~ s/^(.{$p1})(.{$diff})(.*)$/$1<SPAN Style="color:red">$2<\/SPAN>$3/s;
2483 :    
2484 :     $func = $fig_or_sprout->function_of( $fid, $cgi->param('user') );
2485 :    
2486 :     push @$html, $cgi->pre, ">$fid $func\n$seq\n", $cgi->end_pre;
2487 : overbeek 1.173 }
2488 :    
2489 : golsen 1.175
2490 : efrank 1.1 sub show_fusions {
2491 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$prot) = @_;
2492 : efrank 1.1
2493 : overbeek 1.22 my $user = $cgi->param('user');
2494 :     $user = $user ? $user : "";
2495 : overbeek 1.53 my $sprout = $cgi->param('SPROUT') ? 1 : "";
2496 :    
2497 : efrank 1.1 $ENV{"REQUEST_METHOD"} = "GET";
2498 : overbeek 1.53 $ENV{"QUERY_STRING"} = "peg=$prot&user=$user&SPROUT=$sprout";
2499 : efrank 1.1 my @out = `./fusions.cgi`;
2500 :     print join("",@out);
2501 :     exit;
2502 : overbeek 1.2 }
2503 :    
2504 : overbeek 1.53 ###########################################################################
2505 : overbeek 1.2 sub print_compared_regions {
2506 : overbeek 1.53 my($fig_or_sprout,$cgi,$html,$peg) = @_;
2507 :    
2508 :     my $sz_region = $cgi->param('sz_region');
2509 :     $sz_region = $sz_region ? $sz_region : 16000;
2510 :    
2511 :     my $num_close = $cgi->param('num_close');
2512 :     $num_close = $num_close ? $num_close : 5;
2513 : overbeek 1.153
2514 : overbeek 1.189 my $user = $cgi->param('user');
2515 : overbeek 1.65 my @closest_pegs = &closest_pegs($fig_or_sprout,$cgi,$peg,$num_close);
2516 : overbeek 1.40
2517 : parrello 1.60 if (@closest_pegs > 0) {
2518 :     if (&possibly_truncated($fig_or_sprout,$peg)) {
2519 :     push(@closest_pegs,&possible_extensions($peg,\@closest_pegs));
2520 :     }
2521 :     @closest_pegs = &sort_fids_by_taxonomy($fig_or_sprout,@closest_pegs);
2522 :     unshift(@closest_pegs,$peg);
2523 :     my @all_pegs = ();
2524 : overbeek 1.119
2525 : parrello 1.60 my $gg = &build_maps($fig_or_sprout,\@closest_pegs,\@all_pegs,$sz_region);
2526 :     #warn Dumper($gg);
2527 : overbeek 1.68 my $color_sets = &cluster_genes($fig_or_sprout,$cgi,\@all_pegs,$peg);
2528 : parrello 1.60 &set_colors_text_and_links($gg,\@all_pegs,$color_sets);
2529 :     ################################### add commentary capability
2530 :     my $sprout = $cgi->param('SPROUT') ? 1 : "";
2531 :    
2532 :     my($gene,$n,%how_many,$val,@vals,$x);
2533 :     my($i,$map);
2534 :     @vals = ();
2535 :     for ($i=(@$gg - 1); ($i >= 0); $i--) {
2536 :     my @vals1 = ();
2537 :     $map = $gg->[$i];
2538 :     my $found = 0;
2539 :     my $got_red = 0;
2540 :     undef %how_many;
2541 :     foreach $gene (@{$map->[3]}) {
2542 :     if (($x = $gene->[3]) ne "grey") {
2543 :     $n = $gene->[4];
2544 :     if ($n == 1) { $got_red = 1 }
2545 :     $how_many{$n}++;
2546 :     $gene->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/;
2547 : overbeek 1.194 $val = join("@",($n,$i,$1,$map->[0]->[0],$how_many{$n}));
2548 : parrello 1.60 push(@vals1,$val);
2549 :     $found++;
2550 :     }
2551 :     }
2552 :    
2553 :     if (! $got_red) {
2554 :     splice(@$gg,$i,1);
2555 :     } else {
2556 :     push(@vals,@vals1);
2557 :     }
2558 :     }
2559 : overbeek 1.35
2560 : overbeek 1.151 if (@$gg < 2) {
2561 :     push(@$html,$cgi->h3("No alignable regions in close genomes"));
2562 : overbeek 1.189 &add_previous_next($html,undef,undef,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2563 : parrello 1.60 } else {
2564 : overbeek 1.151
2565 :     my @parm_reset_form = ($cgi->hr);
2566 :     push(@parm_reset_form,$cgi->start_form(-action => &cgi_url . "/protein.cgi" ));
2567 :     my $param;
2568 :     foreach $param ($cgi->param()) {
2569 :     next if (($param eq "sz_region") || ($param eq "num_close"));
2570 :     push(@parm_reset_form,$cgi->hidden(-name => $param, -value => $cgi->param($param)));
2571 :     }
2572 :     push(@parm_reset_form,
2573 :     "size region: ",
2574 :     $cgi->textfield(-name => 'sz_region', -size => 10, -value => $sz_region, -override => 1),
2575 :     "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ",
2576 :     "Number genomes: ",
2577 :     $cgi->textfield(-name => 'num_close', -size => 4, -value => $num_close, -override => 1),
2578 :     $cgi->br,
2579 :     $cgi->submit('Resubmit')
2580 :     );
2581 :     push(@parm_reset_form,$cgi->end_form);
2582 :     push(@$html,@parm_reset_form);
2583 : overbeek 1.189
2584 : overbeek 1.151 my @commentary_form = ();
2585 :     my $ctarget = "window$$";
2586 :     push(@commentary_form,$cgi->start_form(-target => $ctarget,
2587 :     -action => &cgi_url . "/chromosomal_clusters.cgi"
2588 :     ));
2589 :    
2590 :     push(@commentary_form,$cgi->hidden(-name => 'SPROUT', -value => $sprout),
2591 :     $cgi->hidden(-name => "request", -value => "show_commentary"));
2592 :     push(@commentary_form,$cgi->hidden(-name => "prot", -value => $peg));
2593 :     push(@commentary_form,$cgi->hidden(-name => "uni", -value => 1));
2594 :     push(@commentary_form,$cgi->hidden(-name => "user", -value => $user));
2595 : parrello 1.60 push(@commentary_form,$cgi->hidden(-name => "show", -value => [@vals]));
2596 :     push(@commentary_form,$cgi->submit('commentary'));
2597 :     push(@commentary_form,$cgi->end_form());
2598 :     push(@$html,@commentary_form);
2599 : overbeek 1.151 push(@$html,@{ &GenoGraphics::render($gg,700,4,0,2) });
2600 : overbeek 1.189
2601 :     my($prev,$next);
2602 :     my $map1 = $gg->[0]->[3];
2603 :     if (($map1->[0]->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/) && ($1 ne $peg))
2604 :     {
2605 :     $prev = $1;
2606 :     }
2607 :     if (($map1->[$#{$map1}]->[5] =~ /(fig\|\d+\.\d+\.peg\.\d+)/) && ($1 ne $peg))
2608 :     {
2609 :     $next = $1;
2610 :     }
2611 :     &add_previous_next($html,$prev,$next,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2612 : parrello 1.60 }
2613 : overbeek 1.151
2614 : parrello 1.120 if (! $cgi->param('SPROUT'))
2615 :     {
2616 :     push @$html, &FIGGenDB::linkClusterGenDB($peg);
2617 :     }
2618 : overbeek 1.2 }
2619 : overbeek 1.151 else
2620 :     {
2621 :     push(@$html,$cgi->h3("No alignable regions in close genomes"));
2622 : overbeek 1.189 &add_previous_next($html,undef,undef,$fig_or_sprout,$peg,$user,$sz_region,$num_close);
2623 :     }
2624 :     }
2625 :    
2626 :     sub add_previous_next {
2627 :     my($html,$prev,$next,$fig_or_sprout,$peg,$user,$sz_region,$num_close) = @_;
2628 :    
2629 :     push(@$html,$cgi->br);
2630 :     if ($prev)
2631 :     {
2632 :     push(@$html,"<a href=protein.cgi?prot=$prev&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>previous</a>");
2633 :     }
2634 :     else
2635 :     {
2636 :     my $genome = &FIG::genome_of($peg);
2637 :     my @contigs = $fig_or_sprout->contigs_of($genome);
2638 :     my @loc = $fig_or_sprout->feature_location($peg);
2639 :     my $contig;
2640 :     if ((@loc > 0) && ($loc[0] =~ /^(\S+)_\d+_\d+$/))
2641 :     {
2642 :     $contig = $1;
2643 :     }
2644 :     my $i;
2645 :     for ($i=0; ($i < @contigs) && ($contig ne $contigs[$i]); $i++) {}
2646 :     if (($i > 0) && ($i < @contigs))
2647 :     {
2648 :     $contig = $contigs[$i-1];
2649 :     my($genes,undef,undef) = $fig_or_sprout->genes_in_region($genome,$contig,1,10000);
2650 :     my @genes = grep { $fig_or_sprout->ftype($_) eq "peg" } @$genes;
2651 :    
2652 :     if (@genes > 0)
2653 :     {
2654 :     my $gene = $genes[0];
2655 :     push(@$html,"<a href=protein.cgi?prot=$gene&compare_region=1&user=$user&sz_region=$sz_region&num_close=$num_close>previous</a>");
2656 :     }
2657 :     }
2658 :     }
2659 :    
2660 :    
2661 :     if ($next)
2662 :     {
2663 :     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>");
2664 :     }
2665 :     else
2666 :     {
2667 :     my $genome = &FIG::genome_of($peg);
2668 :     my @contigs = $fig_or_sprout->contigs_of($genome);
2669 :     my @loc = $fig_or_sprout->feature_location($peg);
2670 :     my $contig;
2671 :     if ((@loc > 0) && ($loc[0] =~ /^(\S+)_\d+_\d+$/))
2672 :     {
2673 :     $contig = $1;
2674 :     }
2675 :     my $i;
2676 :     for ($i=0; ($i < @contigs) && ($contig ne $contigs[$i]); $i++) {}
2677 :     if (($i >= 0) && ($i < $#contigs))
2678 :     {
2679 :     $contig = $contigs[$i+1];
2680 :     my($genes,undef,undef) = $fig_or_sprout->genes_in_region($genome,$contig,1,10000);
2681 :     my @genes = grep { $fig_or_sprout->ftype($_) eq "peg" } @$genes;
2682 :    
2683 :     if (@genes > 0)
2684 :     {
2685 :     my $gene = $genes[0];
2686 :     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>");
2687 :     }
2688 :     }
2689 : overbeek 1.151 }
2690 : overbeek 1.2 }
2691 :    
2692 : overbeek 1.189
2693 : overbeek 1.2 sub closest_pegs {
2694 : overbeek 1.65 my($fig_or_sprout,$cgi,$peg,$n) = @_;
2695 : overbeek 1.2 my($id2,$d,$peg2,$i);
2696 :    
2697 : overbeek 1.65 my @closest;
2698 :     if ($cgi->param('SPROUT'))
2699 :     {
2700 : parrello 1.120 @closest = map { $_->[0] } sort { $a->[1] <=> $b->[1] } &bbhs($fig_or_sprout,$peg, 1.0e-10);
2701 : overbeek 1.65 }
2702 :     else
2703 :     {
2704 : 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));
2705 : overbeek 1.65 }
2706 : overbeek 1.152
2707 : overbeek 1.151 if (@closest >= ($n-1))
2708 :     {
2709 :     $#closest = $n-2 ;
2710 :     }
2711 : overbeek 1.152 my %closest = map { $_ => 1 } @closest;
2712 : overbeek 1.2
2713 : overbeek 1.152 my @pinned_to = grep { ($_ ne $peg) && (! $closest{$_}) } &in_pch_pin_with($fig_or_sprout,$peg);
2714 :     my $g1 = &genome_of($peg);
2715 :     @pinned_to = map {$_->[1] }
2716 :     sort { $a->[0] <=> $b->[0] }
2717 :     map { $peg2 = $_; $d = &crude_estimate_of_distance($fig_or_sprout,$g1,&genome_of($peg2)); [$d,$peg2] }
2718 :     @pinned_to;
2719 : overbeek 1.2
2720 : overbeek 1.152 if (@closest == ($n-1))
2721 :     {
2722 :     $#closest = ($n - 2) - &FIG::min(scalar @pinned_to,int($n/2));
2723 :     for ($i=0; ($i < @pinned_to) && (@closest < ($n-1)); $i++)
2724 :     {
2725 : overbeek 1.151 if (! $closest{$pinned_to[$i]})
2726 :     {
2727 :     $closest{$pinned_to[$i]} = 1;
2728 :     push(@closest,$pinned_to[$i]);
2729 :     }
2730 :     }
2731 : overbeek 1.2 }
2732 : overbeek 1.151 return @closest;
2733 : overbeek 1.2 }
2734 :    
2735 :     sub build_maps {
2736 : overbeek 1.53 my($fig_or_sprout,$pinned_pegs,$all_pegs,$sz_region) = @_;
2737 : overbeek 1.2 my($gg,$loc,$contig,$beg,$end,$mid,$min,$max,$genes,$feat,$fid);
2738 :     my($contig1,$beg1,$end1,$map,$peg);
2739 :    
2740 :     $gg = [];
2741 : parrello 1.60 foreach $peg (@$pinned_pegs) {
2742 :     $loc = &feature_locationS($fig_or_sprout,$peg);
2743 :     ($contig,$beg,$end) = &boundaries_of($fig_or_sprout,$loc);
2744 :     if ($contig && $beg && $end) {
2745 :     $mid = int(($beg + $end) / 2);
2746 :     $min = int($mid - ($sz_region / 2));
2747 :     $max = int($mid + ($sz_region / 2));
2748 :     $genes = [];
2749 : overbeek 1.81 ($feat,undef,undef) = &genes_in_region($fig_or_sprout,$cgi,&genome_of($peg),$contig,$min,$max);
2750 : parrello 1.60 foreach $fid (@$feat) {
2751 :     ($contig1,$beg1,$end1) = &boundaries_of($fig_or_sprout,&feature_locationS($fig_or_sprout,$fid));
2752 :     $beg1 = &in_bounds($min,$max,$beg1);
2753 :     $end1 = &in_bounds($min,$max,$end1);
2754 :     my $aliases = join( ', ', &feature_aliasesL($fig_or_sprout,$fid) );
2755 :     my $function = &function_ofS($fig_or_sprout,$fid);
2756 : golsen 1.192 my ( $uniprot ) = $aliases =~ /(uni\|[^,]+)/;
2757 :     my $user = $cgi->param('user');
2758 :     my $info = join('<br/>', "<b>PEG:</b> $fid",
2759 :     "<b>Contig:</b> $contig1",
2760 :     "<b>Begin:</b> $beg1",
2761 :     "<b>End:</b> $end1",
2762 :     $function ? "<b>Function:</b> $function" : (),
2763 :     $uniprot ? "<b>Uniprot ID:</b> $uniprot" : ()
2764 :     );
2765 : parrello 1.60
2766 :     my $sprout = $cgi->param('SPROUT') ? 1 : "";
2767 : parrello 1.120 my $fmg;
2768 :     if ($sprout)
2769 :     {
2770 : redwards 1.137 $fmg = "<a href=\&quot;protein.cgi?SPROUT=$sprout&compare_region=1\&prot=$fid\&user=$user\&quot>show</a>";
2771 : parrello 1.120 }
2772 :     else
2773 :     {
2774 : redwards 1.137 $fmg = join ('<br/>', "<a href=\&quot;protein.cgi?SPROUT=$sprout&compare_region=1\&prot=$fid\&user=$user\&quot>show</a>",
2775 : parrello 1.60 "<a onClick=\&quot;setValue('bound1', '$fid'); return false;\&quot;>set bound 1</a>",
2776 :     "<a onClick=\&quot;setValue('bound2', '$fid'); return false;\&quot;>set bound 2</a>",
2777 :     "<a onClick=\&quot;setValue('candidates', '$fid'); return false;\&quot;>set candidate</a>");
2778 : parrello 1.120 }
2779 : parrello 1.60 push(@$genes,[&min($beg1,$end1),
2780 :     &max($beg1,$end1),
2781 :     ($beg1 < $end1) ? "rightArrow" : "leftArrow",
2782 :     "grey",
2783 :     "",
2784 :     $fid,
2785 :     $info, $fmg]);
2786 :    
2787 :     if ($fid =~ /peg/) {
2788 :     push(@$all_pegs,$fid);
2789 :     }
2790 :     }
2791 : golsen 1.192
2792 :     # Sequence title can be replaced by [ title, url, popup_text, menu, popup_title ]
2793 :    
2794 :     my $org = org_of( $fig_or_sprout, $peg );
2795 : golsen 1.193 my $desc = "Genome: $org<br />Contig: $contig";
2796 :     $map = [ [ FIG::abbrev( $org ), undef, $desc, undef, 'Contig' ],
2797 : golsen 1.192 0,
2798 :     $max+1 - $min,
2799 :     ($beg < $end) ? &decr_coords($genes,$min) : &flip_map($genes,$min,$max)
2800 :     ];
2801 : parrello 1.60 push(@$gg,$map);
2802 :     }
2803 : overbeek 1.2 }
2804 : overbeek 1.55 &GenoGraphics::disambiguate_maps($gg);
2805 : overbeek 1.2 return $gg;
2806 :     }
2807 :    
2808 :     sub in {
2809 :     my($x,$xL) = @_;
2810 :     my($i);
2811 :    
2812 :     for ($i=0; ($i < @$xL) && ($x != $xL->[$i]); $i++) {}
2813 :     return ($i < @$xL);
2814 :     }
2815 :    
2816 :     sub in_bounds {
2817 :     my($min,$max,$x) = @_;
2818 :    
2819 :     if ($x < $min) { return $min }
2820 :     elsif ($x > $max) { return $max }
2821 :     else { return $x }
2822 :     }
2823 :    
2824 :     sub decr_coords {
2825 :     my($genes,$min) = @_;
2826 :     my($gene);
2827 :    
2828 : parrello 1.60 foreach $gene (@$genes) {
2829 :     $gene->[0] -= $min;
2830 :     $gene->[1] -= $min;
2831 : overbeek 1.2 }
2832 :     return $genes;
2833 :     }
2834 :    
2835 :     sub flip_map {
2836 :     my($genes,$min,$max) = @_;
2837 :     my($gene);
2838 : parrello 1.60
2839 :     foreach $gene (@$genes) {
2840 :     ($gene->[0],$gene->[1]) = ($max - $gene->[1],$max - $gene->[0]);
2841 :     $gene->[2] = ($gene->[2] eq "rightArrow") ? "leftArrow" : "rightArrow";
2842 : overbeek 1.2 }
2843 :     return $genes;
2844 :     }
2845 :    
2846 :     sub cluster_genes {
2847 : overbeek 1.68 my($fig_or_sprout,$cgi,$all_pegs,$peg) = @_;
2848 : overbeek 1.2 my(%seen,$i,$j,$k,$x,$cluster,$conn,$pegI,$red_set);
2849 :    
2850 :     my @color_sets = ();
2851 :    
2852 : overbeek 1.68 $conn = &get_connections_by_similarity($fig_or_sprout,$cgi,$all_pegs);
2853 :    
2854 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2855 :     if ($all_pegs->[$i] eq $peg) { $pegI = $i }
2856 :     if (! $seen{$i}) {
2857 :     $cluster = [$i];
2858 :     $seen{$i} = 1;
2859 :     for ($j=0; ($j < @$cluster); $j++) {
2860 :     $x = $conn->{$cluster->[$j]};
2861 :     foreach $k (@$x) {
2862 :     if (! $seen{$k}) {
2863 :     push(@$cluster,$k);
2864 :     $seen{$k} = 1;
2865 :     }
2866 :     }
2867 :     }
2868 :    
2869 :     if ((@$cluster > 1) || ($cluster->[0] eq $pegI)) {
2870 :     push(@color_sets,$cluster);
2871 :     }
2872 :     }
2873 : overbeek 1.2 }
2874 :     for ($i=0; ($i < @color_sets) && (! &in($pegI,$color_sets[$i])); $i++) {}
2875 :     $red_set = $color_sets[$i];
2876 :     splice(@color_sets,$i,1);
2877 :     @color_sets = sort { @$b <=> @$a } @color_sets;
2878 :     unshift(@color_sets,$red_set);
2879 :    
2880 :     my $color_sets = {};
2881 : parrello 1.60 for ($i=0; ($i < @color_sets); $i++) {
2882 :     foreach $x (@{$color_sets[$i]}) {
2883 :     $color_sets->{$all_pegs->[$x]} = $i;
2884 :     }
2885 : overbeek 1.2 }
2886 :     return $color_sets;
2887 :     }
2888 :    
2889 :     sub get_connections_by_similarity {
2890 : overbeek 1.68 my($fig_or_sprout,$cgi,$all_pegs) = @_;
2891 : parrello 1.108
2892 : overbeek 1.68 if ($cgi->param('SPROUT'))
2893 :     {
2894 :     return &get_connections_by_similarity_SPROUT($fig_or_sprout,$all_pegs);
2895 :     }
2896 :     else
2897 :     {
2898 :     return &get_connections_by_similarity_SEED($fig_or_sprout,$all_pegs);
2899 :     }
2900 :     }
2901 :    
2902 :     sub get_connections_by_similarity_SPROUT {
2903 :     my($fig_or_sprout,$all_pegs) = @_;
2904 :     my(%in,$i,$j,$peg1,$peg2);
2905 :    
2906 :     my $conn = {};
2907 :    
2908 :     for ($i=0; $i < @$all_pegs; $i++)
2909 :     {
2910 :     $in{$all_pegs->[$i]} = $i;
2911 :     }
2912 : parrello 1.108
2913 : overbeek 1.68 foreach $peg1 (@$all_pegs)
2914 :     {
2915 :     $i = $in{$peg1};
2916 : overbeek 1.116 foreach $peg2 (map { $_->[0] } bbhs($fig_or_sprout,$peg1,1.0e-10))
2917 : overbeek 1.68 {
2918 :     $j = $in{$peg2};
2919 :     if (defined($i) && defined($j))
2920 :     {
2921 :     push(@{$conn->{$i}},$j);
2922 :     }
2923 :     }
2924 :     }
2925 :     return $conn;
2926 :     }
2927 :    
2928 :     sub get_connections_by_similarity_SEED {
2929 :     my($fig_or_sprout,$all_pegs) = @_;
2930 : overbeek 1.40 my($i,$j,$tmp,$peg,%pos_of);
2931 :     my($sim,%conn,$x,$y);
2932 : overbeek 1.2
2933 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2934 :     $tmp = &maps_to_id($fig_or_sprout,$all_pegs->[$i]);
2935 :     push(@{$pos_of{$tmp}},$i); # map the representative in nr to subscript in all_pegs
2936 :     if ($tmp ne $all_pegs->[$i]) {
2937 :     push(@{$pos_of{$all_pegs->[$i]}},$i);
2938 :     }
2939 : overbeek 1.2 }
2940 :    
2941 : parrello 1.60 foreach $y (keys(%pos_of)) {
2942 :     $x = $pos_of{$y};
2943 :     for ($i=0; ($i < @$x); $i++) {
2944 :     for ($j=$i+1; ($j < @$x); $j++) {
2945 :     push(@{$conn{$x->[$i]}},$x->[$j]);
2946 :     push(@{$conn{$x->[$j]}},$x->[$i]);
2947 :     }
2948 :     }
2949 : overbeek 1.40 }
2950 :    
2951 : parrello 1.60 for ($i=0; ($i < @$all_pegs); $i++) {
2952 :     foreach $sim (&sims($fig_or_sprout,$all_pegs->[$i],500,1.0e-5,"raw")) {
2953 :     if (defined($x = $pos_of{$sim->id2})) {
2954 :     foreach $y (@$x) {
2955 :     push(@{$conn{$i}},$y);
2956 :     }
2957 :     }
2958 :     }
2959 : overbeek 1.2 }
2960 :     return \%conn;
2961 :     }
2962 :    
2963 :     sub set_colors_text_and_links {
2964 :     my($gg,$all_pegs,$color_sets) = @_;
2965 :     my($map,$gene,$peg,$color);
2966 :    
2967 : parrello 1.60 foreach $map (@$gg) {
2968 :     foreach $gene (@{$map->[3]}) {
2969 :     $peg = $gene->[5];
2970 :     if (defined($color = $color_sets->{$peg})) {
2971 :     $gene->[3] = ($color == 0) ? "red" : "color$color";
2972 :     $gene->[4] = $color + 1;
2973 :     }
2974 :     $gene->[5] = &peg_url($cgi,$peg);
2975 :     }
2976 : overbeek 1.2 }
2977 :     }
2978 :    
2979 :     sub peg_url {
2980 :     my($cgi,$peg) = @_;
2981 :    
2982 :     my $prot = $cgi->param('prot');
2983 :     $cgi->delete('prot');
2984 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1) . "&prot=$peg&compare_region=1";
2985 : overbeek 1.2 $cgi->delete('prot');
2986 :     $cgi->param(-name => 'prot', -value => $prot);
2987 :    
2988 :     return $url;
2989 : parrello 1.60 }
2990 : overbeek 1.2
2991 :     sub possible_extensions {
2992 :     my($peg,$closest_pegs) = @_;
2993 :     my($g,$sim,$id2,$peg1,%poss);
2994 :    
2995 : overbeek 1.53 $g = &genome_of($peg);
2996 : overbeek 1.2
2997 : parrello 1.60 foreach $peg1 (@$closest_pegs) {
2998 :     if ($g ne &genome_of($peg1)) {
2999 :     foreach $sim (&sims($fig_or_sprout,$peg1,500,1.0e-5,"all")) {
3000 :     $id2 = $sim->id2;
3001 :     if (($id2 ne $peg) && ($id2 =~ /^fig\|$g\./) && &possibly_truncated($fig_or_sprout,$id2)) {
3002 :     $poss{$id2} = 1;
3003 :     }
3004 :     }
3005 :     }
3006 : overbeek 1.2 }
3007 :     return keys(%poss);
3008 : efrank 1.1 }
3009 : overbeek 1.53
3010 :     sub display_page {
3011 :     my($fig_or_sprout,$cgi,$html) = @_;
3012 :    
3013 : parrello 1.60 if (ref($html) eq "ARRAY") {
3014 :     if ($traceData) {
3015 :     push @$html, QTrace('html');
3016 :     }
3017 :     &HTML::show_page($cgi,$html);
3018 :     } else {
3019 :     Trace(Dumper($html)) if T(2);
3020 :     if ($cgi->param('SPROUT')) {
3021 :     if ($traceData) {
3022 :     $html->{tracings} = "<h3>Trace Messages</h3>\n" . QTrace('html');
3023 :     } else {
3024 :     $html->{tracings} = "\n";
3025 :     }
3026 :     print "Content-Type: text/html\n";
3027 :     print "\n";
3028 :     my $templ = "$FIG_Config::fig/CGI/Html/Protein_tmpl.html";
3029 : parrello 1.108 print PageBuilder::Build("<$templ", $html,"Html");
3030 : parrello 1.60 } else {
3031 :     my $gathered = [];
3032 :    
3033 :     my $section;
3034 :     foreach $section (qw( javascript
3035 :     general
3036 :     translate_status
3037 :     contig_context
3038 :     context_graphic
3039 :     subsys_connections
3040 : overbeek 1.68 assign_for_equiv_prots
3041 : parrello 1.60 links
3042 :     services
3043 :     kv_pairs
3044 :     compare_region
3045 :     similarities
3046 :     tools
3047 :     ) ) {
3048 :     if (@{$html->{$section}} > 0) {
3049 :     push(@$gathered,@{$html->{$section}});
3050 :     push(@$gathered,$cgi->hr);
3051 :     }
3052 :     }
3053 :     pop @$gathered;
3054 :     &HTML::show_page($cgi,$gathered);
3055 :     }
3056 : overbeek 1.53 }
3057 :     }
3058 :    
3059 :     sub show_html_followed_by_initial {
3060 :     my($fig_or_sprout,$cgi,$html,$prot) = @_;
3061 :    
3062 : overbeek 1.191 my $loc_url = $cgi->url(-absolute => 1, -full => 1, -query => 1, -path_info => 1);
3063 :    
3064 :     #
3065 :     # Truncate it in case the url is humongous (like it will be for the pins commentary page).
3066 :     #
3067 :    
3068 :     $loc_url = substr($loc_url, 0, 100);
3069 :    
3070 : overbeek 1.53 my %html = ( general => [],
3071 :     contig_context => [],
3072 :     context_graphic => [],
3073 :     subsys_connections => [],
3074 :     links => [],
3075 :     services => [],
3076 :     translate_status => [],
3077 :     tools => [],
3078 :     kv_pairs => [],
3079 :     similarities => [],
3080 : overbeek 1.68 assign_for_equiv_prots => [],
3081 : overbeek 1.53 javascript => [],
3082 : overbeek 1.157 compare_region => [],
3083 : overbeek 1.191 location_tag => [uri_escape($loc_url)],
3084 : overbeek 1.53 );
3085 :    
3086 :     push(@{$html{general}},@$html);
3087 :     $html = \%html;
3088 : parrello 1.60 &show_initial($fig_or_sprout,$cgi,$html,$prot);
3089 : overbeek 1.53 return $html;
3090 :     }
3091 :    
3092 :     sub translation_piece {
3093 :     my($fig_or_sprout,$cgi,$html) = @_;
3094 :    
3095 :     my $msg;
3096 : overbeek 1.161 my $url = $cgi->url(-relative => 1, -query => 1, -path_info => 1);
3097 : overbeek 1.53 if ($cgi->param('translate')) {
3098 : parrello 1.60 $url =~ s/[;&]translate(=[^;&])?//i or $url =~ s/translate(=[^;&])?[;&]//i;
3099 :     $msg = "Turn Off Function Translation";
3100 :     } else {
3101 : golsen 1.169 $url .= "&translate=1";
3102 : parrello 1.60 $msg = "Translate Function Assignments";
3103 : overbeek 1.53 }
3104 :     push(@$html, "<a href=\"$url\">$msg</a><br>\n");
3105 :     }
3106 :    
3107 :    
3108 :     #######################################################################################
3109 : overbeek 1.119 sub sims {
3110 :     my( $fig_or_sprout, $peg, $max, $cutoff, $select, $expand, $group_by_genome, $filters ) = @_;
3111 :     my( @tmp, $id, $genome, @genomes, %sims, $sim );
3112 :    
3113 :     @tmp = $fig_or_sprout->sims( $peg, $max, $cutoff, $select, $expand, $filters );
3114 :     if (! $group_by_genome) { return @tmp };
3115 :    
3116 :     # Collect all sims from genome with the first occurance of the genome:
3117 :    
3118 :     foreach $sim ( @tmp )
3119 :     {
3120 :     $id = $sim->id2;
3121 :     $genome = ($id =~ /^fig\|(\d+\.\d+)\.peg\.\d+/) ? $1 : $id;
3122 :     if (! defined( $sims{ $genome } ) ) { push @genomes, $genome }
3123 :     push @{ $sims{ $genome } }, $sim;
3124 :     }
3125 :     return map { @{ $sims{$_} } } @genomes;
3126 :     }
3127 : overbeek 1.121
3128 :     sub in_cluster_with {
3129 :     my($fig_or_sprout,$cgi,$peg) = @_;
3130 :     my %in_cluster;
3131 :    
3132 :     if ($fig_or_sprout->table_exists('fc_pegs') && $fig_or_sprout->is_complete(&FIG::genome_of($peg)))
3133 :     {
3134 :     %in_cluster = map { $_->[0] => &ev_link($cgi,$_->[0],$_->[1]) } $fig_or_sprout->coupled_to($peg);
3135 :     if (keys(%in_cluster) > 0)
3136 :     {
3137 :     $in_cluster{$peg} = "";
3138 :     }
3139 :     elsif ($cgi->param('fc'))
3140 :     {
3141 :     %in_cluster = map { $_ => "" } $fig_or_sprout->in_cluster_with($peg);
3142 : overbeek 1.127 if (keys(%in_cluster) == 1)
3143 :     {
3144 :     my @tmp = keys(%in_cluster);
3145 :     delete $in_cluster{$tmp[0]};
3146 :     }
3147 : overbeek 1.121 }
3148 :     }
3149 :     return \%in_cluster;
3150 :     }
3151 :    
3152 : overbeek 1.141 sub evidence_codes {
3153 :     my($fig_or_sprout,$peg) = @_;
3154 :    
3155 :     if ($peg !~ /^fig\|\d+\.\d+\.peg\.\d+$/) { return "" }
3156 :    
3157 : overbeek 1.142 my @codes = grep { $_->[1] =~ /^evidence_code/i } $fig_or_sprout->get_attributes($peg);
3158 : overbeek 1.141 return (@codes > 0) ? map { $_->[2] } @codes : ();
3159 :     }
3160 :    
3161 : overbeek 1.143 sub evidence_codes_link {
3162 : redwards 1.160 my($cgi) = @_;
3163 :     return "<A href=\"Html/evidence_codes.html\" target=\"SEED_or_SPROUT_help\">Ev</A>";
3164 :     }
3165 :    
3166 : overbeek 1.141
3167 : redwards 1.160 sub evidence_codes_explain {
3168 :     my($ec)=@_;
3169 :     return unless ($ec);
3170 :    
3171 :     $ec=uc($ec);
3172 :     return "IDA: Inferred from Direct Assay" if ($ec eq "IDA");
3173 :     return "IGI: Inferred from Genetic Interaction" if ($ec eq "IGI");
3174 :     return "TAS: Traceable Author Statement" if ($ec eq "TAS");
3175 :     return "ISU: in subsystem unique" if ($ec eq "ISU");
3176 :     return "$ec: in subsystem duplicates" if ($ec =~ /IDU/);
3177 :     return "$ec: in cluster with" if ($ec =~ /ICW/);
3178 :     return "$ec: unknown!";
3179 : overbeek 1.141 }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3