BLAST: Querying a single sequence without input file in C
1
0
Entering edit mode
7.4 years ago

This is with reference to the query posted in Local Blast: Querying A Single Sequence Without Input File. Possible ?. If I try to run the following using command line it runs perfectly fine:

blastn -query <(echo -e ">Name\nATCGTTAGCT") -subject <(echo -e ">Name\nATCGTTAGCT")


But, I am doing the same by a C program where I run BLASTP which takes in two strings (fasta_GWIDD and fasta_UNIPROT in the code) and compares them. The problem that I am encountering is the use of echo/system in the code. Can anyone suggest what am I missing out??

for(i=0;i<index1;i++)
{
sprintf(fasta_GWIDD,">%s\\n%s\n",fasta_name1[i],fasta_seq1[i]);
setenv("GwiddVar", fasta_GWIDD, 1) ;
sprintf(fasta_UNIPROT,">%s\\n%s\n",fasta_name2[i],fasta_seq2[i]);
setenv("UniprotVar", fasta_UNIPROT, 1) ;
system("blastp -query <(echo -e $GwiddVar) -subject<(echo -e$UniprotVar)");
}


The error is:

sh: -c: line 0: syntax error near unexpected token ('
sh: -c: line 0: blastp -query <(echo -e $GwiddVar) -subject<(echo -e$UniprotVar)'

blast C • 1.8k views
0
Entering edit mode

Did you try placing a space between -subject and <(? Also, where does sh point? You're using process substitution for bash. Anyway, there is a C API...

0
Entering edit mode

Placing a space between -subject and <( doesn't help. It gives the same error:

sh: -c: line 0: syntax error near unexpected token ('
sh: -c: line 0: blastp -query <(echo -e $GwiddVar) -subject <(echo -e$UniprotVar)'


Can you please clarify your last lines: "process substitution for bash" and "there is a C API"

0
Entering edit mode

As Pierre Lindenbaum mentioned, <(some process) is process substitution in bash, but not other shells. If sh is a different shell, such as the original sh, then that won't work. If you don't know what a shell is, then, well, you have some reading to do.

Since you're writing in C anyway, you might just want to use the C interface (aka, the C API) to blast and avoid all of this. I'm not sure how else to explain an interface if you don't know what that is other than to just link to the documentation.

0
Entering edit mode
7.4 years ago

as you can see, the shell engine invoked by system is sh NOT bash.

named pipes like <(echo -e \$GwiddVar) are only interpreted by bash

you should first save GwiddVar, in a file using fopen/fputs/fclose , and then invoke system:

blastp -query saved1.fa -subject saved1.fa

0
Entering edit mode

I have already tried writing it into file and got success with it. But I am working with almost 10000 entries and so opening and closing a file takes time. So wanted to use strings rather than files so as to make my program fast and efficient.

Can you suggest any other alternative using strings only.