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

Annotation of /FigWebServices/subsys.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.110 - (view) (download)

1 : overbeek 1.1 # -*- perl -*-
2 :    
3 :     use FIG;
4 : golsen 1.103 use FIGjs; # mouseover()
5 : overbeek 1.1 my $fig = new FIG;
6 : overbeek 1.9
7 : overbeek 1.1 use Subsystem;
8 :    
9 : golsen 1.75 use URI::Escape; # uri_escape()
10 : overbeek 1.1 use HTML;
11 :     use strict;
12 :     use tree_utilities;
13 :    
14 :     use CGI;
15 : overbeek 1.9
16 : overbeek 1.1 my $cgi = new CGI;
17 :     if (0)
18 :     {
19 :     my $VAR1;
20 :     eval(join("",`cat /tmp/ssa_parms`));
21 :     $cgi = $VAR1;
22 :     # print STDERR &Dumper($cgi);
23 :     }
24 :    
25 :     if (0)
26 :     {
27 :     print $cgi->header;
28 :     my @params = $cgi->param;
29 :     print "<pre>\n";
30 :     foreach $_ (@params)
31 :     {
32 :     print "$_\t:",join(",",$cgi->param($_)),":\n";
33 :     }
34 :    
35 :     if (0)
36 :     {
37 :     if (open(TMP,">/tmp/ssa_parms"))
38 :     {
39 :     print TMP &Dumper($cgi);
40 :     close(TMP);
41 :     }
42 :     }
43 :     exit;
44 :     }
45 :    
46 :     # request to display the phylogenetic tree
47 :     #
48 :     my $request = $cgi->param("request");
49 :     if ($request && ($request eq "show_tree"))
50 :     {
51 :     print $cgi->header;
52 :     &show_tree;
53 :     exit;
54 :     }
55 :    
56 :     my $html = [];
57 : golsen 1.98 push @$html, "<TITLE>SEED Subsystems</TITLE>\n"; # RAE: every page deserves a title
58 : overbeek 1.1
59 :     my $user = $cgi->param('user');
60 :     $fig->set_user($user);
61 :    
62 : overbeek 1.14 if ($cgi->param('resynch_peg_connections') && (my $ssa = $cgi->param('ssa_name')))
63 : overbeek 1.9 {
64 :     my $subsystem = new Subsystem($ssa,$fig,0);
65 :     $subsystem->db_sync(0);
66 :     undef $subsystem;
67 :     &one_cycle($fig,$cgi,$html);
68 :     }
69 : overbeek 1.14 elsif ($user && ($cgi->param("extend_with_billogix")))
70 : overbeek 1.1 {
71 :     #
72 :     # Start a bg task to extend the subsystem.
73 :     #
74 :    
75 :     my $ssa = $cgi->param('ssa_name');
76 :    
77 :     my $user = $cgi->param('user');
78 :    
79 :     my $sub = $fig->get_subsystem($ssa);
80 :    
81 : overbeek 1.14 if ($sub && ($user eq $sub->get_curator))
82 : overbeek 1.1 {
83 :     #
84 :     # See if there's already an extend job running.
85 :     #
86 :    
87 :     my $curpid = $sub->get_current_extend_pid();
88 :     if ($curpid)
89 :     {
90 :     warn "Found current pid $curpid\n";
91 :     my $j = $fig->get_job($curpid);
92 :     warn "job is $j\n";
93 :     warn "running is ", $j->running(), "\n" if $j;
94 :     if ($j && $j->running())
95 :     {
96 :     push(@$html, "Subsystem extension is already running as job number $curpid. <br>",
97 : redwards 1.89 "Click <a href=\"seed_ctl.cgi?user=$user\">here</a> to see currently running jobs and their status");
98 : overbeek 1.1 last;
99 :     }
100 :     }
101 :    
102 :     my $pid = $fig->run_in_background(sub {$sub->extend_with_billogix($user);});
103 :    
104 :     push(@$html,
105 :     "Subsystem extension started as background job number $pid <br>\n",
106 : redwards 1.89 "Click <a href=\"seed_ctl.cgi?user=$user\">here</a> to see currently running jobs and their status");
107 : overbeek 1.1
108 :     $sub->set_current_extend_pid($pid);
109 :     }
110 :     else
111 :     {
112 :     push(@$html, "Subsystem '$ssa' could not be loaded");
113 :     }
114 :     &HTML::show_page($cgi, $html);
115 :     exit;
116 :     }
117 :     else
118 :     {
119 :     $request = defined($request) ? $request : "";
120 : overbeek 1.8
121 : overbeek 1.14 if (($request eq "reset") && $user)
122 : overbeek 1.1 {
123 :     &reset_ssa($fig,$cgi,$html); # allow user to go back to a previous version of the ss
124 :     }
125 : overbeek 1.14 elsif (($request eq "reset_to") && $user)
126 : overbeek 1.1 {
127 :     &reset_ssa_to($fig,$cgi,$html); # this actually resets to the previous version
128 : overbeek 1.9 &one_cycle($fig,$cgi,$html);
129 : overbeek 1.1 }
130 : overbeek 1.14 elsif (($request eq "make_exchangable") && $user)
131 : overbeek 1.1 {
132 :     &make_exchangable($fig,$cgi,$html);
133 :     &show_initial($fig,$cgi,$html);
134 :     }
135 : overbeek 1.14 elsif (($request eq "make_unexchangable") && $user)
136 : overbeek 1.1 {
137 :     &make_unexchangable($fig,$cgi,$html);
138 :     &show_initial($fig,$cgi,$html);
139 :     }
140 :     elsif ($request eq "show_ssa")
141 :     {
142 : overbeek 1.79 if ($_ = $cgi->param('check'))
143 :     {
144 :     push(@$html,$cgi->h1('CHECKING SUBSYSTEM'),
145 :     &check_ssa($fig,$cgi),
146 :     $cgi->hr
147 :     );
148 :     }
149 : overbeek 1.1 &one_cycle($fig,$cgi,$html);
150 :     }
151 :     #
152 :     # Note that this is a little different; I added another submit button
153 :     # to the delete_or_export_ssa form, so have to distinguish between them
154 :     # here based on $cgi->param('delete_export') - the original button,
155 :     # or $cgi->param('publish') - the new one.
156 :     #
157 : overbeek 1.14 elsif (($request eq "delete_or_export_ssa") && $user &&
158 :     defined($cgi->param('delete_export')))
159 : overbeek 1.1 {
160 :     my($ssa,$exported);
161 :     $exported = 0;
162 :     foreach $ssa ($cgi->param('export'))
163 :     {
164 :     if (! $exported)
165 :     {
166 :     print $cgi->header;
167 :     print "<pre>\n";
168 :     }
169 :     &export($fig,$cgi,$ssa);
170 :     $exported = 1;
171 :     }
172 :    
173 :     foreach $ssa ($cgi->param('export_assignments'))
174 :     {
175 :     &export_assignments($fig,$cgi,$ssa);
176 :     }
177 :    
178 :     foreach $ssa ($cgi->param('delete'))
179 :     {
180 :     my $sub = $fig->get_subsystem($ssa);
181 :     $sub->delete_indices();
182 :    
183 :     my $cmd = "rm -rf '$FIG_Config::data/Subsystems/$ssa'";
184 :     my $rc = system $cmd;
185 :     }
186 :    
187 :     if (! $exported)
188 :     {
189 : redwards 1.88 &show_initial($fig,$cgi,$html);
190 :     }
191 :     else
192 :     {
193 :     print "</pre>\n";
194 :     exit;
195 :     }
196 :     }
197 :     elsif (($request eq "delete_or_export_ssa") && $user &&
198 :     defined($cgi->param('publish')))
199 :     {
200 :     my($ssa,$exported);
201 :     my($ch) = $fig->get_clearinghouse();
202 : overbeek 1.1
203 : redwards 1.88 print $cgi->header;
204 : overbeek 1.1
205 : redwards 1.88 if (!defined($ch))
206 :     {
207 :     print "cannot publish: clearinghouse not available\n";
208 :     exit;
209 :     }
210 :    
211 :     foreach $ssa ($cgi->param('publish_to_clearinghouse'))
212 :     {
213 :     print "<h2>Publishing $ssa to clearinghouse...</h2>\n";
214 :     $| = 1;
215 :     print "<pre>\n";
216 :     my $res = $fig->publish_subsystem_to_clearinghouse($ssa);
217 :     print "</pre>\n";
218 :     if ($res)
219 :     {
220 :     print "Published <i>$ssa </i> to clearinghouse<br>\n";
221 :     }
222 :     else
223 :     {
224 :     print "<b>Failed</b> to publish <i>$ssa</i> to clearinghouse<br>\n";
225 :     }
226 :     }
227 :     exit;
228 : overbeek 1.1 }
229 : redwards 1.88 elsif (($request eq "delete_or_export_ssa") && $user &&
230 :     defined($cgi->param('reindex')))
231 : overbeek 1.1 {
232 : redwards 1.88
233 :     my @ss=$cgi->param('index_subsystem');
234 :     my $job = $fig->index_subsystems(@ss);
235 :     push @$html, "<h2>ReIndexing these subsystems...</h2>\n<ul>", map {"<li>$_</li>"} @ss;
236 :     push @$html, "</ul>\n<p>... is running in the background with job id $job. You may check it in the ",
237 : redwards 1.89 "<a href=\"seed_ctl.cgi?user=$user\">SEED Control Panel</a></p>\n";
238 : redwards 1.88 &show_initial($fig,$cgi,$html);
239 : overbeek 1.1 }
240 : overbeek 1.14 elsif ($user && ($request eq "new_ssa") && ($cgi->param('copy_from1')) && (! $cgi->param('cols_to_take1')))
241 : overbeek 1.1 {
242 :     my $user = $cgi->param('user');
243 :     my $name = $cgi->param('ssa_name');
244 :     my $copy_from1 = $cgi->param('copy_from1');
245 :     my $copy_from2 = $cgi->param('copy_from2');
246 :     my(@roles1,@roles2);
247 :    
248 :     push(@$html,$cgi->start_form(-action => "subsys.cgi",
249 :     -method => 'post'),
250 :     $cgi->hidden(-name => 'copy_from1', -value => $copy_from1, -override => 1),
251 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
252 :     $cgi->hidden(-name => 'ssa_name', -value => $name, -override => 1),
253 :     $cgi->hidden(-name => 'request', -value => 'new_ssa', -override => 1)
254 :     );
255 :    
256 :     @roles1 = $fig->subsystem_to_roles($copy_from1);
257 :     if (@roles1 > 0)
258 :     {
259 :     push(@$html,$cgi->h1("select columns to be taken from $copy_from1"),
260 :     $cgi->scrolling_list(-name => 'cols_to_take1',
261 :     -values => ['all',@roles1],
262 :     -size => 10,
263 :     -multiple => 1
264 :     ),
265 :     $cgi->hr
266 :     );
267 :     }
268 :    
269 :     if ($copy_from2)
270 :     {
271 :     @roles2 = $fig->subsystem_to_roles($copy_from2);
272 :     if (@roles2 > 0)
273 :     {
274 :     push(@$html,$cgi->hidden(-name => 'copy_from2', -value => $copy_from2, -override => 1));
275 :     push(@$html,$cgi->h1("select columns to be taken from $copy_from2"),
276 :     $cgi->scrolling_list(-name => 'cols_to_take2',
277 :     -values => ['all',@roles2],
278 :     -size => 10,
279 :     -multiple => 1
280 :     ),
281 :     $cgi->hr
282 :     );
283 :     }
284 :     }
285 :     push(@$html,$cgi->submit('build new subsystem'),
286 :     $cgi->end_form
287 :     );
288 :     }
289 : redwards 1.89 elsif ($user && ($request eq "new_ssa") && ($cgi->param('move_from')))
290 :     {
291 :     my $user = $cgi->param('user');
292 :     my $name = $cgi->param('ssa_name');
293 :     $name=$fig->clean_spaces($name);
294 :     $name=~s/ /_/g;
295 :     my $move_from = $cgi->param('move_from');
296 :     if (-d "$FIG_Config::data/Subsystems/$move_from" && !(-e "$FIG_Config::data/Subsystems/$name")) {
297 :     my $res=`mv $FIG_Config::data/Subsystems/$move_from $FIG_Config::data/Subsystems/$name`;
298 :     my $job = $fig->index_subsystems($name);
299 :     push @$html, "<p>The subsystem <b>$move_from</b> was moved to <b>$name</b> and got the result $res. The new subsystem is being indexed with job id $job\n",
300 :     "(check the <a href=\"seed_ctl.cgi?user=$user\">SEED control panel</a> for more information</p>\n";
301 :     }
302 :     elsif (-e "$FIG_Config::data/Subsystems/$name")
303 :     {
304 :     push @$html, "<p>The subsystem <b>$move_from</b> was <b><i>NOT</i></b> moved because the subsystem $name already exists</p>";
305 :     }
306 :     else {
307 :     push @$html, "<p>The subsystem <b>$move_from</b> was not found. Sorry</p>";
308 :     }
309 :     &show_initial($fig,$cgi,$html);
310 :     }
311 : overbeek 1.1 elsif ($request eq "new_ssa")
312 :     {
313 :     &new_ssa($fig,$cgi,$html);
314 :     }
315 : redwards 1.108 #RAE: undelete these 5 commented out line for the new interface
316 :     # elsif ($request eq "manage_ss")
317 : overbeek 1.1 else
318 : redwards 1.108 {
319 :     &manage_subsystems($fig,$cgi,$html);
320 : overbeek 1.1 }
321 : redwards 1.108 # else
322 :     # {
323 :     # &show_initial($fig,$cgi,$html);
324 :     # }
325 : overbeek 1.1 }
326 :    
327 :     &HTML::show_page($cgi,$html);
328 : golsen 1.91 exit;
329 : overbeek 1.1
330 : redwards 1.108 sub show_initial {
331 :     # a new first page written by Rob
332 :     my($fig,$cgi,$html) = @_;
333 : overbeek 1.1
334 : redwards 1.108 my $user = $cgi->param('user');
335 :     my $sort = $cgi->param('sortby'); unless ($sort) {$sort="Classification"}
336 :    
337 :     my @ssa = map {
338 :     my $ss=$_;
339 :     my ($version, $curator, $pedigree, $roles)=$fig->subsystem_info($ss->[0]);
340 :     push @$ss, scalar(@$roles), scalar(@{$fig->subsystem_genomes($ss->[0], 1)}), $version;
341 :     unshift @$ss, @{$fig->subsystem_classification($ss->[0])};
342 :     $ss->[2]=&ssa_link($fig, $ss->[2], $user);
343 :     if ($ss->[3] eq $user) {$ss->[3] = [$ss->[3], "td style='background-color: #BA55D3'"]}
344 :     $_=$ss;
345 :     }
346 :     &existing_subsystem_annotations($fig);
347 :    
348 :    
349 :     # sort the cells
350 :     if ($sort eq "Classification") {@ssa=sort {$a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2]} @ssa}
351 :     elsif ($sort eq "Subsystem") {@ssa=sort {$a->[2] cmp $b->[2]} @ssa}
352 :     elsif ($sort eq "Curator") {@ssa=sort {$a->[3] cmp $b->[3]} @ssa}
353 :     elsif ($sort eq "Number of Roles") {@ssa=sort {$a->[4] <=> $b->[4]} @ssa}
354 :     elsif ($sort eq "Version") {@ssa=sort {$a->[5] <=> $b->[5]} @ssa}
355 :    
356 :     my $col_hdrs=[["Classification", "th colspan=2 style='text-align: center'"], "Subsystem", "Curator", "Number of Roles", "Number of Genomes", "Version"];
357 :     my $tab=HTML->merge_table_rows(\@ssa);
358 :     my $url = &FIG::cgi_url . "/subsys.cgi?user=$user&request=manage_ss";
359 :     my $target = "window$$";
360 :    
361 :     push(@$html,
362 :     $cgi->start_form,
363 :     "<div class='ssinstructions'>\n",
364 :     "Please choose one of the subsystems from this list, or begin working on your own by entering a name in the box at the bottom of the page. ",
365 :     "We suggest that you take some time to look at the subsystems others have developed before working on your own.",
366 :     "<ul><li>Please do not ever edit someone else's spreadsheet</li>\n<li>Please do not open multiple windows to process the same spreadsheet.</li>",
367 :     "<li>Feel free to open a subsystem spreadsheet and then open multiple other SEED windows to access data and modify annotations.</li>",
368 :     "<li>You can access someone else's subsystem spreadsheet using your ID</li>",
369 :     "<li>You can <a href='$url&manage=mine'>manage your subsystems</a></li>",
370 :     "<li>You can <a href='$url'>manage all subsystems</a></li>",
371 :     "</ul></div>",
372 :     "<div class='page_settings' style='width: 75%; margin-left: auto; margin-right: auto'>Please enter your username: ", $cgi->textfield(-name=>"user"), "\n",
373 :     "<table border=1>\n",
374 :     "<tr><th>Settings for this page</th><th>Settings for the links to the next page.<br>Change these and click Update Table View.</th></tr>\n",
375 :     "<tr><td>",
376 :     "<table><tr>",
377 :     "<td valign=center>Sort table by</td><td valign=center>",
378 :     $cgi->popup_menu(-name=>'sortby', -values=>['Classification', 'Subsystem', 'Curator', 'Number of Roles', 'Version']), "</td></tr></table\n",
379 :     "</td>\n<td>",
380 :     "<table><tr>",
381 :     "<td valign=center>Show clusters</td><td valign=center>", $cgi->checkbox(-name=>'show_clusters', -label=>''), "</td>\n",
382 :     "<td valign=center>Default Spreadsheet view</td><td valign=center>",
383 :     $cgi->scrolling_list(-name => 'sort', -value => ['unsorted','alphabetic','by_pattern', 'by_phylo','by_tax_id','by_variant']),
384 :     "</td></tr></table>\n",
385 :     "</td></tr></table>\n",
386 :     $cgi->submit('Update Table View'), $cgi->reset, $cgi->p,
387 :     "</div>\n",
388 :     &HTML::make_table($col_hdrs,$tab,"Subsystems"),
389 :     $cgi->end_form(),
390 :    
391 :    
392 :     # $cgi->h3('To start a new subsystem'), $cgi->p("Please enter the name of the subsystem that you would like to start. You will be provided with a blank",
393 :     # " form that you can fill in with the roles and genomes to create a subsystem like those above."),
394 :     # $cgi->start_form(-action => "subsys.cgi",
395 :     # -target => $target,
396 :     # -method => 'post'),
397 :     # $cgi->hidden(-name => 'user', -value => $user, -override => 1),
398 :     # $cgi->hidden(-name => 'request', -value => 'new_ssa', -override => 1),
399 :     # "Name of New Subsystem: ",
400 :     # $cgi->textfield(-name => "ssa_name", -size => 50),
401 :     # $cgi->hidden(-name => 'can_alter', -value => 1, -override => 1),
402 :     # $cgi->br,
403 :     #
404 :     # $cgi->submit('start new subsystem'),
405 :     $cgi->end_form,
406 :     );
407 :     }
408 :    
409 :    
410 :    
411 :    
412 :    
413 :     sub manage_subsystems {
414 : overbeek 1.1 my($fig,$cgi,$html) = @_;
415 :     my($set,$when,$comment);
416 :    
417 :     my $user = $cgi->param('user');
418 : redwards 1.108 my $ss_to_manage=$cgi->param('manage'); # we will only display a subset of subsystems on the old SS page
419 :     if ($ss_to_manage eq "mine") {$ss_to_manage=$user}
420 :    
421 : overbeek 1.51 my @ssa = &existing_subsystem_annotations($fig);
422 : redwards 1.108 #$ss_to_manage && (@ssa=grep {$_->[1] eq $ss_to_manage} @ssa); # limit the set if we want to
423 : overbeek 1.1
424 :     if (@ssa > 0)
425 :     {
426 :     &format_ssa_table($cgi,$html,$user,\@ssa);
427 :     }
428 :    
429 :     my $target = "window$$";
430 :     push(@$html, $cgi->h1('To Start or Copy a Subsystem'),
431 :     $cgi->start_form(-action => "subsys.cgi",
432 :     -target => $target,
433 :     -method => 'post'),
434 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
435 :     $cgi->hidden(-name => 'request', -value => 'new_ssa', -override => 1),
436 :     "Name of New Subsystem: ",
437 :     $cgi->textfield(-name => "ssa_name", -size => 50),
438 :     $cgi->hidden(-name => 'can_alter', -value => 1, -override => 1),
439 :     $cgi->br,
440 :    
441 :     "Copy from (leave blank to start from scratch): ",
442 :     $cgi->textfield(-name => "copy_from1", -size => 50),
443 :     $cgi->br,
444 :    
445 :     "Copy from (leave blank to start from scratch): ",
446 :     $cgi->textfield(-name => "copy_from2", -size => 50),
447 :     $cgi->br,
448 :    
449 : redwards 1.108 "Rename an existing subsystem: ",
450 : redwards 1.89 $cgi->textfield(-name => "move_from", -size => 50),
451 :     $cgi->br,
452 :    
453 : overbeek 1.1 $cgi->submit('start new subsystem'),
454 :     $cgi->end_form,
455 :     "<br>You can start a subsystem from scratch, in which case you should leave these two \"copy from\"
456 :     fields blank. If you wish to just copy a subsystem (in order to become the owner so that you can modify it),
457 :     just fill in one of the \"copy from\" fields with the name of the subsystem you wish to copy. If you wish to
458 :     extract a a subset of the columns to build a smaller spreadsheet (which could later be merged with another one),
459 :     fill in the name of the subsystem. You will be prompted for the columns that you wish to extract (choose <i>all</i> to
460 :     just copy all of the columns). Finally, if you wish to build a new spreadsheet by including columns from two existing
461 :     spreadsheets (including a complete merger), fill in the names of both the existing \"copy from\" subsystems"
462 :     );
463 :     }
464 :    
465 :     sub new_ssa {
466 :     my($fig,$cgi,$html) = @_;
467 :    
468 :     my $user = $cgi->param('user');
469 : redwards 1.82 my $name = $fig->clean_spaces($cgi->param('ssa_name')); # RAE remove extraneous spaces in the name
470 : overbeek 1.1
471 :     if (! $user)
472 :     {
473 :     push(@$html,$cgi->h1('You need to specify a user before starting a new subsystem annotation'));
474 :     return;
475 :     }
476 :    
477 :     if (! $name)
478 :     {
479 : redwards 1.82 push(@$html,$cgi->h1("You need to specify a subsystem name, $name is not valid"));
480 : overbeek 1.1 return;
481 :     }
482 :    
483 :     my $ssa = $name;
484 :     $ssa =~ s/[ \/]/_/g;
485 :    
486 :     &FIG::verify_dir("$FIG_Config::data/Subsystems");
487 :    
488 :     if (-d "$FIG_Config::data/Subsystems/$ssa")
489 :     {
490 :     push(@$html,$cgi->h1("You need to specify a new subsystem name; $ssa already is being used"));
491 :     return;
492 :     }
493 :    
494 :     my $subsystem = new Subsystem($ssa,$fig,1); # create new subsystem
495 :    
496 :     my $copy_from1 = $cgi->param('copy_from1');
497 :     $copy_from1 =~ s/[ \/]/_/g;
498 :     my $copy_from2 = $cgi->param('copy_from2');
499 :     $copy_from2 =~ s/[ \/]/_/g;
500 :     my @cols_to_take1 = $cgi->param('cols_to_take1');
501 :     my @cols_to_take2 = $cgi->param('cols_to_take2');
502 :    
503 :    
504 :     if ($copy_from1 && (@cols_to_take1 > 0))
505 :     {
506 : overbeek 1.9 $subsystem->add_to_subsystem($copy_from1,\@cols_to_take1,"take notes"); # add columns and notes
507 : overbeek 1.1 }
508 :    
509 :     if ($copy_from2 && (@cols_to_take2 > 0))
510 :     {
511 : overbeek 1.9 $subsystem->add_to_subsystem($copy_from2,\@cols_to_take2,"take notes"); # add columns and notes
512 : overbeek 1.1 }
513 :    
514 :     $subsystem->write_subsystem();
515 :    
516 : redwards 1.82 $cgi->param(-name => "ssa_name",
517 :     -value => $ssa); # RAE this line was needed because otherwise a newly created subsystem was not opened!
518 :     $cgi->param(-name => "can_alter",
519 : overbeek 1.1 -value => 1);
520 :     &one_cycle($fig,$cgi,$html);
521 :     }
522 :    
523 :     # The basic update logic (cycle) includes the following steps:
524 :     #
525 :     # 1. Load the existing spreadsheet
526 :     # 2. reconcile row and subset changes
527 : overbeek 1.9 # 3. process spreadsheet changes (fill/refill/add genomes/update variants)
528 : overbeek 1.1 # 4. write the updated spreadsheet back to disk
529 :     # 5. render the spreadsheet
530 :     #
531 :     sub one_cycle {
532 :     my($fig,$cgi,$html) = @_;
533 : overbeek 1.57 my $subsystem;
534 : overbeek 1.1
535 :     my $user = $cgi->param('user');
536 :     my $ssa = $cgi->param('ssa_name');
537 :    
538 : overbeek 1.57 if ((! $ssa) || (! ($subsystem = new Subsystem($ssa,$fig,0))))
539 : overbeek 1.1 {
540 :     push(@$html,$cgi->h1('You need to specify a subsystem'));
541 :     return;
542 :     }
543 : olson 1.109
544 :     #
545 :     # Initialize can_alter if it is not set.
546 :     #
547 :    
548 :     my $can_alter = $cgi->param("can_alter");
549 :     if (!defined($can_alter))
550 :     {
551 :     if ($user = $cgi->param('user') and ($user eq $subsystem->get_curator))
552 :     {
553 :     $can_alter = 1;
554 :     $cgi->param(-name => 'can_alter', -value => 1);
555 :     }
556 :     }
557 :    
558 : olson 1.104
559 :     if ($cgi->param('can_alter') && ($user = $cgi->param('user')) && ($user eq $subsystem->get_curator))
560 :     {
561 :     handle_diagram_changes($fig, $subsystem, $cgi, $html);
562 :     }
563 : overbeek 1.1
564 :     if (&handle_role_and_subset_changes($fig,$subsystem,$cgi,$html))
565 :     {
566 :     &process_spreadsheet_changes($fig,$subsystem,$cgi,$html);
567 : overbeek 1.10
568 : overbeek 1.14 if ($cgi->param('can_alter') && ($user = $cgi->param('user')) && ($user eq $subsystem->get_curator))
569 :     {
570 :     $subsystem->write_subsystem();
571 :     }
572 : overbeek 1.76
573 :     my $col;
574 : overbeek 1.77 if ($cgi->param('show_sequences_in_column') &&
575 :     ($col = $cgi->param('col_to_align')) &&
576 :     ($col =~ /^\s*(\d+)\s*$/))
577 : overbeek 1.76 {
578 : overbeek 1.77 &show_sequences_in_column($fig,$cgi,$html,$subsystem,$col);
579 : overbeek 1.76 }
580 : overbeek 1.77 else
581 : overbeek 1.76 {
582 : overbeek 1.77 if ($cgi->param('align_column') &&
583 :     ($col = $cgi->param('col_to_align')) && ($col =~ /^\s*(\d+)\s*$/))
584 :     {
585 :     my $col = $1;
586 :     &align_column($fig,$cgi,$html,$col,$subsystem);
587 :     $cgi->delete('col_to_align');
588 :     }
589 :     elsif ($cgi->param('realign_column') &&
590 :     ($col = $cgi->param('subcol_to_realign')) && ($col =~ /^\s*(\d+)\.(\d+)\s*$/))
591 :     {
592 :     &align_subcolumn($fig,$cgi,$html,$1,$2,$subsystem);
593 :     $cgi->delete('subcol_to_realign');
594 :     }
595 :     &produce_html_to_display_subsystem($fig,$subsystem,$cgi,$html,$ssa);
596 : overbeek 1.76 }
597 : overbeek 1.1 }
598 :     }
599 :    
600 :     sub handle_role_and_subset_changes {
601 :     my($fig,$subsystem,$cgi,$html) = @_;
602 : overbeek 1.14 my $user;
603 : overbeek 1.1
604 : overbeek 1.14 if ((! $cgi->param('can_alter')) || (! ($user = $cgi->param('user'))) || ($user ne $subsystem->get_curator))
605 : overbeek 1.1 {
606 :     return 1; # no changes, so...
607 :     }
608 :     else
609 :     {
610 : overbeek 1.97 my @roles = $subsystem->get_roles;
611 :     my($rparm,$vparm);
612 :     foreach $rparm (grep { $_ =~ /^react\d+/ } $cgi->param)
613 :     {
614 :     if ($vparm = $cgi->param($rparm))
615 :     {
616 : overbeek 1.100 $vparm =~ s/ //g;
617 : overbeek 1.97 $rparm =~ /^react(\d+)/;
618 :     my $roleN = $1 - 1;
619 : overbeek 1.100 $subsystem->set_reaction($roles[$roleN],$vparm);
620 : overbeek 1.97 }
621 :     }
622 :    
623 : overbeek 1.1 my($role,$p,$abr,$r,$n);
624 :     my @tuplesR = ();
625 : overbeek 1.97
626 :     ### NOTE: the meaning (order) or @roles shifts here to the NEW order
627 :     @roles = grep { $_ =~ /^role/ } $cgi->param();
628 : overbeek 1.1 if (@roles == 0) { return 1 } # initial call, everything is as it was
629 :    
630 :     foreach $role (@roles)
631 :     {
632 :     if (($role =~ /^role(\d+)/) && defined($n = $1))
633 :     {
634 :     if ($r = $cgi->param("role$n"))
635 :     {
636 : overbeek 1.9 $r =~ s/^\s+//;
637 :     $r =~ s/\s+$//;
638 :    
639 : overbeek 1.1 if (($p = $cgi->param("posR$n")) && ($abr = $cgi->param("abbrev$n")))
640 :     {
641 :     push(@tuplesR,[$p,$r,$abr]);
642 :     }
643 :     else
644 :     {
645 :     push(@$html,$cgi->h1("You need to give a position and abbreviation for $r"));
646 :     return 0;
647 :     }
648 :     }
649 :     }
650 :     }
651 : overbeek 1.97 @tuplesR = sort { $a->[0] <=> $b->[0] } @tuplesR;
652 :     $subsystem->set_roles([map { [$_->[1],$_->[2]] } @tuplesR]);
653 : overbeek 1.9
654 :     my($subset_name,$s,$test,$entries,$entry);
655 :     my @subset_names = grep { $_ =~ /^nameCS/ } $cgi->param();
656 :    
657 :     if (@subset_names == 0) { return 1 }
658 :    
659 :     my %defined_subsetsC;
660 :     foreach $s (@subset_names)
661 : overbeek 1.1 {
662 : overbeek 1.9 if (($s =~ /^nameCS(\d+)/) && defined($n = $1) && ($subset_name = $cgi->param($s)))
663 : overbeek 1.1 {
664 : overbeek 1.9
665 : overbeek 1.1 my($text);
666 : overbeek 1.9 $entries = [];
667 :     if ($text = $cgi->param("subsetC$n"))
668 : overbeek 1.1 {
669 :     foreach $entry (split(/[\s,]+/,$text))
670 :     {
671 :     if ($role = &to_role($entry,\@tuplesR))
672 :     {
673 : overbeek 1.9 push(@$entries,$role);
674 : overbeek 1.1 }
675 :     else
676 :     {
677 :     push(@$html,$cgi->h1("Invalid role designation in subset $s: $entry"));
678 :     return 0;
679 :     }
680 :     }
681 :     }
682 : overbeek 1.9 $defined_subsetsC{$subset_name} = $entries;
683 :     }
684 :     }
685 :    
686 :     foreach $s ($subsystem->get_subset_namesC)
687 :     {
688 :     next if ($s eq "All");
689 :     if ($entries = $defined_subsetsC{$s})
690 :     {
691 :     $subsystem->set_subsetC($s,$entries);
692 :     delete $defined_subsetsC{$s};
693 :     }
694 :     else
695 :     {
696 :     $subsystem->delete_subsetC($s);
697 : overbeek 1.1 }
698 :     }
699 : overbeek 1.9
700 :     foreach $s (keys(%defined_subsetsC))
701 :     {
702 :     $subsystem->set_subsetC($s,$defined_subsetsC{$s});
703 :     }
704 : overbeek 1.27
705 :     my $active_subsetC;
706 :     if ($active_subsetC = $cgi->param('active_subsetC'))
707 :     {
708 :     $subsystem->set_active_subsetC($active_subsetC);
709 :     }
710 : overbeek 1.1 }
711 :     return 1;
712 :     }
713 :    
714 :     sub to_role {
715 :     my($x,$role_tuples) = @_;
716 :     my $i;
717 :    
718 : overbeek 1.9 if (($x =~ /^(\d+)$/) && ($1 <= @$role_tuples)) { return $role_tuples->[$x-1]->[1] }
719 :    
720 : overbeek 1.1 for ($i=0; ($i < @$role_tuples) &&
721 :     ($role_tuples->[0] != $x) &&
722 :     ($role_tuples->[1] != $x) &&
723 :     ($role_tuples->[2] != $x); $i++) {}
724 :     if ($i < @$role_tuples)
725 :     {
726 :     return $role_tuples->[$i]->[1];
727 :     }
728 :     return undef;
729 :     }
730 :    
731 :     sub process_spreadsheet_changes {
732 :     my($fig,$subsystem,$cgi,$html) = @_;
733 :    
734 : overbeek 1.14 my $user;
735 :     if ((! $cgi->param('can_alter')) || (! ($user = $cgi->param('user'))) || ($user ne $subsystem->get_curator))
736 : overbeek 1.1 {
737 :     return 1; # no changes, so...
738 :     }
739 :     else
740 :     {
741 : overbeek 1.12 my $notes = $cgi->param('notes');
742 :     if ($notes)
743 :     {
744 :     $subsystem->set_notes($notes);
745 :     }
746 : redwards 1.108 if ($cgi->param('classif1t') || $cgi->param('classif2t'))
747 :     {
748 :     $subsystem->set_classification([$cgi->param('classif1t'), $cgi->param('classif2t')]);
749 :     }
750 :     elsif ($cgi->param('classif1') || $cgi->param('classif2'))
751 : redwards 1.41 {
752 : redwards 1.108 $subsystem->set_classification([$cgi->param('classif1'), $cgi->param('classif2')]);
753 : redwards 1.41 }
754 : overbeek 1.12
755 : overbeek 1.7 my(@param,$param,$genome,$val);
756 :     @param = grep { $_ =~ /^genome\d+\.\d+$/ } $cgi->param;
757 : overbeek 1.13
758 :     my %removed;
759 : overbeek 1.7 foreach $param (@param)
760 :     {
761 :     if ($cgi->param($param) =~ /^\s*$/)
762 :     {
763 :     $param =~ /^genome(\d+\.\d+)/;
764 :     $genome = $1;
765 :     $subsystem->remove_genome($genome);
766 : overbeek 1.13 $removed{$genome} = 1;
767 : overbeek 1.7 }
768 :     }
769 :    
770 :     @param = grep { $_ =~ /^vcode\d+\.\d+$/ } $cgi->param;
771 :     foreach $param (@param)
772 :     {
773 :     if ($cgi->param($param) =~ /^\s*(\S+)\s*$/)
774 :     {
775 :     $val = $1;
776 :     $param =~ /^vcode(\d+\.\d+)/;
777 :     $genome = $1;
778 : overbeek 1.13 if (! $removed{$genome})
779 :     {
780 :     $subsystem->set_variant_code($subsystem->get_genome_index($genome),$val);
781 :     }
782 : overbeek 1.7 }
783 :     }
784 :    
785 : overbeek 1.1 if ($cgi->param('refill'))
786 :     {
787 :     &refill_spreadsheet($fig,$subsystem);
788 :     }
789 :     elsif ($cgi->param('precise_fill'))
790 :     {
791 :     &fill_empty_cells($fig,$subsystem);
792 :     }
793 :    
794 :     my @orgs = $cgi->param('new_genome');
795 :     @orgs = map { $_ =~ /\((\d+\.\d+)\)/; $1 } @orgs;
796 :    
797 :     my $org;
798 :     foreach $org (@orgs)
799 :     {
800 :     &add_genome($fig,$subsystem,$cgi,$html,$org);
801 :     }
802 : overbeek 1.27
803 :     my $active_subsetR;
804 :     if ($active_subsetR = $cgi->param('active_subsetR'))
805 :     {
806 :     $subsystem->set_active_subsetR($active_subsetR);
807 :     }
808 : overbeek 1.1 }
809 :     }
810 :    
811 :     sub refill_spreadsheet {
812 :     my($fig,$subsystem) = @_;
813 : overbeek 1.5 my($genome,$role,@pegs1,@pegs2,$i);
814 : overbeek 1.1
815 :     foreach $genome ($subsystem->get_genomes())
816 :     {
817 :     foreach $role ($subsystem->get_roles())
818 :     {
819 : overbeek 1.5 @pegs1 = sort $subsystem->get_pegs_from_cell($genome,$role);
820 :     @pegs2 = sort $fig->seqs_with_role($role,"master",$genome);
821 : overbeek 1.9
822 : overbeek 1.5 if (@pegs1 != @pegs2)
823 :     {
824 :     $subsystem->set_pegs_in_cell($genome,$role,\@pegs2);
825 :     }
826 :     else
827 :     {
828 :     for ($i=0; ($i < @pegs1) && ($pegs1[$i] eq $pegs2[$i]); $i++) {}
829 :     if ($i < @pegs1)
830 :     {
831 :     $subsystem->set_pegs_in_cell($genome,$role,\@pegs2);
832 :     }
833 :     }
834 : overbeek 1.1 }
835 :     }
836 :     }
837 :    
838 :     sub fill_empty_cells {
839 :     my($fig,$subsystem) = @_;
840 :     my($genome,$role,@pegs);
841 :    
842 :     foreach $genome ($subsystem->get_genomes())
843 :     {
844 :     foreach $role ($subsystem->get_roles())
845 :     {
846 :     @pegs = $subsystem->get_pegs_from_cell($genome,$role);
847 :     if (@pegs == 0)
848 :     {
849 :     @pegs = $fig->seqs_with_role($role,"master",$genome);
850 :     if (@pegs > 0)
851 :     {
852 :     $subsystem->set_pegs_in_cell($genome,$role,\@pegs);
853 :     }
854 :     }
855 :     }
856 :     }
857 :     }
858 :    
859 :     sub add_genome {
860 :     my($fig,$subsystem,$cgi,$html,$genome) = @_;
861 :     my($role,@pegs);
862 :    
863 :     $subsystem->add_genome($genome);
864 :     foreach $role ($subsystem->get_roles())
865 :     {
866 :     @pegs = $fig->seqs_with_role($role,"master",$genome);
867 :     $subsystem->set_pegs_in_cell($genome,$role,\@pegs);
868 :     }
869 :     }
870 :    
871 :     sub produce_html_to_display_subsystem {
872 : overbeek 1.20 my($fig,$subsystem,$cgi,$html,$ssa) = @_;
873 : overbeek 1.1
874 :     my $user = $cgi->param('user');
875 :     my $ssa = $cgi->param('ssa_name');
876 : overbeek 1.14 my $can_alter = ($cgi->param('can_alter') && $user && ($user eq $subsystem->get_curator));
877 : redwards 1.83 my $tagvalcolor; # RAE: this is a reference to a hash that stores the colors of cells by tag. This has to be consistent over the whole table.
878 : overbeek 1.1
879 :     my $name = $ssa;
880 :     $name =~ s/_/ /g;
881 :     $ssa =~ s/[ \/]/_/g;
882 : overbeek 1.51 my $curator = $fig->subsystem_curator($ssa);
883 : overbeek 1.1 push(@$html, $cgi->h1("Subsystem: $name"),
884 : overbeek 1.28 $cgi->h1("Author: $curator"),
885 : overbeek 1.1 $cgi->start_form(-action => "subsys.cgi",
886 : olson 1.104 -method => 'post',
887 :     -enctype => &CGI::MULTIPART),
888 : overbeek 1.1 $cgi->hidden(-name => 'user', -value => $user, -override => 1),
889 :     $cgi->hidden(-name => 'request', -value => 'show_ssa', -override => 1),
890 :     $cgi->hidden(-name => 'can_alter', -value => $can_alter, -override => 1),
891 :     $cgi->hidden(-name => 'ssa_name', -value => $name, -override => 1),
892 :     $cgi->br,
893 :     );
894 :    
895 : redwards 1.25 # RAE: First, a sanity check.
896 :     # We may have to move this a little earlier, and show probably throw some nicer
897 :     # errors to the end user (.e.g try setting can_alter and choosing an illegitimate ss
898 :     # Do we know about this subsystem:
899 : overbeek 1.26 my $ssaQ = quotemeta $ssa;
900 : overbeek 1.51 unless (grep {/$ssaQ/} map {$_->[0]} &existing_subsystem_annotations($fig))
901 : redwards 1.25 {
902 :     # No, we don't know about this subsystem
903 :     my $url = &FIG::cgi_url . "/subsys.cgi?user=$user";
904 :     push @$html, "Sorry. $name is not a valid subsystem. <p>\n",
905 :     "Please return to the <a href=\"$url\">Subsystems Page</a> and choose an exisiting subsystem. <p>\n",
906 :     "Sorry.";
907 :     return undef;
908 :     }
909 :    
910 : olson 1.109 &format_js_data($fig,$cgi,$html,$subsystem,$can_alter);
911 : redwards 1.25
912 : overbeek 1.14 &format_roles($fig,$cgi,$html,$subsystem,$can_alter);
913 :     &format_subsets($fig,$cgi,$html,$subsystem,$can_alter);
914 : olson 1.18
915 : olson 1.105 &format_diagrams($fig, $cgi, $html, $subsystem, $can_alter);
916 : olson 1.104
917 :     #
918 : olson 1.18 # Put link into constructs tool.
919 :     #
920 :    
921 :     if ($can_alter)
922 :     {
923 :     push(@$html, $cgi->p,
924 :     $cgi->a({href => "construct.cgi?ssa=$ssa&user=$user",
925 :     target => "_blank"},
926 :     "Define higher level constructs."),
927 :     $cgi->p);
928 :     }
929 :    
930 :    
931 : golsen 1.91 # Display the subsystem table rows, saving the list genomes displayed
932 : olson 1.18
933 : golsen 1.91 my $active_genome_list = &format_rows($fig,$cgi,$html,$subsystem, $tagvalcolor);
934 : redwards 1.64
935 : golsen 1.91
936 :     if ( $can_alter ) { format_extend_with($fig,$cgi,$html,$subsystem) }
937 : golsen 1.73
938 : golsen 1.75 my $esc_ssa = uri_escape( $ssa );
939 : golsen 1.73 push @$html, "<TABLE width=\"100%\">\n",
940 :     " <TR>\n",
941 :     ($can_alter) ? " <TD>" . $cgi->checkbox(-name => 'precise_fill', -value => 1, -checked => 0, -override => 1,-label => 'fill') . "</TD>\n" : (),
942 : overbeek 1.107 " <TD><a href=\"Html/conflict_resolution.html\" class=\"help\" target=\"help\">Help on conflict resolution</a></TD>\n",
943 :     " <TD><a href=\"Html/seedtips.html#edit_variants\" class=\"help\" target=\"help\">Help on editing variants</a></TD>\n",
944 : golsen 1.75 " <TD><a href=\"ss_export.cgi?user=$user&ssa_name=$esc_ssa\" class=\"help\">Export subsystem data</a></TD>\n",
945 : golsen 1.73 " </TR>\n",
946 :     "</TABLE>\n";
947 : redwards 1.64
948 :     if ($can_alter)
949 :     {
950 :     push(@$html,$cgi->submit('update spreadsheet'),$cgi->br);
951 : overbeek 1.1 }
952 :     else
953 :     {
954 :     push(@$html,$cgi->br);
955 :     push(@$html,$cgi->submit('show spreadsheet'),$cgi->br);
956 :     }
957 : redwards 1.64
958 : redwards 1.24 push(@$html,$cgi->checkbox(-name => 'ignore_alt', -value => 1, -override => 1, -label => 'ignore alternatives', -checked => ($cgi->param('ignore_alt'))),$cgi->br);
959 : overbeek 1.17 push(@$html,$cgi->checkbox(-name => 'ext_ids', -value => 1, -checked => 0, -label => 'use external ids'),$cgi->br);
960 : overbeek 1.60 push(@$html,$cgi->checkbox(-name => 'show_clusters', -value => 1, -checked => 0,-label => 'show clusters'),$cgi->br);
961 : redwards 1.52 my $opt=$fig->get_tags("genome"); # all the tags we know about
962 :     my @options=sort {uc($a) cmp uc($b)} keys %$opt;
963 :     unshift(@options, undef); # a blank field at the start
964 : redwards 1.54 push(@$html,"color rows by each organism's attribute: &nbsp; ", $cgi->popup_menu(-name => 'color_by_ga', -values=>\@options), $cgi->br);
965 :    
966 :     $opt=$fig->get_tags("peg"); # all the peg tags
967 : mkubal 1.95 @options=sort {$a cmp $b} keys %$opt;
968 : redwards 1.54 unshift(@options, undef);
969 :     push(@$html,"color columns by each PEGs attribute: &nbsp; ", $cgi->popup_menu(-name => 'color_by_peg_tag', -values=>\@options), $cgi->br);
970 :    
971 : golsen 1.91 push @$html, $cgi->checkbox(-name => 'show_missing', -value => 1, -checked => 0, -override => 1,-label => 'show missing'),
972 :     $cgi->br, $cgi->br;
973 :    
974 : overbeek 1.3
975 : golsen 1.91 # Format the organism list for a pop-up menu:
976 : overbeek 1.3
977 : golsen 1.92 my @genomes = sort { lc $a->[1] cmp lc $b->[1] } map { [ $_->[0], "$_->[1] [$_->[0]]" ] } @$active_genome_list;
978 : golsen 1.91 unshift @genomes, [ '', 'select it in this menu' ];
979 : mkubal 1.36
980 : golsen 1.91 # Make a list of index number and roles for pop-up selections:
981 :    
982 :     my @roles = map { [ $subsystem->get_role_index( $_ ) + 1, $_ ] } $subsystem->get_roles;
983 :     unshift @roles, [ '', 'select it in this menu' ];
984 :    
985 :     push @$html, "<table><tr><td>",
986 :     $cgi->checkbox(-name => 'show_missing_including_matches', -value => 1, -checked => 0, -override => 1,-label => 'show missing with matches'), $cgi->br,
987 :     $cgi->checkbox(-name => 'show_missing_including_matches_in_ss', -value => 1, -checked => 0, -override => 1,-label => 'show missing with matches in ss'), "&nbsp;&nbsp;",
988 : golsen 1.93 "</td>\n<td><big><big><big>} {</big></big></big></td>",
989 : golsen 1.91 "<td>",
990 :     "[To restrict to a single genome: ",
991 :     $cgi->popup_menu( -name => 'just_genome',
992 :     -values => [ map { $_->[0] } @genomes ],
993 :     -labels => { map { ( $_->[0], $_->[1] ) } @genomes }
994 :     ), "]", $cgi->br,
995 :     "[To restrict to a single role: ",
996 :     $cgi->popup_menu( -name => 'just_role',
997 :     -values => [ map { $_->[0] } @roles ],
998 :     -labels => { map { ( $_->[0], $_->[1] ) } @roles }
999 :     ),
1000 :     "]</td></tr></table>\n",
1001 :     $cgi->br;
1002 :    
1003 :    
1004 :     push @$html, "<table><tr><td>",
1005 :     $cgi->checkbox(-name => 'check_assignments', -value => 1, -checked => 0, -override => 1, -label => 'check assignments'),
1006 :     "&nbsp;&nbsp;[", $cgi->checkbox(-name => 'strict_check', -value => 1, -checked => 0, -override => 1, -label => 'strict'), "]&nbsp;&nbsp;",
1007 : golsen 1.93 "</td>\n<td><big><big><big>{</big></big></big></td>",
1008 : golsen 1.91 "<td>",
1009 :     "[To restrict to a single genome: ",
1010 :     $cgi->popup_menu( -name => 'just_genome_assignments',
1011 :     -values => [ map { $_->[0] } @genomes ],
1012 :     -labels => { map { ( $_->[0], $_->[1] ) } @genomes }
1013 :     ), "]", $cgi->br,
1014 :     "[To restrict to a single role: ",
1015 :     $cgi->popup_menu( -name => 'just_role_assignments',
1016 :     -values => [ map { $_->[0] } @roles ],
1017 :     -labels => { map { ( $_->[0], $_->[1] ) } @roles }
1018 :     ),
1019 :     "]</td></tr></table>\n",
1020 :     $cgi->br;
1021 : mkubal 1.36
1022 : overbeek 1.3
1023 : overbeek 1.14 if ($can_alter)
1024 :     {
1025 :     push(@$html,$cgi->checkbox(-name => 'refill', -value => 1, -checked => 0, -override => 1,-label => 'refill spreadsheet from scratch'),$cgi->br);
1026 :     }
1027 :    
1028 : overbeek 1.1 push(@$html,$cgi->checkbox(-name => 'show_dups', -value => 1, -checked => 0, -override => 1,-label => 'show duplicates'),$cgi->br);
1029 :     push(@$html,$cgi->checkbox(-name => 'check_problems', -value => 1, -checked => 0, -override => 1,-label => 'show PEGs in roles that do not match precisely'),$cgi->br);
1030 : overbeek 1.14 if ($can_alter)
1031 :     {
1032 : golsen 1.94 push(@$html,$cgi->checkbox(-name => 'add_solid', -value => 1, -checked => 0, -override => 1,-label => 'add genomes with solid hits'),$cgi->br);
1033 : overbeek 1.14 }
1034 :    
1035 : overbeek 1.1 push(@$html,$cgi->checkbox(-name => 'show_coupled_fast', -value => 1, -checked => 0, -override => 1,-label => 'show coupled PEGs fast [depends on existing pins/clusters]'),$cgi->br);
1036 : golsen 1.94
1037 :     push(@$html,$cgi->checkbox(-name => 'show_coupled', -value => 1, -checked => 0, -override => 1,-label => 'show coupled PEGs [figure 2 minutes per PEG in spreadsheet]'),$cgi->br);
1038 :    
1039 : redwards 1.63 # RAE Hide -1 variants
1040 : golsen 1.94 push(@$html,$cgi->checkbox(-name => 'show_minus1', -value=> 1, -checked => 0, -label => 'show -1 variants'),$cgi->br);
1041 :    
1042 :     # Alignment functions:
1043 :    
1044 :     push @$html, $cgi->hr,
1045 :     # $cgi->br, "Column (specify the number of the column): ",
1046 :     # $cgi->textfield(-name => "col_to_align", -size => 7),
1047 :     "For sequences in a column (i.e., role): ",
1048 :     $cgi->popup_menu( -name => 'col_to_align',
1049 :     -values => [ map { $_->[0] } @roles ],
1050 :     -labels => { map { ( $_->[0], $_->[1] ) } @roles }
1051 :     ),
1052 :     $cgi->br,
1053 :     $cgi->submit(-value => "Show Sequences in Column",
1054 :     -name => "show_sequences_in_column"),
1055 :     $cgi->br,
1056 :     $cgi->submit(-value => "Align Sequences in Column",
1057 :     -name => "align_column"),
1058 :     $cgi->br,
1059 :     $cgi->br, "Realign subgroup within a column (adding homologs): ",
1060 :     $cgi->textfield(-name => "subcol_to_realign", -size => 7),
1061 :     $cgi->br, "Include homologs that pass the following threshhold: ",
1062 :     $cgi->textfield(-name => "include_homo", -size => 10)," (leave blank to see just column)",
1063 :     " Max homologous seqs: ",$cgi->textfield(-name => "max_homo", -value => 100, -size => 6),
1064 :     $cgi->br,
1065 :     $cgi->submit(-value => "Realign Sequences in Column",
1066 :     -name => "realign_column"),
1067 :     $cgi->hr;
1068 :    
1069 : redwards 1.22 # RAE: A new function to reannotate a single column
1070 :     # I don't understand how you get CGI.pm to reset (and never have).
1071 :     # $cgi->delete("col_to_annotate"); # this does nothing to my script and there is always the last number in this box
1072 :     #push(@$html, $cgi->br,"Change annotation for column: ", $cgi->textfield(-name => "col_to_annotate", -size => 7));
1073 :     push(@$html, $cgi->br,"Change annotation for column: ", '<input type="text" name="col_to_annotate" value="" size="7">');
1074 : overbeek 1.1
1075 :     if ($can_alter)
1076 :     {
1077 :     push(@$html,
1078 : overbeek 1.20 $cgi->p. $cgi->hr."If you wish to check the subsystem, ",
1079 :     $cgi->a({href => "check_subsys.cgi?user=$user&subsystem=$ssa&request=check_ssa"},
1080 :     "click here"),
1081 : overbeek 1.49 # $cgi->br,
1082 :     # $cgi->p. $cgi->hr."If you wish to reset variants for the subsystem, ",
1083 :     # $cgi->a({href => "set_variants.cgi?user=$user&subsystem=$ssa&request=show_variants",target => "set_variants"},
1084 :     # "click here"),
1085 : overbeek 1.20 $cgi->br,
1086 : overbeek 1.1 $cgi->p,
1087 : overbeek 1.9 $cgi->hr,
1088 :     "You should resynch PEG connections only if you detect PEGs that should be connected to the
1089 :     spreadsheet, but do not seem to be. This can only reflect an error in the code. If you find
1090 :     yourself having to use it, send mail to Ross.",
1091 :     $cgi->br,
1092 :     $cgi->submit(-value => "Resynch PEG Connections",
1093 :     -name => "resynch_peg_connections"),
1094 :     $cgi->br,
1095 : overbeek 1.1 $cgi->submit(-value => "Start automated subsystem extension",
1096 :     -name => "extend_with_billogix"),
1097 :     $cgi->br);
1098 :     }
1099 : overbeek 1.10
1100 : overbeek 1.12 my $notes = $subsystem->get_notes();
1101 : overbeek 1.14 if ($can_alter)
1102 :     {
1103 :     push(@$html,$cgi->hr,"NOTES:\n",$cgi->br,$cgi->textarea(-name => 'notes', -rows => 40, -cols => 100, -value => $notes));
1104 :     }
1105 :     elsif ($notes)
1106 :     {
1107 : redwards 1.31 push(@$html,$cgi->h2('notes'),"<pre width=80>$notes</pre>");
1108 : overbeek 1.14 }
1109 : overbeek 1.10
1110 : redwards 1.41 # RAE Modified to add a line with the classification
1111 :     my $class=$subsystem->get_classification();
1112 :     if ($can_alter)
1113 :     {
1114 : redwards 1.108 my $menu1; my $menu2; # the two menus for the classification of subsystems
1115 :     # make sure we have empty blanks
1116 :     $menu1->{''}=$menu2->{''}=1;
1117 :     map {$menu1->{$_->[0]}=1; $menu2->{$_->[1]}=1} $fig->all_subsystem_classifications();
1118 :    
1119 :     push(@$html, $cgi->hr, "<table><tr><th colspan=2 style='text-align: center'>Subsystem Classification</th></tr>\n",
1120 :     "<tr><td>Please use ours:</td><td>", $cgi->popup_menu(-name=>"classif1", -values=>[sort {$a cmp $b} keys %$menu1], -default=>$$class[0]), "</td><td>",
1121 :     $cgi->popup_menu(-name=>"classif2", -values=>[sort {$a cmp $b} keys %$menu2], -default=>$$class[1]), "</td></tr>\n<tr><td>Or make your own:</td><td>",
1122 :     $cgi->textfield(-name=>"classif1t", -size=>50), "</td><td>", $cgi->textfield(-name=>"classif2t", -size=>50), "</td></tr></table>\n"
1123 :     );
1124 : redwards 1.41 }
1125 :     elsif ($class)
1126 :     {
1127 : redwards 1.42 push (@$html, $cgi->h2('Classification'), "<table><tr><td>$$class[0]</td><td>$$class[1]</td></tr></table>\n");
1128 : redwards 1.41 }
1129 :    
1130 : overbeek 1.1 push(@$html, $cgi->end_form);
1131 :    
1132 : overbeek 1.19 my $target = "align$$";
1133 :     my @roles = $subsystem->get_roles;
1134 :     my $i;
1135 :     my $dir = $subsystem->get_dir;
1136 : overbeek 1.76 my $rolesA = &existing_trees($dir,\@roles);
1137 :    
1138 : overbeek 1.19 if (@$rolesA > 0)
1139 :     {
1140 :     push(@$html, $cgi->hr,
1141 :     $cgi->h1('To Assign Using a Tree'),
1142 :     $cgi->start_form(-action => "assign_using_tree.cgi",
1143 :     -target => $target,
1144 :     -method => 'post'),
1145 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
1146 :     $cgi->hidden(-name => 'ali_dir', -value => "$dir/Alignments", -override => 1),
1147 :     $cgi->scrolling_list(-name => 'ali_num',
1148 :     -values => $rolesA,
1149 :     -size => 10,
1150 :     -multiple => 0
1151 :     ),
1152 :     $cgi->br,
1153 :     $cgi->submit(-value => "use_tree",
1154 :     -name => "use_tree"),
1155 :     $cgi->end_form
1156 :     );
1157 :     }
1158 :    
1159 : overbeek 1.1 push(@$html, $cgi->hr);
1160 :    
1161 :     if ($cgi->param('show_missing'))
1162 :     {
1163 :     &format_missing($fig,$cgi,$html,$subsystem);
1164 :     }
1165 :    
1166 :     if ($cgi->param('show_missing_including_matches'))
1167 :     {
1168 :     &format_missing_including_matches($fig,$cgi,$html,$subsystem);
1169 :     }
1170 : mkubal 1.36 if ($cgi->param('show_missing_including_matches_in_ss'))
1171 :     {
1172 :     &format_missing_including_matches_in_ss($fig,$cgi,$html,$subsystem);
1173 :     }
1174 :    
1175 : overbeek 1.1
1176 : overbeek 1.3 if ($cgi->param('check_assignments'))
1177 :     {
1178 :     &format_check_assignments($fig,$cgi,$html,$subsystem);
1179 :     }
1180 :    
1181 : overbeek 1.1 if ($cgi->param('show_dups'))
1182 :     {
1183 :     &format_dups($fig,$cgi,$html,$subsystem);
1184 :     }
1185 :    
1186 :     if ($cgi->param('show_coupled'))
1187 :     {
1188 :     &format_coupled($fig,$cgi,$html,$subsystem,"careful");
1189 :     }
1190 :     elsif ($cgi->param('show_coupled_fast'))
1191 :     {
1192 :     &format_coupled($fig,$cgi,$html,$subsystem,"fast");
1193 :     }
1194 :    
1195 :     my $col;
1196 : overbeek 1.76 if ($col = $cgi->param('col_to_annotate'))
1197 : redwards 1.22 {
1198 :     &annotate_column($fig,$cgi,$html,$col,$subsystem);
1199 :     }
1200 : overbeek 1.1 }
1201 :    
1202 : golsen 1.29
1203 :     #-----------------------------------------------------------------------------
1204 :     # Selection list of complete genomes not in spreadsheet:
1205 :     #-----------------------------------------------------------------------------
1206 :    
1207 : overbeek 1.1 sub format_extend_with {
1208 : golsen 1.29 my( $fig, $cgi, $html, $subsystem ) = @_;
1209 : overbeek 1.1
1210 :     my %genomes = map { $_ => 1 } $subsystem->get_genomes();
1211 :    
1212 : golsen 1.44 #
1213 :     # Use $fig->genomes( complete, restricted, domain ) to get org list:
1214 :     #
1215 :     my $req_comp = $cgi->param( 'complete' ) || 'Only "complete"';
1216 :     my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
1217 :     my @orgs = map { [ $_ , &ext_genus_species( $fig, $_ ) ] }
1218 :     grep { ! $genomes{ $_ } }
1219 :     $fig->genomes( $complete, undef );
1220 : golsen 1.29
1221 : golsen 1.44 #
1222 :     # Put it in the order requested by the user:
1223 :     #
1224 : golsen 1.29 my $pick_order = $cgi->param('pick_order') || 'Alphabetic';
1225 :     if ( $pick_order eq "Phylogenetic" )
1226 :     {
1227 :     @orgs = sort { $a->[2] cmp $b->[2] }
1228 :     map { push @$_, $fig->taxonomy_of( $_->[0] ); $_ }
1229 :     @orgs;
1230 :     }
1231 :     elsif ( $pick_order eq "Genome ID" )
1232 :     {
1233 :     @orgs = sort { $a->[2]->[0] <=> $b->[2]->[0] || $a->[2]->[1] <=> $b->[2]->[1] }
1234 :     map { push @$_, [ split /\./ ]; $_ }
1235 :     @orgs;
1236 :     }
1237 :     else
1238 :     {
1239 :     $pick_order = 'Alphabetic';
1240 :     @orgs = sort { $a->[1] cmp $b->[1] } @orgs;
1241 :     }
1242 : overbeek 1.1
1243 : golsen 1.29 @orgs = map { "$_->[1] ($_->[0])" } @orgs;
1244 :    
1245 : golsen 1.44 #
1246 :     # Radio buttons to let the user choose the order they want for the list:
1247 :     #
1248 : golsen 1.29 my @order_opt = $cgi->radio_group( -name => 'pick_order',
1249 :     -values => [ 'Alphabetic', 'Phylogenetic', 'Genome ID' ],
1250 :     -default => $pick_order,
1251 :     -override => 1
1252 :     );
1253 :    
1254 : golsen 1.44 #
1255 :     # Radio buttons to let the user choose to include incomplete genomes:
1256 :     #
1257 :     my @complete = $cgi->radio_group( -name => 'complete',
1258 :     -default => $req_comp,
1259 :     -override => 1,
1260 :     -values => [ 'All', 'Only "complete"' ]
1261 :     );
1262 :    
1263 :     #
1264 :     # Display the pick list, and options:
1265 :     #
1266 : golsen 1.29 push( @$html, $cgi->h1('Pick Organisms to Extend with'), "\n",
1267 :     "<TABLE>\n",
1268 :     " <TR>\n",
1269 :     " <TD>",
1270 : golsen 1.30 $cgi->scrolling_list( -name => 'new_genome',
1271 : golsen 1.29 -values => [ @orgs ],
1272 :     -size => 10,
1273 :     -multiple => 1
1274 :     ),
1275 :     " </TD>\n",
1276 : golsen 1.44 " <TD>",
1277 :     join( "<BR>\n", "<b>Order of selection list:</b>", @order_opt,
1278 :     "<b>Completeness?</b>", @complete
1279 :     ), "\n",
1280 : golsen 1.29 " </TD>\n",
1281 :     " </TR>\n",
1282 :     "</TABLE>\n",
1283 :     $cgi->hr
1284 :     );
1285 : overbeek 1.1 }
1286 :    
1287 : olson 1.109 #
1288 :     # Write out information about this subsystem as javascript
1289 :     # data structures. Used for the diagram coloring currently.
1290 :     #
1291 :     sub format_js_data
1292 :     {
1293 :     my($fig,$cgi,$html,$subsystem,$can_alter) = @_;
1294 :    
1295 :     push(@$html, qq(<script language="JavaScript">\n),
1296 :     "subsystemInfo = {\n");
1297 :    
1298 :     my $first = 1;
1299 :     for my $g ($subsystem->get_genomes())
1300 :     {
1301 :     my $txt = '';
1302 :     #
1303 :     # Determine which roles this genome has.
1304 :     #
1305 :     if (!$first)
1306 :     {
1307 :     $txt .= ", ";
1308 :     }
1309 :     else
1310 :     {
1311 :     $first = 0;
1312 :     }
1313 :    
1314 :     $txt .= "'$g': [";
1315 :    
1316 :     my $gi = $subsystem->get_genome_index($g);
1317 :    
1318 :     my $row = $subsystem->get_row($gi);
1319 :    
1320 :     my @r;
1321 :     for (my $ri = 0; $ri < @$row; $ri++)
1322 :     {
1323 :     my $cell = $row->[$ri];
1324 :     if ($#$cell > -1)
1325 :     {
1326 :     push(@r, "'" . $subsystem->get_role_abbr($ri) . "'");
1327 :     }
1328 :     }
1329 :    
1330 :     $txt .= join(", ", @r);
1331 :     $txt .= "]\n";
1332 :     push(@$html, $txt);
1333 :     }
1334 :     push(@$html, "};\n");
1335 :     push(@$html, "</script>\n");
1336 :     }
1337 : golsen 1.29
1338 : overbeek 1.1 sub format_roles {
1339 : overbeek 1.14 my($fig,$cgi,$html,$subsystem,$can_alter) = @_;
1340 : overbeek 1.1 my($i);
1341 :    
1342 : overbeek 1.97 my @roles = $subsystem->get_roles;
1343 : overbeek 1.96 my $sub_dir = $subsystem->get_dir;
1344 :    
1345 : overbeek 1.97 my $reactions = $subsystem->get_reactions;
1346 :    
1347 :     my $n = 1;
1348 :     my $col_hdrs = ["Column","Abbrev","Functional Role"];
1349 :    
1350 : overbeek 1.99 if ($can_alter)
1351 : overbeek 1.97 {
1352 :     push(@$col_hdrs,"KEGG Reactions");
1353 : overbeek 1.99 push(@$col_hdrs,"Edit Reactions");
1354 :     }
1355 :     elsif ($reactions)
1356 :     {
1357 :     push(@$col_hdrs,"KEGG Reactions");
1358 : overbeek 1.96 }
1359 :    
1360 : overbeek 1.1 my $tab = [];
1361 :    
1362 : overbeek 1.97 &format_existing_roles($fig,$cgi,$html,$subsystem,$tab,\$n,$can_alter,$reactions,\@roles);
1363 : overbeek 1.1 if ($cgi->param('can_alter'))
1364 :     {
1365 :     for ($i=0; ($i < 5); $i++)
1366 :     {
1367 : overbeek 1.96 &format_role($fig,$cgi,$html,$subsystem,$tab,$n,"",$can_alter,undef);
1368 : overbeek 1.1 $n++;
1369 :     }
1370 :     }
1371 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Functional Roles"),
1372 :     $cgi->hr
1373 :     );
1374 :     }
1375 :    
1376 :     sub format_existing_roles {
1377 : overbeek 1.97 my($fig,$cgi,$html,$subsystem,$tab,$nP,$can_alter,$reactions,$roles) = @_;
1378 : overbeek 1.1 my($role);
1379 :    
1380 : overbeek 1.97 foreach $role (@$roles)
1381 : overbeek 1.1 {
1382 : overbeek 1.97 &format_role($fig,$cgi,$html,$subsystem,$tab,$$nP,$role,$can_alter,$reactions);
1383 : overbeek 1.1 $$nP++;
1384 :     }
1385 :     }
1386 :    
1387 :     sub format_role {
1388 : overbeek 1.96 my($fig,$cgi,$html,$subsystem,$tab,$n,$role,$can_alter,$reactions) = @_;
1389 :     my($abbrev,$reactT);
1390 :    
1391 : overbeek 1.101 my $react = $reactions ? join(",", map { &HTML::reaction_link($_) } @{$reactions->{$role}}) : "";
1392 : overbeek 1.1
1393 :     $abbrev = $role ? $subsystem->get_role_abbr($subsystem->get_role_index($role)) : "";
1394 :    
1395 :     my($posT,$abbrevT,$roleT);
1396 : overbeek 1.14 if ($can_alter)
1397 : overbeek 1.1 {
1398 : overbeek 1.97 $posT = $cgi->textfield(-name => "posR$n", -size => 3, -value => $n, -override => 1);
1399 : overbeek 1.1 $abbrevT = $cgi->textfield(-name => "abbrev$n", -size => 7, -value => $abbrev, -override => 1);
1400 : overbeek 1.97 $roleT = $cgi->textfield(-name => "role$n", -size => 80, -value => $role, -override => 1);
1401 :     $reactT = $cgi->textfield(-name => "react$n", -size => 20, -value => "", -override => 1);
1402 : overbeek 1.1 }
1403 :     else
1404 :     {
1405 :     push(@$html,$cgi->hidden(-name => "posR$n", -value => $n, -override => 1),
1406 :     $cgi->hidden(-name => "abbrev$n", -value => $abbrev, -override => 1),
1407 :     $cgi->hidden(-name => "role$n", -value => $role, -override => 1));
1408 :     $posT = $n;
1409 :     $abbrevT = $abbrev;
1410 :     $roleT = $role;
1411 :     }
1412 :     #
1413 :     # Wrap the first element in the table with a <A NAME="role_rolename"> tag
1414 :     # so we can zing to it from elsewhere. We remove any non-alphanumeric
1415 :     # chars in the role name.
1416 :     #
1417 :    
1418 :     my $posT_html;
1419 :     {
1420 :     my $rn = $role;
1421 :     $rn =~ s/[ \/]/_/g;
1422 :     $rn =~ s/\W//g;
1423 :    
1424 :     $posT_html = "<a name=\"$rn\">$posT</a>";
1425 :     }
1426 :    
1427 : overbeek 1.97 my $row = [$posT_html,$abbrevT,$roleT];
1428 : overbeek 1.99 if ($can_alter)
1429 :     {
1430 :     push(@$row,$react);
1431 :     push(@$row,$reactT);
1432 :     }
1433 :     elsif ($reactions)
1434 : overbeek 1.97 {
1435 :     push(@$row,$react);
1436 :     }
1437 :     push(@$tab,$row);
1438 : overbeek 1.1
1439 :     if ($cgi->param('check_problems'))
1440 :     {
1441 :     my @roles = grep { $_->[0] ne $role } &gene_functions_in_col($fig,$role,$subsystem);
1442 :     my($x,$peg);
1443 :     foreach $x (@roles)
1444 :     {
1445 :     push(@$tab,["","",$x->[0]]);
1446 :     push(@$tab,["","",join(",",map { &HTML::fid_link($cgi,$_) } @{$x->[1]})]);
1447 :     }
1448 :     }
1449 :     }
1450 :    
1451 :     sub gene_functions_in_col {
1452 :     my($fig,$role,$subsystem) = @_;
1453 :     my(%roles,$peg,$func);
1454 : redwards 1.21
1455 :    
1456 :     # RAE this is dying if $subsystem->get_col($subsystem->get_role_index($role) + 1) is not defined
1457 :     # it is also not returning the right answer, so we need to fix it.
1458 :     # I am not sure why this is incremented by one here (see the note) because it is not right
1459 :     # and if you don't increment it by one it is right.
1460 :    
1461 :     # incr by 1 to get col indexed from 1 (not 0)
1462 :     #my @pegs = map { @$_ } @{$subsystem->get_col($subsystem->get_role_index($role) + 1)};
1463 :    
1464 :     return undef unless ($role); # this takes care of one error
1465 :     my $col_role=$subsystem->get_col($subsystem->get_role_index($role));
1466 :     return undef unless (defined $col_role);
1467 :     my @pegs = map { @$_ } @$col_role;
1468 : overbeek 1.1
1469 :     foreach $peg (@pegs)
1470 :     {
1471 :     if ($func = $fig->function_of($peg))
1472 :     {
1473 :     push(@{$roles{$func}},$peg);
1474 :     }
1475 :     }
1476 :     return map { [$_,$roles{$_}] } sort keys(%roles);
1477 :     }
1478 :    
1479 :     sub format_subsets {
1480 : overbeek 1.14 my($fig,$cgi,$html,$subsystem,$can_alter) = @_;
1481 : overbeek 1.1
1482 : overbeek 1.14 &format_subsetsC($fig,$cgi,$html,$subsystem,$can_alter);
1483 : overbeek 1.1 &format_subsetsR($fig,$cgi,$html,$subsystem);
1484 :     }
1485 :    
1486 :     sub format_subsetsC {
1487 : overbeek 1.14 my($fig,$cgi,$html,$subsystem,$can_alter) = @_;
1488 : overbeek 1.1
1489 :     my $col_hdrs = ["Subset","Includes These Roles"];
1490 :     my $tab = [];
1491 :    
1492 :     my $n = 1;
1493 : overbeek 1.14 &format_existing_subsetsC($cgi,$html,$subsystem,$tab,\$n,$can_alter);
1494 : overbeek 1.9
1495 : overbeek 1.14 if ($can_alter)
1496 : overbeek 1.1 {
1497 :     my $i;
1498 :     for ($i=0; ($i < 5); $i++)
1499 :     {
1500 :     &format_subsetC($cgi,$html,$subsystem,$tab,$n,"");
1501 :     $n++;
1502 :     }
1503 :     }
1504 : overbeek 1.9
1505 : overbeek 1.1 push(@$html,&HTML::make_table($col_hdrs,$tab,"Subsets of Roles"),
1506 :     $cgi->hr
1507 :     );
1508 :    
1509 :     my @subset_names = $subsystem->get_subset_namesC;
1510 :     if (@subset_names > 1)
1511 :     {
1512 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
1513 :     push(@$html,$cgi->scrolling_list(-name => 'active_subsetC',
1514 : overbeek 1.8 -values => [@subset_names],
1515 : overbeek 1.1 -default => $active_subsetC
1516 :     ),
1517 :     $cgi->br
1518 :     );
1519 :     }
1520 :     else
1521 :     {
1522 :     push(@$html,$cgi->hidden(-name => 'active_subsetC', -value => 'All', -override => 1));
1523 :     }
1524 :     }
1525 :    
1526 :     sub format_subsetsR {
1527 :     my($fig,$cgi,$html,$subsystem) = @_;
1528 :     my($i);
1529 :    
1530 :     my $link = &tree_link;
1531 :     push(@$html,$cgi->br,$link,$cgi->br);
1532 :    
1533 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
1534 :    
1535 :     my @tmp = grep { $_ ne "All" } sort $subsystem->get_subset_namesR;
1536 :     push(@$html,$cgi->scrolling_list(-name => 'active_subsetR',
1537 :     -values => ["All",@tmp],
1538 :     -default => $active_subsetR,
1539 :     -size => 5
1540 :     ),
1541 :     $cgi->br
1542 :     );
1543 :     }
1544 :    
1545 :     sub format_existing_subsetsC {
1546 : overbeek 1.14 my($cgi,$html,$subsystem,$tab,$nP,$can_alter) = @_;
1547 : overbeek 1.1 my($nameCS);
1548 :    
1549 :     foreach $nameCS (sort $subsystem->get_subset_namesC)
1550 :     {
1551 : overbeek 1.9 if ($nameCS !~ /all/i)
1552 :     {
1553 :     &format_subsetC($cgi,$html,$subsystem,$tab,$$nP,$nameCS);
1554 :     $$nP++;
1555 :     }
1556 : overbeek 1.1 }
1557 :     }
1558 :    
1559 :     sub format_subsetC {
1560 :     my($cgi,$html,$subsystem,$tab,$n,$nameCS) = @_;
1561 :    
1562 :     if ($nameCS ne "All")
1563 :     {
1564 : overbeek 1.4 my $subset = $nameCS ? join(",",map { $subsystem->get_role_index($_) + 1 } $subsystem->get_subsetC_roles($nameCS)) : "";
1565 : overbeek 1.9
1566 :     $nameCS = $subset ? $nameCS : "";
1567 :    
1568 : overbeek 1.1 my($posT,$subsetT);
1569 : overbeek 1.9
1570 : overbeek 1.14 $posT = $cgi->textfield(-name => "nameCS$n", -size => 30, -value => $nameCS, -override => 1);
1571 :     $subsetT = $cgi->textfield(-name => "subsetC$n", -size => 80, -value => $subset, -override => 1);
1572 :     push(@$tab,[$posT,$subsetT]);
1573 : overbeek 1.1 }
1574 :     }
1575 :    
1576 : olson 1.104
1577 :     #
1578 :     # Handle changes to diagrams.
1579 :     #
1580 :    
1581 :     sub handle_diagram_changes
1582 :     {
1583 :     my($fig, $subsystem, $cgi, $html) = @_;
1584 :     my $changed;
1585 :    
1586 :     return unless $cgi->param("diagram_action");
1587 :    
1588 :     my @actions = grep { /^diagram_/ } $cgi->param();
1589 :    
1590 :     for my $action (@actions)
1591 :     {
1592 :     my $value = $cgi->param($action);
1593 :     warn "Diagram action $action: $value\n";
1594 :     if ($action =~ /^diagram_delete_(\S+)/ and $value eq "on")
1595 :     {
1596 :     $subsystem->delete_diagram($1);
1597 :     $changed++;
1598 :     }
1599 :     elsif ($action =~ /^diagram_rename_(\S+)/ and $value ne "")
1600 :     {
1601 :     $subsystem->rename_diagram($1, $value);
1602 :     $changed++;
1603 :     }
1604 : olson 1.109 elsif ($action =~ /^diagram_new_image_(\S+)/ and $value ne '')
1605 :     {
1606 :     $subsystem->upload_new_image($1, $cgi->upload($action));
1607 :     $changed++;
1608 :     }
1609 :     elsif ($action =~ /^diagram_new_html_(\S+)/ and $value ne '')
1610 :     {
1611 :     $subsystem->upload_new_html($1, $cgi->upload($action));
1612 :     $changed++;
1613 :     }
1614 :    
1615 : olson 1.104 }
1616 :    
1617 :     my $fh = $cgi->upload("diagram_image_file");
1618 : olson 1.109 my $html_fh = $cgi->upload("diagram_html_file");
1619 : olson 1.104
1620 :     if ($fh)
1621 :     {
1622 : olson 1.109 $subsystem->create_new_diagram($fh, $html_fh, $cgi->param("diagram_new_name"));
1623 : olson 1.104 $changed++;
1624 :     }
1625 :    
1626 :     $subsystem->incr_version() if $changed;
1627 :     }
1628 :    
1629 :     #
1630 :     # Format the list of diagrams that a subsystem has.
1631 :     #
1632 :    
1633 :     sub format_diagrams
1634 :     {
1635 :     my($fig, $cgi, $html, $subsystem, $can_alter) = @_;
1636 :    
1637 :     my @diagrams = $subsystem->get_diagrams();
1638 :    
1639 :     if (@diagrams or $can_alter)
1640 :     {
1641 :     push(@$html, $cgi->hr, $cgi->h2("Subsystem Diagrams"));
1642 :     }
1643 :    
1644 :     if (@diagrams)
1645 :     {
1646 :     my @hdr = ("Diagram Name");
1647 :    
1648 :     if ($can_alter)
1649 :     {
1650 : olson 1.109 push(@hdr, "Delete", "Rename", "New image", "New html");
1651 : olson 1.104 }
1652 :    
1653 :     my @tbl;
1654 :     for my $dent (@diagrams)
1655 :     {
1656 :     my($id, $name, $link) = @$dent;
1657 :     my @row;
1658 :    
1659 : olson 1.109 my $js = "showDiagram('$link', '$id'); return false;";
1660 :    
1661 :     push(@row, qq(<a href="$link" onclick="$js" target="show_ss_diagram_$id">$name</a>));
1662 : olson 1.104
1663 :     if ($can_alter)
1664 :     {
1665 :     push(@row, $cgi->checkbox(-name => "diagram_delete_$id", -label => "",
1666 :     -value => undef,
1667 :     -override => 1));
1668 :     push(@row, $cgi->textfield(-name => "diagram_rename_$id",
1669 :     -value => "",
1670 :     -override => 1));
1671 : olson 1.109 push(@row, $cgi->filefield(-name => "diagram_new_image_$id",
1672 :     -value => "",
1673 :     -override => 1,
1674 :     -size => 30));
1675 :     push(@row, $cgi->filefield(-name => "diagram_new_html_$id",
1676 :     -value => "",
1677 :     -override => 1,
1678 :     -size => 30));
1679 : olson 1.104 }
1680 :    
1681 :     push(@tbl, \@row);
1682 :     }
1683 :     push(@$html, &HTML::make_table(\@hdr, \@tbl));
1684 :     }
1685 :    
1686 :     if ($can_alter)
1687 :     {
1688 :     my @tbl;
1689 :    
1690 : olson 1.109
1691 : olson 1.104 push(@tbl, ["Diagram name:", $cgi->textfield(-name => "diagram_new_name",
1692 :     -value => "",
1693 :     -override => 1,
1694 :     -size => 30)]);
1695 :     push(@tbl, ["Diagram image file:", $cgi->filefield(-name => "diagram_image_file",
1696 :     -size => 50)]);
1697 : olson 1.109 push(@tbl, ["Diagram html file:", $cgi->filefield(-name => "diagram_html_file",
1698 :     -size => 50)]);
1699 :    
1700 :     push(@$html, $cgi->h3("Upload a new diagram"));
1701 : olson 1.104 push(@$html, &HTML::make_table(undef, \@tbl));
1702 :    
1703 :     push(@$html, $cgi->submit(-name => 'diagram_action',
1704 :     -label => 'Process diagram actions'));
1705 :     }
1706 :     push(@$html, $cgi->hr);
1707 :     }
1708 :    
1709 : overbeek 1.1 sub tree_link {
1710 :     my $target = "window$$";
1711 :     my $url = &FIG::cgi_url . "/subsys.cgi?request=show_tree";
1712 :     return "<a href=$url target=$target>Show Phylogenetic Tree</a>";
1713 :     }
1714 :    
1715 : golsen 1.91
1716 :     # There is a lot of blood, sweat and tears that go into computing the active
1717 :     # set of rows. This is useful information to have later, when the user can
1718 :     # select genomes to be checked. We will return the genome list as a reference
1719 :     # to a list of [ genomme_number => name ] pairs. -- GJO
1720 :    
1721 : overbeek 1.1 sub format_rows {
1722 : redwards 1.32 my($fig,$cgi,$html,$subsystem, $tagvalcolor) = @_;
1723 : overbeek 1.1 my($i,%alternatives);
1724 : golsen 1.91 my $active_genome_list = [];
1725 : overbeek 1.1
1726 :     my $ignore_alt = $cgi->param('ignore_alt');
1727 :    
1728 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
1729 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
1730 :    
1731 : redwards 1.59 # RAE:
1732 :     # added this to allow determination of an active_subsetR based on a tag value pair
1733 :     if ($cgi->param('active_key'))
1734 :     {
1735 :     $active_subsetR = $cgi->param('active_key');
1736 :     my $active_value = undef;
1737 :     $active_value = $cgi->param('active_value') if ($cgi->param('active_value'));
1738 :     $subsystem->load_row_subsets_by_kv($active_subsetR, $active_value);
1739 :     $subsystem->set_active_subsetR($active_subsetR);
1740 :     }
1741 :    
1742 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
1743 : overbeek 1.1 my %activeC = map { $_ => 1 } @subsetC;
1744 :    
1745 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
1746 :     my %activeR = map { $_ => 1 } @subsetR;
1747 :    
1748 :     if (! $ignore_alt)
1749 :     {
1750 :     my $subset;
1751 :     foreach $subset (grep { $_ =~ /^\*/ } $subsystem->get_subset_namesC)
1752 :     {
1753 : overbeek 1.4 my @mem = grep { $activeC{$_} } $subsystem->get_subsetC_roles($subset);
1754 : overbeek 1.1 if (@mem > 1)
1755 :     {
1756 :     my $mem = [@mem];
1757 :     foreach $_ (@mem)
1758 :     {
1759 :     $alternatives{$_} = [$subset,$mem];
1760 :     }
1761 :     }
1762 :     }
1763 :     }
1764 :    
1765 :     my @in = $subsystem->get_genomes;
1766 : redwards 1.32
1767 : overbeek 1.1 if (@in > 0)
1768 :     {
1769 :     my $col_hdrs = ["Genome ID","Organism","Variant Code"];
1770 :    
1771 : redwards 1.84 if ($cgi->param('color_by_ga')) {push @{$col_hdrs}, "Attribute"}
1772 :    
1773 : overbeek 1.1 my @row_guide = ();
1774 :    
1775 : golsen 1.98 # Add pop-up tool tip with role name to abbreviations in column header
1776 : golsen 1.103 # (a wonderful suggestion from Carl Woese). -- GJO
1777 : golsen 1.98
1778 :     my( $role, %in_col, $abbrev, $mem, $abbrev_html );
1779 : overbeek 1.1 foreach $role (grep { $activeC{$_} } $subsystem->get_roles)
1780 :     {
1781 : golsen 1.98 if ( ! $in_col{ $role } ) # Make sure the role is not already done
1782 : overbeek 1.1 {
1783 : golsen 1.98 if ( $_ = $alternatives{ $role } )
1784 : overbeek 1.1 {
1785 : golsen 1.98 ( $abbrev, $mem ) = @$_;
1786 :     push( @row_guide, [ map { [ $_, "-" . ($subsystem->get_role_index($_) + 1) ] } @$mem ] );
1787 :     foreach $_ ( @$mem ) { $in_col{ $_ } = 1 }; # Mark the roles that are done
1788 :     my $rolelist = join '<br>', map { substr($_->[1],1) . ". $_->[0]" } @{$row_guide[-1]};
1789 : golsen 1.103 $abbrev_html = "<a " . FIGjs::mouseover("Roles of $abbrev", $rolelist, '') . ">$abbrev</a>";
1790 : golsen 1.98 push( @$col_hdrs, $abbrev_html );
1791 : overbeek 1.1 }
1792 :     else
1793 :     {
1794 : golsen 1.98 push( @row_guide, [ [ $role, "" ] ] ); # No suffix on peg number
1795 :     $abbrev = $subsystem->get_role_abbr( $subsystem->get_role_index( $role ) );
1796 : golsen 1.103 $abbrev_html = "<a " . FIGjs::mouseover("Role of $abbrev", $role, '') . ">$abbrev</a>";
1797 : golsen 1.98 push( @$col_hdrs, $abbrev_html );
1798 : overbeek 1.1 }
1799 :     }
1800 :     }
1801 :    
1802 :     my $tab = [];
1803 :     my($genome,@pegs,@cells,$set,$peg_set,$pair,$role,$suffix,$row,$peg,$color_of,$cell,%count,$color,@colors);
1804 : golsen 1.85
1805 :     #
1806 :     # Simplified code for checking variants -- GJO
1807 :     # If specific variants are requested, make a hash of those to keep:
1808 :     #
1809 :     my $variant_list = undef;
1810 :     if ( $cgi->param( 'include_these_variants' ) )
1811 :     {
1812 :     $variant_list = { map { ($_, 1) } split( /\s*,\s*/, $cgi->param( 'include_these_variants' ) ) };
1813 :     }
1814 :    
1815 : overbeek 1.1 foreach $genome (grep { $activeR{$_} } @in)
1816 :     {
1817 : overbeek 1.7 my($genomeV,$vcodeV,$vcode_value);
1818 : golsen 1.85
1819 :     # Get (and if necessary check) the variant code:
1820 :    
1821 :     $vcode_value = $subsystem->get_variant_code( $subsystem->get_genome_index( $genome ) );
1822 :     next if ( $variant_list && ( ! $variant_list->{ $vcode_value } ) );
1823 :    
1824 : golsen 1.91 $row = [ $genome, &ext_genus_species($fig,$genome), $vcode_value ];
1825 :     push @$active_genome_list, [ $row->[0], $row->[1] ]; # Save a list of the active genomes
1826 : overbeek 1.1
1827 :     @pegs = ();
1828 :     @cells = ();
1829 : mkubal 1.47
1830 : overbeek 1.1 foreach $set (@row_guide)
1831 :     {
1832 :     $peg_set = [];
1833 :     foreach $pair (@$set)
1834 :     {
1835 :     ($role,$suffix) = @$pair;
1836 : overbeek 1.2 foreach $peg ($subsystem->get_pegs_from_cell($genome,$role))
1837 : overbeek 1.1 {
1838 :     push(@$peg_set,[$peg,$suffix]);
1839 :     }
1840 :     }
1841 :     push(@pegs,map { $_->[0] } @$peg_set);
1842 :     push(@cells,$peg_set);
1843 :     }
1844 :     $color_of = &group_by_clusters($fig,\@pegs);
1845 : redwards 1.32 # RAE added a new call to get tag/value pairs
1846 :     # Note that $color_of is not overwritten.
1847 :     my $superscript;
1848 : redwards 1.52 if ($cgi->param('color_by_ga'))
1849 :     {
1850 :     # add colors based on the genome attributes
1851 :     # get the value
1852 :     my $ga=$cgi->param('color_by_ga');
1853 :     my $valuetype=$fig->guess_value_format($ga);
1854 : redwards 1.66 my @array=$fig->get_attributes($genome, $ga);
1855 : redwards 1.84 unless ($array[0]) {$array[0]=[]}
1856 : redwards 1.66 # for the purposes of this page, we are going to color on the
1857 :     # value of the last attribute
1858 : redwards 1.67 my ($gotpeg, $gottag, $value, $url)=@{$array[0]};
1859 : redwards 1.52 if (defined $value) # we don't want to color undefined values
1860 :     {
1861 :     my @color=&cool_colors();
1862 :     my $colval; # what we are basing the color on.
1863 : overbeek 1.106 if ($valuetype->[0] eq "float")
1864 :     {
1865 : redwards 1.58 # Initially spllit numbers into groups of 10.
1866 : redwards 1.52 # $valuetype->[2] is the maximum number for this value
1867 : redwards 1.58 # but I don't like this
1868 :     # $colval = int($value/$valuetype->[2]*10);
1869 :    
1870 :     # we want something like 0-1, 1-2, 2-3, 3-4 as the labels.
1871 :     # so we will do it in groups of ten
1872 :     my ($type, $min, $max)=@$valuetype;
1873 :     for (my $i=$min; $i<$max; $i+=$max/10) {
1874 :     if ($value >= $i && $value < $i+$max/10) {$colval = $i . "-" . ($i+($max/10))}
1875 :     }
1876 : redwards 1.52 }
1877 : overbeek 1.106 else {$colval=$value}
1878 : redwards 1.58
1879 : redwards 1.52 if (!$tagvalcolor->{$colval}) {
1880 :     # figure out the highest number used in the array
1881 :     $tagvalcolor->{$colval}=0;
1882 :     foreach my $t (keys %$tagvalcolor) {
1883 :     ($tagvalcolor->{$t} > $tagvalcolor->{$colval}) ? $tagvalcolor->{$colval}=$tagvalcolor->{$t} : 1;
1884 :     }
1885 :     $tagvalcolor->{$colval}++;
1886 :     }
1887 : redwards 1.84 # RAE Add a column for the description
1888 :     splice @$row, 3, 0, $colval;
1889 : redwards 1.52
1890 :     foreach my $cell (@cells) {
1891 :     foreach $_ (@$cell)
1892 :     {
1893 :     $color_of->{$_->[0]} = $color[$tagvalcolor->{$colval}]
1894 :     }
1895 :     }
1896 :     }
1897 : redwards 1.84 else
1898 :     {
1899 :     # RAE Add a column for the description
1900 :     splice @$row, 3, 0, " &nbsp; ";
1901 :     }
1902 : redwards 1.52 }
1903 : redwards 1.54 if ($cgi->param("color_by_peg_tag"))
1904 : redwards 1.32 {
1905 : redwards 1.54 ($color_of, $superscript, $tagvalcolor) = color_by_tag($fig, \@pegs, $color_of, $tagvalcolor, $cgi->param("color_by_peg_tag"));
1906 : redwards 1.32 }
1907 : golsen 1.85 foreach $cell ( @cells ) # $cell = [peg, suffix]
1908 : overbeek 1.1 {
1909 : golsen 1.85 # Deal with the trivial case (no pegs) at the start
1910 :    
1911 :     if ( ! @$cell )
1912 : overbeek 1.1 {
1913 : golsen 1.85 # Push an empty cell onto the row
1914 :    
1915 :     push @$row, '@bgcolor="#FFFFFF": &nbsp; ';
1916 :     next;
1917 :     }
1918 :    
1919 :     # Figure out html text for each peg and cluster by color.
1920 :    
1921 :     my ( $peg, $suffix, $txt, $color );
1922 :     my @colors = ();
1923 :     my %text_by_color; # Gather like-colored peg text
1924 :     foreach ( @$cell )
1925 :     {
1926 :     ( $peg, $suffix ) = @$_;
1927 :     # Hyperlink each peg, and add its suffix:
1928 :     $txt = ( $cgi->param('ext_ids') ? external_id($fig,$cgi,$peg)
1929 :     : HTML::fid_link($cgi,$peg, "local") )
1930 :     . ( $suffix ? $suffix : '' );
1931 :     $color = $color_of->{ $peg };
1932 :     defined( $text_by_color{ $color } ) or push @colors, $color;
1933 :     push @{ $text_by_color{ $color } }, $txt;
1934 :     }
1935 :     my $ncolors = @colors;
1936 :    
1937 :     # Join text strings within a color (and remove last comma):
1938 :    
1939 :     my @str_by_color = map { [ $_, join( ', ', @{ $text_by_color{$_} }, '' ) ] } @colors;
1940 :     $str_by_color[-1]->[1] =~ s/, $//;
1941 :    
1942 :     # Build the "superscript" string:
1943 :    
1944 :     my $sscript = "";
1945 : golsen 1.86 if ( $superscript && @$cell )
1946 : golsen 1.85 {
1947 : golsen 1.86 my ( %sscript, $ss );
1948 : golsen 1.85 foreach my $cv ( @$cell ) # Should this be flattened across all pegs?
1949 : overbeek 1.1 {
1950 : golsen 1.85 next unless ( $ss = $superscript->{ $cv->[0] } );
1951 : golsen 1.86 # my %flatten = map { ( $_, 1 ) } @$ss;
1952 :     # $sscript{ join ",", sort { $a <=> $b } keys %flatten } = 1; # string of all values for peg
1953 :     foreach ( @$ss ) { $sscript{ $_ } = 1 }
1954 :     }
1955 :     if (scalar keys %sscript) # order by number, and format
1956 :     {
1957 :     my @ss = map { $_->[0] }
1958 :     sort { $a->[1] <=> $b->[1] }
1959 :     map { my ( $num ) = $_ =~ /\>(\d+)\</; [ $_, $num || 0 ] } keys %sscript;
1960 :     $sscript = "&nbsp;<sup>[" . join( ", ", @ss ) . "]</sup>"
1961 : overbeek 1.1 }
1962 : golsen 1.85 }
1963 :    
1964 :     my $cell_data;
1965 :    
1966 :     # If there is one color, just write a unicolor cell.
1967 :    
1968 :     if ( $ncolors == 1 )
1969 :     {
1970 :     my ( $color, $txt ) = @{ shift @str_by_color };
1971 :     $cell_data = qq(\@bgcolor="$color":) . $txt . $sscript;
1972 : overbeek 1.1 }
1973 : golsen 1.85
1974 :     # Otherwise, write pegs into a subtable with one cell per color.
1975 :    
1976 :     else
1977 : redwards 1.32 {
1978 : golsen 1.85 $cell_data = '<table><tr valign=bottom>'
1979 :     . join( '', map { ( $color, $txt ) = @$_ ; qq(<td bgcolor="$color">$txt</td>) } @str_by_color )
1980 : redwards 1.87 . ( $sscript ? "<td>$sscript</td>" : '' )
1981 : golsen 1.85 . '</tr></table>';
1982 : redwards 1.32 }
1983 : golsen 1.85
1984 :     # Push the cell data onto the row:
1985 :    
1986 : redwards 1.32 push(@$row, $cell_data);
1987 : overbeek 1.1 }
1988 :     push(@$tab,$row);
1989 :     }
1990 :    
1991 :    
1992 :     my($sort);
1993 :     if ($sort = $cgi->param('sort'))
1994 :     {
1995 : overbeek 1.55 if ($sort eq "by_pattern")
1996 : overbeek 1.1 {
1997 : overbeek 1.8 my @tmp = ();
1998 :     my $row;
1999 :     foreach $row (@$tab)
2000 :     {
2001 :     my @var = ();
2002 :     my $i;
2003 :     for ($i=3; ($i < @$row); $i++)
2004 :     {
2005 : overbeek 1.39 push(@var, ($row->[$i] =~ /\|/) ? 1 : 0);
2006 : overbeek 1.8 }
2007 :     push(@tmp,[join("",@var),$row]);
2008 :     }
2009 :     $tab = [map { $_->[1] } sort { $a->[0] cmp $b->[0] } @tmp];
2010 : overbeek 1.1 }
2011 :     elsif ($sort eq "by_phylo")
2012 :     {
2013 :     $tab = [map { $_->[0] }
2014 :     sort { ($a->[1] cmp $b->[1]) or ($a->[0]->[1] cmp $b->[0]->[1]) }
2015 :     map { [$_, $fig->taxonomy_of($_->[0])] }
2016 :     @$tab];
2017 :     }
2018 :     elsif ($sort eq "by_tax_id")
2019 :     {
2020 :     $tab = [sort { $a->[0] <=> $b->[0] } @$tab];
2021 :     }
2022 :     elsif ($sort eq "alphabetic")
2023 :     {
2024 :     $tab = [sort { ($a->[1] cmp $b->[1]) or ($a->[0] <=> $b->[0]) } @$tab];
2025 :     }
2026 : overbeek 1.56 elsif ($sort eq "by_variant")
2027 :     {
2028 :     $tab = [sort { ($a->[2] cmp $b->[2]) or ($a->[1] <=> $b->[1]) } @$tab];
2029 :     }
2030 : overbeek 1.1 }
2031 :    
2032 : mkubal 1.47 foreach $row (@$tab)
2033 : overbeek 1.8 {
2034 : redwards 1.90 next if ($row->[2] == -1 && !$cgi->param('show_minus1')); # RAE don't show -1 variants if checked
2035 : overbeek 1.8 my($genomeV,$vcodeV,$vcode_value);
2036 :     $genome = $row->[0];
2037 :     $vcode_value = $row->[2];
2038 :     if ($cgi->param('can_alter'))
2039 :     {
2040 :     $genomeV = $cgi->textfield(-name => "genome$genome", -size => 15, -value => $genome, -override => 1);
2041 : overbeek 1.19 $vcodeV = $cgi->textfield(-name => "vcode$genome", -value => $vcode_value, -size => 10);
2042 : overbeek 1.8 }
2043 :     else
2044 :     {
2045 :     push(@$html,$cgi->hidden(-name => "genome$genome", -value => $genome, -override => 1),
2046 :     $cgi->hidden(-name => "vcode$genome", -value => $vcode_value));
2047 :     $genomeV = $genome;
2048 :     $vcodeV = $vcode_value;
2049 :     }
2050 : olson 1.109
2051 : overbeek 1.8 $row->[0] = $genomeV;
2052 :     $row->[2] = $vcodeV;
2053 : olson 1.109
2054 :     #
2055 :     # JS link for coloring diagrams.
2056 :     #
2057 :    
2058 : olson 1.110 if (1 or $cgi->param("bob_js"))
2059 : olson 1.109 {
2060 :     my $colorJS = qq(<a href="" onclick="colorGenome('$genome'); return false;">Color</a>);
2061 :     $row->[0] .= " " . $colorJS;
2062 :     }
2063 : overbeek 1.8 }
2064 :    
2065 : overbeek 1.6 my $tab1 = [];
2066 : redwards 1.84
2067 : overbeek 1.6 foreach $row (@$tab)
2068 :     {
2069 : redwards 1.90 next if ($row->[2] == -1 && !$cgi->param('show_minus1')); # RAE don't show -1 variants if checked
2070 : overbeek 1.6 if ((@$tab1 > 0) && ((@$tab1 % 10) == 0))
2071 :     {
2072 :     push(@$tab1,[map { "<b>$_</b>" } @$col_hdrs]) ;
2073 :     }
2074 :     push(@$tab1,$row);
2075 :     }
2076 :    
2077 :     push(@$html,&HTML::make_table($col_hdrs,$tab1,"Basic Spreadsheet"),
2078 : overbeek 1.1 $cgi->hr
2079 :     );
2080 :    
2081 :     push(@$html,$cgi->scrolling_list(-name => 'sort',
2082 : overbeek 1.56 -value => ['unsorted','alphabetic','by_pattern',
2083 :     'by_phylo','by_tax_id','by_variant'],
2084 : overbeek 1.1 -default => 'unsorted'
2085 :     ));
2086 : mkubal 1.47
2087 :     push(@$html,'<br><br>Enter comma-separated list of variants to display in spreadsheet<br>',
2088 :     $cgi->textfield(-name => "include_these_variants", -size => 50)
2089 :     );
2090 :     }
2091 : redwards 1.52
2092 :     # add an explanation for the colors if we want one.
2093 :     if ($cgi->param('color_by_ga'))
2094 :     {
2095 : redwards 1.59 push(@$html, &HTML::make_table(undef,&describe_colors($tagvalcolor),"Color Descriptions<br><small>Link limits display to those organisms</small>"));
2096 : redwards 1.52 }
2097 : golsen 1.91
2098 :     return $active_genome_list; # [ [ id1, gs1 ], [ id2, gs2 ], ... ]
2099 : overbeek 1.1 }
2100 :    
2101 : golsen 1.91
2102 : overbeek 1.1 sub group_by_clusters {
2103 :     my($fig,$pegs) = @_;
2104 :     my($peg,@clusters,@cluster,@colors,$color,%seen,%conn,$x,$peg1,@pegs,$i);
2105 :    
2106 :     my $color_of = {};
2107 :     foreach $peg (@$pegs) { $color_of->{$peg} = '#FFFFFF' }
2108 :    
2109 :     if ($cgi->param('show_clusters'))
2110 :     {
2111 : golsen 1.85 @pegs = keys(%$color_of); # Use of keys makes @pegs entries unique
2112 : overbeek 1.1
2113 :     foreach $peg (@pegs)
2114 :     {
2115 :     foreach $peg1 (grep { $color_of->{$_} && ($_ ne $peg) } $fig->close_genes($peg,5000))
2116 :     {
2117 :     push(@{$conn{$peg}},$peg1);
2118 :     }
2119 :     }
2120 :    
2121 :     @clusters = ();
2122 :     while ($peg = shift @pegs)
2123 :     {
2124 :     if (! $seen{$peg})
2125 :     {
2126 :     @cluster = ($peg);
2127 :     $seen{$peg} = 1;
2128 :     for ($i=0; ($i < @cluster); $i++)
2129 :     {
2130 :     $x = $conn{$cluster[$i]};
2131 :     foreach $peg1 (@$x)
2132 :     {
2133 :     if (! $seen{$peg1})
2134 :     {
2135 :     push(@cluster,$peg1);
2136 :     $seen{$peg1} = 1;
2137 :     }
2138 :     }
2139 :     }
2140 :     push(@clusters,[@cluster]);
2141 :     }
2142 :     }
2143 :    
2144 : redwards 1.52 @colors = &cool_colors();
2145 : overbeek 1.1
2146 :     @clusters = grep { @$_ > 1 } sort { @$a <=> @$b } @clusters;
2147 :    
2148 :     if (@clusters > @colors) { splice(@clusters,0,(@clusters - @colors)) } # make sure we have enough colors
2149 :    
2150 :     my($cluster);
2151 :     foreach $cluster (@clusters)
2152 :     {
2153 :     $color = shift @colors;
2154 :     foreach $peg (@$cluster)
2155 :     {
2156 :     $color_of->{$peg} = $color;
2157 :     }
2158 :     }
2159 :     }
2160 :     return $color_of;
2161 :     }
2162 :    
2163 : redwards 1.32
2164 :     =head1 color_by_tag
2165 :    
2166 :     Change the color of cells by the pir superfamily. This is taken from the key/value pair
2167 :     Note that we will not change the color if $cgi->param('show_clusters') is set.
2168 :    
2169 :     This is gneric and takes the following arguments:
2170 :     fig,
2171 :     pointer to list of pegs,
2172 :     pointer to hash of colors by peg,
2173 :     pointer to a hash that retains numbers across rows. The number is based on the value.
2174 :     tag to use in encoding
2175 :    
2176 :     eg. ($color_of, $superscript, $tagvalcolor) = color_by_tag($fig, $pegs, $color_of, $tagvalcolor, "PIRSF");
2177 :    
2178 :     =cut
2179 :    
2180 :     sub color_by_tag {
2181 : redwards 1.35 # RAE added this so we can color individual cells across a column
2182 : redwards 1.32 my ($fig, $pegs, $color_of, $tagvalcolor, $want)=@_;
2183 :     # figure out the colors and the superscripts for the pirsf
2184 :     # superscript will be a number
2185 :     # color will be related to the number somehow
2186 :     # url will be the url for each number
2187 :     my $number; my $url;
2188 : redwards 1.33 my $count=0;
2189 : redwards 1.32 #count has to be the highest number if we increment it
2190 : redwards 1.33 foreach my $t (keys %$tagvalcolor) {($tagvalcolor->{$t} > $count) ? $count=$tagvalcolor->{$t} : 1}
2191 :     $count++; # this should now be the next number to assign
2192 : redwards 1.32 foreach my $peg (@$pegs) {
2193 : redwards 1.54 next unless (my @attr=$fig->get_attributes($peg));
2194 : redwards 1.32 foreach my $attr (@attr) {
2195 : redwards 1.54 next unless (defined $attr);
2196 : redwards 1.67 my ($gotpeg, $tag, $val, $link)=@$attr;
2197 : redwards 1.32 next unless ($tag eq $want);
2198 :     if ($tagvalcolor->{$val}) {
2199 :     $number->{$peg}=$tagvalcolor->{$val};
2200 : redwards 1.66 push (@{$url->{$peg}}, "<a href='$link'>" . $number->{$peg} . "</a>");
2201 : redwards 1.32 }
2202 :     else {
2203 :     $number->{$peg}=$tagvalcolor->{$val}=$count++;
2204 : redwards 1.66 push (@{$url->{$peg}}, "<a href='$link'>" . $number->{$peg} . "</a>");
2205 : redwards 1.32 }
2206 :     #### This is a botch at the moment. I want PIRSF to go to my page that I am working on, not PIR
2207 :     #### so I am just correcting those. This is not good, and I should change the urls in the tag/value pairs or something
2208 :     if ($want eq "PIRSF") {
2209 : redwards 1.66 pop @{$url->{$peg}};
2210 : redwards 1.32 $val =~ /(^PIRSF\d+)/;
2211 : redwards 1.66 push (@{$url->{$peg}}, $cgi->a({href => "pir.cgi?&user=$user&pirsf=$1"}, $number->{$peg}));
2212 : redwards 1.32 }
2213 :     }
2214 :     }
2215 :    
2216 :    
2217 :     # if we want to assign some colors, lets do so now
2218 : redwards 1.52 my @colors = &cool_colors();
2219 : redwards 1.32 unless ($cgi->param('show_clusters')) {
2220 :     foreach my $peg (@$pegs) { $color_of->{$peg} = '#FFFFFF' }
2221 :     foreach my $peg (keys %$number) {
2222 :     # the color is going to be the location in @colors
2223 :     unless ($number->{$peg} > @colors) {$color_of->{$peg}=$colors[$number->{$peg}-1]}
2224 :     }
2225 :     }
2226 :     return ($color_of, $url, $tagvalcolor);
2227 :     }
2228 :    
2229 :    
2230 : overbeek 1.1 sub format_ssa_table {
2231 :     my($cgi,$html,$user,$ssaP) = @_;
2232 :     my($ssa,$curator);
2233 :     my($url1,$link1);
2234 :    
2235 :     my $can_alter = $cgi->param('can_alter');
2236 :     push(@$html, $cgi->start_form(-action => "subsys.cgi",
2237 :     -method => 'post'),
2238 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
2239 :     $cgi->hidden(-name => 'can_alter', -value => $can_alter, -override => 1),
2240 :     $cgi->hidden(-name => 'request', -value => 'delete_or_export_ssa', -override => 1)
2241 :     );
2242 :     push(@$html,"<font size=\"+2\">Please do not ever edit someone else\'s spreadsheet (by using their
2243 :     user ID), and <b>never open multiple windows to
2244 :     process the same spreadsheet</b></font>. It is, of course, standard practice to open a subsystem
2245 :     spreadsheet and then to have multiple other SEED windows to access data and modify annotations. Further,
2246 :     you can access someone else's subsystem spreadsheet using your ID (which will make it impossible
2247 :     for you to edit the spreadsheet).
2248 : redwards 1.46 Just do not open the same subsystem spreadsheet for editing in multiple windows simultaneously.
2249 : redwards 1.62 A gray color means that the subsystem has no genomes attached to it. Go ahead and make these your own\n",
2250 : overbeek 1.107 "<a href=\"Html/conflict_resolution.html\" class=\"help\" target=\"help\">Help on conflict resolution</a>\n",
2251 : overbeek 1.1 $cgi->br,
2252 :     $cgi->br
2253 :     );
2254 :    
2255 : redwards 1.65 # RAE: removed this from above push because VV want's it kept secret
2256 :     # "<a href=\"/FIG/Html/seedtips.html#change_ownership\" class=\"help\" target=\"help\">Help on changing subsystem ownership</a>\n",
2257 :    
2258 : redwards 1.81 # RAE: Added a new cgi param colsort for sort by column. This url will just recall the script with username to allow column sorting.
2259 : redwards 1.88 # RAE: Added a column to allow indexing of one subsystem. This is also going to be used in the renaming of a subsystem, too
2260 : redwards 1.81
2261 : overbeek 1.1 my $col_hdrs = [
2262 : redwards 1.81 "<a href='" . &FIG::cgi_url . "/subsys.cgi?user=$user'>Name</a><br><small>Sort by Subsystem</small>",
2263 :     "<a href='" . &FIG::cgi_url . "/subsys.cgi?user=$user&colsort=curator'>Curator</a><br><small>Sort by curator</small>",
2264 :     "Exchangable","Version",
2265 : overbeek 1.1 "Reset to Previous Timestamp","Delete",
2266 : redwards 1.88 "Export Full Subsystem","Export Just Assignments", "Publish to Clearinghouse", "Reindex Subsystem",
2267 : overbeek 1.1 ];
2268 :     my $title = "Existing Subsystem Annotations";
2269 :     my $tab = [];
2270 :     foreach $_ (@$ssaP)
2271 :     {
2272 : redwards 1.88 my($publish_checkbox, $index_checkbox);
2273 : overbeek 1.1 ($ssa,$curator) = @$_;
2274 :    
2275 : olson 1.74 my $esc_ssa = uri_escape($ssa);
2276 :    
2277 : overbeek 1.1 my($url,$link);
2278 :     if ((-d "$FIG_Config::data/Subsystems/$ssa/Backup") && ($curator eq $cgi->param('user')))
2279 :     {
2280 : olson 1.74 $url = &FIG::cgi_url . "/subsys.cgi?user=$user&ssa_name=$esc_ssa&request=reset";
2281 : overbeek 1.1 $link = "<a href=$url>reset</a>";
2282 :     }
2283 :     else
2284 :     {
2285 :     $link = "";
2286 :     }
2287 :    
2288 :     if (($fig->is_exchangable_subsystem($ssa)) && ($curator eq $cgi->param('user')))
2289 :     {
2290 : olson 1.74 $url1 = &FIG::cgi_url . "/subsys.cgi?user=$user&ssa_name=$esc_ssa&request=make_unexchangable";
2291 : overbeek 1.1 $link1 = "Exchangable<br><a href=$url1>Make not exchangable</a>";
2292 :     }
2293 :     elsif ($curator eq $cgi->param('user'))
2294 :     {
2295 : olson 1.74 $url1 = &FIG::cgi_url . "/subsys.cgi?user=$user&ssa_name=$esc_ssa&request=make_exchangable";
2296 : overbeek 1.1 $link1 = "Not exchangable<br><a href=$url1>Make exchangable</a>";
2297 :     }
2298 :     else
2299 :     {
2300 :     $link1 = "";
2301 :     }
2302 :    
2303 :     #
2304 :     # Only allow publish for subsystems we are curating?
2305 :     #
2306 :     if ($curator eq $cgi->param('user'))
2307 :     {
2308 :     $publish_checkbox = $cgi->checkbox(-name => "publish_to_clearinghouse",
2309 :     -value => $ssa,
2310 : redwards 1.88 -label => "Publish");
2311 : overbeek 1.1
2312 :     }
2313 : redwards 1.46
2314 : redwards 1.88 #
2315 :     # Initially I am going to allow indexing of any subsystem since you may want to index it to allow
2316 :     # better searhing on a local system
2317 :     $index_checkbox=$cgi->checkbox(-name => "index_subsystem", -value=> $ssa, -label => "Index");
2318 :    
2319 : redwards 1.46 # RAE color the background if the subsystem is empty
2320 :     # this uses a modification to HTML.pm that I made earlier to accept refs to arrays as cell data
2321 : overbeek 1.51 my $cell1=&ssa_link($fig,$ssa,$user);
2322 : redwards 1.46 #unless (scalar $fig->subsystem_to_roles($ssa)) {$cell1 = [$cell1, 'td bgcolor="Dark grey"']} ## THIS IS DOG SLOW, BUT WORKS
2323 :     #unless (scalar $fig->get_subsystem($ssa)->get_genomes()) {$cell1 = [$cell1, 'td bgcolor="#A9A9A9"']} ## WORKS PERFECTLY, but sort of slow
2324 :     unless (scalar @{$fig->subsystem_genomes($ssa, 1)}) {$cell1 = [$cell1, 'td bgcolor="silver"']}
2325 :    
2326 : overbeek 1.1 push(@$tab,[
2327 : redwards 1.46 $cell1,
2328 : overbeek 1.1 $curator,
2329 :     $link1,
2330 :     $fig->subsystem_version($ssa),
2331 :     $link,
2332 :     ($curator eq $cgi->param('user')) ? $cgi->checkbox(-name => "delete", -value => $ssa) : "",
2333 :     $cgi->checkbox(-name => "export", -value => $ssa, -label => "Export full"),
2334 :     $cgi->checkbox(-name => "export_assignments", -value => $ssa, -label => "Export assignments"),
2335 : redwards 1.88 $publish_checkbox, $index_checkbox,
2336 : overbeek 1.1 ]);
2337 :     }
2338 :     push(@$html,
2339 :     &HTML::make_table($col_hdrs,$tab,$title),
2340 :     $cgi->submit(-name => 'delete_export',
2341 :     -label => 'Process marked deletions and exports'),
2342 :     $cgi->submit(-name => 'publish',
2343 :     -label => "Publish marked subsystems"),
2344 : redwards 1.88 $cgi->submit(-name => 'reindex',
2345 :     -label => "Reindex selected subsystems"),
2346 : overbeek 1.1 $cgi->end_form
2347 :     );
2348 :     }
2349 :    
2350 : redwards 1.25 # RAE: I think this should be placed as a method in
2351 :     # Subsystems.pm and called subsystems I know about or something.
2352 :     # Cowardly didn't do though :-)
2353 : overbeek 1.1 sub existing_subsystem_annotations {
2354 : overbeek 1.51 my($fig) = @_;
2355 : overbeek 1.1 my($ssa,$name);
2356 :     my @ssa = ();
2357 :     if (opendir(SSA,"$FIG_Config::data/Subsystems"))
2358 :     {
2359 : overbeek 1.51 @ssa = map { $ssa = $_; $name = $ssa; $ssa =~ s/[ \/]/_/g; [$name,$fig->subsystem_curator($ssa)] } grep { $_ !~ /^\./ } readdir(SSA);
2360 : overbeek 1.1 closedir(SSA);
2361 :     }
2362 : redwards 1.81 # RAE Adding sort of current subsystems
2363 :     if ($cgi->param('colsort') && $cgi->param('colsort') eq "curator")
2364 :     {
2365 :     # sort by the ss curator
2366 :     return sort { (lc $a->[1]) cmp (lc $b->[1]) || (lc $a->[0]) cmp (lc $b->[0]) } @ssa;
2367 :     }
2368 :     else
2369 :     {
2370 :     return sort { (lc $a->[0]) cmp (lc $b->[0]) } @ssa;
2371 :     }
2372 : overbeek 1.1 }
2373 :    
2374 :     sub ssa_link {
2375 : overbeek 1.51 my($fig,$ssa,$user) = @_;
2376 : overbeek 1.1 my $name = $ssa; $name =~ s/_/ /g;
2377 :     my $target = "window$$";
2378 : overbeek 1.9 if ($name =~ /([a-zA-Z]{3})/)
2379 :     {
2380 :     $target .= ".$1";
2381 :     }
2382 :    
2383 : overbeek 1.80 my $check;
2384 :     my $can_alter = $check = $fig->subsystem_curator($ssa) eq $user;
2385 : redwards 1.108 my $sort=$cgi->param('sort');
2386 :     my $show_clusters=$cgi->param('show_clusters');
2387 :    
2388 : olson 1.74 my $esc_ssa = uri_escape($ssa);
2389 : redwards 1.108 my $url = &FIG::cgi_url . "/subsys.cgi?user=$user&ssa_name=$esc_ssa&request=show_ssa&can_alter=$can_alter&check=$check&sort=$sort&show_clusters=$show_clusters";
2390 : overbeek 1.1 return "<a href=$url target=$target>$name</a>";
2391 :     }
2392 :    
2393 :     sub log_update {
2394 :     my($ssa,$user) = @_;
2395 :    
2396 :     $ssa =~ s/[ \/]/_/g;
2397 :    
2398 :     if (open(LOG,">>$FIG_Config::data/Subsystems/$ssa/curation.log"))
2399 :     {
2400 :     my $time = time;
2401 :     print LOG "$time\t$user\tupdated\n";
2402 :     close(LOG);
2403 :     }
2404 :     else
2405 :     {
2406 :     print STDERR "failed to open $FIG_Config::data/Subsystems/$ssa/curation.log\n";
2407 :     }
2408 :     }
2409 :    
2410 :     sub export {
2411 :     my($fig,$cgi,$ssa) = @_;
2412 :     my($line);
2413 :    
2414 :     my ($exportable,$notes) = $fig->exportable_subsystem($ssa);
2415 :     foreach $line (@$exportable,@$notes)
2416 :     {
2417 :     print $line;
2418 :     }
2419 :     }
2420 :    
2421 :     sub export_assignments {
2422 :     my($fig,$cgi,$ssa) = @_;
2423 :     my(@roles,$i,$entry,$id,$user);
2424 :    
2425 :     if (($user = $cgi->param('user')) && open(SSA,"<$FIG_Config::data/Subsystems/$ssa/spreadsheet"))
2426 :     {
2427 :     $user =~ s/^master://;
2428 :     &FIG::verify_dir("$FIG_Config::data/Assignments/$user");
2429 : overbeek 1.51 my $who = $fig->subsystem_curator($ssa);
2430 : overbeek 1.1 my $file = &FIG::epoch_to_readable(time) . ":$who:generated_from_subsystem_$ssa";
2431 :    
2432 :     if (open(OUT,">$FIG_Config::data/Assignments/$user/$file"))
2433 :     {
2434 :     while (defined($_ = <SSA>) && ($_ !~ /^\/\//))
2435 :     {
2436 :     chop;
2437 :     push(@roles,$_);
2438 :     }
2439 :     while (defined($_ = <SSA>) && ($_ !~ /^\/\//)) {}
2440 :     while (defined($_ = <SSA>))
2441 :     {
2442 :     chop;
2443 :     my @flds = split(/\t/,$_);
2444 :     my $genome = $flds[0];
2445 :     for ($i=2; ($i < @flds); $i++)
2446 :     {
2447 :     my @entries = split(/,/,$flds[$i]);
2448 :     foreach $id (@entries)
2449 :     {
2450 :     my $peg = "fig|$genome.peg.$id";
2451 :     my $func = $fig->function_of($peg);
2452 :     print OUT "$peg\t$func\n";
2453 :     }
2454 :     }
2455 :     }
2456 :     close(OUT);
2457 :     }
2458 :     close(SSA);
2459 :     }
2460 :     }
2461 :    
2462 :     sub format_missing {
2463 :     my($fig,$cgi,$html,$subsystem) = @_;
2464 :     my($org,$abr,$role,$missing);
2465 :    
2466 :     $user = $cgi->param('user');
2467 :    
2468 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2469 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2470 :    
2471 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2472 : overbeek 1.1 my %activeC = map { $_ => 1 } @subsetC;
2473 :    
2474 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2475 :    
2476 :     my @alt_sets = grep { ($_ =~ /^\*/) } $subsystem->get_subset_namesC;
2477 :     my($set,$col,%in);
2478 :     foreach $set (@alt_sets)
2479 :     {
2480 : overbeek 1.4 my @mem = grep { $activeC{$_} } $subsystem->get_subsetC_roles($set);
2481 : overbeek 1.1 foreach $col (@mem)
2482 :     {
2483 :     $in{$col} = $set;
2484 :     }
2485 :     }
2486 :     push(@$html,$cgi->h1('To Check Missing Entries:'));
2487 :    
2488 :     foreach $org (@subsetR)
2489 :     {
2490 :     my @missing = &columns_missing_entries($cgi,$subsystem,$org,\@subsetC,\%in);
2491 :    
2492 :     $missing = [];
2493 :     foreach $role (@missing)
2494 :     {
2495 :     $abr = $subsystem->get_role_abbr($subsystem->get_role_index($role));
2496 :     my $roleE = $cgi->escape($role);
2497 :    
2498 :     my $link = "<a href=" . &FIG::cgi_url . "/pom.cgi?user=$user&request=find_in_org&role=$roleE&org=$org>$abr $role</a>";
2499 :     push(@$missing,$link);
2500 :     }
2501 :    
2502 :     if (@$missing > 0)
2503 :     {
2504 :     my $genus_species = &ext_genus_species($fig,$org);
2505 :     push(@$html,$cgi->h2("$org: $genus_species"));
2506 :     push(@$html,$cgi->ul($cgi->li($missing)));
2507 :     }
2508 :     }
2509 :     }
2510 :    
2511 :     sub columns_missing_entries {
2512 :     my($cgi,$subsystem,$org,$roles,$in) = @_;
2513 :    
2514 : overbeek 1.71 my $just_genome = $cgi->param('just_genome');
2515 : overbeek 1.72 if ($just_genome && ($just_genome =~ /(\d+\.\d+)/) && ($org != $1)) { return () }
2516 : overbeek 1.71
2517 : overbeek 1.1 my $just_col = $cgi->param('just_col');
2518 :     my(@really_missing) = ();
2519 :    
2520 :     my($role,%missing_cols);
2521 :     foreach $role (@$roles)
2522 :     {
2523 :     next if ($just_col && ($role ne $just_col));
2524 :     if ($subsystem->get_pegs_from_cell($org,$role) == 0)
2525 :     {
2526 :     $missing_cols{$role} = 1;
2527 :     }
2528 :     }
2529 :    
2530 :     foreach $role (@$roles)
2531 :     {
2532 :     if ($missing_cols{$role})
2533 :     {
2534 :     my($set);
2535 :     if (($set = $in->{$role}) && (! $cgi->param('ignore_alt')))
2536 :     {
2537 : overbeek 1.4 my @set = $subsystem->get_subsetC_roles($set);
2538 : overbeek 1.1
2539 :     my($k);
2540 :     for ($k=0; ($k < @set) && $missing_cols{$set[$k]}; $k++) {}
2541 :     if ($k == @set)
2542 :     {
2543 :     push(@really_missing,$role);
2544 :     }
2545 :     }
2546 :     else
2547 :     {
2548 :     push(@really_missing,$role);
2549 :     }
2550 :     }
2551 :     }
2552 :     return @really_missing;
2553 :     }
2554 :    
2555 :     sub format_missing_including_matches
2556 :     {
2557 :     my($fig,$cgi,$html,$subsystem) = @_;
2558 :     my($org,$abr,$role,$missing);
2559 :    
2560 :     my $user = $cgi->param('user');
2561 :    
2562 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2563 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2564 :    
2565 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2566 : overbeek 1.1 my %activeC = map { $_ => 1 } @subsetC;
2567 :    
2568 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2569 :    
2570 :     my @alt_sets = grep { ($_ =~ /^\*/) } $subsystem->get_subset_namesC;
2571 :     my($set,$col,%in);
2572 :     foreach $set (@alt_sets)
2573 :     {
2574 : overbeek 1.4 my @mem = grep { $activeC{$_} } $subsystem->get_subsetC_roles($set);
2575 : overbeek 1.1 foreach $col (@mem)
2576 :     {
2577 :     $in{$col} = $set;
2578 :     }
2579 :     }
2580 :     push(@$html,$cgi->h1('To Check Missing Entries:'));
2581 :    
2582 :     push(@$html, $cgi->start_form(-action=> "fid_checked.cgi"));
2583 :    
2584 :     my $can_alter = $cgi->param('can_alter');
2585 :     push(@$html,
2586 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
2587 :     $cgi->hidden(-name => 'can_alter', -value => $can_alter, -override => 1));
2588 : overbeek 1.11
2589 : overbeek 1.14 my $just_role = &which_role($subsystem,$cgi->param('just_role'));
2590 : overbeek 1.70 # print STDERR "There are ", scalar @subsetR, " organisms to check\n";
2591 : overbeek 1.1 foreach $org (@subsetR)
2592 :     {
2593 :     my @missing = &columns_missing_entries($cgi,$subsystem,$org,\@subsetC,\%in);
2594 :     $missing = [];
2595 :     foreach $role (@missing)
2596 :     {
2597 : overbeek 1.14 # next if (($_ = $cgi->param('just_role')) && ($_ != ($subsystem->get_role_index($role) + 1)));
2598 :     next if ($just_role && ($just_role ne $role));
2599 : overbeek 1.1
2600 :     my @hits = $fig->find_role_in_org($role, $org, $user, $cgi->param("sims_cutoff"));
2601 :     push(@$missing,@hits);
2602 :     }
2603 : overbeek 1.70 # print STDERR "Found ", scalar @$missing, " for $org\n";
2604 : overbeek 1.1 if (@$missing > 0)
2605 :     {
2606 : overbeek 1.11 my $genus_species = &ext_genus_species($fig,$org);
2607 :     push(@$html,$cgi->h2("$org: $genus_species"));
2608 :    
2609 : overbeek 1.1 my $colhdr = ["Assign", "P-Sc", "PEG", "Len", "Current fn", "Matched peg", "Len", "Function"];
2610 :     my $tbl = [];
2611 :    
2612 :     for my $hit (@$missing)
2613 :     {
2614 :     my($psc, $my_peg, $my_len, $my_fn, $match_peg, $match_len, $match_fn) = @$hit;
2615 :    
2616 :     my $my_peg_link = &HTML::fid_link($cgi, $my_peg, 1);
2617 :     my $match_peg_link = &HTML::fid_link($cgi, $match_peg, 0);
2618 :    
2619 :     my $checkbox = $cgi->checkbox(-name => "checked",
2620 :     -value => "to=$my_peg,from=$match_peg",
2621 :     -label => "");
2622 :    
2623 :     push(@$tbl, [$checkbox,
2624 :     $psc,
2625 :     $my_peg_link, $my_len, $my_fn,
2626 :     $match_peg_link, $match_len, $match_fn]);
2627 :     }
2628 :    
2629 :     push(@$html, &HTML::make_table($colhdr, $tbl, ""));
2630 :     }
2631 :     }
2632 :     push(@$html,
2633 :     $cgi->submit(-value => "Process assignments",
2634 :     -name => "batch_assign"),
2635 :     $cgi->end_form);
2636 :     }
2637 :    
2638 : mkubal 1.36
2639 :    
2640 :     sub columns_missing_entries {
2641 :     my($cgi,$subsystem,$org,$roles,$in) = @_;
2642 :    
2643 :     next if (($_ = $cgi->param('just_genome')) && ($org != $_));
2644 :     my $just_col = $cgi->param('just_col');
2645 :     my(@really_missing) = ();
2646 :    
2647 :     my($role,%missing_cols);
2648 :     foreach $role (@$roles)
2649 :     {
2650 :     next if ($just_col && ($role ne $just_col));
2651 :     if ($subsystem->get_pegs_from_cell($org,$role) == 0)
2652 :     {
2653 :     $missing_cols{$role} = 1;
2654 :     }
2655 :     }
2656 :    
2657 :     foreach $role (@$roles)
2658 :     {
2659 :     if ($missing_cols{$role})
2660 :     {
2661 :     my($set);
2662 :     if (($set = $in->{$role}) && (! $cgi->param('ignore_alt')))
2663 :     {
2664 :     my @set = $subsystem->get_subsetC_roles($set);
2665 :    
2666 :     my($k);
2667 :     for ($k=0; ($k < @set) && $missing_cols{$set[$k]}; $k++) {}
2668 :     if ($k == @set)
2669 :     {
2670 :     push(@really_missing,$role);
2671 :     }
2672 :     }
2673 :     else
2674 :     {
2675 :     push(@really_missing,$role);
2676 :     }
2677 :     }
2678 :     }
2679 :     return @really_missing;
2680 :     }
2681 :    
2682 :     sub format_missing_including_matches_in_ss
2683 :     {
2684 :     my($fig,$cgi,$html,$subsystem) = @_;
2685 :     my($org,$abr,$role,$missing);
2686 :    
2687 :     my $user = $cgi->param('user');
2688 :    
2689 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2690 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2691 :    
2692 :     my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2693 :     my %activeC = map { $_ => 1 } @subsetC;
2694 :    
2695 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2696 :    
2697 :     my @alt_sets = grep { ($_ =~ /^\*/) } $subsystem->get_subset_namesC;
2698 :     my($set,$col,%in);
2699 :     foreach $set (@alt_sets)
2700 :     {
2701 :     my @mem = grep { $activeC{$_} } $subsystem->get_subsetC_roles($set);
2702 :     foreach $col (@mem)
2703 :     {
2704 :     $in{$col} = $set;
2705 :     }
2706 :     }
2707 :     push(@$html,$cgi->h1('To Check Missing Entries:'));
2708 :    
2709 :     push(@$html, $cgi->start_form(-action=> "fid_checked.cgi"));
2710 :    
2711 :     my $can_alter = $cgi->param('can_alter');
2712 :     push(@$html,
2713 :     $cgi->hidden(-name => 'user', -value => $user, -override => 1),
2714 :     $cgi->hidden(-name => 'can_alter', -value => $can_alter, -override => 1));
2715 :    
2716 :     my $just_role = &which_role($subsystem,$cgi->param('just_role'));
2717 :    
2718 :     foreach $org (@subsetR)
2719 :     {
2720 :     my @missing = &columns_missing_entries($cgi,$subsystem,$org,\@subsetC,\%in);
2721 :     $missing = [];
2722 :     foreach $role (@missing)
2723 :     {
2724 :     # next if (($_ = $cgi->param('just_role')) && ($_ != ($subsystem->get_role_index($role) + 1)));
2725 :     next if ($just_role && ($just_role ne $role));
2726 :    
2727 : mkubal 1.40 my $flag = 0;
2728 : mkubal 1.48 my $filler;
2729 : mkubal 1.40 my $rdbH = $fig->db_handle;
2730 : olson 1.45 my $q = "SELECT subsystem, role FROM subsystem_index WHERE role = ?";
2731 :     if (my $relational_db_response = $rdbH->SQL($q, 0, $role))
2732 : mkubal 1.40 {
2733 :     my $pair;
2734 :     foreach $pair (@$relational_db_response)
2735 :     {
2736 :     my ($ss, $role) = @$pair;
2737 : mkubal 1.48 #if($ss =="")
2738 :     #{
2739 :     # $filler = 1;
2740 :     #}
2741 :    
2742 : mkubal 1.40 if ($ss !~/Unique/)
2743 :     {
2744 :     $flag = 1;
2745 :     }
2746 :     }
2747 :     }
2748 :    
2749 : mkubal 1.48 if ($flag == 1)
2750 : mkubal 1.40 {
2751 :     my @hits = $fig->find_role_in_org($role, $org, $user, $cgi->param("sims_cutoff"));
2752 :     push(@$missing,@hits);
2753 :     }
2754 : mkubal 1.36 }
2755 :    
2756 :     if (@$missing > 0)
2757 :     {
2758 :     my $genus_species = &ext_genus_species($fig,$org);
2759 :     push(@$html,$cgi->h2("$org: $genus_species"));
2760 :    
2761 : mkubal 1.40 my $colhdr = ["Assign","Sub(s)", "P-Sc", "PEG", "Len", "Current fn", "Matched peg", "Len", "Function"];
2762 : mkubal 1.36 my $tbl = [];
2763 :    
2764 :     for my $hit (@$missing)
2765 :     {
2766 : mkubal 1.40 my($psc, $my_peg, $my_len, $my_fn, $match_peg, $match_len, $match_fn) = @$hit;
2767 : mkubal 1.36 my $my_peg_link = &HTML::fid_link($cgi, $my_peg, 1);
2768 :     my $match_peg_link = &HTML::fid_link($cgi, $match_peg, 0);
2769 :    
2770 :     my $checkbox = $cgi->checkbox(-name => "checked",
2771 :     -value => "to=$my_peg,from=$match_peg",
2772 :     -label => "");
2773 : mkubal 1.48 my $good = 0;
2774 : mkubal 1.40 my @list_of_ss = ();
2775 :     my $ss_table_entry = "none";
2776 : mkubal 1.48
2777 : mkubal 1.40 my (@list_of_returned_ss,$ss_name,$ss_role);
2778 : mkubal 1.48 @list_of_returned_ss = $fig->subsystems_for_peg($match_peg);
2779 : mkubal 1.40 if (@list_of_returned_ss > 0)
2780 :     {
2781 :     for my $ret_ss (@list_of_returned_ss)
2782 :     {
2783 :     ($ss_name,$ss_role)= @$ret_ss;
2784 :     if ($ss_name !~/Unique/)
2785 :     {
2786 : mkubal 1.48 $good = 1;
2787 :     }
2788 :     }
2789 :     }
2790 :    
2791 :     if ($good)
2792 :     {
2793 :     my (@list_of_returned_ss,$ss_name,$ss_role);
2794 :     @list_of_returned_ss = $fig->subsystems_for_peg($my_peg);
2795 :     if (@list_of_returned_ss > 0)
2796 :     {
2797 :     for my $ret_ss (@list_of_returned_ss)
2798 :     {
2799 :     ($ss_name,$ss_role)= @$ret_ss;
2800 :     if ($ss_name !~/Unique/)
2801 :     {
2802 :     push (@list_of_ss,$ss_name);
2803 : mkubal 1.40 $ss_table_entry = join("<br>",@list_of_ss);
2804 :    
2805 :     }
2806 :     }
2807 :     }
2808 : mkubal 1.48
2809 :     push(@$tbl, [$checkbox,$ss_table_entry,
2810 :     $psc,
2811 :     $my_peg_link, $my_len, $my_fn,
2812 :     $match_peg_link, $match_len, $match_fn]);
2813 :     }
2814 :    
2815 :    
2816 :     }
2817 : mkubal 1.36
2818 :     push(@$html, &HTML::make_table($colhdr, $tbl, ""));
2819 :     }
2820 :     }
2821 :     push(@$html,
2822 :     $cgi->submit(-value => "Process assignments",
2823 :     -name => "batch_assign"),
2824 :     $cgi->end_form);
2825 :     }
2826 :    
2827 :    
2828 : overbeek 1.3 sub format_check_assignments {
2829 :     my($fig,$cgi,$html,$subsystem) = @_;
2830 :     my($org,$role);
2831 :    
2832 :     my $user = $cgi->param('user');
2833 :    
2834 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2835 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2836 :    
2837 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2838 : overbeek 1.3 my %activeC = map { $_ => 1 } @subsetC;
2839 :    
2840 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2841 :    
2842 :     push(@$html,$cgi->h1('Potentially Bad Assignments:'));
2843 :    
2844 :     foreach $org (@subsetR)
2845 :     {
2846 :     next if (($_ = $cgi->param('just_genome_assignments')) && ($_ != $org));
2847 :     my @bad = ();
2848 :    
2849 :     foreach $role (@subsetC)
2850 :     {
2851 :     next if (($_ = $cgi->param('just_role_assignments')) && ($_ != ($subsystem->get_role_index($role) + 1)));
2852 :     push(@bad,&checked_assignments($cgi,$subsystem,$org,$role));
2853 :     }
2854 :    
2855 :     if (@bad > 0)
2856 :     {
2857 :     my $genus_species = &ext_genus_species($fig,$org);
2858 :     push(@$html,$cgi->h2("$org: $genus_species"),
2859 :     $cgi->ul($cgi->li(\@bad)));
2860 :    
2861 :     }
2862 :     }
2863 :     push(@$html,$cgi->hr);
2864 :     }
2865 :    
2866 :     sub checked_assignments {
2867 :     my($cgi,$subsystem,$genome,$role) = @_;
2868 :     my($peg,$line1,$line2,@out,$curr,$auto);
2869 :    
2870 :     my(@bad) = ();
2871 :     my @pegs = $subsystem->get_pegs_from_cell($genome,$role);
2872 :     if (@pegs > 0)
2873 :     {
2874 :     my $tmp = "/tmp/tmp.pegs.$$";
2875 :     open(TMP,">$tmp") || die "could not open $tmp";
2876 :     foreach $peg (@pegs)
2877 :     {
2878 :     print TMP "$peg\n";
2879 :     }
2880 :     close(TMP);
2881 :     my $strict = $cgi->param('strict_check') ? "strict" : "";
2882 :     @out = `$FIG_Config::bin/check_peg_assignments $strict < $tmp 2> /dev/null`;
2883 :     unlink($tmp);
2884 :    
2885 :     while (($_ = shift @out) && ($_ =~ /^(fig\|\d+\.\d+\.peg\.\d+)/))
2886 :     {
2887 :     $peg = $1;
2888 :     if (($line1 = shift @out) && ($line1 =~ /^current:\s+(\S.*\S)/) && ($curr = $1) &&
2889 :     ($line2 = shift @out) && ($line2 =~ /^auto:\s+(\S.*\S)/) && ($auto = $1))
2890 :     {
2891 :     if (! $fig->same_func($curr,$auto))
2892 :     {
2893 :     my $link = &HTML::fid_link($cgi,$peg);
2894 :     push(@bad,"$link<br>$line1<br>$line2<br><br>");
2895 :     }
2896 :     }
2897 :     }
2898 :     }
2899 :     return @bad;
2900 :     }
2901 :    
2902 : overbeek 1.1 sub format_dups {
2903 :     my($fig,$cgi,$html,$subsystem) = @_;
2904 :    
2905 :     my $user = $cgi->param('user');
2906 :    
2907 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2908 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2909 :    
2910 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2911 : overbeek 1.1 my %activeC = map { $_ => 1 } @subsetC;
2912 :    
2913 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2914 :    
2915 :     push(@$html,$cgi->h1('To Check Duplicates:'));
2916 :    
2917 :     my($org,$duplicates,$role,$genus_species);
2918 :     foreach $org (@subsetR)
2919 :     {
2920 :     $duplicates = [];
2921 :     foreach $role (@subsetC)
2922 :     {
2923 :     my(@pegs,$peg,$func);
2924 :     if ((@pegs = $subsystem->get_pegs_from_cell($org,$role)) > 1)
2925 :     {
2926 :     push(@$duplicates,"$role<br>" . $cgi->ul($cgi->li([map { $peg = $_; $func = $fig->function_of($peg,$user); &HTML::fid_link($cgi,$peg) . " $func" } @pegs])));
2927 :     }
2928 :     }
2929 :    
2930 :     if (@$duplicates > 0)
2931 :     {
2932 :     $genus_species = &ext_genus_species($fig,$org);
2933 :     push(@$html,$cgi->h2("$org: $genus_species"));
2934 :     push(@$html,$cgi->ul($cgi->li($duplicates)));
2935 :     }
2936 :     }
2937 :     }
2938 :    
2939 :     sub format_coupled {
2940 :     my($fig,$cgi,$html,$subsystem,$type) = @_;
2941 :     my($i,$j,@show,$user,$org,$link,$gs,$func,$peg,$peg1,$peg2,%in,%seen,%seen2);
2942 :     my(@cluster,$sc,$x,$id2,@in,$sim,@coupled);
2943 :     my($org,$role);
2944 :    
2945 :     $user = $cgi->param('user');
2946 :    
2947 :     my $active_subsetC = ($cgi->param('active_subsetC') or $subsystem->get_active_subsetC );
2948 :     my $active_subsetR = ($cgi->param('active_subsetR') or $subsystem->get_active_subsetR );
2949 :    
2950 : overbeek 1.4 my @subsetC = $subsystem->get_subsetC_roles($active_subsetC);
2951 : overbeek 1.1 my %activeC = map { $_ => 1 } @subsetC;
2952 :    
2953 :     my @subsetR = $subsystem->get_subsetR($active_subsetR);
2954 :    
2955 :     foreach $org (@subsetR)
2956 :     {
2957 :     foreach $role (@subsetC)
2958 :     {
2959 :     push(@in,$subsystem->get_pegs_from_cell($org,$role));
2960 :     }
2961 :     }
2962 :    
2963 :     %in = map { $_ => 1 } @in;
2964 :     @show = ();
2965 :     foreach $peg1 (@in)
2966 :     {
2967 :     if ($type eq "careful")
2968 :     {
2969 :     @coupled = $fig->coupling_and_evidence($peg1,5000,1.0e-10,0.2,1);
2970 :     }
2971 :     else
2972 :     {
2973 :     @coupled = $fig->fast_coupling($peg1,5000,1);
2974 :     }
2975 :    
2976 :     foreach $x (@coupled)
2977 :     {
2978 :     ($sc,$peg2) = @$x;
2979 :     if ((! $in{$peg2}) && ((! $seen{$peg2}) || ($seen{$peg2} < $sc)))
2980 :     {
2981 :     $seen{$peg2} = $sc;
2982 :     # print STDERR "$sc\t$peg1 -> $peg2\n";
2983 :     }
2984 :     }
2985 :     }
2986 :    
2987 :     foreach $peg1 (sort { $seen{$b} <=> $seen{$a} } keys(%seen))
2988 :     {
2989 :     if (! $seen2{$peg1})
2990 :     {
2991 :     @cluster = ($peg1);
2992 :     $seen2{$peg1} = 1;
2993 :     for ($i=0; ($i < @cluster); $i++)
2994 :     {
2995 :     foreach $sim ($fig->sims($cluster[$i],1000,1.0e-10,"fig"))
2996 :     {
2997 :     $id2 = $sim->id2;
2998 :     if ($seen{$id2} && (! $seen2{$id2}))
2999 :     {
3000 :     push(@cluster,$id2);
3001 :     $seen2{$id2} = 1;
3002 :     }
3003 :     }
3004 :     }
3005 :     push(@show, [scalar @cluster,
3006 :     $cgi->br .
3007 :     $cgi->ul($cgi->li([map { $peg = $_;
3008 :     $sc = $seen{$peg};
3009 :     $func = $fig->function_of($peg,$user);
3010 :     $gs = $fig->genus_species($fig->genome_of($peg));
3011 :     $link = &HTML::fid_link($cgi,$peg);
3012 :     "$sc: $link: $func \[$gs\]" }
3013 :     sort { $seen{$b} <=> $seen{$a} }
3014 :     @cluster]))
3015 :     ]);
3016 :     }
3017 :     }
3018 :    
3019 :     if (@show > 0)
3020 :     {
3021 :     @show = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @show;
3022 :     push(@$html,$cgi->h1('Coupled, but not in Spreadsheet:'));
3023 :     push(@$html,$cgi->ul($cgi->li(\@show)));
3024 :     }
3025 :     }
3026 :    
3027 :     sub ext_genus_species {
3028 :     my($fig,$genome) = @_;
3029 :    
3030 :     my $gs = $fig->genus_species($genome);
3031 :     my $c = substr($fig->taxonomy_of($genome),0,1);
3032 :     return "$gs [$c]";
3033 :     }
3034 :    
3035 :     sub show_tree {
3036 :    
3037 :     my($id,$gs);
3038 :     my($tree,$ids) = $fig->build_tree_of_complete;
3039 :     my $relabel = {};
3040 :     foreach $id (@$ids)
3041 :     {
3042 :     if ($gs = $fig->genus_species($id))
3043 :     {
3044 :     $relabel->{$id} = "$gs ($id)";
3045 :     }
3046 :     }
3047 :     $_ = &display_tree($tree,$relabel);
3048 :     print $cgi->pre($_),"\n";
3049 :     }
3050 :    
3051 :     sub export_align_input
3052 :     {
3053 :    
3054 :     }
3055 :    
3056 : redwards 1.22 sub annotate_column {
3057 :     # RAE: I added this function to allow you to reannotate a single column all at once
3058 :     # this is because I wanted to update some of my annotations after looking at UniProt
3059 :     # and couldn't see an easy way to do it.
3060 :     my($fig,$cgi,$html,$col,$subsystem) = @_;
3061 :     my $checked;
3062 :     my $roles = [$subsystem->get_roles];
3063 : overbeek 1.76 my $role = &which_role_for_column($col,$roles);
3064 :     my @checked = &seqs_to_align($role,$subsystem);
3065 : redwards 1.22 return undef unless (@checked);
3066 :    
3067 :     # the following is read from fid_checked.cgi
3068 :     push( @$html, "<table border=1>\n",
3069 :     "<tr><td>Protein</td><td>Organism</td><td>Current Function</td><td>By Whom</td></tr>"
3070 :     );
3071 :    
3072 :     foreach my $peg ( @checked ) {
3073 :     my @funcs = $fig->function_of( $peg );
3074 :     if ( ! @funcs ) { @funcs = ( ["", ""] ) }
3075 :     my $nfunc = @funcs;
3076 :     my $org = $fig->org_of( $peg );
3077 :     push( @$html, "<tr>",
3078 :     "<td rowspan=$nfunc>$peg</td>",
3079 :     "<td rowspan=$nfunc>$org</td>"
3080 :     );
3081 :     my ($who, $what);
3082 :     push( @$html, join( "</tr>\n<tr>", map { ($who,$what) = @$_; "<td>$what</td><td>$who</td>" } @funcs ) );
3083 :     push( @$html, "</tr>\n" );
3084 :     }
3085 :     push( @$html, "</table>\n" );
3086 :    
3087 :     push( @$html, $cgi->start_form(-action => "fid_checked.cgi", -target=>"_blank"),
3088 :     $cgi->br, $cgi->br,
3089 :     "<table>\n",
3090 :     "<tr><td>New Function:</td>",
3091 :     "<td>", $cgi->textfield(-name => "function", -size => 60), "</td></tr>",
3092 :     "<tr><td colspan=2>", $cgi->hr, "</td></tr>",
3093 :     "<tr><td>New Annotation:</td>",
3094 :     "<td rowspan=2>", $cgi->textarea(-name => "annotation", -rows => 30, -cols => 60), "</td></tr>",
3095 :     "<tr><td valign=top width=20%><br>", $cgi->submit('add annotation'),
3096 :     "<p><b>Please note:</b> At the moment you need to make sure that the annotation in the table at the ",
3097 :     "top of this page reflects the new annotation. This may not be updated automatically.</p>",
3098 :     "</td></tr>",
3099 :     "</table>",
3100 :     $cgi->hidden(-name => 'user', -value => $user),
3101 :     $cgi->hidden(-name => 'checked', -value => [@checked]),
3102 :     $cgi->end_form
3103 :     );
3104 :     }
3105 :    
3106 :    
3107 : overbeek 1.76
3108 : overbeek 1.1 sub align_column {
3109 : overbeek 1.76 my($fig,$cgi,$html,$colN,$subsystem) = @_;
3110 :     my(@pegs,$peg,$pseq,$role);
3111 : overbeek 1.1
3112 :     my $roles = [$subsystem->get_roles];
3113 : overbeek 1.76 my $name = $subsystem->get_name;
3114 :     &check_index("$FIG_Config::data/Subsystems/$name/Alignments",$roles);
3115 :     if (($role = &which_role_for_column($colN,$roles)) &&
3116 :     ((@pegs = &seqs_to_align($role,$subsystem)) > 1))
3117 :     {
3118 :     my $tmpF = "/tmp/seqs.fasta.$$";
3119 :     open(TMP,">$tmpF") || die "could not open $tmpF";
3120 : redwards 1.22
3121 : overbeek 1.76 foreach $peg (@pegs)
3122 : overbeek 1.1 {
3123 : overbeek 1.76 if ($pseq = $fig->get_translation($peg))
3124 :     {
3125 :     $pseq =~ s/[uU]/x/g;
3126 :     print TMP ">$peg\n$pseq\n";
3127 :     }
3128 : overbeek 1.1 }
3129 : overbeek 1.76 close(TMP);
3130 : overbeek 1.1
3131 : overbeek 1.76 my $name = $subsystem->get_name;
3132 :     my $dir = "$FIG_Config::data/Subsystems/$name/Alignments/$colN";
3133 : overbeek 1.1
3134 : overbeek 1.76 if (-d $dir)
3135 :     {
3136 :     system "rm -rf \"$dir\"";
3137 :     }
3138 :    
3139 :     &FIG::run("$FIG_Config::bin/split_and_trim_sequences \"$dir/split_info\" < $tmpF");
3140 : overbeek 1.1
3141 : overbeek 1.76 if (-s "$dir/split_info/set.sizes")
3142 :     {
3143 :     open(SZ,"<$dir/split_info/set.sizes") || die " could not open $dir/split_info/set.sizes";
3144 :     while (defined($_ = <SZ>))
3145 : overbeek 1.1 {
3146 : overbeek 1.76 if (($_ =~ /^(\d+)\t(\d+)/) && ($2 > 3))
3147 :     {
3148 :     my $n = $1;
3149 :     &FIG::run("$FIG_Config::bin/make_phob_from_seqs \"$dir/$n\" < \"$dir/split_info\"/$n");
3150 :     }
3151 : overbeek 1.1 }
3152 : overbeek 1.76 close(SZ);
3153 :     &update_index("$FIG_Config::data/Subsystems/$name/Alignments/index",$colN,$role);
3154 :     }
3155 :     else
3156 :     {
3157 :     system("rm -rf \"$dir\"");
3158 : overbeek 1.1 }
3159 :     }
3160 : overbeek 1.76 }
3161 :    
3162 :     sub align_subcolumn {
3163 :     my($fig,$cgi,$html,$colN,$subcolN,$subsystem) = @_;
3164 :     my($role,@pegs,$cutoff,$peg);
3165 :    
3166 :     my $name = $subsystem->get_name;
3167 :     my $dir = "$FIG_Config::data/Subsystems/$name/Alignments/$colN/$subcolN";
3168 :     my $roles = [$subsystem->get_roles];
3169 :     if (&check_index("$FIG_Config::data/Subsystems/$name/Alignments",$roles))
3170 : overbeek 1.1 {
3171 : overbeek 1.76 my @pegs = map { $_ =~ /^(\S+)/; $1 } `cut -f2 $dir/ids`;
3172 :    
3173 :     if ($cutoff = $cgi->param('include_homo'))
3174 :     {
3175 :     my $max = $cgi->param('max_homo');
3176 :     $max = $max ? $max : 100;
3177 :     push(@pegs,&get_homologs($fig,\@pegs,$cutoff,$max));
3178 :     }
3179 :    
3180 :     system "rm -rf \"$dir\"";
3181 :     open(MAKE,"| make_phob_from_ids \"$dir\"") || die "could not make PHOB";
3182 :     foreach $peg (@pegs)
3183 : overbeek 1.1 {
3184 : overbeek 1.76 print MAKE "$peg\n";
3185 : overbeek 1.1 }
3186 : overbeek 1.76 close(MAKE);
3187 : overbeek 1.1 }
3188 :     }
3189 :    
3190 : overbeek 1.76 sub which_role_for_column {
3191 : overbeek 1.1 my($col,$roles) = @_;
3192 :     my($i);
3193 :    
3194 :     if (($col =~ /^(\d+)/) && ($1 <= @$roles))
3195 :     {
3196 :     return $roles->[$1-1];
3197 :     }
3198 :     return undef;
3199 :     }
3200 :    
3201 :     sub seqs_to_align {
3202 :     my($role,$subsystem) = @_;
3203 :     my($genome);
3204 :    
3205 :     my @seqs = ();
3206 : overbeek 1.76 foreach $genome ($subsystem->get_genomes)
3207 : overbeek 1.1 {
3208 :     push(@seqs,$subsystem->get_pegs_from_cell($genome,$role));
3209 :     }
3210 :     return @seqs;
3211 :     }
3212 :    
3213 :     sub get_homologs {
3214 :     my($fig,$checked,$cutoff,$max) = @_;
3215 :     my($peg,$sim,$id2);
3216 :    
3217 :     my @homologs = ();
3218 :     my %got = map { $_ => 1 } @$checked;
3219 :    
3220 :     foreach $peg (@$checked)
3221 :     {
3222 :     foreach $sim ($fig->sims($peg,$max,$cutoff,"fig"))
3223 :     {
3224 :     $id2 = $sim->id2;
3225 : overbeek 1.16 if ((! $got{$id2}) && ($id2 =~ /^fig\|(\d+\.\d+)/) && ($fig->is_complete($1)))
3226 : overbeek 1.1 {
3227 :     push(@homologs,[$sim->psc,$id2]);
3228 :     $got{$id2} = 1;
3229 :     }
3230 :     }
3231 :     }
3232 :     @homologs = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @homologs;
3233 :     if (@homologs > $max) { $#homologs = $max-1 }
3234 :    
3235 :     return @homologs;
3236 :     }
3237 :    
3238 :     sub set_links {
3239 :     my($cgi,$out) = @_;
3240 :    
3241 :     my @with_links = ();
3242 :     foreach $_ (@$out)
3243 :     {
3244 :     if ($_ =~ /^(.*)(fig\|\d+\.\d+\.peg\.\d+)(.*)$/)
3245 :     {
3246 :     my($before,$peg,$after) = ($1,$2,$3);
3247 :     push(@with_links, $before . &HTML::fid_link($cgi,$peg) . $after . "\n");
3248 :     }
3249 :     else
3250 :     {
3251 :     push(@with_links,$_);
3252 :     }
3253 :     }
3254 :     return @with_links;
3255 :     }
3256 :    
3257 :     sub reset_ssa {
3258 :     my($fig,$cgi,$html) = @_;
3259 :     my($ssa,@spreadsheets,$col_hdrs,$tab,$t,$readable,$url,$link,@tmp);
3260 :    
3261 :     if (($ssa = $cgi->param('ssa_name')) && opendir(BACKUP,"$FIG_Config::data/Subsystems/$ssa/Backup"))
3262 :     {
3263 :     @spreadsheets = sort { $b <=> $a }
3264 :     map { $_ =~ /^spreadsheet.(\d+)/; $1 }
3265 :     grep { $_ =~ /^spreadsheet/ }
3266 :     readdir(BACKUP);
3267 :     closedir(BACKUP);
3268 :     $col_hdrs = ["When","Number Genomes"];
3269 :     $tab = [];
3270 :     foreach $t (@spreadsheets)
3271 :     {
3272 :     $readable = &FIG::epoch_to_readable($t);
3273 : golsen 1.75 $url = &FIG::cgi_url . "/subsys.cgi?user=$user&ssa_name=" . uri_escape( $ssa ) . "&request=reset_to&ts=$t";
3274 : overbeek 1.1 $link = "<a href=$url>$readable</a>";
3275 :     open(TMP,"<$FIG_Config::data/Subsystems/$ssa/Backup/spreadsheet.$t")
3276 :     || die "could not open $FIG_Config::data/Subsystems/$ssa/Backup/spreadsheet.$t";
3277 :     $/ = "//\n";
3278 :     $_ = <TMP>;
3279 :     $_ = <TMP>;
3280 :     $_ = <TMP>;
3281 :     chomp;
3282 :     $/ = "\n";
3283 :    
3284 :     @tmp = grep { $_ =~ /^\d+\.\d+/ } split(/\n/,$_);
3285 :     push(@$tab,[$link,scalar @tmp]);
3286 :     }
3287 :     }
3288 :     push(@$html,&HTML::make_table($col_hdrs,$tab,"Possible Points to Reset From"));
3289 :     }
3290 :    
3291 :     sub reset_ssa_to {
3292 :     my($fig,$cgi,$html) = @_;
3293 :     my($ts,$ssa);
3294 :    
3295 :     if (($ssa = $cgi->param('ssa_name')) &&
3296 :     ($ts = $cgi->param('ts')) &&
3297 :     (-s "$FIG_Config::data/Subsystems/$ssa/Backup/spreadsheet.$ts"))
3298 :     {
3299 :     system "cp -f $FIG_Config::data/Subsystems/$ssa/Backup/spreadsheet.$ts $FIG_Config::data/Subsystems/$ssa/spreadsheet";
3300 :     chmod(0777,"$FIG_Config::data/Subsystems/$ssa/spreadsheet");
3301 :     if (-s "$FIG_Config::data/Subsystems/$ssa/Backup/notes.$ts")
3302 :     {
3303 :     system "cp -f $FIG_Config::data/Subsystems/$ssa/Backup/notes.$ts $FIG_Config::data/Subsystems/$ssa/notes";
3304 :     chmod(0777,"$FIG_Config::data/Subsystems/$ssa/notes");
3305 :     }
3306 : overbeek 1.9
3307 : overbeek 1.97 if (-s "$FIG_Config::data/Subsystems/$ssa/Backup/reactions.$ts")
3308 :     {
3309 :     system "cp -f $FIG_Config::data/Subsystems/$ssa/Backup/reactions.$ts $FIG_Config::data/Subsystems/$ssa/reactions";
3310 :     chmod(0777,"$FIG_Config::data/Subsystems/$ssa/reactions");
3311 :     }
3312 :    
3313 : overbeek 1.9 my $subsystem = new Subsystem($ssa,$fig,0);
3314 :     $subsystem->db_sync(0);
3315 :     undef $subsystem;
3316 : overbeek 1.1 }
3317 :     }
3318 :    
3319 :     sub make_exchangable {
3320 :     my($fig,$cgi,$html) = @_;
3321 :     my($ssa);
3322 :    
3323 :     if (($ssa = $cgi->param('ssa_name')) &&
3324 :     (-s "$FIG_Config::data/Subsystems/$ssa/spreadsheet") &&
3325 :     open(TMP,">$FIG_Config::data/Subsystems/$ssa/EXCHANGABLE"))
3326 :     {
3327 :     print TMP "1\n";
3328 :     close(TMP);
3329 :     chmod(0777,"$FIG_Config::data/Subsystems/$ssa/EXCHANGABLE");
3330 :     }
3331 :     }
3332 :    
3333 :     sub make_unexchangable {
3334 :     my($fig,$cgi,$html) = @_;
3335 :     my($ssa);
3336 :    
3337 :     if (($ssa = $cgi->param('ssa_name')) &&
3338 :     (-s "$FIG_Config::data/Subsystems/$ssa/EXCHANGABLE"))
3339 :     {
3340 :     unlink("$FIG_Config::data/Subsystems/$ssa/EXCHANGABLE");
3341 :     }
3342 :     }
3343 : overbeek 1.14
3344 :     sub which_role {
3345 :     my($subsystem,$role_indicator) = @_;
3346 :     my($n,$role,$abbr);
3347 :    
3348 :     if (($role_indicator =~ /^\s*(\d+)\s*$/) && ($n = $1) && ($role = $subsystem->get_role($n-1)))
3349 :     {
3350 :     return $role;
3351 :     }
3352 :     elsif (($role_indicator =~ /^\s*(\S+)\s*$/) && ($abbr = $1) && ($role = $subsystem->get_role_from_abbr($abbr)))
3353 :     {
3354 :     return $role;
3355 :     }
3356 :     return "";
3357 :     }
3358 : overbeek 1.17
3359 :     sub external_id {
3360 :     my($fig,$cgi,$peg) = @_;
3361 :     my @tmp;
3362 :     my @aliases = ($fig->feature_aliases($peg),map { $_->[0] } $fig->mapped_prot_ids($peg));
3363 :     if ((@tmp = grep { $_ =~ /^uni\|/ } @aliases) > 0)
3364 :     {
3365 :     @aliases = map { &HTML::uni_link($cgi,$_) } @tmp;
3366 :     }
3367 :     elsif ((@tmp = grep { $_ =~ /^sp\|/ } @aliases) > 0)
3368 :     {
3369 :     @aliases = map { &HTML::sp_link($cgi,$_) } @tmp;
3370 :     }
3371 :     elsif ((@tmp = grep { $_ =~ /^gi\|/ } @aliases) > 0)
3372 :     {
3373 :     @aliases = map { &HTML::gi_link($cgi,$_) } @tmp;
3374 :     }
3375 :     elsif ((@tmp = grep { $_ =~ /^kegg\|/ } @aliases) > 0)
3376 :     {
3377 :     @aliases = map { &HTML::kegg_link($cgi,$_) } @tmp;
3378 :     }
3379 :     else
3380 :     {
3381 :     return wantarray() ? (&HTML::fid_link($cgi,$peg)) : &HTML::fid_link($cgi,$peg);
3382 :     }
3383 :    
3384 :     if (wantarray())
3385 :     {
3386 :     return @aliases;
3387 :     }
3388 :     else
3389 :     {
3390 :     return $aliases[0];
3391 :     }
3392 :     }
3393 : redwards 1.52
3394 :     sub cool_colors {
3395 :     # just an array of "websafe" colors or whatever colors we want to use. Feel free to remove bad colors (hence the lines not being equal length!)
3396 :     return (
3397 :     '#C0C0C0', '#FF40C0', '#FF8040', '#FF0080', '#FFC040', '#40C0FF', '#40FFC0', '#C08080', '#C0FF00', '#00FF80', '#00C040',
3398 :     "#6B8E23", "#483D8B", "#2E8B57", "#008000", "#006400", "#800000", "#00FF00", "#7FFFD4",
3399 :     "#87CEEB", "#A9A9A9", "#90EE90", "#D2B48C", "#8DBC8F", "#D2691E", "#87CEFA", "#E9967A", "#FFE4C4", "#FFB6C1",
3400 :     "#E0FFFF", "#FFA07A", "#DB7093", "#9370DB", "#008B8B", "#FFDEAD", "#DA70D6", "#DCDCDC", "#FF00FF", "#6A5ACD",
3401 :     "#00FA9A", "#228B22", "#1E90FF", "#FA8072", "#CD853F", "#DC143C", "#FF6347", "#98FB98", "#4682B4",
3402 :     "#D3D3D3", "#7B68EE", "#2F4F4F", "#FF7F50", "#FF69B4", "#BC8F8F", "#A0522D", "#DEB887", "#00DED1",
3403 :     "#6495ED", "#800080", "#FFD700", "#F5DEB3", "#66CDAA", "#FF4500", "#4B0082", "#CD5C5C",
3404 :     "#EE82EE", "#7CFC00", "#FFFF00", "#191970", "#FFFFE0", "#DDA0DD", "#00BFFF", "#DAA520", "#008080",
3405 :     "#00FF7F", "#9400D3", "#BA55D3", "#D8BFD8", "#8B4513", "#3CB371", "#00008B", "#5F9EA0",
3406 :     "#4169E1", "#20B2AA", "#8A2BE2", "#ADFF2F", "#556B2F",
3407 :     "#F0FFFF", "#B0E0E6", "#FF1493", "#B8860B", "#FF0000", "#F08080", "#7FFF00", "#8B0000",
3408 :     "#40E0D0", "#0000CD", "#48D1CC", "#8B008B", "#696969", "#AFEEEE", "#FF8C00", "#EEE8AA", "#A52A2A",
3409 :     "#FFE4B5", "#B0C4DE", "#FAF0E6", "#9ACD32", "#B22222", "#FAFAD2", "#808080", "#0000FF",
3410 :     "#000080", "#32CD32", "#FFFACD", "#9932CC", "#FFA500", "#F0E68C", "#E6E6FA", "#F4A460", "#C71585",
3411 :     "#BDB76B", "#00FFFF", "#FFDAB9", "#ADD8E6", "#778899",
3412 :     );
3413 :     }
3414 :    
3415 :     sub describe_colors {
3416 :     my ($tvc)=@_;
3417 :     my $tab = [];
3418 :     my @colors=&cool_colors();
3419 : redwards 1.58 my @labels=sort {$a cmp $b} keys %$tvc;
3420 : redwards 1.59 my $selfurl=$cgi->url();
3421 :     # recreate the url for the link
3422 : golsen 1.75 $selfurl .= "?user=" . $cgi->param('user')
3423 :     . "&ssa_name=" . uri_escape( $cgi->param('ssa_name') )
3424 :     . "&request=" . $cgi->param('request')
3425 :     . "&can_alter=" . $cgi->param('can_alter');
3426 : redwards 1.59
3427 : redwards 1.52 my $row;
3428 :     for (my $i=0; $i<= scalar @labels; $i++) {
3429 :     next unless (defined $labels[$i]);
3430 : redwards 1.59 my $link='<a href="' . $selfurl . "&active_key=" . $cgi->param('color_by_ga') . "&active_value=" . $labels[$i] . '">' . $labels[$i] . "</a>\n";
3431 :     push @$row, [$link, "td style=\"background-color: $colors[$tvc->{$labels[$i]}]\""];
3432 : redwards 1.52 unless (($i+1) % 10) {
3433 :     push @$tab, $row;
3434 :     undef $row;
3435 :     }
3436 :     }
3437 :     push @$tab, $row;
3438 :     return $tab;
3439 :     }
3440 : overbeek 1.76
3441 :     sub existing_trees {
3442 :     my($dir,$roles) = @_;
3443 :     my(@rolesI,$roleI,@subrolesI,$subroleI);
3444 :    
3445 :     &check_index("$dir/Alignments",$roles);
3446 :    
3447 :     my @rolesA = ();
3448 :    
3449 :     if (opendir(DIR,"$dir/Alignments"))
3450 :     {
3451 :     @rolesI = grep { $_ =~ /^(\d+)$/ } readdir(DIR);
3452 :     closedir(DIR);
3453 :    
3454 :     foreach $roleI (@rolesI)
3455 :     {
3456 :     if ((-d "$dir/Alignments/$roleI/split_info") && opendir(SUBDIR,"$dir/Alignments/$roleI"))
3457 :     {
3458 :     @subrolesI = grep { $_ =~ /^(\d+)$/ } readdir(SUBDIR);
3459 :     closedir(SUBDIR);
3460 :    
3461 :     foreach $subroleI (@subrolesI)
3462 :     {
3463 :     push(@rolesA,"$roleI.$subroleI: $roles->[$roleI-1]");
3464 :     }
3465 :     }
3466 :     }
3467 :     }
3468 :    
3469 :     my($x,$y);
3470 :     return [sort { $a =~ /^(\d+\.\d+)/; $x = $1;
3471 :     $b =~ /^(\d+\.\d+)/; $y = $1;
3472 :     $x <=> $y
3473 :     } @rolesA];
3474 :     }
3475 :    
3476 :     sub check_index {
3477 :     my($alignments,$roles) = @_;
3478 :    
3479 :     if (-s "$alignments/index")
3480 :     {
3481 :     my $ok = 1;
3482 :     foreach $_ (`cat \"$alignments/index\"`)
3483 :     {
3484 :     $ok = $ok && (($_ =~ /^(\d+)\t(\S.*\S)/) && ($roles->[$1 - 1] eq $2));
3485 :     }
3486 :     if (! $ok)
3487 :     {
3488 :     system "rm -rf \"$alignments\"";
3489 :     return 0;
3490 :     }
3491 :     return 1;
3492 :     }
3493 :     else
3494 :     {
3495 :     system "rm -rf \"$alignments\"";
3496 :     }
3497 :     return 0;
3498 :     }
3499 :    
3500 :     sub update_index {
3501 :     my($file,$colN,$role) = @_;
3502 :    
3503 :     my @lines = ();
3504 :     if (-s $file)
3505 :     {
3506 :     @lines = grep { $_ !~ /^$colN\t/ } `cat $file`;
3507 :     }
3508 :     push(@lines,"$colN\t$role\n");
3509 :     open(TMP,">$file") || die "could not open $file";
3510 :     foreach $_ (@lines)
3511 :     {
3512 :     print TMP $_;
3513 :     }
3514 :     close(TMP);
3515 :     }
3516 : overbeek 1.77
3517 :     sub show_sequences_in_column {
3518 :     my($fig,$cgi,$html,$subsystem,$colN) = @_;
3519 :     my(@pegs,$role);
3520 :    
3521 :     my $roles = [$subsystem->get_roles];
3522 :     if (($role = &which_role_for_column($colN,$roles)) &&
3523 :     ((@pegs = &seqs_to_align($role,$subsystem)) > 0))
3524 :     {
3525 :     push(@$html, "<pre>\n");
3526 :     foreach my $peg (@pegs)
3527 :     {
3528 :     my $seq;
3529 :     if ($seq = $fig->get_translation($peg))
3530 :     {
3531 : overbeek 1.78 push(@$html, ">$peg\n",&formatted_seq($seq));
3532 : overbeek 1.77 }
3533 :     else
3534 :     {
3535 :     push(@$html, "could not find translation for $peg\n");
3536 :     }
3537 :     }
3538 :     push(@$html, "\n</pre>\n");
3539 :     }
3540 :     else
3541 :     {
3542 :     push(@$html,$cgi->h1("Could not determine the role from $colN"));
3543 :     }
3544 :     }
3545 :    
3546 : overbeek 1.78 sub formatted_seq {
3547 :     my($seq) = @_;
3548 :     my($i,$ln);
3549 :    
3550 :     my @seqs = ();
3551 :     my $n = length($seq);
3552 :     for ($i=0; ($i < $n); $i += 60) {
3553 :     if (($i + 60) <= $n) {
3554 :     $ln = substr($seq,$i,60);
3555 :     } else {
3556 :     $ln = substr($seq,$i,($n-$i));
3557 :     }
3558 :     push(@seqs,"$ln\n");
3559 :     }
3560 :     return @seqs;
3561 :     }
3562 : overbeek 1.79
3563 :     sub check_ssa {
3564 :     my($fig,$cgi) = @_;
3565 :    
3566 :     my $user = $cgi->param('user');
3567 :     my $ssa = $cgi->param('ssa_name');
3568 :     my $checked;
3569 :     if ($user && $ssa)
3570 :     {
3571 :     $ENV{'REQUEST_METHOD'} = 'GET';
3572 :     $ENV{'QUERY_STRING'} = "user=$user&subsystem=$ssa&request=check_ssa";
3573 :     $checked = join("",`$FIG_Config::fig/CGI/check_subsys.cgi`);
3574 :     if ($checked =~ /^.*?(<form .*form>)/s)
3575 :     {
3576 :     return $1;
3577 :     }
3578 :     }
3579 :     return "";
3580 :     }
3581 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3