<p>You can get the data from the API of the European Nucleotide Archive (ENA) which is synched with NCBI/GenBank:</p>
<p><a href="https://www.ebi.ac.uk/ena/browser/api/fasta/MZ039713,MZ039682,OV522182" rel="nofollow noreferrer">https://www.ebi.ac.uk/ena/browser/api/fasta/MZ039713,MZ039682,OV522182</a></p>

CC BY-SA 4.0
2022-02-28T18:12:21.523Z
2022-02-28T18:12:21.523Z
CC.
<p>In the <code>efetch.fcgi</code> URL, you can set <code>rettype=fasta</code> to download the nucleotide sequence or <code>rettype=fasta_cds_aa</code> to download protein coding sequences:</p>
<pre><code><span class="math-container">$ curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&amp;rettype=fasta&amp;id=NC_045512.2'|head -n3
&gt;NC_045512.2 Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome
ATTAAAGGTTTATACCTTCCCAGGTAACAAACCAACCAACTTTCGATCTCTTGTAGATCTGTTCTCTAAA
CGAACTTTAAAATCTGTGTGGCTGTCACTCGGCTGCATGCTTAGTGCACTCACGCAGTATAATTAATAAC
$</span> curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&amp;rettype=fasta_cds_aa&amp;id=NC_045512.2'|head -n3
&gt;lcl|NC_045512.2_prot_YP_009724389.1_1 [gene=ORF1ab] [locus_tag=GU280_gp01] [db_xref=GeneID:43740578] [protein=ORF1ab polyprotein] [exception=ribosomal slippage] [protein_id=YP_009724389.1] [location=join(266..13468,13468..21555)] [gbkey=CDS]
MESLVPGFNEKTHVQLSLPVLQVRDVLVRGFGDSVEEVLSEARQHLKDGTCGLVEVEKGVLPQLEQPYVF
IKRSDARTAPHGHVMVELVAELEGIQYGRSGETLGVLVPHVGEIPVAYRKVLLRKNGNKGAGGHSYGADL
</code></pre>

CC BY-SA 4.0
2023-03-18T08:45:20.397Z
2023-03-18T08:45:20.397Z
nisetama
<p>You can try the <a href="https://www.ncbi.nlm.nih.gov/datasets/docs/v1/reference-docs/rest-api/" rel="nofollow noreferrer">NCBI Datasets API</a>. We have an endpoint that would allow you to download virus sequences by <a href="https://www.ncbi.nlm.nih.gov/datasets/docs/v1/reference-docs/rest-api/#get-/virus/accession/-accessions-/genome/download" rel="nofollow noreferrer">accession</a>  The only thing to be aware (based on your list of accessions) is that our API needs the accession version to return results. In the case of your examples, they would need to be MZ039713.1, MZ039682.1 and OV522182.1.
I hope this helps!</p>

CC BY-SA 4.0
2022-03-03T20:47:14.960Z
Thanks! Can you provide an example query? The API documentation is a bit overwhelming to me. Also, am I correct in assuming you need a private API key?
Cornelius Roemer
CC BY-SA 4.0
2022-03-04T18:30:09.873Z
You don't need a private API key.
Using the accessions you provided as an example, you can create a json file (`accessions.json`):    
`{"accessions":["MZ039713.1", "MZ039682.1", "OV522182.1"]}`

Then, you can use the following command to download everything using the API:  
`cat accessions.json | curl -H "Content-Type: application/json" -X POST --data-binary @- "https://api.ncbi.nlm.nih.gov/datasets/v1/virus/genome/download" --output file.zip`

Let me know if you run into any issues.
MirianT
CC BY-SA 4.0
2022-03-03T18:18:16.070Z
2022-03-03T18:18:16.070Z
MirianT
<p>There are three ways to do this,</p>
<ol>
<li>If you click on this link <a href="https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&amp;VirusLineage_ss=SARS-CoV-2,%20taxid:2697049&amp;ids=MZ039713%20MZ039682%20OV522182%20" rel="nofollow noreferrer">Your NCBI examples</a>. Its done.</li>
<li>You would then just click &quot;download&quot;</li>
<li>Click &quot;next&quot;, click &quot;next&quot;</li>
</ol>
<p>The sequence then downloads.</p>
<p>Essentially all I did was in the website click on the left hand navigation bar and clicked &quot;accession number&quot; and type in <code>MZ039713 MZ039682 OV522182</code>.</p>
<ol>
<li>The second way is to go to <a href="https://ncbi.nlm.nih.gov/nuccore" rel="nofollow noreferrer">https://ncbi.nlm.nih.gov/nuccore</a></li>
<li>Type type in <code>MZ039713 MZ039682 OV522182</code></li>
<li>Click on the &quot;Summary&quot; and click on &quot;Fasta&quot;</li>
<li>Click on &quot;send to&quot; and click on &quot;File&quot;</li>
</ol>
<p>I'm not certain is point 3 immediately above is required.</p>
<p>The final approach is to use efetch to automate the download, but that requires downloading the NCBI's efetch suite, which is then flipped through on a bash loop.</p>
<pre><code>efetch -db nuccore -id MZ039682 -format fasta
</code></pre>
<p>The link for looking to automate is:
<a href="https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&amp;VirusLineage_ss=SARS-CoV-2,%20taxid:2697049&amp;ids=MZ039713%20MZ039682%20OV522182%20" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&amp;VirusLineage_ss=SARS-CoV-2,%20taxid:2697049&amp;ids=MZ039713%20MZ039682%20OV522182%20</a></p>
<p>Just to highlight
<strong>MZ039713</strong>%20<strong>MZ039682</strong>%20<strong>OV522182%20</strong></p>
<p>The API is <a href="https://www.ncbi.nlm.nih.gov/home/develop/api/" rel="nofollow noreferrer">here</a>, but I don't use them.</p>

