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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.168 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3