<p>I looked back at the question and have a more comprehensive solution.</p>
<ol>
<li>There is no option for <code>-entrez_query</code> on a local blast search. The information is <a href="https://www.ncbi.nlm.nih.gov/books/NBK279684/table/appendices.T.options_common_to_all_blast/" rel="nofollow noreferrer">here</a></li>
</ol>
<blockquote>
<p>entrez_query   Restrict search with the given Entrez query. Remote searches only.</p>
</blockquote>
<p>There is an option without <code>-outfmt</code> for <code>length</code> and that is worth investigating.</p>
<blockquote>
<p>length means Alignment length</p>
</blockquote>
<ol start="2">
<li><h3>Perl one liner solution to NCBI's many parameter problem</h3>
</li>
</ol>
<p>a) Preprocess your fasta file into separate databases of the required length ... by turning a fasta flatfile db into one where all the subject sequences are 700 - 1000.</p>
<pre><code>perl -0777 -nle 'while (/^(&gt;.+\n^[AGCT-NRYMKWS]{700,1000})\n/gm){print $1,&quot;\n&quot;}' example.fa &gt; example700-1000.fa
</code></pre>
<p>b) Now make the database on the restricted length fasta flatfile db,</p>
<pre><code>makeblastdb -in example700-1000.fa -parse_seqids -blastdb_version 5  -out laura700-1000.db -title &quot;Laura 700 - 1000&quot; -dbtype nucl
</code></pre>
<p>This db will now contain an equivalent of the <code>-entrez_query 700:1000[slen]</code>. Obviously, you would need to make a new db for each change in the sequence length query. Note the option <code>-taxid_map</code>.</p>
<p>c) Finally, run the blast search on the restricted length blast db.</p>
<pre><code>blastn -query laura.fas -db laura700-1000.db -evalue 1e-6 -num_threads 4 -out blasthits.txt
</code></pre>
<hr />
<h4>Code testing</h4>
<p><strong>Input is test.fa</strong></p>
<pre><code>&gt;here
AGAGACGTAGAGAAAAAAAAAA
&gt;here2
TAGAGA
&gt;here3
AGAGACGTAGAGA
</code></pre>
<p>Modified perl oneliner because sequence length is different,</p>
<pre><code>perl -0777 -nle 'while (/^(&gt;.+\n^[AGC-T]{6,13})\n/gm){print $1,&quot;\n&quot;}' test.fa
</code></pre>
<p><strong>Output</strong></p>
<pre><code>&gt;here2
TAGAGA
&gt;here3
AGAGACGTAGAGA
</code></pre>
<p>Thus the sequence that was outside the range 6 to 13 (sequence <code>here2</code> and <code>here3</code>) is excluded (<code>here</code>). This seems alot easier to me that all those <code>blastn</code> options.</p>
<p><strong>Note</strong> NRYMKWS refer to the degenerate nucleotide code</p>

CC BY-SA 4.0
2022-10-11T13:50:00.357Z
2022-10-14T21:34:28.830Z
2022-10-14T21:34:28.830Z
M__
<p>&quot;Often, one needs to search ... a specific subset of sequences within an existing database. For these type of searches a convenient way to conduct them is by creating a virtual BLAST database&quot;</p>
<p>From &quot;Use blastdb_aliastool to manage the BLAST databases&quot; <a href="https://www.ncbi.nlm.nih.gov/books/NBK569848/" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/books/NBK569848/</a></p>

CC BY-SA 4.0
2022-10-20T05:05:56.143Z
2022-10-20T05:05:56.143Z
malcook
<p>I have been having some trouble with running command line BLASTn remotely. Therefore, upon recommendations, and considering I have &gt;100 searches planned, I am considering just downloading the nt database (thankfully possible).</p>
<p>My issue is that one of the settings that proved valuable with my data in WebBlast is running an Entrez query. I get more useful results for each query when instead of one search, I run three, with each of the sub-searches delimited by subject sequence length (e.g. <code>-entrez_query 700:1000[slen]</code> to only get the results which are between 700 and 1000 nucleotides long).</p>
<p>WebBlast and remote Blast have that, local Blast does not.</p>
<p>Since I only really need 2 Entrez queries, I guess it would not be conceptually impossible to get my copy of nt database as FASTA, and then run a script to split it into three directories (700-1000nt, 1000-1400nt, the rest while discarding all&lt;700 nt), then make three blastable databases out of it. However it does feel rather inelegant. I was wondering if anyone might have a better solution!</p>

