[Bio] / FigKernelPackages / P2Pupdate.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/P2Pupdate.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (view) (download) (as text)

1 : efrank 1.1 package P2Pupdate;
2 :    
3 :     use FIG_Config;
4 :     use FIG;
5 :     use Carp;
6 :     use Data::Dumper;
7 :     use Cwd;
8 :    
9 :     =pod
10 :    
11 :     =head1 updating code
12 :    
13 :     This routine packages what is needed to upgrade an older system to the
14 :     current code. Code releases are numered
15 :    
16 :     p1n1.p2n2.p3n3...
17 :    
18 :     where "." is added at the point the code moved to another branch of
19 :     the tree. FIG, who provided the initial release of the SEED, will
20 :     number all of their code releases as
21 :    
22 :     FIGn
23 :    
24 :     where n is an integer. Suppose that between releases 13 and 14 a
25 :     second group (which we will term "Idiots" for convenience) took
26 :     release 13 and wished to branch the code tree. At that point, they
27 :     would name their first release as
28 :    
29 :     FIG13.Idiots1
30 :    
31 :     We are, of course, being both cavalier and nasty when we make such a
32 :     reference. We do, however, wish to express the view that it will
33 :     benefit everyone to attempt to reconcile differences and maintain a
34 :     single code progression as long as possible. There are often good
35 :     reasons to part ways, but we urge people to think carefully before
36 :     taking such a step.
37 :    
38 :     Two code releases
39 :    
40 :     i1.i2.i3...in
41 :     and j1.j2.j3...jm with m <= n
42 :    
43 :     are compatible iff
44 :    
45 :     ip == jp for p < m, and
46 :     jm and im have the same "source" and
47 :     jm <= im
48 :    
49 :     A new code release must have the property that it can bring any
50 :     "older" compatible release up to its release.
51 :    
52 :     Note that there is an issue relating to the code to build/install packages.
53 :     Since a system may be radically restructured between releases of code, the
54 :     code to build a "package" and the code to "install" a package are radically
55 :     separated. For example, the code in P2Pupdate.pm for building an assignment
56 :     package and the code for installing an assignment package both apply to the
57 :     release of code current on the system containing P2Pupdate.pm. In fact, the
58 :     code releases may be quite different on two synchronizing systems.
59 :    
60 :     To make things work the following rules must be observed:
61 :    
62 :     1. a code release is a tar file containing VERSION, Packages,
63 :     bin/ToolTemplates, and CGI/ToolTemplates. The installing system needs
64 :     to place these at the appropriate spots, and then run bring_system_up_to_date,
65 :     which is supposed to do any required restructuring.
66 :    
67 :     2. an assignments package is a tar file containing a single directory. The directory
68 :     contains subdirectories -- one per genome. Each genome subdirectory contains zero
69 :     or more files. The name of the file is the "user" and the contents will be the
70 :     assignments made by that user.
71 :    
72 :     3. an annotations package is a tar file containing a single directory. The files in
73 :     the directory are named by genome. They contain the annotations for the genome.
74 :    
75 :     =cut
76 :    
77 :     =pod
78 :    
79 :     =head1 what_code_do_I_have
80 :    
81 :     usage: &what_code_do_I_have($fig_base)
82 :    
83 :     This just returns the current version of the code.
84 :    
85 :     =cut
86 :    
87 :     sub what_code_do_I_have {
88 :     my($fig_base) = @_;
89 :    
90 :     my $version = `cat $fig_base/VERSION`;
91 :     chop $version;
92 :     return $version;
93 :     }
94 :    
95 :     =pod
96 :    
97 :     =head1 updatable_code
98 :    
99 :     usage: &updatable_code_code($v1,$v2)
100 :    
101 :     This just returns true iff the two versions of code are compatible and $v1
102 :     is "more recent".
103 :    
104 :     =cut
105 :    
106 :     sub updatable_code {
107 :     my($v1,$v2) = @_;
108 :     my($i,$v1p,$v1n,$v2p,$v2n);
109 :    
110 :     my @v1 = split(/\./,$v1);
111 :     my @v2 = split(/\./,$v2);
112 :     if (@v1 < @v2) { return 0 }
113 :    
114 :     for ($i=0; ($i < $#v2) && ($v1[$i] eq $v2[$i]); $i++) {}
115 :     if ($i == $#v2)
116 :     {
117 :     $v1[$i] =~ /^(.*[^\d])(\d+)$/;
118 :     $v1p = $1;
119 :     $v1n = $2;
120 :    
121 :     $v2[$i] =~ /^(.*[^\d])(\d+)$/;
122 :     $v2p = $1;
123 :     $v2n = $2;
124 :    
125 :     return (($v2p eq $v1p) && ($v2n < $v1n));
126 :     }
127 :     return 0;
128 :     }
129 :    
130 :     =pod
131 :    
132 :     =head1 package_code
133 :    
134 :     usage: &package_code($fig_disk,$file)
135 :    
136 :     $fig_base must be an absolute filename (begins with "/") giving the FIG from which
137 :     the updated code release will be taken.
138 :    
139 :     $file must be an absolute filename where the "code package" will be built.
140 :    
141 :     =cut
142 :    
143 :     sub package_code {
144 :     my($fig_disk,$file) = @_;
145 :    
146 :     &force_absolute($fig_disk);
147 :     &force_absolute($file);
148 : overbeek 1.2 my @tmp = `cat $fig_disk/CURRENT_RELEASE`;
149 :     my $current_release = $tmp[0];
150 :     chop $current_release;
151 :    
152 :     &FIG::run("cd $fig_disk/dist/releases; tar czf $file $current_release");
153 : efrank 1.1 }
154 :    
155 :     sub force_absolute {
156 :     my($file) = @_;
157 :    
158 :     if (substr($file,0,1) ne "/")
159 :     {
160 : overbeek 1.2 print "Error: Please use absolute file names (i.e., /Users/fig/... or /home/fig/...)\n";
161 :     exit;
162 : efrank 1.1 }
163 :     }
164 :    
165 :     =pod
166 :    
167 :     =head1 install_code
168 :    
169 :     usage: &install_code($fig_disk,$package)
170 :    
171 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
172 :    
173 :     $package must be an absolute filename where the "code package" from which to make
174 :     the update exists.
175 :    
176 :     Note that this routine does not check that the updated code is compatible, or even less
177 :     current. It is assumed that upper level logic is doing that.
178 :    
179 :     =cut
180 :    
181 :     sub install_code {
182 :     my($fig_disk,$package) = @_;
183 :     my $fig_base = "$fig_disk/FIG";
184 :     &force_absolute($fig_base);
185 :     &force_absolute($package);
186 :    
187 :     if (getcwd() !~ /FIGdisk$/) { print die "Sorry, you must run this while in $FIG_Config::fig_disk" }
188 :    
189 :    
190 :     (! -d "$fig_disk/BackupCode") || &FIG::run("rm -rf $fig_disk/BackupCode");
191 :     mkdir("$fig_disk/BackupCode",0777) || die "Could not make the BackupCode directory";
192 :     (! -d "$fig_disk/BackupEnv") || &FIG::run("rm -rf $fig_disk/BackupEnv");
193 :     mkdir("$fig_disk/BackupEnv",0777) || die "Could not make the BackupEnv directory";
194 :    
195 :     my $version = &what_code_do_I_have($fig_base);
196 :     &FIG::run("cd $fig_disk; mv README install lib man env src $fig_disk/BackupEnv");
197 :     &FIG::run("cd $fig_base; mv VERSION Packages CGI $fig_disk/BackupCode");
198 :     print STDERR "made backups\n";
199 :    
200 :     &FIG::run("cd $fig_disk; tar xzf $package");
201 :     print STDERR "untarred new code\n";
202 :    
203 :     &fix_config("$fig_base/Packages/FIG_Config.pm","$fig_disk/BackupCode/Packages/FIG_Config.pm");
204 :     &FIG::run("cd $fig_base/bin; touch ToolTemplates/*/*; make all");
205 :     &FIG::run("cd $fig_base/CGI; touch ToolTemplates/*/*; make all");
206 :     print STDERR "installed new bin and CGI\n";
207 :    
208 :     &FIG::run("bring_system_up_to_date $version");
209 :     }
210 :    
211 :     =pod
212 :    
213 :     =head1 package_lightweight_code
214 :    
215 :     usage: &package_lightweight_code($fig_disk,$file)
216 :    
217 :     $fig_base must be an absolute filename (begins with "/") giving the FIG from which
218 :     the updated code release will be taken.
219 :    
220 :     $file must be an absolute filename where the "code package" will be built.
221 :    
222 :     =cut
223 :    
224 :     sub package_lightweight_code {
225 :     my($fig_disk,$file) = @_;
226 :    
227 :     &force_absolute($fig_disk);
228 :     &force_absolute($file);
229 : overbeek 1.2 my @tmp = `cat $fig_disk/CURRENT_RELEASE`;
230 :     my $current_release = $tmp[0];
231 :     chop $current_release;
232 :    
233 :     &FIG::run("cd $fig_disk/dist/releases; tar czf $file $current_release");
234 : efrank 1.1 }
235 :    
236 :     =pod
237 :    
238 :     =head1 install_lightweight_code
239 :    
240 :     usage: &install_lightweight_code($fig_disk,$package)
241 :    
242 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
243 :    
244 :     $package must be an absolute filename where the "code package" from which to make
245 :     the update exists.
246 :    
247 :     Note that this routine does not check that the updated code is compatible, or even less
248 :     current. It is assumed that upper level logic is doing that.
249 :    
250 :     =cut
251 :    
252 :     sub install_lightweight_code {
253 :     my($fig_disk,$package) = @_;
254 :     my $fig_base = "$fig_disk/FIG";
255 :     &force_absolute($fig_base);
256 :     &force_absolute($package);
257 :    
258 : overbeek 1.2 if (! mkdir("$fig_disk/Tmp$$",0777))
259 :     {
260 :     print "Error: could not make $fig_disk/Tmp$$\n";
261 :     exit;
262 :     }
263 : efrank 1.1
264 : overbeek 1.2 &FIG::run("cd $fig_disk/Tmp$$; tar xzf $package");
265 :     if (! opendir(TMP,"$fig_disk/Tmp$$"))
266 :     {
267 :     print "Error: could not open $fig_disk/Tmp$$\n";
268 :     exit;
269 :     }
270 : efrank 1.1
271 : overbeek 1.2 my @rels = grep { $_ !~ /^\./ } readdir(TMP);
272 :     closedir(TMP);
273 :     if (@rels != 1)
274 :     {
275 :     print "Error: Bad code package: $package\n";
276 :     exit;
277 :     }
278 : efrank 1.1
279 : overbeek 1.2 my $new_release = $rels[0];
280 :     if (-d "$fig_disk/dist/releases/$new_release")
281 :     {
282 :     print "Error: $new_release already exists; we are doing nothing\n";
283 :     exit;
284 :     }
285 : efrank 1.1
286 : efrank 1.3 &FIG::run("mv $fig_disk/Tmp$$/$new_release $fig_disk/dist/releases");
287 :     &FIG::run("rm -rf $fig_disk/Tmp$$");
288 : olson 1.22
289 :     #
290 :     # Ugh. For now, find the arch in the fig config file $fig_disk/config/fig-user-env.sh"
291 :     #
292 :    
293 :     my $arch;
294 :     open(FH, "<$fig_disk/config/fig-user-env.sh");
295 :     while (<FH>)
296 :     {
297 :     if (/RTARCH="(.*)"/)
298 :     {
299 :     $arch = $1;
300 :     last;
301 :     }
302 :     }
303 :     close(FH);
304 :    
305 :     if ($arch eq "")
306 :     {
307 :     die "Couldn't determine SEED install architecture, not switching to release.";
308 :     }
309 :    
310 :     $ENV{RTARCH} = $arch;
311 :    
312 : efrank 1.9 &FIG::run("$FIG_Config::bin/switch_to_release $new_release");
313 : efrank 1.1 }
314 :    
315 :    
316 :     sub fix_config {
317 :     my($new,$old) = @_;
318 :     my($line,$i);
319 :    
320 :     my @new = `cat $new`;
321 :     foreach $line (`cat $old`)
322 :     {
323 :     if ($line =~ /^(\S+)\s+\=/)
324 :     {
325 :     $var = $1;
326 :     $varQ = quotemeta $var;
327 :    
328 :     for ($i=0; ($i < $#new) && ($new[$i] !~ /^$varQ\s+\=/); $i++) {}
329 :     if ($i == $#new)
330 :     {
331 :     splice(@new,$i,0,$line);
332 :     }
333 :     else
334 :     {
335 :     splice(@new,$i,1,$line);
336 :     }
337 :     }
338 :     }
339 :     open(NEW,">$new") || confess "could not overwrite $new";
340 :     foreach $line (@new)
341 :     {
342 :     print NEW $line;
343 :     }
344 :     close(NEW);
345 :     }
346 :    
347 :     =pod
348 :    
349 :     =head1 what_genomes_will_I_sync
350 :    
351 :     usage: &what_genomes_will_I_sync($fig_base,$who)
352 :    
353 :     This routine returns the list of genome IDs that you are willing to sync with $who.
354 :    
355 :     =cut
356 :    
357 :     sub what_genomes_will_I_sync {
358 :     my($fig_base,$who) = @_;
359 :    
360 :     # This is the promiscuous version - it will sync all genomes with anyone.
361 :    
362 :     opendir(GENOMES,"$fig_base/Data/Organisms") || die "could not open $fig_base/Data/Organisms";
363 :     my @genomes = grep { $_ =~ /^\d+\.\d+$/ } readdir(GENOMES);
364 :     closedir(GENOMES);
365 :     return @genomes;
366 :     }
367 :    
368 :     =pod
369 :    
370 :     =head1 package_annotations
371 :    
372 : overbeek 1.29 usage: &package_annotations($fig,$genomes,$file)
373 : efrank 1.1
374 :     $genomes is a pointer to a list of genome IDs that will be exchanged.
375 :    
376 :     $file must be an absolute filename where the "annotation package" will be built.
377 :    
378 :     =cut
379 :    
380 :     sub package_annotations {
381 : overbeek 1.29 my($fig,$who,$date,$genomes,$file) = @_;
382 :     my $fig_base = "$FIG_Config::fig_disk/FIG";
383 : efrank 1.1
384 : overbeek 1.29 if (open(ANNOTATIONS,">$file"))
385 : efrank 1.1 {
386 : overbeek 1.29 my @annotations = sort { $a->[0] cmp $b->[0] } $fig->annotations_made($genomes,$who,$date);
387 :     foreach $x (@annotations)
388 : efrank 1.1 {
389 : overbeek 1.29 print ANNOTATIONS join("\n",@$x),"\n///\n";
390 : efrank 1.1 }
391 : overbeek 1.29 print ANNOTATIONS "//\n";
392 : efrank 1.15
393 : overbeek 1.29 foreach $x (@annotations)
394 : efrank 1.15 {
395 : overbeek 1.29 $peg = $x->[0];
396 :     my @aliases = grep { $_ =~ /^(sp\||gi\||pirnr\||kegg\||N[PGZ]_)/ } $self->feature_aliases($peg);
397 :     print ANNOTATIONS join("\t",($peg,join(",",@aliases),$self->genus_species($self->genome_of($peg)),scalar $self->function_of($peg))) . "\n";
398 : efrank 1.15 }
399 : overbeek 1.29 print ANNOTATIONS "//\n";
400 :    
401 :     foreach $x (@annotations)
402 : efrank 1.15 {
403 : overbeek 1.29 ($peg,undef) = @$x;
404 :     my $seq = $self->get_translation($peg);
405 :     &FIG::display_id_and_seq($peg,\$seq,\*ANNOTATIONS);
406 : efrank 1.15 }
407 : overbeek 1.29 close(ANNOTATIONS);
408 : efrank 1.15 }
409 : efrank 1.1 }
410 :    
411 : overbeek 1.29
412 : efrank 1.1 =pod
413 :    
414 :     =head1 install_annotations
415 :    
416 :     usage: &install_annotations($fig_disk,$package)
417 :    
418 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
419 :    
420 :     $package must be an absolute filename where the "annotations package" from which to make
421 :     the update exists.
422 :    
423 :     =cut
424 :    
425 :     sub install_annotations {
426 : overbeek 1.29 my($fig,$package) = @_;
427 :     my($user,$who,$date,$userR,@assignments,$peg,$aliases,$org,$func);
428 :     my(%pegs,%seq_of,@seq,$peg_to,$trans_pegs,$seq,$line,@ann,$ann);
429 : efrank 1.1 my($genome);
430 :    
431 : overbeek 1.29 my $fig_disk = $FIG_Config::fig_disk;
432 :     open(IN,"<$package") || die "could not open $package";
433 :     $/ = "\n//\n";
434 :     if (defined($line = <IN>))
435 :     {
436 :     $line =~ s/\n\/\/\n/\n/s;
437 :     $line =~ s/\n\/\/\/\n//s;
438 :     @ann = split(/\n\/\/\/\n/,$line);
439 :     foreach $ann (@ann)
440 :     {
441 :     if ($ann =~ /^(fig\|\d+\.\d+\.peg\.\d+)\n(\d+)\n(\S+)\n(.*)/s)
442 :     {
443 :     push(@annotations,[$1,$2,$3,$4]);
444 :     }
445 :     }
446 :     $/ = "\n";
447 :     while ($line && defined($line = <IN>) && ($line !~ /^\/\//))
448 :     {
449 :     chop $line;
450 :     ($peg,$aliases,$org,$func) = split(/\t/,$line);
451 :     $pegs{$peg} = [$aliases,$org,$func];
452 :     }
453 :    
454 :     if ($line) { $line = <IN> }
455 :     while (defined($line) && ($line !~ /^\/\//))
456 :     {
457 :     if ($line =~ /^>(\S+)/)
458 :     {
459 :     $peg = $1;
460 :     @seq = ();
461 :     while (defined($line = <IN>) && ($line !~ /^[>\/]/) && ($line !~ /^\/\//))
462 :     {
463 :     push(@seq,$line);
464 :     $line = <IN>;
465 :     }
466 :     $seq = join("",@seq);
467 :     $seq =~ s/[ \n\t]//gs;
468 :     $seq_of{$peg} = uc $seq;
469 :     }
470 :     }
471 :     close(IN);
472 :     $trans_pegs = $fig->translate_pegs(\%pegs,\%seq_of);
473 :     @annotations = sort { ($a->[0] cmp $b->[0]) or ($a->[1] <=> $b->[1]) }
474 :     map { ($peg = $trans_pegs->{$_->[0]}) ? [$peg,$_->[1],$_->[2],$_->[3]] : () }
475 :     @annotations;
476 :    
477 :     if (-d "$fig_disk/BackupAnnotations") { system "rm -rf $fig_disk/BackupAnnotations" }
478 :     mkdir("$fig_disk/BackupAnnotations",0777);
479 :     mkdir("$fig_disk/BackupAnnotations/New",0777);
480 :     for ($i=0; ($i < @annotation); $i++)
481 :     {
482 :     if (($i == 0) || ($fig->genome_of($annotations[$i]->[0]) ne $fig->genome_of($annotations[$i-1]->[0])))
483 :     {
484 :     if ($i != 0)
485 :     {
486 :     close(OUT);
487 :     }
488 :     $genome = $fig->genome_of($annotations[$i]->[0]);
489 :     open(OUT,">$fig_disk/BackupAnnotations/New/$genome")
490 :     || die "could not open $fig_disk/BackupAnnotations/New/$genome";
491 :     }
492 :     print OUT join("\n",@{$annotations[$i]}),"\n//\n";
493 :     }
494 :     if ($i > 0) { close(OUT) }
495 :     }
496 : efrank 1.15
497 : efrank 1.1 opendir(TMP,"$fig_disk/BackupAnnotations/New") || die "could not open $fig_disk/BackupAnnotations/New";
498 :     my @genomes = grep { $_ =~ /^\d+\.\d+$/ } readdir(TMP);
499 :     closedir(TMP);
500 :     foreach $genome (@genomes)
501 :     {
502 : efrank 1.14 next if (! -d "$fig_disk/FIG/Data/organisms/$genome");
503 : efrank 1.13
504 : efrank 1.1 print STDERR "installing $fig_disk/FIG/Data/Organisms/$genome/annotations\n";
505 :     if (-s "$fig_disk/FIG/Data/Organisms/$genome/annotations")
506 :     {
507 :     &FIG::run("cp -p $fig_disk/FIG/Data/Organisms/$genome/annotations $fig_disk/BackupAnnotations/$genome");
508 : efrank 1.9 &FIG::run("$FIG_Config::bin/merge_annotations $fig_disk/BackupAnnotations/$genome $fig_disk/BackupAnnotations/New/$genome > $fig_disk/FIG/Data/Organisms/$genome/annotations");
509 : efrank 1.1 }
510 :     else
511 :     {
512 :     &FIG::run("cp $fig_disk/BackupAnnotations/New/$genome $fig_disk/FIG/Data/Organisms/$genome/annotations");
513 :     }
514 :     chmod 0777,"$fig_disk/FIG/Data/Organisms/$genome/annotations";
515 :     }
516 : efrank 1.9 &FIG::run("$FIG_Config::bin/index_annotations");
517 : efrank 1.1 }
518 :    
519 :     =pod
520 :    
521 :     =head1 restore_annotations
522 :    
523 :     usage: &restore_annotations($fig_disk);
524 :    
525 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
526 :    
527 :     =cut
528 :    
529 :     sub restore_annotations {
530 :     my($fig_disk) = @_;
531 :    
532 :     &force_absolute($fig_disk);
533 :     (-d "$fig_disk/BackupAnnotations") || die "could not find an active backup";
534 :     opendir(TMP,"$fig_disk/BackupAnnotations") || die "could not open $fig_disk/BackupAnnotations";
535 :     my @genomes = grep { $_ =~ /^\d+\.\d+$/ } readdir(TMP);
536 :     closedir(TMP);
537 :     foreach $genome (@genomes)
538 :     {
539 :     unlink("$fig_disk/FIG/Data/Organisms/$genome/annotations");
540 :     &FIG::run("cp $fig_disk/BackupAnnotations/$genome $fig_disk/FIG/Data/Organisms/$genome/annotations");
541 :     system "chmod 777 $fig_disk/FIG/Data/Organisms/$genome/annotations";
542 :     }
543 : efrank 1.9 &FIG::run("$FIG_Config::bin/index_annotations");
544 : efrank 1.1 }
545 :    
546 :     =pod
547 :    
548 :     =head1 package_aassignments
549 :    
550 : overbeek 1.20 usage: package_assignments($fig,$user,$who,$date,$genomes,$file)
551 : efrank 1.1
552 : overbeek 1.20 $user designates the user wishing to get the assignments
553 : efrank 1.1
554 : overbeek 1.5 $who designates whose assignments you want (defaults to "master")
555 :    
556 :     $date if given indicates a point in time (get assignments after that point)
557 :    
558 : efrank 1.1 $genomes is a pointer to a list of genome IDs that will be exchanged.
559 :    
560 :     $file must be an absolute filename where the "assignment package" will be built.
561 :    
562 :     =cut
563 :    
564 :     sub package_assignments {
565 : overbeek 1.20 my($fig,$user,$who,$date,$genomes,$file) = @_;
566 : overbeek 1.27 my($genome,$x,$org,$curr,$peg);
567 : overbeek 1.4 $who = $who ? $who : "master";
568 : overbeek 1.7 $date = $date ? $date : 0;
569 : overbeek 1.27
570 : overbeek 1.20 if (open(ASSIGNMENTS,">$file"))
571 : efrank 1.1 {
572 : overbeek 1.20 print ASSIGNMENTS "$user\t$who\t$date\n";
573 : overbeek 1.27 my @assignments = sort { $a->[0] cmp $b->[0] } $fig->assignments_made($genomes,$who,$date);
574 :     foreach $x (@assignments)
575 : efrank 1.1 {
576 : overbeek 1.20 print ASSIGNMENTS join("\t",@$x),"\n";
577 : overbeek 1.4 }
578 : overbeek 1.27 print ASSIGNMENTS "//\n";
579 :    
580 :     foreach $x (@assignments)
581 :     {
582 :     ($peg,undef) = @$x;
583 : overbeek 1.28 my @aliases = grep { $_ =~ /^(sp\||gi\||pirnr\||kegg\||N[PGZ]_)/ } $self->feature_aliases($peg);
584 :     print ASSIGNMENTS join("\t",($peg,join(",",@aliases),$self->genus_species($self->genome_of($peg)),scalar $self->function_of($peg))) . "\n";
585 :     }
586 :     print ASSIGNMENTS "//\n";
587 :    
588 :     foreach $x (@assignments)
589 :     {
590 :     ($peg,undef) = @$x;
591 : overbeek 1.27 my $seq = $self->get_translation($peg);
592 :     &FIG::display_id_and_seq($peg,\$seq,\*ASSIGNMENTS);
593 :     }
594 :     close(ASSIGNMENTS);
595 : efrank 1.1 }
596 :     }
597 :    
598 :     =pod
599 :    
600 :     =head1 install_assignments
601 :    
602 : overbeek 1.20 usage: &install_assignments($package)
603 : efrank 1.1
604 : overbeek 1.20 $package must be a filename where the "assignments package" from which to make
605 :     the assignment set exists
606 : efrank 1.1
607 :     =cut
608 :    
609 :     sub install_assignments {
610 : overbeek 1.29 my($fig,$package) = @_;
611 :     my($user,$who,$date,$userR,@assignments,$peg,$aliases,$org,$func);
612 :     my(%pegs,%seq_of,@seq,$peg_to,$trans_pegs,$seq);
613 : efrank 1.1
614 : overbeek 1.20 open(IN,"<$package") || die "could not open $package";
615 :     my $line = <IN>;
616 :     chop $line;
617 :     ($user,$who,$date) = split(/\t/,$line);
618 : olson 1.26 $userR = $user;
619 :     $userR =~ s/^master://;
620 : overbeek 1.29
621 :     while (defined($line = <IN>) && ($line !~ /^\/\./))
622 :     {
623 :     if ($line =~ /^(fig\|\d+\.\d+\.peg\.\d+)\t(\S.*\S)/)
624 :     {
625 :     push(@assignments,[$1,$2]);
626 :     }
627 :     }
628 :     while ($line && defined($line = <IN>) && ($line !~ /^\/\//))
629 :     {
630 :     chop $line;
631 :     ($peg,$aliases,$org,$func) = split(/\t/,$line);
632 :     $pegs{$peg} = [$aliases,$org,$func];
633 :     }
634 :    
635 :     if ($line) { $line = <IN> }
636 :     while (defined($line) && ($line !~ /^\/\//))
637 :     {
638 :     if ($line =~ /^>(\S+)/)
639 :     {
640 :     $peg = $1;
641 :     @seq = ();
642 :     while (defined($line = <IN>) && ($line !~ /^[>\/]/) && ($line !~ /^\/\//))
643 :     {
644 :     push(@seq,$line);
645 :     $line = <IN>;
646 :     }
647 :     $seq = join("",@seq);
648 :     $seq =~ s/[ \n\t]//gs;
649 :     $seq_of{$peg} = uc $seq;
650 :     }
651 :     }
652 :     close(IN);
653 :     $trans_pegs = $fig->translate_pegs(\%pegs,\%seq_of);
654 :    
655 : olson 1.26 &FIG::verify_dir("$FIG_Config::data/Assignments/$userR");
656 : overbeek 1.29 my $file = &FIG::epoch_to_readable($date) . ":$who:imported";
657 : overbeek 1.20 $file =~ s/\//-/g;
658 : olson 1.26 open(OUT,">$FIG_Config::data/Assignments/$userR/$file")
659 :     || die "could not open $FIG_Config::data/Assignments/$userR/$file";
660 : overbeek 1.29
661 :     foreach $peg (keys(%$trans_pegs))
662 : overbeek 1.20 {
663 : overbeek 1.29 $peg_to = $trans_pegs->{$peg};
664 :     $func = $pegs{$peg}->[2];
665 :     if ($fig->function_of($peg_to) ne $func)
666 :     {
667 :     print OUT "$peg_to\t$func\n";
668 :     }
669 : overbeek 1.20 }
670 : overbeek 1.29
671 : overbeek 1.20 close(OUT);
672 : olson 1.26 if (! -s "$FIG_Config::data/Assignments/$userR/$file") { unlink("$FIG_Config::data/Assignments/$userR/$file") }
673 : efrank 1.1 }
674 :    
675 :     =pod
676 :    
677 :     =head1 package_translation_rules
678 :    
679 :     usage: &package_translation_rules($fig_base,$file)
680 :    
681 :     $fig_base must be an absolute filename (begins with "/") giving the FIG from which
682 :     the updated code release will be taken.
683 :    
684 :     $file must be an absolute filename where the "translation_rules package" will be built.
685 :    
686 :     =cut
687 :    
688 :     sub package_translation_rules {
689 :     my($fig_base,$file) = @_;
690 :    
691 :     &force_absolute($fig_base);
692 :     &force_absolute($file);
693 :     &FIG::run("cp $fig_base/Data/Global/function.synonyms $file");
694 :     }
695 :    
696 :     =pod
697 :    
698 :     =head1 install_translation_rules
699 :    
700 : efrank 1.10 usage: &install_translation_rules($fig_disk,$from,$package)
701 : efrank 1.1
702 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
703 :    
704 :     $package must be an absolute filename where the "translation_rules package" from which to make
705 :     the update exists.
706 :    
707 :     =cut
708 :    
709 :     sub install_translation_rules {
710 : efrank 1.10 my($fig_disk,$from,$package) = @_;
711 : efrank 1.1
712 :     my $file = "$fig_disk/FIG/Data/Global/function.synonyms";
713 :     &force_absolute($fig_disk);
714 :     if (-d "$fig_disk/BackupTranslation_Rules") { system "rm -rf $fig_disk/BackupTranslation_Rules" }
715 :     mkdir("$fig_disk/BackupTranslation_Rules",0777);
716 : efrank 1.11 chmod 0777,"$fig_disk/BackupTranslation_Rules";
717 : efrank 1.1 if (-s $file)
718 :     {
719 :     &FIG::run("cp $file $fig_disk/BackupTranslation_Rules");
720 :     }
721 : efrank 1.10 &FIG::run("$FIG_Config::bin/merge_translation_rules $fig_disk/BackupTranslation_Rules/function.synonyms $package $from > $file");
722 : efrank 1.1 chmod 0777,$file;
723 :     }
724 :    
725 :     =pod
726 :    
727 :     =head1 restore_translation_rules
728 :    
729 :     usage: &restore_translation_rules($fig_disk);
730 :    
731 :     $fig_disk must be an absolute filename (begins with "/") giving the FIG to be updated.
732 :    
733 :     =cut
734 :    
735 :     sub restore_translation_rules {
736 :     my($fig_disk) = @_;
737 :    
738 :     &force_absolute($fig_disk);
739 :    
740 :     my $file = "$fig_disk/FIG/Data/Global/function.synonyms";
741 :     (-s "$fig_disk/BackupTranslation_Rules/function.synonyms") || die "could not find an active backup";
742 :     if (-s "$fig_disk/BackupTranslation_Rules/function.synonyms")
743 :     {
744 :     &FIG::run("cp $fig_disk/BackupTranslation_Rules/function.synonyms $file");
745 :     chmod 0777, $file;
746 :     }
747 :     }
748 :    
749 : overbeek 1.23 sub package_subsystems {
750 : overbeek 1.27 my($file,$just_exchangable) = @_;
751 : overbeek 1.23 my($ssa);
752 :    
753 : overbeek 1.27 $just_exchangable = defined($just_exchangable) ? $just_exchangable : 1;
754 :     my @exchangable = grep { (! $just_exchangable) || $fig->is_exchangable_subsystem($_) }
755 :     $fig->all_subsystems;
756 :    
757 : overbeek 1.23 my $fig = new FIG;
758 : overbeek 1.24 if ((@exchangable > 0) && open(SUB,">$file"))
759 : overbeek 1.23 {
760 : overbeek 1.24 foreach $ssa (@exchangable)
761 : overbeek 1.23 {
762 : overbeek 1.25 # print STDERR "writing $ssa to $file\n";
763 :     my($spreadsheet,$notes) = $fig->exportable_subsystem($ssa);
764 : overbeek 1.23 print SUB join("",@$spreadsheet),join("",@$notes),"########################\n";
765 :     }
766 :     close(SUB);
767 :     }
768 : overbeek 1.25 else
769 :     {
770 :     # print STDERR &Dumper(\@exchangable,$file);
771 :     }
772 : overbeek 1.23 }
773 :    
774 : efrank 1.1 1

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3