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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.154 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3