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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.180 - (view) (download)

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3