<p>I inquired with the NCBI BLAST help desk today, and within an hour they provided a very helpful response.</p>
<p>To summarize, when redundant records in the database are collapsed, the deflines (accessions + descriptions) of the original entries are placed on a single line separated by an invisible control character (Ctrl-A or <code>\x01</code>). The <code>makeblastdb</code> program will recognize this and associate multiple accessions (from the combined defline) and taxids (from the taxid_map file) to a single entry. If you are retrieving entries from e.g. nt or nr with <code>blastdbcmd</code>, you can use the <code>-ctrl_a</code> flag to format the data with these invisible control characters—by default the <code>&gt;</code> character is used.</p>
<hr />
<p><strong>tl;dr</strong> I can reproduce the behavior described in the original question by:</p>
<ol>
<li>creating a FASTA file containing an entry with multiple accessions separated by the invisible <code>\x01</code> character</li>
<li>create a taxid_map file mapping the accessions to different taxids</li>
<li>format the FASTA file with <code>makeblastdb -taxid_map ...</code></li>
<li>perform a BLAST search with a query that matches the entry in question; <code>-outfmt &quot;6 staxids&quot;</code> will return a string with multiple taxids.</li>
</ol>

CC BY-SA 4.0
2022-01-26T20:41:56.410Z
Thanks for answering your question. Its good to know the NCBI helpdesk is fast and knowledgeable.
M__
CC BY-SA 4.0
2022-01-26T19:34:50.797Z
2022-01-26T19:34:50.797Z
Daniel Standage
<p>I recently had a script fail due to poor handling of BLAST output. The BLAST <code>-outfmt staxids</code> field usually returns a single taxid, but occasionally it returns two or more taxids separated by a semicolon, such as <code>556514;701533</code>. Fixing the script to handle this should be fairly straightforward. But the original failure happened when I was searching a local copy of the NCBI nt database, and I'd like to create a test case with a small query and small database that reproduces this issue more rapidly.</p>
<p>I am familiar with the <code>-taxid</code> and <code>-taxid_map</code> flags of the <code>makeblastdb</code> command, but I have been unable to reproduce this behavior with BLAST; that is, make BLAST return multiple taxids for a sequence.</p>
<ul>
<li>If I provide <code>556514;701533</code> or <code>556514,701533</code> as a sequence's taxid with <code>-taxid</code> or <code>-taxid_map</code>, the <code>makeblastdb</code> command fails citing an integer conversion error.</li>
<li>If I provide <code>556514 701533</code> as the taxid in the <code>taxid_map</code> file, the database will be indexed successfully but BLAST will return the invalid value <code>0</code> for <code>staxids</code>.</li>
<li>If I duplicate each entry in the <code>-taxid_map</code> file so that there is an entry for each taxid (see below), only a single taxid is reported by BLAST.
<pre><code>seq1 556514
seq1 701533
seq2 556514
seq2 701533
seq3 556514
seq3 701533
...
</code></pre>
</li>
</ul>
<p>When constructing a custom local BLAST database, how do I associated a database sequence with more than one taxid?</p>
<hr />
<p><strong>UPDATE</strong>: The offending entry (or one such entry) appears to be a duplicate or merged entry in the nt database. When I use <code>blastdbcmd</code> to retrieve the subject sequence by accession, nt returns a sequence with two deflines on single line, like so.</p>
<pre><code>&gt;accession1 plain text description &gt;accession2 other description
ACGT...
</code></pre>
<p>Using either of the two accessions, <code>blastdbcmd</code> will return the exact same entry, and the two staxids shown above correspond to the two distinct accessions.</p>
<p><strong>So part of the issue seems to be how to construct a BLAST database such that multiple accessions can point to a single entry/subject.</strong></p>

