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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.164 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3