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

Diff of /FigKernelPackages/FIG.pm

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

revision 1.92, Mon May 24 21:14:16 2004 UTC revision 1.93, Mon May 24 21:55:18 2004 UTC
# Line 5  Line 5 
5  use Blast;  use Blast;
6  use FIG_Config;  use FIG_Config;
7  use tree_utilities;  use tree_utilities;
8    use Subsystem;
9    
10  #  #
11  # Conditionally evaluate this in case its prerequisites are not available.  # Conditionally evaluate this in case its prerequisites are not available.
# Line 21  Line 22 
22  use Carp;  use Carp;
23  use Data::Dumper;  use Data::Dumper;
24  use Time::Local;  use Time::Local;
25    use File::Spec;
26    
27  use strict;  use strict;
28  use Fcntl qw/:flock/;  # import LOCK_* constants  use Fcntl qw/:flock/;  # import LOCK_* constants
# Line 76  Line 78 
78      my($self,$genomeF) = @_;      my($self,$genomeF) = @_;
79    
80      my $rc = 0;      my $rc = 0;
81      if (($genomeF =~ /((.*\/)?(\d+\.\d+))$/) && (! -d "$FIG_Config::organisms/$3"))  
82        my(undef, $path, $genome) = File::Spec->splitpath($genomeF);
83    
84        if ($genome !~ /^\d+\.\d+$/)
85      {      {
86          my $genome = $3;          warn "Invalid genome filename $genomeF\n";
87            return $rc;
88        }
89    
90        if (-d $FIG_Config::organisms/$genome)
91        {
92            warn "Organism already exists for $genome\n";
93            return $rc;
94        }
95    
96    
97        #
98        # We're okay, it doesn't exist.
99        #
100    
101          my @errors = `$FIG_Config::bin/verify_genome_directory $genomeF`;          my @errors = `$FIG_Config::bin/verify_genome_directory $genomeF`;
102          if (@errors == 0)  
103        if (@errors)
104          {          {
105            warn "Errors found while verifying genome directory $genomeF:\n";
106            print join("", @errors);
107            return $rc;
108        }
109    
110              &run("cp -r $genomeF $FIG_Config::organisms");              &run("cp -r $genomeF $FIG_Config::organisms");
111              &run("chmod -R 777 $FIG_Config::organisms/$genome");              &run("chmod -R 777 $FIG_Config::organisms/$genome");
112    
113              &run("index_contigs $genome");              &run("index_contigs $genome");
114              &run("compute_genome_counts $genome");              &run("compute_genome_counts $genome");
115              &run("load_features $genome");              &run("load_features $genome");
116    
117              $rc = 1;              $rc = 1;
118              if (-s "$FIG_Config::organisms/$genome/Features/peg/fasta")              if (-s "$FIG_Config::organisms/$genome/Features/peg/fasta")
119              {              {
# Line 94  Line 121 
121                  my @tmp = `cut -f1 $FIG_Config::organisms/$genome/Features/peg/tbl`;                  my @tmp = `cut -f1 $FIG_Config::organisms/$genome/Features/peg/tbl`;
122                  chomp @tmp;                  chomp @tmp;
123                  &run("cat $FIG_Config::organisms/$genome/Features/peg/fasta >> $FIG_Config::data/Global/nr");                  &run("cat $FIG_Config::organisms/$genome/Features/peg/fasta >> $FIG_Config::data/Global/nr");
124                  &make_similarities(\@tmp);          &enqueue_similarities(\@tmp);
125              }              }
126              if ((-s "$FIG_Config::organisms/$genome/assigned_functions") ||              if ((-s "$FIG_Config::organisms/$genome/assigned_functions") ||
127                  (-d "$FIG_Config::organisms/$genome/UserModels"))                  (-d "$FIG_Config::organisms/$genome/UserModels"))
128              {              {
129                  &run("add_assertions_of_function $genome");                  &run("add_assertions_of_function $genome");
130              }              }
131          }  
     }  