CC BY-SA 4.0
2022-10-15T01:19:15.557Z
Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/139871/discussion-on-question-by-laura-is-there-an-equivalent-of-entrez-queries-for-loc).
gringer
<blast><bash><blastn><entrez>
Is there an equivalent of Entrez queries for local BLAST?
# Is there an equivalent of Entrez queries for local BLAST?

(Asked by: username_0 on 2022-10-11)

I have been having some trouble with running command line BLASTn remotely. Therefore, upon recommendations, and considering I have >100 searches planned, I am considering just downloading the nt database (thankfully possible).

My issue is that one of the settings that proved valuable with my data in WebBlast is running an Entrez query. I get more useful results for each query when instead of one search, I run three, with each of the sub-searches delimited by subject sequence length (e.g. `-entrez_query 700:1000[slen]` to only get the results which are between 700 and 1000 nucleotides long).

WebBlast and remote Blast have that, local Blast does not.

Since I only really need 2 Entrez queries, I guess it would not be conceptually impossible to get my copy of nt database as FASTA, and then run a script to split it into three directories (700-1000nt, 1000-1400nt, the rest while discarding all<700 nt), then make three blastable databases out of it. However it does feel rather inelegant. I was wondering if anyone might have a better solution!

**Tags:** blast, bash, blastn, entrez
> **Comments:**
> **username_1**: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/139871/discussion-on-question-by-laura-is-there-an-equivalent-of-entrez-queries-for-loc).  

---

## 2 answers

### Answer by username_2 on 2022-10-11. Score: 1

I looked back at the question and have a more comprehensive solution.

There is no option for -entrez_query on a local blast search. The information is here


entrez_query   Restrict search with the given Entrez query. Remote searches only.

There is an option without -outfmt for length and that is worth investigating.

length means Alignment length


Perl one liner solution to NCBI's many parameter problem


a) Preprocess your fasta file into separate databases of the required length ... by turning a fasta flatfile db into one where all the subject sequences are 700 - 1000.
perl -0777 -nle 'while (/^(>.+\n^[AGCT-NRYMKWS]{700,1000})\n/gm){print $1,"\n"}' example.fa > example700-1000.fa

b) Now make the database on the restricted length fasta flatfile db,
makeblastdb -in example700-1000.fa -parse_seqids -blastdb_version 5  -out laura700-1000.db -title "Laura 700 - 1000" -dbtype nucl

This db will now contain an equivalent of the -entrez_query 700:1000[slen]. Obviously, you would need to make a new db for each change in the sequence length query. Note the option -taxid_map.
c) Finally, run the blast search on the restricted length blast db.
blastn -query laura.fas -db laura700-1000.db -evalue 1e-6 -num_threads 4 -out blasthits.txt


Code testing
Input is test.fa
>here
AGAGACGTAGAGAAAAAAAAAA
>here2
TAGAGA
>here3
AGAGACGTAGAGA

Modified perl oneliner because sequence length is different,
perl -0777 -nle 'while (/^(>.+\n^[AGC-T]{6,13})\n/gm){print $1,"\n"}' test.fa

Output
>here2
TAGAGA
>here3
AGAGACGTAGAGA

Thus the sequence that was outside the range 6 to 13 (sequence here2 and here3) is excluded (here). This seems alot easier to me that all those blastn options.
Note NRYMKWS refer to the degenerate nucleotide code


---

### Answer by username_3 on 2022-10-20. Score: 0

"Often, one needs to search ... a specific subset of sequences within an existing database. For these type of searches a convenient way to conduct them is by creating a virtual BLAST database"

From "Use blastdb\_aliastool to manage the BLAST databases" <https://www.ncbi.nlm.nih.gov/books/NBK569848/>


---

