Answers.Body: <p>Just <code>wget</code> or <code>curl</code> each as <code>https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&amp;log$=seqview&amp;format=text</code>...</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T18:02:17.283Z
Answers.Text: Thank you very much.
Answers.UserDisplayName: MudithMMBc
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-27T15:30:16.157Z
Answers.Text: This doesn’t seem to work (any longer?). For instance, `curl -L 'https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&log$=seqview&format=text'` downloads a HTML page with an (invisible) form on it, not a FASTA file.
Answers.UserDisplayName: Konrad Rudolph
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-06T16:21:23.373Z
Answers.LastActivityDate: 2019-11-06T16:21:23.373Z
Answers.UserDisplayName: Matteo Ferla
Answers.Body: <ol>
  <li>Go to <a href="https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&amp;log$=seqview&amp;format=text..." rel="nofollow noreferrer">the main FASTA sequence page</a>, view source, and get the "ncbi_uidlist" value.  In this case, it's <code>1061361601</code></li>
  <li><p>Use the ID in the query string to download directly:</p>
  
  <p><a href="https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?id=" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?id=</a><strong>1061361601</strong>&amp;db=nuccore&amp;report=fasta&amp;retmode=text&amp;withmarkup=on&amp;tool=portal&amp;log$=seqview&amp;maxdownloadsize=100000000</p></li>
  </ol>
  
  <p>You can also get this link directly, by using Chrome's developer tools (F12), viewing the Network tab, then loading the page in (1).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-24T19:45:19.593Z
Answers.LastActivityDate: 2020-02-24T19:45:19.593Z
Answers.UserDisplayName: BlueSky
Answers.Body: <h2>Downloading entire genomes</h2>
  
  <p>The best way to download FASTA sequences for an entire genome is to search for the genome, for example <code>Theobroma cacao genome</code> in the <a href="https://www.ncbi.nlm.nih.gov/assembly" rel="nofollow noreferrer">NCBI Assembly</a> portal and use the big blue Download button. 
  <a href="https://i.sstatic.net/VCa0e.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VCa0e.png" alt="enter image description here"></a></p>
  
  <h2>Downloading individual chromosomes</h2>
  
  <p>For a given assembly, if you want to download the FASTA sequences for a bunch of chromosomes, you can do that by going to the Genomes FTP path highlighted in the screenshot:
  <a href="https://i.sstatic.net/xWl5Y.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xWl5Y.png" alt="enter image description here"></a>
  Once you are in the Genomes FTP path, you can navigate to the FASTA folder as follows: 
  <a href="ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822" rel="nofollow noreferrer">Theobroma FTP directory</a> >> <a href="ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/" rel="nofollow noreferrer">Assembly Structure</a> >> <a href="ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/" rel="nofollow noreferrer">Primary Assembly</a> >> <a href="ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/assembled_chromosomes/" rel="nofollow noreferrer">Assembled Chromosomes</a> >> <a href="ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/assembled_chromosomes/FASTA/" rel="nofollow noreferrer">FASTA</a>. </p>
  
  <h2>Downloading a few sequences</h2>
  
  <p>For this, you can use <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="nofollow noreferrer">Entrez Direct</a> as mentioned by @dc37. Why not always use Entrez Direct? While it is fine for a small number of sequences, it can be slow to download a large number of sequences. Entrez Direct by default will download uncompressed data so you will end up spending more time downloading a larger file instead of downloading a smaller, compressed file from FTP more quickly. </p>
  
  <p>If you were to use Entrez Direct for this purpose, I'd not bother with a bash script and use <code>epost</code> to first post the entire list of accessions and then pipe it to <code>efetch</code> as shown below: </p>
  
  <pre><code>epost -db nuccore -input &lt;file_with_accs&gt; -format acc \
    | efetch -format fasta &gt; sequences.fasta
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T18:02:38.693Z
Answers.Text: Thank you very much for all the support.
Answers.UserDisplayName: MudithMMBc
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-07T14:33:49.310Z
Answers.LastActivityDate: 2019-11-07T14:33:49.310Z
Answers.UserDisplayName: vkkodali
Answers.Body: <p>(Sorry, I can't post a comment with my reputation score). 
  @vkkodali, interesting command I did not know about it ;). However, your command is downloading all sequences from the input file into a single fasta file. I believe that if you have a big bunch of sequences, it could be a little bit tricky after to manipulate that kind of file. Just by curiosity, do you have a trick to create one sequence per file using <code>efetch</code> ?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-08T02:28:26.817Z
