I have a list of accessions for the the entire mitochondrial genomes for big cats. I need to download the COX1 genes for each of these accessions. Here is one accession and here is a link to its COX1 gene, which I found manually on that page.
I have downloaded all the accessions as an XML genbank file:
#!/usr/bin/env python3 from Bio import Entrez from Bio import GenBank from Bio import SeqIO import os if os.path.exists('cats.xml') ==False: with open('accessions.txt', 'r') as fin: #for line accs = [line.rstrip() for line in fin ] print(accs) Entrez.email = "[email protected]" rec = Entrez.efetch(db='nuccore', id=accs, rettype="gb", retmode="xml") with open('cats.xml', 'w') as out: print(rec.read().decode("utf-8"), file=out)
Then I tried to parse this file:
with open('cats.xml', 'rb') as xin: for record in Entrez.parse(xin): #print(dir(record)) #print(record.keys()) pass print(record['GBSeq_feature-table'])
But it's a mess of nested lists and dictionaries. Help!