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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3