Answers.Text: If you have a big bunch of sequences, you will end up with a lot of files. Whether you want a large number of files or just one file is, I guess, a personal choice. A multifasta file is fairly standard though. I don't think you can create individual files for each sequence using `epost` and `efetch`; you will have to either use a bash script or postprocess the `efetch` output using the unix tool `split`.
Answers.UserDisplayName: vkkodali
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-08T02:31:19.837Z
Answers.Text: Ok, I understand it. Thanks for your thoughts ;)
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-07T21:04:30.853Z
Answers.LastActivityDate: 2019-11-07T21:04:30.853Z
Answers.UserDisplayName: dc37
Answers.Body: <p>Alternatively, you can use the <strong>NCBI Entrez Direct UNIX E-utilities</strong></p>
  
  <p>Basically, you have to download the install file here: <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/bin/install-edirect.sh" rel="noreferrer">https://www.ncbi.nlm.nih.gov/books/NBK179288/bin/install-edirect.sh</a></p>
  
  <p>In the terminal, install it using: <code>source ./install-edirect.sh</code></p>
  
  <p>Then, you can download your sequence by doing:</p>
  
  <p><code>esearch -db nucleotide -query "NC_030850.1" | efetch -format fasta &gt; NC_030850.1.fasta</code></p>
  
  <p>And you should find your fasta sequence downloaded. </p>
  
  <p>As you have several sequences to download, I think it will be quite easy to add this command into a little bash script to process all of them.</p>
  
  <p>More readings about that: <a href="http://bioinformatics.cvr.ac.uk/blog/ncbi-entrez-direct-unix-e-utilities/" rel="noreferrer">http://bioinformatics.cvr.ac.uk/blog/ncbi-entrez-direct-unix-e-utilities/</a> and <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="noreferrer">https://www.ncbi.nlm.nih.gov/books/NBK179288/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T18:02:01.350Z
Answers.Text: Thank you very much for all the support.
Answers.UserDisplayName: MudithMMBc
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-13T18:49:48.273Z
Answers.Text: @MudithMMBc, you're welcome ;)
Answers.UserDisplayName: dc37
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-06T07:57:39.483Z
Answers.Text: @MudithMMBc Try to get a `NCBI_API_KEY` for batch downloading with `GNU parallel` at a max rate of 10 sequences/s. Then save accessions in one file and run `parallel -a accession.txt -j8 'efetch -db nuccore -id {} -format fasta >{}.fa'`. Adjust `-j8` to `-j3` if you do not have a key.
Answers.UserDisplayName: Forrest Vigor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-06T19:17:12.890Z
Answers.LastActivityDate: 2019-11-06T19:17:12.890Z
Answers.UserDisplayName: dc37
Body: <p>I have following accession numbers of the 10 chromosomes of <em>Theobroma cacao</em> genome.</p>
  
  <pre><code>NC_030850.1
  NC_030851.1
  NC_030852.1
  NC_030853.1
  NC_030854.1
  NC_030855.1
  NC_030856.1
  NC_030857.1
  NC_030858.1
  NC_030859.1
  </code></pre>
  
  <p>I need to download these FASTA files using the terminal because I'm working on a server. I'll be grateful if someone can help me.
  Thank you.</p>
  
