This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get 1 top hit only for each query in blastx

I am running blastx using the following command:

blastx -query CDS.fa -db local_path_nr -num_threads 36 -evalue 1e-5 -outfmt 6 -max_target_seqs 1 -out CDS_blast.txt

I aim to get one hit for each query only but there are still, say 2-3 hits, per query occasionally. How do I save the top hit only? I know this can be done post-blast, but can I simply achieve it while running blast? Thanks!

blast rna-seq blastx

It should be easy for you to parse the output file such that only the top hit is retained.

I guess this command does not apply to blastx

2 answers

The max_hsps never really worked properly, they have some explanation for this if I recall. You can use sort to do that:

sort -k1,1 -k11,11g CDS_blast.txt | sort --merge -u  -k1,1

This will sort by query sequence and p-value (assuming default format 6 output), then will select the first result (lowest p-value) for each query

Thanks Asaf, yeh I agree the built-in option does not work properly.

Have you tried this option:

-num_alignments 1

You can also check other options using:

blastx --help

Hi Fatima, I tried it and I got the same result...

Log in to answer this question.