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

Annotation of /FigKernelScripts/salvage_subsystem_rows.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1 use FIG;
2 :     my $fig = new FIG;
3 :    
4 : overbeek 1.2 my $usage = "usage: salvage_subsystem_rows From To Maps";
5 : overbeek 1.1
6 :     # Foreach Subsystem in To (a directory of subsystems), if Subsystem is in From,
7 :     # then each row representing an organism in Mapping will be "salvaged" and added
8 :     # to Subsystem in To
9 :     #
10 :    
11 :     (
12 :     ($from = shift @ARGV) &&
13 :     ($to = shift @ARGV) &&
14 :     ($mapping = shift @ARGV)
15 :     )
16 :     || die $usage;
17 :    
18 : overbeek 1.2 foreach $_ (`cat $mapping/*`)
19 : overbeek 1.1 {
20 :     if ($_ =~ /^(fig\|(\d+\.\d+)\.peg\.\d+)\t(fig\|(\d+\.\d+)\.peg\.(\d+))$/)
21 :     {
22 :     $old{$2} = $4;
23 :     $map{$1} = $5;
24 :     }
25 :     }
26 :    
27 :     opendir(SUBS,$to) || die "could not open $to";
28 :     @subs = grep { $_ !~ /^\./ } readdir(SUBS);
29 :     closedir(SUBS);
30 :    
31 :     foreach $sub (@subs)
32 :     {
33 :     next if (! -d "$from/$sub/spreadsheet");
34 :    
35 :     undef %salvaged;
36 :     open(IN,"<$from/$sub/spreadsheet") || die "$from/$sub/spreadsheet";
37 :     while (defined($_ = <IN>))
38 :     {
39 :     if (($_ =~ /^(\d+\.\d+)\t(\S+)\t(.*)$/) && ($new = $old{$1}))
40 :     {
41 :     $var = $2;
42 :     @old_pegs = split(/\t/,$3);
43 :     @new_pegs = ();
44 :     foreach $peg (@old_pegs)
45 :     {
46 :     if ($peg && ($pegN = $map{$peg}))
47 :     {
48 :     push(@new_pegs,"fig|$new\.peg\.$pegN");
49 :     }
50 :     else
51 :     {
52 :     push(@new_pegs,"");
53 :     }
54 :     }
55 :     salvaged{$new} = join("\t",($new,$var,@new_pegs));
56 :     }
57 :     }
58 :     close(IN);
59 :    
60 :     open(IN,"<$to/$sub/spreadsheet") || die "$to/$sub/spreadsheet";
61 :     $/ = "\n//\n";
62 :     @spreadsheet = <IN>;
63 :     close(IN);
64 :    
65 :     open(OUT,">$to/$sub/spreadsheet") || die "$to/$sub/spreadsheet";
66 :     for ($i=0; ($i < @spreadsheet); $i++)
67 :     {
68 :     if ($i != 2)
69 :     {
70 :     print OUT $spreadsheet[$i];
71 :     }
72 :     else
73 :     {
74 :     $_ = spreadsheet[$i];
75 :     chomp;
76 :     @lines = split(/\n/,$_);
77 :     %in_already = map { $_ =~ /^(\d+\.\d+)/; $1 => 1 } @lines;
78 :     foreach $new (keys(%salvaged))
79 :     {
80 :     if (($new =~ /^(\d+\.\d+)/) && (! $in_already{$1}))
81 :     {
82 :     push(@lines,$salvaged{$new});
83 :     }
84 :     }
85 :     print OUT join("\n",@lines),$/;
86 :     }
87 :     }
88 :     close(OUT);
89 :     $/ = "\n";
90 :     }
91 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3