CC BY-SA 4.0
2022-01-25T15:27:28.497Z
Can't you just jiggle it around in pandas? That was my approach leveraging local blast, albeit for something it was probably not intended to do
M__
CC BY-SA 4.0
2022-01-25T18:43:25.303Z
@M__ I already have what I think is a solution, yes involving post-processing the BLAST tabular results in a dataframe. But I'll re-emphasize that I'm trying to construct a test case that will reproduce this behavior *in BLAST*.
Daniel Standage
CC BY-SA 4.0
2022-01-25T18:53:34.180Z
Thanks now I understand. If a Blast expert answers I'll be enlightened too.
M__
<blast><taxonomy><makeblastdb>
Assign multiple taxids to a sequence when constructing a local BLAST database
# Assign multiple taxids to a sequence when constructing a local BLAST database

(Asked by: username_0 on 2022-01-24)

I recently had a script fail due to poor handling of BLAST output. The BLAST -outfmt staxids field usually returns a single taxid, but occasionally it returns two or more taxids separated by a semicolon, such as 556514;701533. Fixing the script to handle this should be fairly straightforward. But the original failure happened when I was searching a local copy of the NCBI nt database, and I'd like to create a test case with a small query and small database that reproduces this issue more rapidly.
I am familiar with the -taxid and -taxid_map flags of the makeblastdb command, but I have been unable to reproduce this behavior with BLAST; that is, make BLAST return multiple taxids for a sequence.

If I provide 556514;701533 or 556514,701533 as a sequence's taxid with -taxid or -taxid_map, the makeblastdb command fails citing an integer conversion error.
If I provide 556514 701533 as the taxid in the taxid_map file, the database will be indexed successfully but BLAST will return the invalid value 0 for staxids.
If I duplicate each entry in the -taxid_map file so that there is an entry for each taxid (see below), only a single taxid is reported by BLAST.
seq1 556514
seq1 701533
seq2 556514
seq2 701533
seq3 556514
seq3 701533
...



When constructing a custom local BLAST database, how do I associated a database sequence with more than one taxid?

UPDATE: The offending entry (or one such entry) appears to be a duplicate or merged entry in the nt database. When I use blastdbcmd to retrieve the subject sequence by accession, nt returns a sequence with two deflines on single line, like so.
>accession1 plain text description >accession2 other description
ACGT...

Using either of the two accessions, blastdbcmd will return the exact same entry, and the two staxids shown above correspond to the two distinct accessions.
So part of the issue seems to be how to construct a BLAST database such that multiple accessions can point to a single entry/subject.

**Tags:** blast, taxonomy, makeblastdb
> **Comments:**
> **username_1**: Can't you just jiggle it around in pandas? That was my approach leveraging local blast, albeit for something it was probably not intended to do  
> **username_0**: @M__ I already have what I think is a solution, yes involving post-processing the BLAST tabular results in a dataframe. But I'll re-emphasize that I'm trying to construct a test case that will reproduce this behavior *in BLAST*.  
> **username_1**: Thanks now I understand. If a Blast expert answers I'll be enlightened too.  

---

## 1 answers

### Answer by username_0 on 2022-01-26. Score: 4 | Accepted answer

I inquired with the NCBI BLAST help desk today, and within an hour they provided a very helpful response.

To summarize, when redundant records in the database are collapsed, the deflines (accessions + descriptions) of the original entries are placed on a single line separated by an invisible control character (Ctrl-A or `\x01`). The `makeblastdb` program will recognize this and associate multiple accessions (from the combined defline) and taxids (from the taxid\_map file) to a single entry. If you are retrieving entries from e.g. nt or nr with `blastdbcmd`, you can use the `-ctrl_a` flag to format the data with these invisible control characters—by default the `>` character is used.

---

**tl;dr** I can reproduce the behavior described in the original question by:

1. creating a FASTA file containing an entry with multiple accessions separated by the invisible `\x01` character
2. create a taxid\_map file mapping the accessions to different taxids
3. format the FASTA file with `makeblastdb -taxid_map ...`
4. perform a BLAST search with a query that matches the entry in question; `-outfmt "6 staxids"` will return a string with multiple taxids.

> **Comments:**
> **username_1**: Thanks for answering your question. Its good to know the NCBI helpdesk is fast and knowledgeable.  

---

