mkatari-bioinformatics-august-2013-more-slurm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
mkatari-bioinformatics-august-2013-more-slurm [2014/06/09 07:53] – [Some more useful SLURM notes] mkatari | mkatari-bioinformatics-august-2013-more-slurm [2014/06/09 08:06] – mkatari | ||
---|---|---|---|
Line 32: | Line 32: | ||
</ | </ | ||
+ | === Generating sbatch scripts on the fly === | ||
+ | |||
+ | In the case where you have have hundreds of files, it is still quite cumbersome to execute the same script manually. In the example below we will get a list of inputs we want to use as input and create a separate sbatch file for each of them. | ||
+ | |||
+ | The single quote (not the apostraphe, on the US keyboard it is located to the left of 1) can be used to capture command line results. Here we get a list of fasta files that start with the word test and store it in the variable $FILES. Notice that $FILES is not just one string, but an array of files returned as a result to the ls command. Then we start a loop and work with one file at a time. At each iteration of the for loop the file name will be stored in the variable $INPUT. | ||
+ | |||
+ | < | ||
+ | #!/bin/env bash | ||
+ | #SBATCH -p batch | ||
+ | #SBATCH -J blastn | ||
+ | #SBATCH -n 4 | ||
+ | |||
+ | #results of the ls command is captured in the variable FILES | ||
+ | FILES=`ls test*fa` | ||
+ | |||
+ | #loop through all files in FILES and each iteration, INPUT will have name of one file | ||
+ | for INPUT in $FILES | ||
+ | do | ||
+ | |||
+ | #this line gets printed into screen | ||
+ | echo "file name " | ||
+ | |||
+ | #creating variables to store values | ||
+ | SBATCH=$INPUT.blast.sbatch | ||
+ | OUTPUT=$INPUT.output | ||
+ | |||
+ | #the following echo is going to be saved in sbatch file to be executed later | ||
+ | echo "# | ||
+ | #SBATCH -p batch | ||
+ | #SBATCH -J blastn | ||
+ | #SBATCH -n 4 | ||
+ | |||
+ | module load blast/ | ||
+ | |||
+ | echo \" | ||
+ | |||
+ | blastn -query $INPUT -db nt -out $OUTPUT -num_threads 4 | ||
+ | echo \" | ||
+ | " > $SBATCH | ||
+ | |||
+ | #now that the file is done writing, execute the sbatch file | ||
+ | sbatch $SBATCH | ||
+ | |||
+ | #end of the loop. code will be repeated (starting at " | ||
+ | done | ||
+ | |||
+ | </ |
mkatari-bioinformatics-august-2013-more-slurm.txt · Last modified: 2014/06/09 08:19 by mkatari