Error: Too many positional arguments (1) when using BLAST w/ a bash for loop

1.5k Views Asked by At

I'm trying to write a script that will go through all of the directories within a directory where it will query a specific sequence against a local blast database. I've run the BLAST search without the bash for loop and used a for loop to create the databases in the first place. I have tried everything suggested by others having this problem (where applicable) to no avail. I'm not copying and pasting anything, I've retyped the script and looked for stupid errors (of which I make plenty). Maybe I'm just not seeing it? Anyway here's the code:

SRV01:~$ for d in ~/data/Shen_transcriptomes/transcriptomes/*/; do tblastn -query ~/data/chitin_binding_protein/cbp_Tectaria_macrodonta.fa -db "$d"*BLASTdb* -out "$(basename "$d")".out; done

When I run the same thing with: echo "$d"*BLASTdb*, it returns the correct files. So the for loop seems to be working but the above script returns:

Error: Too many positional arguments (1), the offending value: /home/dwickell/data/Shen_transcriptomes/transcriptomes/Acrostichum_aureum_RS90/RS_90_BLASTdb.nin

for every BLASTdb file in the directory.

-edit-

So this works, but I don't know enough about bash to understand why:

SRV01:~/data$ for d in /home/dwickell/data/Shen_transcriptome/transcriptomes/*/*.nin; do 
    name=$(echo "$d" | cut -f 1 -d '.')
    blastn -query ./chitin_binding_protein/cbp_Tectaria_macrodonta.fa -db "$name" -outfmt 6 -out RS_103_tblastn.out; done
2

There are 2 best solutions below

1
On

I'm betting you have a directory with more than one matching BLAST file. Try this test:

for d in ~/data/Shen_transcriptomes/transcriptomes/*/; do
  echo "For directory $d have:"
  ls -1 "$d"*BLASTdb*
  echo
done
2
On

Okay so as I mentioned in the edit to my question above. I seem to have found a solution:

for d in /home/dwickell/data/Shen_transcriptomes/transcriptomes/*/*.nin; do 
    name=$(echo "$d" | cut -f 1 -d '.')
    blastn -query ./chitin_binding_protein/cbp_Tectaria_macrodonta.fa -db "$name" -outfmt 6 -out "$(basename "$d" .nin)".out; done

I'm not clear on why this works but it does. Perhaps it has something to do with the trailing asterisk in my earlier attempt? If anyone can clarify please do! However for my own purposes I consider this solved.

Thanks to everyone for commenting.