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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3