[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.280, Fri May 20 11:23:07 2005 UTC revision 1.281, Wed May 25 16:07:23 2005 UTC
# Line 294  Line 294 
294      close(TMP);      close(TMP);
295  }  }
296    
297    =head3 export_similarity_request
298    
299    Creates a similarity computation request from the queued similarities and
300    the current NR.
301    
302    We keep track of the exported requests in case one gets lost.
303    
304    =cut
305    
306    sub export_similarity_request
307    {
308        my($self, $nr_file, $fasta_file) = @_;
309    
310        my $req_dir = "$FIG_Config::fig/var/sim_requests";
311        &verify_dir("$FIG_Config::fig/var");
312        &verify_dir($req_dir);
313    
314        $req_dir = "$req_dir/" . time;
315        &verify_dir($req_dir);
316    
317        #
318        # Open all of our output files before zeroing out the sim queue, in case
319        # there is a problem.
320        #
321    
322        open(my $user_fasta_fh, ">$fasta_file") or confess "Cannot open $fasta_file for writing: $!";
323        open(my $fasta_fh, ">$req_dir/fasta.in");
324    
325        open(my $user_nr_fh, ">$nr_file") or confess "Cannot open $nr_file for writing: $!";
326        open(my $nr_fh, ">$req_dir/nr") or confess "Cannot open $req_dir/nr for writing: $!";
327    
328        open(my $nr_read_fh, "<$FIG_Config::data/Global/nr") or die "Cannot open $FIG_Config::data/Global/nr for reading: $!";
329    
330        my $sim_q = "$FIG_Config::global/queued_similarities";
331    
332        #
333        # We need to lock here so that if a computation is creating a snapshot of the
334        # queue, we block until it's done.
335        #
336    
337        open(my $sim_q_lock, ">>$sim_q") or confess "could not open $sim_q";
338        flock($sim_q_lock, LOCK_EX) or confess "Cannot lock $sim_q\n";
339    
340        #
341        # Everything open & locked, start copying.
342        #
343    
344        copy("$sim_q", "$req_dir/q") or confess "Copy $sim_q $req_dir/q failed: $!";
345    
346        my($buf);
347        while (1)
348        {
349            my $n = read($nr_read_fh, $buf, 4096);
350            defined($n) or confess "Error reading nr: $!";
351            last unless $n;
352            syswrite($user_nr_fh, $buf) or confess "Error writing $nr_file: $!";
353            syswrite($nr_fh, $buf) or confess "Error writing $req_dir/nr: $!";
354        }
355    
356        close($nr_read_fh);
357        close($nr_fh);
358        close($user_nr_fh);
359    
360        #
361        # We can zero out the queue and unlock now.
362        #
363    
364        open(F, ">$sim_q") or die "Cannot open $sim_q to truncate it: $!\n";
365        close(F);
366    
367        close($sim_q_lock);
368    
369        #
370        # Generate the fasta input from the queued ids.
371        #
372    
373        open(my $q_fh, "<$req_dir/q");
374        while (my $id = <$q_fh>)
375        {
376            chomp $id;
377    
378            my $seq = $self->get_translation($id);
379    
380            display_id_and_seq($id, \$seq, $user_fasta_fh);
381            display_id_and_seq($id, \$seq, $fasta_fh);
382        }
383        close($q_fh);
384    
385        close($user_fasta_fh);
386        close($fasta_fh);
387    }
388    
389  =head3 create_sim_askfor_pool  =head3 create_sim_askfor_pool
390    
391  usage: create_sim_askfor_pool()  usage: create_sim_askfor_pool()

Legend:
Removed from v.1.280  
changed lines
  Added in v.1.281

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3