[Bio] / FortyEight / batch_rast.pl Repository:
ViewVC logotype

Diff of /FortyEight/batch_rast.pl

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

revision 1.4, Tue Jan 12 20:23:30 2010 UTC revision 1.12, Wed Jun 8 21:00:28 2011 UTC
# Line 49  Line 49 
49    
50  my $job_dir = shift;  my $job_dir = shift;
51    
52    #
53    # Only write process startup log if we're not doing sims
54    # or we're not in the SGE context. Otherwise we are
55    # flaying the NFS locking system badly.
56    #
57    my $log_subprocesses;
58    if (!$phase{3} || ($ENV{SGE_TASK_ID} eq '' || $ENV{SGE_TASK_ID} < 2))
59    {
60        $log_subprocesses++;
61    }
62    
63    if (-f "$job_dir/CANCEL")
64    {
65        die "Job exiting due to earlier CANCEL\n";
66    }
67    
68  my $job = new Job48($job_dir);  my $job = new Job48($job_dir);
69    
70  my $sims_data_dir = $FIG_Config::rast_sims_data;  my $sims_data_dir = $FIG_Config::rast_sims_data;
# Line 62  Line 78 
78  my $sims_peg_synonyms = "$sims_data_dir/peg.synonyms";  my $sims_peg_synonyms = "$sims_data_dir/peg.synonyms";
79  my $sims_keep_count = 300;  my $sims_keep_count = 300;
80    
81    my $job48 = new Job48($job_dir);
82    my $meta = $job48->meta;
83    
84    my $host = `hostname`;
85    chomp $host;
86    $meta->add_log_entry($0, "Running phases @phase on $host") if $log_subprocesses;
87    
88  #  #
89  # Emulate execution of SGE parallel environment via the  # Emulate execution of SGE parallel environment via the
90  # --parallel N argument.  # --parallel N argument.
# Line 72  Line 95 
95      $ENV{NSLOTS} = $parallel;      $ENV{NSLOTS} = $parallel;
96  }  }
97    
98  if ($phase == 1)  if ($phase{1})
99  {  {
100      &do_upload($job);      &do_upload($job);
101      &do_rp($job);      &do_rp($job);
102  }  }
103    
104  if ($phase == 2)  if ($phase{2})
105  {  {
106      &do_qc($job);      &do_qc($job);
107      &do_correction($job);      &do_correction($job);
108      &do_sims_preprocess($job);      &do_sims_preprocess($job);
109  }  }
110    
111  if ($phase == 3)  if ($phase{3})
112  {  {
113      #      #
114      # If running inside a SGE task array job, execute      # If running inside a SGE task array job, execute
# Line 101  Line 124 
124      }      }
125  }  }
126    
127  if ($phase == 4)  if ($phase{4})
128  {  {
129      &run("$FIG_Config::bin/rp_postproc_sims", $job->dir, $sims_nr_len, $sims_peg_synonyms, $sims_keep_count);      &do_sims_postprocess($job);
130      &do_bbhs($job);      &do_bbhs($job);
131      &do_auto_assign($job);      &do_auto_assign($job);
132      &do_glue_contigs($job);      &do_glue_contigs($job);
133      &do_pchs($job);      &do_pchs($job);
134      &do_scenario($job);      &do_scenario($job);
135      &do_export($job);      &do_export($job);
136        &mark_job_user_complete($job);
137  }  }
138    
139  sub do_upload  sub do_upload
# Line 197  Line 221 
221          die "Tasks not found";          die "Tasks not found";
222      }      }
223    
224        for my $task ($task_start .. $task_end)
225        {
226            $ENV{SGE_TASK_ID} = $task;
227            &run("$FIG_Config::bin/rp_compute_sims", $job->dir);
228        }
229    }
230    
231    sub do_sims_postprocess
232    {
233        my($job) = @_;
234    
235      my $sims_nr_len = $sims_nr;      my $sims_nr_len = $sims_nr;
236      if (-f "$sims_nr-len.btree")      if (-f "$sims_nr-len.btree")
237      {      {
238          $sims_nr_len = "$sims_nr-len.btree";          $sims_nr_len = "$sims_nr-len.btree";
239      }      }
240    
241      for my $task ($task_start .. $task_end)      &run("$FIG_Config::bin/rp_postproc_sims", $job->dir, $sims_nr_len, $sims_peg_synonyms, $sims_keep_count);
     {  
         $ENV{SGE_TASK_ID} = $task;  
         &run("$FIG_Config::bin/rp_compute_sims", $job->dir);  
     }  
242  }  }
243    
244  sub do_bbhs  sub do_bbhs
# Line 246  Line 277 
277      &run("$FIG_Config::bin/rp_write_exports", $job->dir);      &run("$FIG_Config::bin/rp_write_exports", $job->dir);
278  }  }
279    
280    sub mark_job_user_complete
281    {
282        my($job) = @_;
283    
284        my $job_dir = $job->dir;
285        my $meta = $job->meta;
286        my $job_id = $job->id;
287    
288        system("$FIG_Config::bin/send_job_completion_email", $job_dir);
289    
290        $meta->set_metadata("status.final", "complete");
291    
292        #
293        # If the job is a SEED candidate, send VV email.
294        #
295    
296        if ($meta->get_metadata("import.suggested") or
297            $meta->get_metadata("import.candidate"))
298        {
299            my $gname = $job->genome_name;
300            my $mail = Mail::Mailer->new();
301            $mail->open({
302                To => 'Veronika Vonstein <veronika@thefig.info>, Robert Olson<olson@mcs.anl.gov>, Andreas Wilke<wilke@mcs.anl.gov>',
303                From => 'Annotation Server <rast@mcs.anl.gov>',
304                Subject => "RAST job $job_id marked for SEED inclusion",
305            });
306    
307            print $mail <<END;
308    RAST job #$job_id ($gname) was submitted for inclusion into the SEED, and has finished its processing.
309    END
310            $mail->close();
311    
312            #
313            # We also mark the job as ACTIVE again so that the
314            # normal post-seed-acceptance pipeline stages may execute.
315            #
316            open(F, ">$job_dir/ACTIVE");
317            close(F);
318        }
319        else
320        {
321            #
322            # Otherwise it is completely done.
323            #
324            &mark_job_done($job);
325        }
326    }
327    
328    sub mark_job_done
329    {
330        my($job) = @_;
331    
332        #
333        # If we spooled the job out onto the lustre disk, we need to
334        # spool it back.
335        #
336    
337        my $meta = $job->meta;
338        my $job_dir = $job->dir;
339    
340        if ($meta->get_metadata("lustre_required"))
341        {
342            &run("$FIG_Config::bin/rp_lustre_finish", $job_dir);
343        }
344        if (open(D, ">$job_dir/DONE"))
345        {
346            print D time . "\n";
347            close(D);
348        }
349        else
350        {
351            warn "Error opening $job_dir/DONE: $!\n";
352        }
353    
354        unlink("$job_dir/ACTIVE");
355    }
356    
357  sub run  sub run
358  {  {
359      my(@cmd) = @_;      my(@cmd) = @_;
360    
361      print "Start: @cmd\n";      my $cmd_str = join(" ", @cmd);
362        print "Start: $cmd_str\n";
363        $meta->add_log_entry($0, ['Start', $cmd_str]) if $log_subprocesses;
364      my $rc = system(@cmd);      my $rc = system(@cmd);
365      if ($rc != 0)      if ($rc != 0)
366      {      {
367          confess "Cmd failed with rc=$rc: @cmd\n";          $meta->add_log_entry($0, ['Failed', $rc, $cmd_str]);
368            print STDERR "Failed: $rc $cmd_str\n";
369            if (open(FH, ">", "$job_dir/CANCEL"))
370            {
371                print FH "Cancel job due to error in $0 @cmd\n";
372                close(FH);
373            }
374            #
375            # Attempt to qdel any other parts of this job that are queued or running.
376            # Only if we are running in the SGE environment.
377            #
378            if ($ENV{SGE_ARCH} ne '')
379            {
380                my @jobs;
381    
382                for my $k ($meta->get_metadata_keys())
383                {
384                    if ($k  =~ /p_.*\.sge_job_id/)
385                    {
386                        my $job_id = $meta->get_metadata($k);
387                        #
388                        # Don't qdel this job.
389                        #
390                        if ($job_id =~ /^\d+$/ && $job_id != $ENV{JOB_ID})
391                        {
392                            push(@jobs, $job_id);
393                        }
394    
395                    }
396                }
397                if (@jobs)
398                {
399                    my $rc2 = system("qdel", @jobs);
400                    print "qdel @jobs returned $rc2\n";
401                    $meta->add_log_entry($0, "Qdel @jobs due to failure returned status $rc2") if $log_subprocesses;
402                }
403            }
404    
405            confess "Cmd failed with rc=$rc: $cmd_str\n";
406      }      }
407      print "Done: @cmd\n";      $meta->add_log_entry($0, ['Done', $cmd_str]) if $log_subprocesses;
408        print "Done: $cmd_str\n";
409  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3