This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Looping local blastn in bash

Hello,

I have a Folder containing multiple genomes as .fasta files.

strainA.fasta
strainB.fasta
strainC.fasta
....

I have set up a local blast db called "dbGOI.fasta"

I want to blast all the genomes against my local db.

for file in dir
do
   blastn -in *.fasta -db dbGOI.fasta -out blast[strainname].txt
done

But as you might guess, it does not work as intended.

blast bash

It should be something like:

for file in *fasta
do
   blastn -in $file -db dbGOI.fasta -out blast$(basename $file .fasta).txt
done

For explanation: the variable yyou use to loop is called file. You call this variable in with $file . to get the name of the fasta without the file-ending you call basename with the variable and the ending you want to remove. with $() you use the output of basename as a string.

I just don't know if it is -in or -query in the blastn function

1 answer

for F in dir/*.fasta
do
   blastn -in $F -db dbGOI.fasta -out ${F%.*}.txt
done

Log in to answer this question.