Bio-Grid-Run-SGE

 view release on metacpan or  search on metacpan

bin/rocksblast  view on Meta::CPAN

             	
		if (($todocount - $arrayjobcount) % 100 == 0) {
		    print "CREATING SGE SCRIPTS: " . ($todocount - $arrayjobcount) . " sequences to go\r";

		}
		
		$nf = $to_be_blasted;
		$nf =~ s/ /_/g;
		
		# no dots in filename exept extension of course
		$nf =~ s/(\.\w*$)//;
		$extension = $1;		
		$nf =~ s/\./_/g;
		$nf .= $extension;
		
		# check on extension name				
		#$nf =~ s/\.fasta/_fasta\.seq/;
		#$nf =~ s/\.fas/_fas\.seq/;
		#$nf =~ s/\.pro/_pro\.seq/;		
		
		$nftot = "$submit_dir/$nf";		
		$of = "$submit_dir/$to_be_blasted";
		
		unless ($nftot eq $of) {
		   `mv '$of' '$nftot'`;
		   $to_be_blasted = $nf;
		   print STDERR "mv $of $nf\n";
		}

		############
		
		$blast_out = $job_dir . '/out/' . $to_be_blasted;
		$blast_out =~ s/\..+$/\.out/;
		$file_submit = $submit_dir    . '/' . $to_be_blasted;
		$file_seq    = $job_dir . '/seq/' . $to_be_blasted;
		
		#produce blast job script
		$single_script_template = $job_script_template;
		$single_script_template =~ s/inputfile/$file_submit/g;
		$single_script_template =~ s/outputfile/$blast_out/g;
		$single_script_template =~ s/seqdonefile/$file_seq/g;
		$single_script_template =~ s/blast_user/$cuser/g;
		
		
		$pbs_error_file = $pbs_error_dir   . '/' . $Blast_param{'job_name'}  . '_' . $to_be_blasted;
		$pbs_error_file =~ s/\..+/\.ER/;
		$pbs_output_file = $pbs_output_dir . '/' . $Blast_param{'job_name'}  . '_' . $to_be_blasted;
		$pbs_output_file =~ s/\..+/\.OU/;
		

		$tmp_script_filename = $pbs_batch_script_dir . '/array-job' . $arrayjobcount;	  

		############################
                #write the blast script
                ###########################
		
		open SCRIPT_OUT, ">$tmp_script_filename";
		print SCRIPT_OUT $single_script_template;
		close SCRIPT_OUT;
		#make it executable for this user
		`chmod u+x $tmp_script_filename`;
			                      		                  
	} ## end do all seqs in jobdir


# create the basic sge_arrayjob_run.sh
print "\nCREATING JOB_ARRAY SCRIPT\n";
open SCRIPT_OUT, ">$job_dir/tmp/sge_arrayjob_run.sh";
print SCRIPT_OUT "#!/bin/bash\n";
print SCRIPT_OUT "export SGE_ROOT=/opt/gridengine" . "\n";
print SCRIPT_OUT 'echo "Task id is $SGE_TASK_ID"' . "\n";
print SCRIPT_OUT "$job_dir/tmp/tmp_scripts/array-job" . '$SGE_TASK_ID' . "\n";
close SCRIPT_OUT;

##############################################################################
# NOW SUBMIT A SGE ARRAY JOB
##############################################################################
$ENV{'SGE_ROOT'} = '/opt/gridengine';





$submitcommand = "$qdir/qsub -t 1-$arrayjobcount:1 -N $Blast_param{'job_name'} -p $prio -e $job_dir/tmp/tmp_error -o $job_dir/tmp/tmp_output $job_dir/tmp/sge_arrayjob_run.sh";
#print $submitcommand;
$retval = `$submitcommand`;
print STDERR "JOB_ARRAY: $retval\n";
$retval =~ /^Your\s*job(-array)?\s*(\d+)/; #/job-array (\d+?)\./;
$job_id = $2;
print STDERR "JOB ID: $job_id\n";

####################################
# HTML part if parameter set
###################################
if ($create_html eq 'on') {
		   		
				
	  	   
		        $blastix_base_dir = $job_dir;
		        $id = $Blast_param{'job_name'};
			$align = $Blast_param{'blastic_short'};
		        	  
		        # create script
			
			$job_blastix_template = $global_blastix_template;
	                $job_blastix_template =~ s/GODIR/$blastix_base_dir/g;
			$job_blastix_template =~ s/GOID/$id/g;
			$job_blastix_template =~ s/GOALIGN/$align/g;	  		
			 
			$blastix_script_name = $pbs_batch_script_dir . '/' . $Blast_param{'job_name'}  . '_BLASTIX';
			
			open SCRIPT_OUT, ">$blastix_script_name";
			print SCRIPT_OUT $job_blastix_template;
			close SCRIPT_OUT;
			
			$pbs_blastix_error_file = $pbs_error_dir   . '/' . $Blast_param{'job_name'}  . '_BLASTIX.ER';
			$pbs_blastix_output_file = $pbs_output_dir . '/' . $Blast_param{'job_name'}  . '_BLASTIX.OU';
											

			# create the sge sh script to run run blastic
			open SCRIPT_OUT, ">$job_dir/tmp/sge_blastix_run.sh";
			print SCRIPT_OUT "#!/bin/bash\n";
			print SCRIPT_OUT "export PERL5LIB=/home/opt/lib/perl\n";
			print SCRIPT_OUT "$blastix_script_name\n";
			close SCRIPT_OUT;
			
                        #make it executable for this user
			`chmod u+x $blastix_script_name`;

			##################################
			# now submit the job
			##################################

			print STDERR "QSUB: $qdir/qsub -hold_jid $job_id -N $Blast_param{'job_name'} -p $prio -e $job_dir/tmp/tmp_error -o $job_dir/tmp/tmp_output $job_dir/tmp/sge_blastix_run.sh\n";


			$retval = `$qdir/qsub -hold_jid $job_id -N $Blast_param{'job_name'} -p $prio -e $job_dir/tmp/tmp_error -o $job_dir/tmp/tmp_output $job_dir/tmp/sge_blastix_run.sh`;
			
			#print STDERR "$qdir/qsub -hold_jid $job_id -N $Blast_param{'job_name'} -p $prio -e $job_dir/tmp/tmp_error -o $job_dir/tmp/tmp_output $job_dir/tmp/sge_blastix_run.sh\n";
			
			print STDERR "HTML: $retval\n";	
						
} else {
    # html off but at least delete lock file after finished (deletion is arranged in blastix script when html = on
    open DELLOCK, ">$pbs_batch_script_dir/dellock.sh";
    print DELLOCK "rm -f $job_dir/blast.lock\n";
    close SCRIPT_OUT;

    # submit with hold
    $retval = `$qdir/qsub -hold_jid $job_id -N $Blast_param{'job_name'} -p $prio -e $job_dir/tmp/tmp_error -o $job_dir/tmp/tmp_output $pbs_batch_script_dir/dellock.sh`;
    print STDERR  "LOCKFILE: $retval\n";
    
		    
} # fi html on




} else {
		print "This one is easy, nothing to do, please put something in submit if you want to blast\n";
}

print STDERR "ROCKSBLAST SCRIPT DONE\n";



( run in 1.802 second using v1.01-cache-2.11-cpan-39bf76dae61 )