<p>If these are all GenBank or RefSeq accessions, you can use <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="nofollow noreferrer">Entrez Direct</a> for this as shown below:</p>
<pre><code>$ cat accs.txt 
ATO98108.1
ATO98120.1
ATO98132.1
AVP78031.1
AVP78042.1
$ cat accs.txt | epost -db nuccore | efetch -format acc
## no output because none of them are nucleotide accessions
$ cat accs.txt | epost -db protein -format acc | efetch -format acc
AVP78042.1
AVP78031.1
ATO98132.1
ATO98120.1
ATO98108.1
</code></pre>
<p><strong>NOTE</strong>: This will work only if the accessions are currently live because <code>epost</code> does not find any suppressed accessions. For example:</p>
<pre><code>$ cat accs.txt 
NM_002826.3
NM_002826.4
NM_002826.5
$ cat accs.txt | epost -db nuccore -format acc | efetch -format acc
NM_002826.5
</code></pre>
<p>Here, all three accessions are valid nucleotide accessions but only the last one, NM_002826.5, is alive.</p>
<p>An alternate way is to use the accession prefixes defined <a href="https://www.ncbi.nlm.nih.gov/genbank/acc_prefix/" rel="nofollow noreferrer">here</a> and come up with an appropriate regular expression query.</p>

CC BY-SA 4.0
2021-04-28T13:37:36.300Z
The alternate way (accession prefixes) is a great idea!
Someone_1313
CC BY-SA 4.0
2021-04-26T21:25:12.763Z
2021-04-27T11:34:00.910Z
2021-04-27T11:34:00.910Z
vkkodali
<p>I have a text file that contains a list of IDs (314 sequences):</p>
<pre><code>AVP78031.1
AVP78042.1
ATO98108.1
ATO98120.1
ATO98132.1
...
</code></pre>
<p>My goal is to make a script (maybe using Python or Perl) to check in the list if all the IDs are nucleotide or protein sequences.
For example:</p>
<pre><code>AVP78031.1 -&gt; protein (this is a nucleotide sequence, I change nucleotide for protein to show an example).
AVP78042.1 -&gt; nucleotide
ATO98108.1 -&gt; nucleotide
ATO98120.1 -&gt; nucleotide
ATO98132.1 -&gt; nucleotide
</code></pre>
<p>Any idea to do a script?</p>
<p>Thank everybody!</p>

<python><perl><sequence>
How to know if ID correspond to nucleotide sequence or protein with a script
# How to know if ID correspond to nucleotide sequence or protein with a script

(Asked by: username_0 on 2021-04-26)

I have a text file that contains a list of IDs (314 sequences):
AVP78031.1
AVP78042.1
ATO98108.1
ATO98120.1
ATO98132.1
...

My goal is to make a script (maybe using Python or Perl) to check in the list if all the IDs are nucleotide or protein sequences.
For example:
AVP78031.1 -> protein (this is a nucleotide sequence, I change nucleotide for protein to show an example).
AVP78042.1 -> nucleotide
ATO98108.1 -> nucleotide
ATO98120.1 -> nucleotide
ATO98132.1 -> nucleotide

Any idea to do a script?
Thank everybody!

**Tags:** python, perl, sequence

---

## 1 answers

### Answer by username_1 on 2021-04-26. Score: 2 | Accepted answer

If these are all GenBank or RefSeq accessions, you can use Entrez Direct for this as shown below:
$ cat accs.txt 
ATO98108.1
ATO98120.1
ATO98132.1
AVP78031.1
AVP78042.1
$ cat accs.txt | epost -db nuccore | efetch -format acc
## no output because none of them are nucleotide accessions
$ cat accs.txt | epost -db protein -format acc | efetch -format acc
AVP78042.1
AVP78031.1
ATO98132.1
ATO98120.1
ATO98108.1

NOTE: This will work only if the accessions are currently live because epost does not find any suppressed accessions. For example:
$ cat accs.txt 
NM_002826.3
NM_002826.4
NM_002826.5
$ cat accs.txt | epost -db nuccore -format acc | efetch -format acc
NM_002826.5

Here, all three accessions are valid nucleotide accessions but only the last one, NM_002826.5, is alive.
An alternate way is to use the accession prefixes defined here and come up with an appropriate regular expression query.

> **Comments:**
> **username_0**: The alternate way (accession prefixes) is a great idea!  

---

