Answers.Body: <p>In order to download the FASTA sequence of transcript variants using Entrez eutilities, you will have to use <code>Entrez.elink</code> to get a list of transcript accessions for the gene of interest and then use <code>Entrez.efetch</code> to fetch the sequence(s). Just to give you an idea, you can use <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="nofollow noreferrer">Entrez Direct</a> for this as follows:</p>
  <pre><code>elink -db gene -id 682 -target nuccore -name gene_nuccore_refseqrna \
    | efetch -format fasta
  </code></pre>
  <p>You can find more Entrez Link descriptions <a href="https://eutils.ncbi.nlm.nih.gov/entrez/query/static/entrezlinks.html" rel="nofollow noreferrer">here</a>. Note, there is a <code>gene_fasta</code> option for <code>efetch</code> but it still returns only the transcript sequence (i.e., no intron sequence).</p>
  <p>If you need the full gene sequence (including the intronic regions), you can use the commands mentioned <a href="https://github.com/NCBI-Hackathons/EDirectCookbook/issues/47" rel="nofollow noreferrer">here</a>.</p>
  <p>Alternatively, you can use <a href="https://www.ncbi.nlm.nih.gov/datasets" rel="nofollow noreferrer">NCBI Datasets</a> for this. You can use the web interface, command line tool or the python API. <a href="https://www.ncbi.nlm.nih.gov/datasets/new/docs/how-tos/genes/" rel="nofollow noreferrer">This page</a> with the how-to articles has the information you seek.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-23T11:38:11.627Z
Answers.LastActivityDate: 2021-04-23T11:38:11.627Z
Answers.UserDisplayName: vkkodali
Body: <p>I tried to use these python codes to retrieve a .fasta file from gene database, but the output were the parameters of the report</p>
  <pre><code>from Bio import Entrez
  Entrez.email = &quot;send_helps@earth.com&quot;
  handle = Entrez.efetch(db = &quot;gene&quot;,id = &quot;682&quot;,rettype=&quot;fasta&quot;, retmode=&quot;xml&quot;)
  print(Entrez.read(handle))
  </code></pre>
  <p>i also read the documentation on <a href="http://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EFetch" rel="nofollow noreferrer">this site</a> about efetch() and seems like this function can only retrieve certain kinds of data for each database. So i can't take fasta file from gene database !?</p>
  <p>I don't want to use the NCBI web UI. What's wrong with my code? Is there a way i can guarantee to retreive a .fasta file through python from NCBI ? Am i misundertanding something severly ?</p>
  <p>Sorry for bad English. thank you.</p>
  
Tags: <fasta><python><phylogenetics><entrez><efetch>
Title: Using Entrez.efetch() to retrive .fasta file from any NCBI database?
ThreadText: # Using Entrez.efetch() to retrive .fasta file from any NCBI database?
  
  (Asked by: username_0 on 2021-04-23)
  
  I tried to use these python codes to retrieve a .fasta file from gene database, but the output were the parameters of the report
  
  ```
  from Bio import Entrez
  Entrez.email = "send_helps@earth.com"
  handle = Entrez.efetch(db = "gene",id = "682",rettype="fasta", retmode="xml")
  print(Entrez.read(handle))
  
  ```
  
  i also read the documentation on [this site](http://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EFetch) about efetch() and seems like this function can only retrieve certain kinds of data for each database. So i can't take fasta file from gene database !?
  
  I don't want to use the NCBI web UI. What's wrong with my code? Is there a way i can guarantee to retreive a .fasta file through python from NCBI ? Am i misundertanding something severly ?
  
  Sorry for bad English. thank you.
  
  **Tags:** fasta, python, phylogenetics, entrez, efetch
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-04-23. Score: 2 | Accepted answer
  
  In order to download the FASTA sequence of transcript variants using Entrez eutilities, you will have to use `Entrez.elink` to get a list of transcript accessions for the gene of interest and then use `Entrez.efetch` to fetch the sequence(s). Just to give you an idea, you can use [Entrez Direct](https://www.ncbi.nlm.nih.gov/books/NBK179288/) for this as follows:
  
  ```
  elink -db gene -id 682 -target nuccore -name gene_nuccore_refseqrna \
    | efetch -format fasta
  
  ```
  
  You can find more Entrez Link descriptions [here](https://eutils.ncbi.nlm.nih.gov/entrez/query/static/entrezlinks.html). Note, there is a `gene_fasta` option for `efetch` but it still returns only the transcript sequence (i.e., no intron sequence).
  
  If you need the full gene sequence (including the intronic regions), you can use the commands mentioned [here](https://github.com/NCBI-Hackathons/EDirectCookbook/issues/47).
  
  Alternatively, you can use [NCBI Datasets](https://www.ncbi.nlm.nih.gov/datasets) for this. You can use the web interface, command line tool or the python API. [This page](https://www.ncbi.nlm.nih.gov/datasets/new/docs/how-tos/genes/) with the how-to articles has the information you seek.
  
  
  ---
  
  