Changeset 209

Show
Ignore:
Timestamp:
04/28/09 15:01:45 (7 months ago)
Author:
cholt
Message:

lock file update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • INSTALL

    r180 r209  
    8686 
    8787  a.  You will have to download the source code and complile it on your machine. 
    88       You will also have to install Glib.  If your using Mac OS-X you can do this 
    89       by typing fink install glib
     88      You will also have to install Glib or Glib 2.0.  If your using Mac OS-X you 
     89      can do this by typing fink install glib and fink install glib2-dev
    9090  b.  Change to the directory containing the Exonerate package to be compiled. 
    9191  c.  To install exonerate in the directory /usr/local/exonerate, type: 
  • MPI/mpi_maker

    r198 r209  
    260260               "again|a" =>\$OPT{again}, 
    261261               "quiet" =>\$main::quiet, 
     262               "no_thread" =>\$main::no_thread, 
    262263               "CTL" => sub {GI::generate_control_files() if($rank == $root); MPI_Finalize(); exit(0);}, 
    263264               "help|?" => sub {print $usage if($rank == $root); MPI_Finalize(); exit(0)} 
     
    343344   #---main code for distribution of mpi data starts here 
    344345 
    345    #thread for root node to other things than just manage mpi 
     346   #thread for root node to do other things than just manage mpi 
    346347   my $thr = threads->create(\&node_thread); 
    347348   my $go_mpi_status = 1; 
    348    $t_need_flag = 1; 
     349   $t_need_flag = ($main::no_thread) ? 0 : 1; #set to true for threads false for no threads 
    349350 
    350351   while($go_mpi_status){ 
     
    818819   my $tier; 
    819820   my $chunk; 
     821 
     822   if($main::no_thread){ #pause and return if no thread is needed 
     823       $t_need_flag = 0; 
     824       return; 
     825   } 
     826 
    820827   $t_need_flag = 1; 
    821828 
  • README

    r206 r209  
    3535    *Augustus 2.0 or higher (augustus.gobics.de) 
    3636    *GeneMark.hmm-E 3.9 or higher (exon.biology.gatech.edu) 
    37     *FgenesH (www.softberry.com/) - requires licence 
     37    *FgenesH 2.6 or higher (www.softberry.com/) - requires licence 
    3838 
    3939To install mpi_maker, you must have an mpi package installed, try the 
  • lib/File/NFSLock.pm

    r159 r209  
    133133      time() + $self->{blocking_timeout} : 0; 
    134134 
    135   ### remove an old lockfile if it is older than the stale_timeout 
    136   if( -e $self->{lock_file} && 
    137       $self->{stale_lock_timeout} > 0 && 
    138       time() - (stat _)[9] > $self->{stale_lock_timeout} ){ 
    139     unlink $self->{lock_file}; 
    140   } 
    141  
    142135  while (1) { 
     136    ### remove an old lockfile if it is older than the stale_timeout 
     137    if( -e $self->{lock_file} && 
     138        $self->{stale_lock_timeout} > 0 && 
     139        time() - (stat _)[9] > $self->{stale_lock_timeout} ){ 
     140        unlink $self->{lock_file}; 
     141    } 
     142 
    143143    ### open the temporary file 
    144144    $self->create_magic 
     
    161161    ### If lock exists and is readable, see who is mooching on the lock 
    162162 
    163     if ( -e $self->{lock_file} && 
    164          open (_FH,"+<$self->{lock_file}") ){ 
    165  
    166       my @mine = (); 
    167       my @them = (); 
    168       my @dead = (); 
    169  
    170       my $has_lock_exclusive = !((stat _)[2] & $SHARE_BIT); 
    171       my $try_lock_exclusive = !($self->{lock_type} & LOCK_SH); 
    172  
    173       while(defined(my $line=<_FH>)){ 
    174         if ($line =~ /^$HOSTNAME (\d+) /) { 
    175           my $pid = $1; 
    176           if ($pid == $$) {       # This is me. 
    177             push @mine, $line; 
    178           }elsif(kill 0, $pid) {  # Still running on this host. 
    179             push @them, $line; 
    180           }else{                  # Finished running on this host. 
    181             push @dead, $line; 
    182           } 
    183         } else {                  # Running on another host, so 
    184           push @them, $line;      #  assume it is still running. 
    185         } 
    186       } 
    187  
    188       ### If there was at least one stale lock discovered... 
    189       if (@dead) { 
    190         # Lock lock_file to avoid a race condition. 
    191         local $LOCK_EXTENSION = ".shared"; 
    192         my $lock = new File::NFSLock { 
    193           file => $self->{lock_file}, 
    194           lock_type => LOCK_EX, 
    195           blocking_timeout => 62, 
    196           stale_lock_timeout => 60, 
    197         }; 
    198  
    199         ### Rescan in case lock contents were modified between time stale lock 
    200         ###  was discovered and lockfile lock was acquired. 
    201         seek (_FH, 0, 0); 
    202         my $content = ''; 
    203         while(defined(my $line=<_FH>)){ 
    204           if ($line =~ /^$HOSTNAME (\d+) /) { 
    205             my $pid = $1; 
    206             next if (!kill 0, $pid);  # Skip dead locks from this host 
    207           } 
    208           $content .= $line;          # Save valid locks 
    209         } 
    210  
    211         ### Save any valid locks or wipe file. 
    212         if( length($content) ){ 
    213           seek     _FH, 0, 0; 
    214           print    _FH $content; 
    215           truncate _FH, length($content); 
    216           close    _FH; 
    217         }else{ 
    218           close _FH; 
    219           unlink $self->{lock_file}; 
    220         } 
    221  
    222       ### No "dead" or stale locks found. 
    223       } else { 
    224         close _FH; 
    225       } 
    226  
    227       ### If attempting to acquire the same type of lock 
    228       ###  that it is already locked with, and I've already 
    229       ###  locked it myself, then it is safe to lock again. 
    230       ### Just kick out successfully without really locking. 
    231       ### Assumes locks will be released in the reverse 
    232       ###  order from how they were established. 
    233       if ($try_lock_exclusive eq $has_lock_exclusive && @mine){ 
    234         return $self; 
    235       } 
     163    if ( -e $self->{lock_file} && open (_FH,"+<$self->{lock_file}") ){ 
     164        my @mine = (); 
     165        my @them = (); 
     166        my @dead = (); 
     167         
     168        my $has_lock_exclusive = !((stat _)[2] & $SHARE_BIT); 
     169        my $try_lock_exclusive = !($self->{lock_type} & LOCK_SH); 
     170 
     171        while(defined(my $line=<_FH>)){ 
     172            if ($line =~ /^$HOSTNAME (\d+) /) { 
     173                my $pid = $1; 
     174                if ($pid == $$) {       # This is me. 
     175                    push @mine, $line; 
     176                }elsif(kill 0, $pid) {  # Still running on this host. 
     177                    push @them, $line; 
     178                }else{                  # Finished running on this host. 
     179                    push @dead, $line; 
     180                } 
     181            } else {                  # Running on another host, so 
     182                push @them, $line;      #  assume it is still running. 
     183            } 
     184        } 
     185         
     186        ### If there was at least one stale lock discovered... 
     187        if (@dead) { 
     188            # Lock lock_file to avoid a race condition. 
     189            local $LOCK_EXTENSION = ".shared"; 
     190            my $lock = new File::NFSLock { 
     191                file => $self->{lock_file}, 
     192                lock_type => LOCK_EX, 
     193                blocking_timeout => 62, 
     194                stale_lock_timeout => 60, 
     195            }; 
     196             
     197            ### Rescan in case lock contents were modified between time stale lock 
     198            ###  was discovered and lockfile lock was acquired. 
     199            seek (_FH, 0, 0); 
     200            my $content = ''; 
     201            while(defined(my $line=<_FH>)){ 
     202                if ($line =~ /^$HOSTNAME (\d+) /) { 
     203                    my $pid = $1; 
     204                    next if (!kill 0, $pid);  # Skip dead locks from this host 
     205                } 
     206                $content .= $line;          # Save valid locks 
     207            } 
     208             
     209            ### Save any valid locks or wipe file. 
     210            if( length($content) ){ 
     211                seek     _FH, 0, 0; 
     212                print    _FH $content; 
     213                truncate _FH, length($content); 
     214                close    _FH; 
     215            }else{ 
     216                close _FH; 
     217                unlink $self->{lock_file}; 
     218            } 
     219             
     220            ### No "dead" or stale locks found. 
     221        } else { 
     222            close _FH; 
     223        } 
     224         
     225        ### If attempting to acquire the same type of lock 
     226        ###  that it is already locked with, and I've already 
     227        ###  locked it myself, then it is safe to lock again. 
     228        ### Just kick out successfully without really locking. 
     229        ### Assumes locks will be released in the reverse 
     230        ###  order from how they were established. 
     231        if ($try_lock_exclusive eq $has_lock_exclusive && @mine){ 
     232            return $self; 
     233        } 
    236234    } 
    237235 
     
    434432  ### hard link to the actual file which will bring it up to date 
    435433  return ( link( $file, $rand_file) && unlink($rand_file) ); 
     434} 
     435 
     436sub refresh { 
     437  my $self = shift; 
     438 
     439  $errstr = undef; 
     440  my $rand_file = $self->{rand_file}; 
     441  my $file = $self->{lock_file}; 
     442  $self->{lock_line} = "$HOSTNAME $self->{lock_pid} ".time()." ".int(rand()*10000)."\n"; 
     443  local *_FH; 
     444  open (_FH,">$rand_file") or do { $errstr = "Couldn't open \"$rand_file\" [$!]"; return undef; }; 
     445  print _FH $self->{lock_line}; 
     446  close _FH; 
     447 
     448  my $err; 
     449  system("mv $rand_file $file") && ($err = "ERROR: Could not refresh lock\n"); 
     450  unlink($rand_file) if(-e $rand_file); 
     451  die $err if($err); 
     452 
     453  return 1; 
    436454} 
    437455 
  • lib/GI.pm

    r198 r209  
    55 
    66use strict; 
    7 use vars qw(@ISA @EXPORT $VERSION $TMP); 
     7use vars qw(@ISA @EXPORT $VERSION $TMP $LOCK); 
     8use FindBin; 
    89use Exporter; 
    910use FileHandle; 
     
    4142use maker::sens_spec; 
    4243use File::NFSLock; 
     44use threads; 
    4345 
    4446@ISA = qw( 
     
    796798   my $CTL_OPT     = shift; 
    797799   my $LOG         = shift; 
    798     
    799    my $exe    = $CTL_OPT->{gmhmme3}; 
     800 
     801   #genemark sometimes fails if called directly so I built a wrapper 
     802   my $exe = "$FindBin::Bin/../lib/Widget/genemark/gmhmme3_wrap"; 
     803   my $gm  = $CTL_OPT->{gmhmme3}; #genemark 
     804   my $pro = $CTL_OPT->{probuild}; #helper exe 
    800805   my $hmm = $CTL_OPT->{gmhmm}; 
    801806    
     
    807812   $LOG->add_entry("STARTED", $out_file, "");    
    808813 
     814 
    809815   my $command  = $exe; 
    810816   $command .= " -m $hmm"; 
     817   $command .= " -g $gm"; 
     818   $command .= " -p $pro"; 
    811819   $command .= " -o $out_file"; 
    812820   $command .= " $in_file"; 
     
    12621270   #copy db to local tmp dir and run xdformat or formatdb 
    12631271   if ((! @{[<$tmp_db.x?d*>]} || ! @{[<$tmp_db.?sq*>]}) && (! -e $blast_finished)) { 
    1264        if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', , 300)){ 
     1272       if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', undef, 300)){ 
    12651273           copy($db, $tmp_db) if(! -e $tmp_db); 
    12661274           dbformat($formater, $tmp_db, 'blastn'); 
     
    15081516   #copy db to local tmp dir and run xdformat or format db  
    15091517   if ((! @{[<$tmp_db.x?d*>]} || ! @{[<$tmp_db.?sq*>]}) && (! -e $blast_finished) ) { 
    1510        if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', , 300)){ 
     1518       if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', undef, 300)){ 
    15111519           copy($db, $tmp_db) if(! -e $tmp_db); 
    15121520           dbformat($formater, $tmp_db, 'blastx'); 
     
    17661774   #copy db to local tmp dir and run xdformat or formatdb 
    17671775   if ((! @{[<$tmp_db.x?d*>]} || ! @{[<$tmp_db.?sq*>]}) && (! -e $blast_finished) ) { 
    1768        if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', , 300)){ 
     1776       if(my $lock = new File::NFSLock("$tmp_db.lock", 'EX', undef, 300)){ 
    17691777           copy($db, $tmp_db) if(! -e $tmp_db); 
    17701778           dbformat($formater, $tmp_db, 'tblastx'); 
     
    20612069 
    20622070   return $the_void; 
     2071} 
     2072#----------------------------------------------------------------------------- 
     2073#refreshes the maker directory lock every 30 seconds 
     2074sub maintain_lock { 
     2075   my $lock  = shift; 
     2076 
     2077   while(1){ 
     2078       sleep 30; 
     2079       $lock->refresh; 
     2080   } 
    20632081} 
    20642082#----------------------------------------------------------------------------- 
     
    21822200                  'qrna', 
    21832201                  'fathom', 
     2202                  'probuild' 
    21842203                 ); 
    21852204 
     
    23982417   push (@infiles, 'snap') if (grep (/snap/, @{$CTL_OPT{_run}})); 
    23992418   push (@infiles, 'gmhmme3') if (grep (/genemark/, @{$CTL_OPT{_run}})); 
     2419   push (@infiles, 'probuild') if (grep (/genemark/, @{$CTL_OPT{_run}})); 
    24002420   push (@infiles, 'augustus') if (grep (/augustus/, @{$CTL_OPT{_run}}));  
    24012421   push (@infiles, 'fgenesh') if (grep (/fgenesh/, @{$CTL_OPT{_run}})); 
     
    25562576        if(! -d $CTL_OPT{out_base}); 
    25572577 
     2578   #--check if another instance of maker is running, if not lock the directory 
     2579   my $check; 
     2580   if(-e $CTL_OPT{out_base}."/.maker_lock.NFSLock"){ 
     2581       warn "WARNING: Lock found, maker may already be running.\n". 
     2582           "Checking for other instance.\n\n"; 
     2583       $check = 1; 
     2584   } 
     2585 
     2586   #lock must be global or it is detroyed outside of block 
     2587   if($LOCK = new File::NFSLock($CTL_OPT{out_base}."/.maker_lock", 'EX', 40, 40)){ 
     2588       warn "Everything seems ok!!\n\n" if($check); 
     2589 
     2590       my $thr = threads->create(\&maintain_lock, $LOCK);  
     2591       $thr->detach; 
     2592   } 
     2593   else{ 
     2594       die "ERROR: Another instance of maker is already running for this dataset\n"; 
     2595   } 
     2596    
     2597 
    25582598   #--set up optional global TMP 
    25592599   if($CTL_OPT{TMP}){ 
     
    25762616   my %O = (@_) ? @_ : set_defaults(); 
    25772617   my $ev = 1 if($main::eva); 
     2618   my $log = 1 if(@_); 
    25782619 
    25792620   #--build opts.ctl file 
    25802621   open (OUT, "> $dir/eval_opts.ctl") if($ev); 
    2581    open (OUT, "> $dir/maker_opts.ctl") if(!$ev); 
     2622   open (OUT, "> $dir/maker_opts.log") if(!$ev && $log); 
     2623   open (OUT, "> $dir/maker_opts.ctl") if(!$ev && !$log); 
    25822624   print OUT "#-----Genome (Required for De-Novo Annotation)\n" if(!$ev); 
    25832625   print OUT "#-----Genome (Required if not internal to GFF3 file)\n" if($ev); 
     
    26262668   print OUT "fgenesh_par_file:$O{fgenesh_par_file} #Fgenesh parameter file\n"; 
    26272669   print OUT "model_gff:$O{model_gff} #gene models from an external gff3 file (annotation pass-through)\n" if(!$ev); 
    2628    print OUT "pred_gff:$O{model_gff} #ab-initio predictions from an external gff3 file\n"; 
     2670   print OUT "pred_gff:$O{pred_gff} #ab-initio predictions from an external gff3 file\n"; 
    26292671   print OUT "\n"; 
    26302672   print OUT "#-----Other Annotation Type Options (features maker doesn't recognize)\n" if(!$ev); 
     
    26622704   #--build bopts.ctl file 
    26632705   open (OUT, "> $dir/eval_bopts.ctl") if($ev); 
    2664    open (OUT, "> $dir/maker_bopts.ctl") if(!$ev); 
     2706   open (OUT, "> $dir/maker_bopts.log") if(!$ev && $log); 
     2707   open (OUT, "> $dir/maker_bopts.ctl") if(!$ev && !$log); 
    26652708   print OUT "#-----BLAST and Exonerate Statistics Thresholds\n"; 
    26662709   print OUT "blast_type:$O{blast_type} #set to 'wublast' or 'ncbi'\n"; 
     
    26972740   #--build maker_exe.ctl file 
    26982741   open (OUT, "> $dir/eval_exe.ctl") if($ev); 
    2699    open (OUT, "> $dir/maker_exe.ctl") if(!$ev); 
     2742   open (OUT, "> $dir/maker_exe.log") if(!$ev && $log); 
     2743   open (OUT, "> $dir/maker_exe.ctl") if(!$ev && !$log); 
    27002744   print OUT "#-----Location of Executables Used by Maker/Evaluator\n"; 
    27012745   print OUT "formatdb:$O{formatdb} #location of NCBI formatdb executable\n"; 
     
    27192763   print OUT "qrna:$O{qrna} #location of qrna executable (not yet implemented)\n"; 
    27202764   print OUT "fathom:$O{fathom} #location of fathom executable (not yet implemented)\n"; 
     2765   print OUT "probuild:$O{probuild} #location of probuild executable (required for genemark)\n"; 
    27212766   close(OUT);     
    27222767} 
  • lib/ds_utility.pm

    r127 r209  
    124124sub add_entry { 
    125125   my $self = shift; 
    126    my $entry = join("\t", @_); 
     126   my @F = @_; 
     127 
     128   #remove deep directory data so log is relative 
     129   my $cwd = Cwd::cwd(); 
     130   my $entry = join("\t", @F); 
     131 
     132   if($entry =~ /\tFINISHED|\tSTARTED|\tDIED|\tSKIPPED|\tRETRY/){ 
     133       $entry =~ s/$cwd\/.*\.maker\.output\/*//; 
     134   } 
    127135 
    128136   open(my $IN, ">>", $self->{log}); 
  • lib/runlog.pm

    r197 r209  
    506506 
    507507                my ($te) = $CTL_OPTIONS{repeat_protein} =~ /([^\/]+)$/; 
    508                 $te =~ s/\.fasta$//; 
    509  
    510                 @f = grep { ! /$te\.blastx$/} @f; 
    511  
     508 
     509                if($te){ 
     510                    $te =~ s/\.fasta$//;     
     511                    @f = grep { ! /$te\.blastx$/} @f; 
     512                } 
     513                     
    512514                foreach my $f (@f){ 
    513515                    push (@files, $f) if (-f $f); 
    514516                    push (@dirs, $f) if (-d $f); 
    515517                } 
     518 
    516519            } 
    517520