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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3