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

Diff of /FigKernelScripts/load_coupling.pl

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

revision 1.7, Mon Dec 5 18:56:37 2005 UTC revision 1.8, Sun Feb 19 04:15:44 2006 UTC
# Line 20  Line 20 
20    
21  use FIG;  use FIG;
22  use Tracer;  use Tracer;
23    use strict;
24    
25  my $fig = new FIG;  my $fig = new FIG;
26    
27  # usage: load_coupling  # usage: load_coupling [G1 G2 ...]
28    
29  $pchD   = "$FIG_Config::data/CouplingData/PCHs";  my $pchD   = "$FIG_Config::data/CouplingData/PCHs";
30  $scores = "$FIG_Config::data/CouplingData/scores";  my $scores = "$FIG_Config::data/CouplingData/scores";
31    
32  use DBrtns;  use DBrtns;
33    
34    my @genomes;
35    if (@ARGV > 0)
36    {
37        for my $g (@ARGV)
38        {
39            if ($g =~ /^\d+\.\d+$/)
40            {
41                push(@genomes, $g);
42            }
43            else
44            {
45                die "Invalid genome '$g' in argument list\n";
46            }
47        }
48    }
49    
50  if (!(-d $pchD)) {  if (!(-d $pchD)) {
51      Trace("Coupling directory $pchD not found.") if T(1);      Trace("Coupling directory $pchD not found.") if T(1);
52      exit;      exit;
# Line 37  Line 54 
54      Trace("Coupling data file $scores not found.") if T(1);      Trace("Coupling data file $scores not found.") if T(1);
55      exit;      exit;
56  }  }
57  Trace("Re-creating coupling table.") if T(2);  
58  my $dbf = $fig->db_handle;  my $dbf = $fig->db_handle;
59    
60    Trace("Re-creating coupling table.") if T(2);
61    
62    my %genomes = map { $_ => 1 } @genomes;
63    
64    if (@genomes)
65    {
66        my $tmp = "$FIG_Config::temp/lc_tmp.$$";
67        open(TMP, ">$tmp") or die "Cannot open $tmp for writing: $!\n";
68    
69        #
70        # Extract the scores for our genomes to $tmp.
71        #
72    
73        open(S, "<$scores") or die "Cannot open $scores: $!\n";
74        while (<S>)
75        {
76            if (/^fig\|(\d+\.\d+)\.peg/ and $genomes{$1})
77            {
78                print TMP $_;
79            }
80        }
81        close(TMP);
82        close(S);
83    
84        #
85        # Need to drop any entries with our genome.
86        #
87    
88        my $cond = join(" or ", map { "peg1 like 'fig|$_.peg%'" } @genomes);
89        my $where = "($cond)";
90        my $res = $dbf->SQL("delete from fc_pegs where $where");
91    
92        #
93        # Now insert.
94        #
95    
96        $dbf->load_table(tbl => 'fc_pegs', file => $tmp);
97    }
98    else
99    {
100        die;
101  $dbf->reload_table('all', 'fc_pegs',  $dbf->reload_table('all', 'fc_pegs',
102                     "peg1 varchar(32), peg2 varchar(32), score integer",                     "peg1 varchar(32), peg2 varchar(32), score integer",
103                     { fc_pegs_ix => "peg1, peg2" },                     { fc_pegs_ix => "peg1, peg2" },
104                     $scores                     $scores
105            );            );
106    }
107    
108    #
109    # Now load the PCHs files.
110    #
111    
112    if (@genomes == 0)
113    {
114        #
115        # Reload all PCHs.
116        #
117    
118  Trace("Estimating size of PCH table.") if T(2);  Trace("Estimating size of PCH table.") if T(2);
119    
120  @files = grep { (-s $_) } map { "$pchD/$_" }  OpenDir($pchD, 1);      my @files = grep { (-s $_) } map { "$pchD/$_" }  OpenDir($pchD, 1);
121    
122  my($row_size, $max_rows) = $dbf->estimate_table_size(\@files);  my($row_size, $max_rows) = $dbf->estimate_table_size(\@files);
123    
# Line 61  Line 131 
131    
132  Trace("Reading PCH directory.") if T(2);  Trace("Reading PCH directory.") if T(2);
133    
134  foreach $file (@files) {      foreach my $file (@files) {
135      Trace("Loading PCH data from $file.") if T(3);      Trace("Loading PCH data from $file.") if T(3);
136      $dbf->load_table( tbl => "pchs",      $dbf->load_table( tbl => "pchs",
137                        file => $file );                        file => $file );
138  }  }
139  Trace("Finishing PCH load.") if T(2);  Trace("Finishing PCH load.") if T(2);
140  $dbf->finish_load('all', 'pchs');  $dbf->finish_load('all', 'pchs');
141    }
142    else
143    {
144        #
145        # Reload a subset.
146        #
147    
148        die;
149    
150        for my $g (@genomes)
151        {
152            my $pch_file = "$pchD/$g";
153            if (! -f $pch_file)
154            {
155                die "Cannot open PCH file $pch_file\n";
156            }
157    
158            $dbf->load_table(tbl => 'pchs', file => $pch_file);
159        }
160    }
161    
162  Trace("Couplings loaded.") if T(2);  Trace("Couplings loaded.") if T(2);
163    
164    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3