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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.173 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3