132      return $rc;      return $rc;
133  }  }
134    
135  sub make_similarities {  =pod
136    
137    =head1 enqueue_similarities
138    
139    usage: enqueue_similarities(\@sims)
140    
141    Queue the passed fids (a reference to a list) for similarity
142    computation.
143    
144    =cut
145    sub enqueue_similarities {
146      my($fids) = @_;      my($fids) = @_;
147      my $fid;      my $fid;
148    
149      open(TMP,">>$FIG_Config::global/queued_similarities")      my $sim_q = "$FIG_Config::global/queued_similarities";
150          || die "could not open $FIG_Config::global/queued_similarities";  
151        open(TMP,">>$sim_q")
152            || die "could not open $sim_q";
153    
154        #
155        # We need to lock here so that if a computation is creating a snapshot of the
156        # queue, we block until it's done.
157        #
158    
159        flock(TMP, LOCK_EX) or die "Cannot lock $sim_q\n";
160    
161      foreach $fid (@$fids)      foreach $fid (@$fids)
162      {      {
163          print TMP "$fid\n";          print TMP "$fid\n";
# Line 119  Line 165 
165      close(TMP);      close(TMP);
166  }  }
167    
168    =pod
169    
170    =head1 create_sim_askfor_pool
171    
172    usage: create_sim_askfor_pool()
173    
174    Creates an askfor pool, a snapshot of the current NR and
175    similarity queue. Zeros out the old queue. We also create a
176    queue index, a file of records
177    
178        offset    length    assigned_time    status
179    
180    offset and length are 8 bytes, assigned time is a 4-byte integer
181    holding seconds-since-the-epoch of when this chunk was assigned, or
182    0 if unassigned. Status is a 4-byte integer containing status information.
183    
184    =cut
185    
186    sub create_sim_askfor_pool
187    {
188        my($self) = @_;
189    
190        my $pool_dir = "$FIG_Config::global/sim_pools";
191        &verify_dir($pool_dir);
192    
193        #
194        # Lock the pool directory.
195        #
196        open(my $lock, ">$pool_dir/lockfile");
197    
198        flock($lock, LOCK_EX);
199    
200        my $num = 0;
201        if (open(my $toc, "<$pool_dir/TOC"))
202        {
203            while (<$toc>)
204            {
205                chomp;
206                print STDERR "Have toc entry  $_\n";
207                my ($idx, $time, $str) = split(/\s+/, $_, 3);
208    
209                $num = max($num, $idx);
210            }
211            close($toc);
212        }
213        $num++;
214        open(my $toc, ">>$pool_dir/TOC") or die "Cannot write $pool_dir/TOC: $!\n";
215    
216        print $toc "$num ", time(), " New toc entry\n";
217        close($toc);
218    
219        my $cpool_dir = sprintf "$pool_dir/%04d", $num;
220    
221        #
222        # All set, create the directory for this pool.
223        #
224    
225        &verify_dir($cpool_dir);
226    
227        #
228        # Now we can copy the nr and sim queue here.
229        # Do this stuff inside an eval so we can clean up
230        # the lockfile.
231        #
232    
233        eval {
234    
235            my $sim_q = "$FIG_Config::global/queued_similarities";
236    
237            &run("cp $sim_q $cpool_dir/q");
238    
239            open(F, ">$sim_q") or die "Cannot open $sim_q to truncate it: $!\n";
240            close(F);
241    
242            #
243            # Create the index
244    
245            #
246        };
247    
248        unlink("$pool_dir/lockfile");
249        close($lock);
250    
251    }
252    
253    =pod
254    
255    =head1 get_sim_chunk
256    
257    usage: get_sim_chunk($n_seqs, $worker_id)
258    
259    Returns a chunk of $n_seqs of work.
260    
261    =cut
262    sub get_sim_chunk
263    {
264        my($self, $n_seqs, $worker_id) = @_;
265    
266    
267    }
268    
269  sub get_local_hostname {  sub get_local_hostname {
270    
271      #      #
# Line 465  Line 612 
612              $i++;              $i++;
613              last if $i >= $n;              last if $i >= $n;
614          }          }
615            close($fh);
616          return @ret;          return @ret;
617      }      }
618  }  }
# Line 973  Line 1121 
1121          {          {
1122              @fxs = sort { $fxs->{$a}->[1] <=> $fxs->{$b}->[1] } @fxs;              @fxs = sort { $fxs->{$a}->[1] <=> $fxs->{$b}->[1] } @fxs;
1123              $x = $fxs->{$fxs[0]};              $x = $fxs->{$fxs[0]};
1124                print "Closed $fxs[0]\n";
1125              undef $x->[0];              undef $x->[0];
1126              delete $fxs->{$fxs[0]};              delete $fxs->{$fxs[0]};
1127          }          }
# Line 3901  Line 4050 
4050      return ();      return ();
4051  }  }
4052    
 sub map_to_roles {  
     my($self,$map) = @_;  
   
     return $self->map_to_ecs($map);  
 }  
   
4053  =pod  =pod
4054    
4055  =head1 map_name  =head1 map_name
# Line 4837  Line 4980 
4980    
4981  ################################# Subsystems  ####################################  ################################# Subsystems  ####################################
4982    
4983    
4984    
4985  sub exportable_subsystem {  sub exportable_subsystem {
4986      my($self,$ssa) = @_;      my($self,$ssa) = @_;
4987      my(%seqs,@genomes);      my(%seqs,@genomes);
# Line 5138  Line 5283 
5283      return $genomes;      return $genomes;
5284  }  }
5285    
5286    #
5287    #    @pegs              = $fig->pegs_in_subsystem_cell($genome,$role)
5288    #    @roles              = $fig->subsystem_to_roles($subsystem)
5289    #    @maps             = $fig->role_to_maps($role)
5290    #    @subsystems = $fig->peg_to_subsystems($peg);
5291    
5292    sub pegs_in_subsystem_cell
5293    {
5294        my($self, $subsystem, $genome, $role) = @_;
5295    
5296        my $sub = new Subsystem($subsystem, $self);
5297    
5298        return undef unless $sub;
5299    
5300        return $sub->get_pegs_from_cell($genome, $role);
5301    }
5302    
5303  sub get_clearinghouse  sub get_clearinghouse
5304  {  {
5305      my($self, $url) = @_;      my($self, $url) = @_;

Legend:
Removed from v.1.92  
changed lines
  Added in v.1.93

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3