CC BY-SA 4.0
2022-02-22T14:16:05.530Z
Thanks! I clarified that I would like the download link to be programmatic = API, not needing to do any clicking in a web app.
So do I understand it correctly that there really is _no_ simple API to download these fastas? I need to download some efetch suite to do programmatic = non-interactive downloads?
Cornelius Roemer
CC BY-SA 4.0
2022-02-22T14:13:47.893Z
2022-02-22T14:45:28.263Z
2022-02-22T14:45:28.263Z
M__
<p>I would like to download a number of SARS-CoV-2 fastas from <a href="https://www.ncbi.nlm.nih.gov/sars-cov-2/" rel="nofollow noreferrer">NCBI/Genbank</a> using a web endpoint. I looked on their website but it's confusing.</p>
<p>I have the accession numbers, but can't figure out how to use the NCBI/Genbank Entrez API.</p>
<p>This is how I would do it using cov-spectrum: <a href="https://lapis.cov-spectrum.org/open/v1/sample/fasta?genbankAccession=MZ039713,MZ039682,OV522182" rel="nofollow noreferrer">https://lapis.cov-spectrum.org/open/v1/sample/fasta?genbankAccession=MZ039713,MZ039682,OV522182</a></p>
<p>Is there something similar for NCBI/Genbank?</p>
<p>There must be a way, I just can't figure it out. The whole entrez thing is overwhelming to me, all I want is a simple API, like covSpectrum offers, for example. I scanned this but didn't help: <a href="https://www.ncbi.nlm.nih.gov/sars-cov-2/" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/sars-cov-2/</a></p>
<p>E.g. how could I download all these SARS-CoV-2 nucleotide sequences with accession numbers: <code>MZ039713</code>,<code>MZ039682</code> and <code>OV522182</code> using a URL?</p>
<p>Some command line tools are advertised, but I don't want to have to use a CLI tool. Just a simple URL, does that not exist? CLI tools: <a href="https://www.ncbi.nlm.nih.gov/datasets/docs/v1/quickstarts/command-line-tools/" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/datasets/docs/v1/quickstarts/command-line-tools/</a></p>
<p>I also don't want to do any clicking through a web interface, just a URL so that other web apps can download it behind the scenes.</p>

CC BY-SA 4.0
2022-02-22T13:38:54.807Z
Could you please let us know which ones?
M__
CC BY-SA 4.0
2022-02-22T13:42:09.350Z
@M__ what do you mean by "which ones"? For example fastas for these accession IDs: MZ039713, MZ039682 and OV522182 like displayed here: https://www.ncbi.nlm.nih.gov/nuccore/OV522182
Cornelius Roemer
CC BY-SA 4.0
2022-02-22T13:43:41.713Z
Thanks I'll put a response together. Can't do it immediately, but will do today
M__
<fasta><phylogenetics><sars-cov-2><covid-19><genbank>
How to programatically download SARS-CoV-2 fasta from NCBI/Genbank via API?
# How to programatically download SARS-CoV-2 fasta from NCBI/Genbank via API?

(Asked by: username_0 on 2022-02-22)