Tags: <fasta><phylogenetics><linux>
Title: How to download FASTA sequences from NCBI using the terminal?
ThreadText: # How to download FASTA sequences from NCBI using the terminal?
  
  (Asked by: username_0 on 2019-11-06)
  
  I have following accession numbers of the 10 chromosomes of *Theobroma cacao* genome.
  
  ```
  NC_030850.1
  NC_030851.1
  NC_030852.1
  NC_030853.1
  NC_030854.1
  NC_030855.1
  NC_030856.1
  NC_030857.1
  NC_030858.1
  NC_030859.1
  
  ```
  
  I need to download these FASTA files using the terminal because I'm working on a server. I'll be grateful if someone can help me.
  Thank you.
  
  **Tags:** fasta, phylogenetics, linux
  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_5 on 2019-11-06. Score: 11 | Accepted answer
  
  Alternatively, you can use the **NCBI Entrez Direct UNIX E-utilities**
  
  Basically, you have to download the install file here: <https://www.ncbi.nlm.nih.gov/books/NBK179288/bin/install-edirect.sh>
  
  In the terminal, install it using: `source ./install-edirect.sh`
  
  Then, you can download your sequence by doing:
  
  `esearch -db nucleotide -query "NC_030850.1" | efetch -format fasta > NC_030850.1.fasta`
  
  And you should find your fasta sequence downloaded.
  
  As you have several sequences to download, I think it will be quite easy to add this command into a little bash script to process all of them.
  
  More readings about that: <http://bioinformatics.cvr.ac.uk/blog/ncbi-entrez-direct-unix-e-utilities/> and <https://www.ncbi.nlm.nih.gov/books/NBK179288/>
  
  > **Comments:**
  > **username_0**: Thank you very much for all the support.  
  > **username_5**: @username_0, you're welcome ;)  
  > **username_6**: @username_0 Try to get a `NCBI_API_KEY` for batch downloading with `GNU parallel` at a max rate of 10 sequences/s. Then save accessions in one file and run `parallel -a accession.txt -j8 'efetch -db nuccore -id {} -format fasta >{}.fa'`. Adjust `-j8` to `-j3` if you do not have a key.  
  
  ---
  
  ### Answer by username_1 on 2019-11-06. Score: 4
  
  Just `wget` or `curl` each as `https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&log$=seqview&format=text`...
  
  > **Comments:**
  > **username_0**: Thank you very much.  
  > **username_2**: This doesn’t seem to work (any longer?). For instance, `curl -L 'https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&log$=seqview&format=text'` downloads a HTML page with an (invisible) form on it, not a FASTA file.  
  
  ---
  
  ### Answer by username_3 on 2020-02-24. Score: 2
  
  1. Go to [the main FASTA sequence page](https://www.ncbi.nlm.nih.gov/nuccore/NC_030853.1?report=fasta&log$=seqview&format=text...), view source, and get the "ncbi\_uidlist" value. In this case, it's `1061361601`
  2. Use the ID in the query string to download directly:
  
     <https://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?id=>**1061361601**&db=nuccore&report=fasta&retmode=text&withmarkup=on&tool=portal&log$=seqview&maxdownloadsize=100000000
  
  You can also get this link directly, by using Chrome's developer tools (F12), viewing the Network tab, then loading the page in (1).
  
  
  ---
  
  ### Answer by username_4 on 2019-11-07. Score: 2
  
  ## Downloading entire genomes
  
  The best way to download FASTA sequences for an entire genome is to search for the genome, for example `Theobroma cacao genome` in the [NCBI Assembly](https://www.ncbi.nlm.nih.gov/assembly) portal and use the big blue Download button.
  [![enter image description here](https://i.sstatic.net/VCa0e.png)](https://i.sstatic.net/VCa0e.png)
  
  ## Downloading individual chromosomes
  
  For a given assembly, if you want to download the FASTA sequences for a bunch of chromosomes, you can do that by going to the Genomes FTP path highlighted in the screenshot:
  [![enter image description here](https://i.sstatic.net/xWl5Y.png)](https://i.sstatic.net/xWl5Y.png)
  Once you are in the Genomes FTP path, you can navigate to the FASTA folder as follows:
  [Theobroma FTP directory](ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822) >> [Assembly Structure](ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/) >> [Primary Assembly](ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/) >> [Assembled Chromosomes](ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/assembled_chromosomes/) >> [FASTA](ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/403/535/GCA_000403535.1_Theobroma_cacao_20110822/GCA_000403535.1_Theobroma_cacao_20110822_assembly_structure/Primary_Assembly/assembled_chromosomes/FASTA/).
  
  ## Downloading a few sequences
  
  For this, you can use [Entrez Direct](https://www.ncbi.nlm.nih.gov/books/NBK179288/) as mentioned by @username_5. Why not always use Entrez Direct? While it is fine for a small number of sequences, it can be slow to download a large number of sequences. Entrez Direct by default will download uncompressed data so you will end up spending more time downloading a larger file instead of downloading a smaller, compressed file from FTP more quickly.
  
  If you were to use Entrez Direct for this purpose, I'd not bother with a bash script and use `epost` to first post the entire list of accessions and then pipe it to `efetch` as shown below:
  
  ```
  epost -db nuccore -input <file_with_accs> -format acc \
    | efetch -format fasta > sequences.fasta
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you very much for all the support.  
  
  ---
  
  ### Answer by username_5 on 2019-11-07. Score: 0
  
  (Sorry, I can't post a comment with my reputation score).
  @username_4, interesting command I did not know about it ;). However, your command is downloading all sequences from the input file into a single fasta file. I believe that if you have a big bunch of sequences, it could be a little bit tricky after to manipulate that kind of file. Just by curiosity, do you have a trick to create one sequence per file using `efetch` ?
  
  > **Comments:**
  > **username_4**: If you have a big bunch of sequences, you will end up with a lot of files. Whether you want a large number of files or just one file is, I guess, a personal choice. A multifasta file is fairly standard though. I don't think you can create individual files for each sequence using `epost` and `efetch`; you will have to either use a bash script or postprocess the `efetch` output using the unix tool `split`.  
  > **username_5**: Ok, I understand it. Thanks for your thoughts ;)  
  
  ---
  
  