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

Diff of /FigKernelScripts/salvage_subsystem_rows.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3, Mon Dec 5 18:56:38 2005 UTC revision 1.4, Thu Jan 5 01:09:56 2006 UTC
# Line 1  Line 1 
1    ########################################################################
2  #  #
3  # Copyright (c) 2003-2006 University of Chicago and Fellowship  # Copyright (c) 2003-2006 University of Chicago and Fellowship
4  # for Interpretations of Genomes. All Rights Reserved.  # for Interpretations of Genomes. All Rights Reserved.
# Line 18  Line 19 
19  use FIG;  use FIG;
20  my $fig = new FIG;  my $fig = new FIG;
21    
22  my $usage = "usage: salvage_subsystem_rows From To Maps";  my $usage = "usage: salvage_subsystem_rows From To Maps [ToData]";
23    
24  # Foreach Subsystem in To (a directory of subsystems), if Subsystem is in From,  # Foreach Subsystem in To (a directory of subsystems), if Subsystem is in From,
25  # then each row representing an organism in Mapping will be "salvaged" and added  # then each row representing an organism in Mapping will be "salvaged" and added
26  # to Subsystem in To  # to Subsystem in To.  If ToData is included, then any subsystems in From, but not in To
27    # will be copied to To (deleting rows for genomes not in ToData)
28  #  #
29    
30  (  (
# Line 32  Line 34 
34  )  )
35      || die $usage;      || die $usage;
36    
37    my $tmpF = "$FIG_Config::temp/extract_subsystems.$$";
38    if (@ARGV == 1)
39    {
40        open(TMP,">$tmpF")
41            || die "could not open $tmpF";
42        while (defined($_ = <DATA>))
43        {
44            print TMP $_;
45        }
46        close(TMP);
47        &copy_new($from,$to,$ARGV[0],$tmpF);
48    }
49    
50  foreach $_ (`cat $mapping/*`)  foreach $_ (`cat $mapping/*`)
51  {  {
52      if ($_ =~ /^(fig\|(\d+\.\d+)\.peg\.\d+)\t(fig\|(\d+\.\d+)\.peg\.(\d+))$/)      if ($_ =~ /^(fig\|(\d+\.\d+)\.peg\.\d+)\t(fig\|(\d+\.\d+)\.peg\.(\d+))$/)
# Line 48  Line 63 
63  foreach $sub (@subs)  foreach $sub (@subs)
64  {  {
65      next if (! -d "$from/$sub/spreadsheet");      next if (! -d "$from/$sub/spreadsheet");
66        print STDERR "updating $sub\n";
67      undef %salvaged;      undef %salvaged;
68      open(IN,"<$from/$sub/spreadsheet") || die "$from/$sub/spreadsheet";      open(IN,"<$from/$sub/spreadsheet") || die "$from/$sub/spreadsheet";
69      while (defined($_ = <IN>))      while (defined($_ = <IN>))
# Line 88  Line 103 
103          }          }
104          else          else
105          {          {
106              $_ = spreadsheet[$i];              $_ = $spreadsheet[$i];
107              chomp;              chomp;
108              @lines = split(/\n/,$_);              @lines = split(/\n/,$_);
109              %in_already = map { $_ =~ /^(\d+\.\d+)/; $1 => 1 } @lines;              %in_already = map { $_ =~ /^(\d+\.\d+)/; $1 => 1 } @lines;
# Line 105  Line 120 
120      close(OUT);      close(OUT);
121      $/ = "\n";      $/ = "\n";
122  }  }
123    if (@ARGV == 1) { unlink($tmpF); }
124    
125    sub copy_new {
126        my($from,$to,$to_data,$tmpF) = @_;
127    
128        opendir(ORG,"$to_data/Organisms") || die "$to/Organisms does not exist";
129        my @orgs = grep { $_ =~ /^\d+\.\d+$/ } readdir(ORG);
130        closedir(ORG);
131    
132        opendir(FROM,$from) || die "could not open $from";
133        my @subsystems = grep { $_ !~ /^\./ } readdir(FROM);
134        closedir(FROM);
135    
136        foreach my $subsystem (@subsystems)
137        {
138            if (! -d "$to/$subsystem")
139            {
140                print STDERR "copying $subsystem\n";
141                &filter_genomes("$from/$subsystem","$to/$subsystem",\@orgs,$subsystem,$tmpF);
142            }
143        }
144    }
145    
146    sub filter_genomes {
147        my($from,$to,$orgs,$subsystem,$tmpF) = @_;
148    
149        my $genomesF = "$FIG_Config::temp/genomes.$$";
150        open(TMP,">$genomesF") || die "could not open $genomesF";
151        foreach $org (@orgs)
152        {
153            print TMP "$org\n";
154        }
155        close(TMP);
156    
157        my $rc = system("extract_genomes",$genomesF,$from,$to,$tmpF);
158        if ($rc != 0)
159        {
160            print STDERR "failed to copy $from $to\n";
161        }
162        unlink($genomesF);
163    }
164    
165    __DATA__
166    /^\S.*\S$/
167            Alignments,erase
168            Backup,erase
169            /^[CEV].*$/,copy
170            curation.log,copy
171            notes,copy
172            reactions,copy
173            spreadsheet,filter_rows
174            SubsystemDiagrams,copyR
175            diagrams,copyR
176            /^assignments*/,erase
177            /^rowss*/,erase
178            constructs,copyR
179            rows,erase
180            /\.log$/,copyR
181            MAP_SUPPORT,copyR
182            /^.*~$/,erase

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3