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

Annotation of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3