#!/usr/local/bin/perl -w ############################################## ############################################## # SCRIPT NAME: QUICKMINE_script # FUNCTION: Do lots of command line processing quickly! ############################################## # This script is intended to be as simple as possible. # Its purpose it to quickly population a MINE database # with a variety of analysis files (e.g. blast reports) # by automating the process of doing batch jobs # on the command line. # In summary, this script accepts a group of files # and a list of commands. It performs all the commands # on each file and outputs a result file that shares # the same 'basename' as the input file. # Files must be in fasta format. # This script accepts a single argument - the # name of your config file (must # end in .config) # Usage: scriptname your.config ############################################################ # Default Usage: ./QUICKMINE_script QUICKMINE.config # ############################################################ ############################################################ # print a reminder about local applications required # ############################################################ print <; ########################################################### # Parse the command line and die if it doesn't look right # ########################################################### unless (@ARGV ==1) { die "\n\nProper Command Line Usage: QUICKMINE_script your.config\nPlease try again.\n\n\n";} # shift the first command line arg passed through @ARGV $config_file = shift; unless ($config_file =~ /([a-zA-Z0-9]+)\.config/) { die "\n\n Your config file must contain only alphanumeric characters and be the first argument and must end with .config\nPlease try again.\n\n";} print "You have chosen to process ".@input_files." input files with the commands in config file $config_file\n"; ######################################################## # make a blast database using formatdb # ######################################################## # the most basic command for formatdb # formatdb -i SELF_blast_database -p F -o F # type "formatdb" on the command line to see all options for preparing blast databases # path to the formatdb application (comes with blastall from NCBI) -i path to the database (add flags you want) #system ("/usr/software/blast/blast2/formatdb -i /usr/users/paed/dfield/public_html/cgi-bin/BIOPERL/$contig -p F -o F"); #$blast_database = $contig; ################################################# # LOOP over each file ... # ################################################# foreach $file (@input_files) { ########################################################## # check if if the config file exists and get commands # ########################################################## # user set commands # all values to be interpolated inside the commands must be set at this point # or they go into @cmd as blanks # Here's where the array of commands should go - we'll get them # from the $config_file with a do statement - # This is just like having them in the code, but since they # are separate, we can change them independently to create # lots of config files # if it does, we should now have an array called @cmd unless ($return = do $config_file) { warn "couldn't parse $config_file: $@" if $@; warn "couldn't do $config_file: $!" unless defined $return; warn "couldn't run $config_file" unless $return; die "Sorry, couldn't open your config file. Does it exist? Is the permission 644?\nError: $!"; } print "Total commands read from config file $config_file: ". @cmd." \n"; ################################################# # ...AND DO ALL THE WORK - loop over commands # ################################################# for $i (0 .. $#cmd) { $ext = $cmd[$i][0]; # get the extension $cmd = $cmd[$i][1]; # get the command # append the $ext onto the end of the output file #if ($file eq $contig) { # # append the $ext onto the end of the output file # $cmd .= ".all.".$ext; #} else { $cmd .= ".".$ext; #} # get the output file name @options = split (/\s+/,$cmd); $output_file = pop @options; # make a system call print "System call should create output file $output_file.\n"; print "Running command: $cmd ...\n"; system($cmd); warn "Warning: Couldn't run $cmd! :$?" if $?; push (@output_files, $output_file) if !$?; # make it web readable system ("chmod 644 $output_file"); } # end foreach $cmd } # end foreach file ################################################# # Print all the new files we made and exit ... # ################################################# print "\n\nCreated the following output files:\n\n"; for (@output_files) { print "$_\n"; } print "\n\n\nDone!\n\n\n";