<p>Concept code only</p>
<pre><code>from Bio import Entrez

Entrez.email = &quot;m@M__&quot;
handle = Entrez.efetch(db=&quot;protein&quot;, id=&quot;GCF_000145295&quot;, &quot;GCF_000145294&quot;, &quot;GCF_000145293&quot;, retmode=&quot;text&quot;,rettype=&quot;gb&quot;) # check the quotes
records = Entrez.parse(handle)
handle.close()
for record in records:
    print (record)
</code></pre>
<p>You can write a loop, flatten it and then insert it to the <code>id=</code> tag.</p>
<pre><code>mylist = ['GCF_000145295', 'GCF_000145294', 'GCF_000145293']
flattened = ','.join(mylist)
</code></pre>

CC BY-SA 4.0
2022-07-04T15:33:40.647Z
2022-07-04T21:31:14.373Z
2022-07-04T21:31:14.373Z
M__
<p>The above answer is right - here are some more links that describe what you want to do in more detail:</p>
<ul>
<li><a href="https://eeob-biodata.github.io/BCB546X-python/06-biopython/" rel="nofollow noreferrer">https://eeob-biodata.github.io/BCB546X-python/06-biopython/</a></li>
<li><a href="https://medium.com/@insidedna/biopython-to-retrieving-fasta-sequences-from-ncbi-databases-20e35772a25" rel="nofollow noreferrer">https://medium.com/@insidedna/biopython-to-retrieving-fasta-sequences-from-ncbi-databases-20e35772a25</a></li>
</ul>
<p>You're going to want to use the BioPython package as it has functions that do exactly what you're looking for.</p>

CC BY-SA 4.0
2022-09-20T15:18:42.843Z
2022-09-20T15:18:42.843Z
rimo
<p>I am trying to download the <code>_protein.faa.gz</code> files for genomes given their accession numbers through Python. Ideally, I would like to do this without third party libraries. Essentially what I have is a list of just the GCA or GCF accessions. The issue with the ftp site is that it includes the project name along with the accession, which I do not have ahead of time. It would be perfect if I could run downloads from within Python that matched a pattern something like this:</p>
<p><code>https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/145/295/GCF_000145295.1_*/*_protein.faa.gz</code></p>
<p>Is it at all possible to do this? Or is it possible to run something similar <em>via</em> efetch in Biopython?</p>
<p>Thanks in advance!</p>

<python><phylogenetics>
Downloading genomic protein files from accessions in Python
# Downloading genomic protein files from accessions in Python

(Asked by: username_0 on 2022-07-04)

I am trying to download the `_protein.faa.gz` files for genomes given their accession numbers through Python. Ideally, I would like to do this without third party libraries. Essentially what I have is a list of just the GCA or GCF accessions. The issue with the ftp site is that it includes the project name along with the accession, which I do not have ahead of time. It would be perfect if I could run downloads from within Python that matched a pattern something like this:

`https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/145/295/GCF_000145295.1_*/*_protein.faa.gz`

Is it at all possible to do this? Or is it possible to run something similar *via* efetch in Biopython?

Thanks in advance!

**Tags:** python, phylogenetics

---

## 2 answers

### Answer by username_1 on 2022-07-04. Score: 1 | Accepted answer

Concept code only
from Bio import Entrez

Entrez.email = "m@M__"
handle = Entrez.efetch(db="protein", id="GCF_000145295", "GCF_000145294", "GCF_000145293", retmode="text",rettype="gb") # check the quotes
records = Entrez.parse(handle)
handle.close()
for record in records:
    print (record)

You can write a loop, flatten it and then insert it to the id= tag.
mylist = ['GCF_000145295', 'GCF_000145294', 'GCF_000145293']
flattened = ','.join(mylist)


---

### Answer by username_2 on 2022-09-20. Score: 3

The above answer is right - here are some more links that describe what you want to do in more detail:

* <https://eeob-biodata.github.io/BCB546X-python/06-biopython/>
* <https://medium.com/@insidedna/biopython-to-retrieving-fasta-sequences-from-ncbi-databases-20e35772a25>

You're going to want to use the BioPython package as it has functions that do exactly what you're looking for.


---

