Run BLASTN command line using string rather than file
1
0
Entering edit mode
5.4 years ago

Hello,

I am running Blastn from terminal to search for a sequence. The parameter -query takes a file; would it be possible to use a string instead? If I have the sequence in a variable Q. what would be the flag for blastn ... -? $Q? Thank you

blastn terminal input format • 3.9k views
ADD COMMENT
5
Entering edit mode
5.4 years ago
GenoMax 148k

Take the following with a grain of salt until you test it out yourself. Much to my surprise blastn seems to work with a variable containing just sequence as input.

I made a test database with one sequence in it (truncated for brevity).

$ more test.fa
>Z18649.1 L.obscurus gene for large subunit rRNA
GGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTAGCATAATCAC
TTGTTCTCTAAATAAGGACTTGTATGAATGGCCACACGAGGGTTTTACTGTCTCTTACTCTTAATCAGTG

Defined a variable with sequence that wrapped around on multiple lines.

$ export C="GGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTAGCATAATCAC
TTGTTCTCTAAATAAGGACTTGTATGAATGGCCACACGAGGGTTTTACTGTCTCTTACTCTTAATCAGTG
AAATTGACCTCCCCGTGAAGAGGCGGGGATAACACAATAAGACGAGAAGACCCTATGGAGCTTTAATTAA"

Echo the sequence out (it still has new line gaps, which you can remove).

$ echo $C
GGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTAGCATAATCAC TTGTTCTCTAAATAAGGACTTGTATGAATGGCCACACGAGGGTTTTACTGTCTCTTACTCTTAATCAGTG AAATTGACCTCCCCGTGAAGAGGCGGGGATAACACAATAAGACGAGAAGACCCTATGGAGCTTTAATTAA

Run blast search.

$ blastn -db ./junk -task blastn -query <(echo $C) -out blasting

Get the search results (truncated).

Database: test.fa
           1 sequences; 505 total letters

Query= 
Length=210
                                                                      Score        E
Sequences producing significant alignments:                          (Bits)     Value

Z18649.1 L.obscurus gene for large subunit rRNA                       388        8e-113

>Z18649.1 L.obscurus gene for large subunit rRNA
Length=505

 Score = 388 bits (210),  Expect = 8e-113
 Identities = 210/210 (100%), Gaps = 0/210 (0%)
 Strand=Plus/Plus

Query  1    GGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTA  60
            ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sbjct  1    GGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTA  60
ADD COMMENT
0
Entering edit mode

Just a small note, the OS will make it appear as a file to blast

ls <(echo $C) will give an output like /dev/fd/63

ADD REPLY
1
Entering edit mode

Blast can parse fasta files as direct query, then it would output the regular sequence name. See this very old thread:

Local Blast: Querying A Single Sequence Without Input File. Possible ?

seq=">SeqName\nGGCACTGCCTGCCCAGTGACAATCGTTAAACGGCCGCGGTATCTTGACCGTGCAAAGGTAGCATAATCACTTGTTCTCTAAATAAGGACTTGTATGAATGGCCACACGAGGGTTTTACTGTCTCTTACTCTTAATCAGTGAAATTGACCTCCCCGTGAAGAGGCGGGGATAACACAATAAGACGAGAAGACCCTATGGAGCTTTAATTAA"

blastn -db ./junk -task blastn -query <(echo -e $seq) -out blasting
ADD REPLY
0
Entering edit mode

looks like it is working indeed: I obtained a file with the output. Thank you.

ADD REPLY
0
Entering edit mode

I would argue the answer to this question is simply “no”. Just creating an ad hoc file input from a variable isn’t really the same thing as passing a string.

ADD REPLY

Login before adding your answer.

Traffic: 2109 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6