1

I'm running an exe with multiple arguments that may or may not contain spaces. I encloses them with quotes but they are somehow not passed to the exe correctly.

Here's the command i'm using:

makeblastdb -in "D:\d b\sequence.fasta" -input_type fasta -dbtype prot -title xd -out "D:\d b\xd"

which I think cmd should pass 10 arguments to the exe but somehow it isn't passing correctly.

this is the result i get

BLAST options error: File "D:\d" does not exist.

which is basically saying that the second argument is being chopped for some reason?

Any help will be appreciated, thanks!

Jugal Shah
  • 3,621
  • 1
  • 24
  • 35
Jacob Wang
  • 4,411
  • 5
  • 29
  • 43
  • is the space in `D:\d b\sequence.fasta` intentional? – Baiyan Huang Feb 28 '13 at 01:49
  • 2
    It is the executables responsibility to parse the arguments, but as long as makeblastdb follows normal conventions, the quotes should protect the space such that the command should work. Is that command appearing in a larger context that could be throwing off the quote state? – dbenham Feb 28 '13 at 01:53
  • I'm suspecting that myself and is currently trying to find the source code of the exe. – Jacob Wang Feb 28 '13 at 02:09
  • If you have an argument that contains spaces, you need to surround it in double quotes or it assumes you're passing two arguments instead of one. – BDM Feb 28 '13 at 05:44
  • If you actually read my code you would see that I did put double quotes around them. I've figured out it is a problem of the executable makeblastdb which somehow can't deal with spaces in paths. I wrote an application myself and gave it the same inputs and they are received correctly. – Jacob Wang Feb 28 '13 at 09:18
  • This question is a real *blast* from the past :-) I used to develop cheminformatics software (RS3), and a bioinformatics subsidiary of our company developed software with BLAST. – dbenham Feb 28 '13 at 10:43

4 Answers4

3

Based on your comments to your question, the BLAST utility does not properly handle quoted paths with spaces, and your volume does not support short file names.

Obviously you can move your working directory to a path that does not contain spaces.

An alternative is to use SUBST to temporarily create a virtual drive that points to your problematic path.

subst K: "d:\d b"
makeblastdb -in "K:\sequence.fasta" -input_type fasta -dbtype prot -title xd -out "K:\xd"
subst /d K:

Type subst /? for help with the command.

Update based on fact that you are running the command from within python

In your comment to this answer, you state you will attempt to get the command to work from within python. That could be the entire source of your problem.

You should try to run the command in your question directly from a Windows command prompt (cmd.exe console).

If the command does not work from the command prompt, then the problem is indeed with the BLAST utility, and SUBST is a good solution.

If the command does work from the command prompt, then the problem is with how you are shelling out the command from python, and the SUBST command should not be required.

I'm not a python user, but I see that many people have similar problems when using python on Windows. Perhaps this will help: How do I execute a program from python? os.system fails due to spaces in path

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • That is very interesting. I'll surely try that to give the users more flexibility! Thanks heaps! (Will select as answer once I got it to work within the python file) – Jacob Wang Feb 28 '13 at 21:45
  • @JacobWang - This is the first time you meantioned python. That could be the source of your problem. See my updated answer. – dbenham Feb 28 '13 at 22:22
  • Yes I'm test that command on the windows shell and it is indeed the makeblastdb's problem. I copied the line above directly from what the python string is (which then gets run by subprocess.Popen). Also, I'm writing a cross-platform program for both windows and linux, so I'll probably need to find the equivalent of subst in linux too. Thanks! – Jacob Wang Mar 01 '13 at 07:00
  • @JacobWang - I believe the equivalent linux command is mount. – dbenham Mar 01 '13 at 13:07
2

makeblastdb has an odd escaping convention. Try this:

-in \""D:\d b\sequence.fasta"\"

Unfortunately this doesn't work for -out, so dbenham's answer is probably best.

Craig W
  • 4,390
  • 5
  • 33
  • 51
  • This worked for me. Als see [this relevant section from the BLAST manual](http://www.ncbi.nlm.nih.gov/books/NBK279669). – BioGeek Jul 08 '15 at 12:58
0

Alternative is you can try using directory shortname for "D:\d b" which you can find by running dir /X command on your D drive. For instance if I run dir /X on my C drive here is what I get:

01/21/2013    09:47 AM    <DIR>      PROGRA~1     Program Files

So you want to use C:\Program Files you can alternatively use C:\PROGRA~1.

Jugal Shah
  • 3,621
  • 1
  • 24
  • 35
  • I see, the name is not long enough for windows to create a short name. – Jugal Shah Feb 28 '13 at 02:05
  • but it has a space, which qualifies for a short filename. It should be something like `dbE960~1` (don't ask me where it takes the filler `E960` from) – Stephan Mar 17 '23 at 08:00
0

The answers here that worked for me in Windows were creating a transient virtual drive, as shown by dbenham (but this is not a viable solution for a general automated process that may be run on different computers and would be inefficient and impractical for multiple parallel threaded operations) or getting the short path string as pointed out by Jugal Shah (which is not always convenient, as it requires unmanaged code accessing kernel32.dll to utilize in C#, for example). However, it's an easy fix if you recompile the necessary blast project files from the source code.

If you are able to download the blast project code (e.g. version 2.12.0 from https://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/2.12.0/), you can rebuild makeblastdb.exe after modifying just two lines of code, and after rebuilding makeblastdb, db targets enclosed in quotes should work correctly when there are spaces in the path. Note: This was tested with v2.12.0 in Windows 11 with Visual Studio 2019, after first following project configuration instructions included with the ncbi code package and building and testing makeblastdb.exe, blastn.exe and blast_formatter.exe.

Lines of code to modify:

-- In .\ncbi-blast-2.12.0\c++\src\app\blastdb\makeblastdb.cpp, line 202 reads (if not line 202, close to it):

static const string kInputSeparators(" ");

To change the multi-input separator to, for example, a comma instead of a space, change it to:

static const string kInputSeparators(",");

-- In .\ncbi-blast-2.12.0\c++\src\objtools\blast\seqdb_reader\seqdbcommon.cpp, line 1789 reads (if not line 1789, close to it):

if (ch == ' ') {

Change it to:

if (ch == ',') {

Rebuild makeblastdb.exe and the problem should be solved. Enclose the target "-in" path in quotes and it should no longer be parsed into space-delimited strings.

If you want other programs (e.g. blastn, blast_formatter, etc.) to work correctly with quote-enclosed paths with spaces in the path, those modules will need to be rebuilt as well.

Tom Hall
  • 1
  • 1