[Bio] / FigKernelScripts / install_new_coupling_data.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/install_new_coupling_data.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1 # -*- perl -*-
2 :     #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 :     use strict;
20 :     use Carp;
21 :     use Data::Dumper;
22 :     use File::Copy;
23 :    
24 :     #
25 :     # Install newly computed PCH data.
26 :     #
27 :     # For each file in the pchdir, skip if zero length.
28 :     # See if we already have a file with that name (genome) in the CouplingData/PCHs directory.
29 :     # If we do, we will replace it, and remove the scores for that genome's pegs from the
30 :     # CouplingData/scores file.
31 :     #
32 :     # Compute scores for the files we have added, and append to the scores file.
33 :     #
34 :    
35 :     use FIG;
36 :     use FIG_Config;
37 :    
38 : olson 1.3 my $usage = "usage: install_new_coupling_data [-jobdir jobdir] [Genome PCHs Scores]";
39 : olson 1.1
40 : olson 1.3 my($genome, $pchs_file, $scores_file);
41 :    
42 :     if (@ARGV ==2 and $ARGV[0] eq '-jobdir')
43 :     {
44 :     my $jd = $ARGV[1];
45 :    
46 :     $genome = &FIG::file_head("$jd/GENOME_ID");
47 :     chomp $genome;
48 :     $genome =~ /^\d+\.\d+$/ or die "Invalid jobdir or GENOME_ID file";
49 :     $pchs_file = "$jd/rp/$genome/pchs";
50 :     $scores_file = "$jd/rp/$genome/pchs.scored";
51 :     }
52 :     elsif (@ARGV == 3)
53 :     {
54 :     $genome = shift;
55 :     $pchs_file = shift;
56 :     $scores_file = shift;
57 :     }
58 :     else
59 : olson 1.1 {
60 :     die $usage;
61 :     }
62 :    
63 : olson 1.2 $genome =~ /^\d+\.\d+$/ or die "Invalid genome identifier $genome\n";
64 :     open(PCHS, "<$pchs_file") or die "Cannot open pchs file $pchs_file: $!";
65 :     open(SCORES, "<$scores_file") or die "Cannot open scores file $scores_file: $!";
66 : olson 1.1
67 : olson 1.2 my $did_replace;
68 : olson 1.1
69 : olson 1.2 my $dest = "$FIG_Config::data/CouplingData/PCHs/$genome";
70 :     if (-f $dest)
71 : olson 1.1 {
72 : olson 1.2 print "Replacing $genome\n";
73 :     copy($dest, "$FIG_Config::temp/$genome.$$") or die "Cannot copy $dest to $FIG_Config::temp/$genome.$$: $!\n";
74 :     print "Moved $dest to $FIG_Config::temp/pchs.$genome.$$\n";
75 :     $did_replace = 1;
76 : olson 1.1 }
77 : olson 1.2 else
78 : olson 1.1 {
79 : olson 1.2 print "New coupling data for $genome\n";
80 : olson 1.1 }
81 : olson 1.2 copy($pchs_file, $dest) or die "Cannot copy $pchs_file to $dest: $!\n";
82 : olson 1.1
83 :     #
84 :     # If we replaced, remove the replacement scores from the scores file.
85 :     #
86 :    
87 :     my $scores = "$FIG_Config::data/CouplingData/scores";
88 : olson 1.2 if ($did_replace)
89 : olson 1.1 {
90 :     my $bak = "$scores.bak.$$";
91 :     rename($scores, $bak) or die "Cannot rename $scores $bak: $!\n";
92 :    
93 :     open(B, "<$bak") or die "Cannot open $bak: $!\n";
94 :     open(S, ">$scores") or die "Cannot open $scores for writing: $!\n";
95 :    
96 :     while (<B>)
97 :     {
98 :     if (/^fig\|(\d+\.\d+)\.peg\.\d+/)
99 :     {
100 : olson 1.2 if ($1 ne $genome)
101 : olson 1.1 {
102 :     print S $_;
103 :     }
104 :     }
105 :     }
106 :     close(B);
107 :     close(S);
108 :     }
109 :    
110 :     open(S, ">>$scores") or die "Cannot open $scores for append: $!\n";
111 : olson 1.2 copy(\*SCORES, \*S);
112 : olson 1.1 close(S);
113 : olson 1.2 close(SCORES);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3