Changeset 258

Show
Ignore:
Timestamp:
09/08/09 11:32:56 (3 months ago)
Author:
cholt
Message:

better iprscan wrapper

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MPI/mpi_iprscan

    r256 r258  
    168168 
    169169#---global variables 
    170 my %OPT; 
     170my %CTL_OPT; 
     171my @appl; 
     172 
    171173my $root = 0; #define root node (only changed for debugging) 
    172174 
    173175#---Process options on the command line 
    174 my $infile; 
    175 my $outfile; 
    176 my @appl; 
    177 my $chpc; 
    178 my $cli; #always enabled, just here for implementation 
    179  
    180 GetOptions("i=s" => \$infile, 
    181            "o=s" => \$outfile, 
    182            "appl=s" => \@appl, 
    183            "chpc" => \$chpc, #hidden option used on the CHPC's computer farm 
    184            "cli" => \$cli, #just used to strip off the option 
     176GetOptions("i=s"       => \$CTL_OPT{infile}, 
     177           "o=s"       => \$CTL_OPT{outfile}, 
     178           "appl=s"    => \@appl, 
     179           "nocrc"     => $CTL_OPT{nocrc}, 
     180           "seqtype=s" => $CTL_OPT{seqtype}, 
     181           "trtable=i" => $CTL_OPT{trtable}, 
     182           "goterms"   => $CTL_OPT{goterms}, 
     183           "iprlookup" => $CTL_OPT{iprlookup}, 
     184           "format=s"  => $CTL_OPT{format}, 
     185           "verbose"   => $CTL_OPT{verbose}, 
     186           "chpc"      => \$CTL_OPT{chpc}, #hidden option used on the CHPC's computer farm 
     187           "cli"       => \$CTL_OPT{cli}, #just used to strip off the option 
    185188           ); 
    186189 
    187 $main::quiet = 1; #suppress status messages 
     190$main::quiet = 1 unless($CTL_OPT{verbose}); #suppress status messages 
    188191 
    189192if(! @appl){ 
     
    204207} 
    205208 
    206 #build localized database for each node 
    207 if($chpc && ! -e "$TMP/iprscan/data/ok"){ 
     209$CTL_OPT{appl} = \@appl; #apply apps to CTL_OPT 
     210 
     211#build localized iprscan database for each node 
     212if($CTL_OPT{chpc} && ! -e "$TMP/iprscan/data/ok"){ 
    208213    my $lock = new File::NFSLock("$TMP/.iprscan_lock", 'EX', 1200, 1205); 
    209214     
     
    278283        #---test command line  options here 
    279284        #test input files existance 
    280         if($infile && ! -e $infile){ 
    281             die "ERROR: The input file \'$infile\' does not exist.\n"; 
     285        if($CTL_OPT{infile} && ! -e $CTL_OPT{infile}){ 
     286            die "ERROR: The input file \'$CTL_OPT{infile}\' does not exist.\n"; 
    282287        } 
    283288         
     
    286291        my $exe = "$EXE -cli"; 
    287292        my $command = "$exe " . join(' ', @ARGV); 
    288         $command .= " -appl " . join(" -appl ", @appl) if(@appl); 
    289         $command .= " -i $tfile" if($infile); #test options on dummy file 
     293        $command .= " -nocrc" if($CTL_OPT{nocrc}); 
     294        $command .= " -seqtype $CTL_OPT{seqtype}" if(defined $CTL_OPT{seqtype}); 
     295        $command .= " -trtable $CTL_OPT{trtable}" if(defined $CTL_OPT{trtable}); 
     296        $command .= " -goterms" if($CTL_OPT{goterms}); 
     297        $command .= " -iprlookup" if($CTL_OPT{iprlookup}); 
     298        $command .= " -format $CTL_OPT{format}" if(defined $CTL_OPT{format}); 
     299        $command .= " -appl " . join(" -appl ", @{$CTL_OPT{appl}}) if(@{$CTL_OPT{appl}}); 
     300        $command .= " -i $tfile" if($CTL_OPT{infile}); #test options on dummy file 
    290301        open(my $PAR, "$command 2>&1 |"); 
    291302        my @err = <$PAR>; 
     
    314325    #---main code for distribution of mpi data starts here 
    315326 
    316     my ($name) = $infile =~ /([^\/]+)$/; 
    317     $name = $outfile if($outfile); 
     327    my ($name) = $CTL_OPT{infile} =~ /([^\/]+)$/; 
     328    $name = $CTL_OPT{outfile} if($CTL_OPT{outfile}); 
    318329 
    319330    my $DS_CTL = new basiclog("$name.log"); 
    320     my $iterator = new Iterator::Fasta($infile); 
     331    my $iterator = new Iterator::Fasta($CTL_OPT{infile}); 
    321332 
    322333    #thread for root node to do other things than just manage mpi 
     
    367378            my $tier; 
    368379            while (my $fasta = $iterator->nextFasta() || shift @failed){ 
    369                 $tier = Process::MpiTiers->new({fasta => $fasta, 
    370                                                 appl => \@appl, 
    371                                                 params => \@ARGV, 
    372                                                 iprscan => "$EXE -cli", 
    373                                                 infile => $infile, 
    374                                                 outfile => $outfile, 
    375                                                 DS_CTL  => $DS_CTL}, 
     380                $tier = Process::MpiTiers->new({fasta     => $fasta, 
     381                                                CTL_OPT   => \%CTL_OPT 
     382                                                params    => \@ARGV, 
     383                                                iprscan   => "$EXE -cli", 
     384                                                DS_CTL    => $DS_CTL}, 
    376385                                               $root, 
    377386                                               'Process::IPRchunk' 
     
    435444                 
    436445                while (my $fasta = $iterator->nextFasta() || shift @failed){ 
    437                     $tier = Process::MpiTiers->new({fasta => $fasta, 
    438                                                     appl => \@appl, 
    439                                                     params => \@ARGV, 
    440                                                     iprscan => "$EXE -cli", 
    441                                                     infile => $infile, 
    442                                                     outfile => $outfile, 
    443                                                     DS_CTL  => $DS_CTL}, 
    444                                                    $who, 
    445                                                    'Process::IPRchunk' 
    446                                                    ); 
     446                $tier = Process::MpiTiers->new({fasta     => $fasta, 
     447                                                CTL_OPT   => \%CTL_OPT 
     448                                                params    => \@ARGV, 
     449                                                iprscan   => "$EXE -cli", 
     450                                                DS_CTL    => $DS_CTL}, 
     451                                               $who, 
     452                                               'Process::IPRchunk' 
     453                                              ); 
    447454                     
    448455                    last if(! $tier->terminated); 
  • lib/Process/IPRchunk.pm

    r256 r258  
    116116      #=== 
    117117       
    118       my ($outname) = $VARS->{infile} =~ /([^\/]+)$/; 
    119       $outname = $VARS->{outfile} if($VARS->{outfile}); 
     118      my ($outname) = $VARS->{CTL_OPT}{infile} =~ /([^\/]+)$/; 
     119      $outname = $VARS->{CTL_OPT}{outfile} if($VARS->{outfile}); 
    120120 
    121121      $VARS->{seq_id} = Fasta::getSeqID(\$VARS->{fasta}); 
    122122      $VARS->{safe_id} = Fasta::seqID2SafeID($VARS->{seq_id}); 
    123       $VARS->{c_flag} = $VARS->{DS_CTL}->continue_flag($VARS->{seq_id}); 
    124  
    125       my $failed .= "$outname.failed/".$VARS->{safe_id}.".fasta"; 
    126  
    127       if(! $VARS->{c_flag}){ 
    128           warn "WARNING: ".$VARS->{seq_id} ."failed 2 time and will not be tried again\n", 
    129                "The fasta sequence will be saved for debugging in $failed\n"; 
    130  
    131           mkdir("$outname.failed") if(! -d "$outname.failed"); 
    132  
    133           open(my $OUT, ">$failed"); 
    134           print $OUT $VARS->{fasta}; 
    135           close($OUT); 
    136           $VARS->{DS_CTL}->add_entry($VARS->{seq_id}, 'DIED_PERMANENT'); 
    137       } 
    138       else{ 
    139           unlink($failed) if(-e $failed); #remove old failed 
    140       } 
    141  
    142       $VARS->{DS_CTL}->add_entry($VARS->{seq_id}, 'STARTED'); 
     123 
     124      #set up base and void directories for output 
     125      ($VARS->{out_dir}, $VARS->{the_void}) = $VARS->{DS_CTL}->seq_dirs($VARS->{seq_id}); 
     126 
     127      #contig combined output file 
     128      $VARS->{cfile} = $VARS->{out_dir}."/".$VARS->{safe_id}.".ipr"; 
     129 
     130      #=== 
     131      $status = 'trying to build/process the run.log file'; 
     132      #=== 
     133 
     134      $VARS->{LOG} = iprscan::runlog->new($VARS->{CTL_OPT}, 
     135                                          {seq_id     => $VARS->{seq_id}, 
     136                                           seq_length => length(${$VARS->{q_seq_ref}}), 
     137                                           out_dir    => $VARS->{out_dir}, 
     138                                           the_void   => $VARS->{the_void}, 
     139                                           fasta_ref  => \$VARS->{fasta}}, 
     140                                          $VARS->{the_void}."/run.log" 
     141                                          ); 
     142 
     143      ($VARS->{c_flag}, my $message) = $VARS->{LOG}->get_continue_flag(); 
     144      $VARS->{DS_CTL}->add_entry($VARS->{seq_id}, $VARS->{out_dir}, $message); 
     145      if($VARS->{c_flag} == 0){ 
     146          my $cfile = $VARS->{c_flag}; 
     147          die "ERROR: Can't find $cfile yet iprscan::runlog says the contig is finished\n" 
     148              if(! -e $cfile); 
     149           
     150          my $lock = new File::NFSLock(".iprscan_lock", 'EX', 40, 40); 
     151          my $outfile = $VARS->{CTL_OPT}{outfile}; 
     152 
     153          my $FH; 
     154          if($outfile){ 
     155              open($FH, ">> $outfile"); 
     156          } 
     157          else{ 
     158              open($FH, ">&STDOUT"); 
     159          } 
     160           
     161          my $CFH; 
     162          open($CFH, "> $cfile"); 
     163           
     164          while(my $key = each %{$VARS}){ 
     165              next if($key eq 'outfile'); 
     166              print $FH $VARS->{$key}; 
     167              print $CFH $cfile; 
     168          } 
     169           
     170          close($FH); 
     171          close($CFH); 
     172           
     173          $lock->unlock; 
     174      } 
    143175   } 
    144176   catch Error::Simple with { 
     
    287319         if ($flag eq 'load') { 
    288320            #-------------------------CHUNKER 
    289              foreach my $app (@{$VARS->{appl}}) { 
     321             foreach my $app (@{$VARS->{CTL_OPT}{appl}}) { 
    290322                 $VARS->{app} = $app; 
    291323                 my $chunk = new Process::IPRchunk($level, $VARS); 
     
    296328         elsif ($flag eq 'init') { 
    297329            #------------------------ARGS_IN 
    298             @args = (qw{safe_fasta 
     330            @args = (qw{CTL_OPT 
     331                        safe_fasta 
    299332                        app 
    300333                        params 
    301334                        iprscan 
     335                        the_void 
    302336                        } 
    303337                    ); 
     
    306340         elsif ($flag eq 'run') { 
    307341            #-------------------------CODE 
     342            my %CTL_OPT    = %{$VARS->{CTL_OPT}}; 
    308343            my $safe_fasta = $VARS->{safe_fasta}; 
    309344            my $app        = $VARS->{app}; 
    310345            my $params     = $VARS->{params}; 
    311346            my $iprscan    = $VARS->{iprscan}; 
     347            my $the_void   = $VARS->{the_void}; 
    312348 
    313349            #make files 
    314350            my (undef, $ifile) = tempfile(); 
    315             my (undef, $ofile) = tempfile()
     351            my $ofile = "$the_void/$CTL_OPT{safe_id}.$app"
    316352            FastaFile::writeFile($safe_fasta, $ifile); 
    317353 
    318354            #build command 
    319             my $command = $iprscan . " " . join(' ', @$params); 
     355            my $command = $iprscan; 
     356            $command .= " -nocrc" if($CTL_OPT{nocrc}); 
     357            $command .= " -seqtype $CTL_OPT{seqtype}" if(defined $CTL_OPT{seqtype}); 
     358            $command .= " -trtable $CTL_OPT{trtable}" if(defined $CTL_OPT{trtable}); 
     359            $command .= " -goterms" if($CTL_OPT{goterms}); 
     360            $command .= " -iprlookup" if($CTL_OPT{iprlookup}); 
     361            $command .= " -format $CTL_OPT{format}" if(defined $CTL_OPT{format}); 
     362            $command .= " " . join(' ', @$params); 
    320363            $command .= " -appl $app -i $ifile -o $ofile"; 
    321364 
    322365            my $w = new Widget::iprscan(); 
    323             print STDERR "running iprscan $app...\n" unless($main::quiet); 
    324             $w->run($command); 
     366            if(-e $ofile){ 
     367                print STDERR "rereading $ofile...\n" unless($main::quiet); 
     368            } 
     369            else{ 
     370                print STDERR "running iprscan $app...\n" unless($main::quiet); 
     371                $w->run($command); 
     372            } 
    325373 
    326374            unlink($ifile); 
     
    331379            } 
    332380            close($IN); 
    333             unlink($ofile); 
    334381            #-------------------------CODE 
    335382 
     
    354401         elsif ($flag eq 'init') { 
    355402            #------------------------ARGS_IN 
    356             @args = (qw{outfile}, 
    357                      @{$VARS->{appl}} 
     403            @args = (qw{CTL_OPT 
     404                        cfile 
     405                        outfile 
     406                       },                     
     407                     @{$VARS->{CTL_OPT}{appl}} 
    358408                     ); 
    359409            #------------------------ARGS_IN 
     
    361411         elsif ($flag eq 'run') { 
    362412            #-------------------------CODE 
    363             my $outfile = $VARS->{outfile}; 
     413            my $cfile = $VARS->{cfile}; #combined contig output file 
     414            my $outfile = $VARS->{outfile}; #combined every contig output file 
    364415 
    365416            my $lock = new File::NFSLock(".iprscan_lock", 'EX', 40, 40); 
     
    373424            } 
    374425 
     426            my $CFH; 
     427            open($CFH, "> $cfile"); 
     428 
    375429            while(my $key = each %{$VARS}){ 
    376430                next if($key eq 'outfile'); 
    377431                print $FH $VARS->{$key}; 
     432                print $CFH $cfile; 
    378433            } 
     434 
    379435            close($FH); 
     436            close($CFH); 
    380437 
    381438            $lock->unlock; 
  • lib/Process/MpiTiers.pm

    r256 r258  
    44 
    55use strict; 
     6use FindBin; 
     7use lib "$FindBin::Bin/../lib"; 
     8use lib "$FindBin::Bin/../perl/lib"; 
    69use Error qw(:try); 
    710use Error::Simple; 
     
    4346          #optionaly override chunk type 
    4447          $self->{CHUNK_REF} = shift @args || "Process::MpiChunk"; 
     48          require $self->{CHUNK_REF}; 
    4549          $self->{CHUNK_REF} = new $self->{CHUNK_REF}; #turn into object 
    4650