I would like to download a number of SARS-CoV-2 fastas from [NCBI/Genbank](https://www.ncbi.nlm.nih.gov/sars-cov-2/) using a web endpoint. I looked on their website but it's confusing.

I have the accession numbers, but can't figure out how to use the NCBI/Genbank Entrez API.

This is how I would do it using cov-spectrum: <https://lapis.cov-spectrum.org/open/v1/sample/fasta?genbankAccession=MZ039713,MZ039682,OV522182>

Is there something similar for NCBI/Genbank?

There must be a way, I just can't figure it out. The whole entrez thing is overwhelming to me, all I want is a simple API, like covSpectrum offers, for example. I scanned this but didn't help: <https://www.ncbi.nlm.nih.gov/sars-cov-2/>

E.g. how could I download all these SARS-CoV-2 nucleotide sequences with accession numbers: `MZ039713`,`MZ039682` and `OV522182` using a URL?

Some command line tools are advertised, but I don't want to have to use a CLI tool. Just a simple URL, does that not exist? CLI tools: <https://www.ncbi.nlm.nih.gov/datasets/docs/v1/quickstarts/command-line-tools/>

I also don't want to do any clicking through a web interface, just a URL so that other web apps can download it behind the scenes.

**Tags:** fasta, phylogenetics, sars-cov-2, covid-19, genbank
> **Comments:**
> **username_1**: Could you please let us know which ones?  
> **username_0**: @M__ what do you mean by "which ones"? For example fastas for these accession IDs: MZ039713, MZ039682 and OV522182 like displayed here: https://www.ncbi.nlm.nih.gov/nuccore/OV522182  
> **username_1**: Thanks I'll put a response together. Can't do it immediately, but will do today  

---

## 4 answers

### Answer by username_2 on 2022-02-28. Score: 2 | Accepted answer

You can get the data from the API of the European Nucleotide Archive (ENA) which is synched with NCBI/GenBank:

<https://www.ebi.ac.uk/ena/browser/api/fasta/MZ039713,MZ039682,OV522182>


---

### Answer by username_3 on 2023-03-18. Score: 2

In the efetch.fcgi URL, you can set rettype=fasta to download the nucleotide sequence or rettype=fasta_cds_aa to download protein coding sequences:
$ curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&rettype=fasta&id=NC_045512.2'|head -n3
>NC_045512.2 Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1, complete genome
ATTAAAGGTTTATACCTTCCCAGGTAACAAACCAACCAACTTTCGATCTCTTGTAGATCTGTTCTCTAAA
CGAACTTTAAAATCTGTGTGGCTGTCACTCGGCTGCATGCTTAGTGCACTCACGCAGTATAATTAATAAC
$ curl 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&rettype=fasta_cds_aa&id=NC_045512.2'|head -n3
>lcl|NC_045512.2_prot_YP_009724389.1_1 [gene=ORF1ab] [locus_tag=GU280_gp01] [db_xref=GeneID:43740578] [protein=ORF1ab polyprotein] [exception=ribosomal slippage] [protein_id=YP_009724389.1] [location=join(266..13468,13468..21555)] [gbkey=CDS]
MESLVPGFNEKTHVQLSLPVLQVRDVLVRGFGDSVEEVLSEARQHLKDGTCGLVEVEKGVLPQLEQPYVF
IKRSDARTAPHGHVMVELVAELEGIQYGRSGETLGVLVPHVGEIPVAYRKVLLRKNGNKGAGGHSYGADL


---

### Answer by username_4 on 2022-03-03. Score: 2

You can try the [NCBI Datasets API](https://www.ncbi.nlm.nih.gov/datasets/docs/v1/reference-docs/rest-api/). We have an endpoint that would allow you to download virus sequences by [accession](https://www.ncbi.nlm.nih.gov/datasets/docs/v1/reference-docs/rest-api/#get-/virus/accession/-accessions-/genome/download) The only thing to be aware (based on your list of accessions) is that our API needs the accession version to return results. In the case of your examples, they would need to be MZ039713.1, MZ039682.1 and OV522182.1.
I hope this helps!

> **Comments:**
> **username_0**: Thanks! Can you provide an example query? The API documentation is a bit overwhelming to me. Also, am I correct in assuming you need a private API key?  
> **username_4**: You don't need a private API key. Using the accessions you provided as an example, you can create a json file (`accessions.json`):     `{"accessions":["MZ039713.1", "MZ039682.1", "OV522182.1"]}`  Then, you can use the following command to download everything using the API:   `cat accessions.json | curl -H "Content-Type: application/json" -X POST --data-binary @- "https://api.ncbi.nlm.nih.gov/datasets/v1/virus/genome/download" --output file.zip`  Let me know if you run into any issues.  

---

### Answer by username_1 on 2022-02-22. Score: 1

There are three ways to do this,

If you click on this link Your NCBI examples. Its done.
You would then just click "download"
Click "next", click "next"

The sequence then downloads.
Essentially all I did was in the website click on the left hand navigation bar and clicked "accession number" and type in MZ039713 MZ039682 OV522182.

The second way is to go to https://ncbi.nlm.nih.gov/nuccore
Type type in MZ039713 MZ039682 OV522182
Click on the "Summary" and click on "Fasta"
Click on "send to" and click on "File"

I'm not certain is point 3 immediately above is required.
The final approach is to use efetch to automate the download, but that requires downloading the NCBI's efetch suite, which is then flipped through on a bash loop.
efetch -db nuccore -id MZ039682 -format fasta

The link for looking to automate is:
https://www.ncbi.nlm.nih.gov/labs/virus/vssi/#/virus?SeqType_s=Nucleotide&VirusLineage_ss=SARS-CoV-2,%20taxid:2697049&ids=MZ039713%20MZ039682%20OV522182%20
Just to highlight
MZ039713%20MZ039682%20OV522182%20
The API is here, but I don't use them.

> **Comments:**
> **username_0**: Thanks! I clarified that I would like the download link to be programmatic = API, not needing to do any clicking in a web app. So do I understand it correctly that there really is _no_ simple API to download these fastas? I need to download some efetch suite to do programmatic = non-interactive downloads?  

---

