1
$\begingroup$

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'][0])

But it's a mess of nested lists and dictionaries. Help!

$\endgroup$
1
  • $\begingroup$ Please edit your question and show us the output you expect from your example input. I get what looks like a perfectly normal and valid JSON output. What exactly do you need? COX1 gene accessions? DNA sequence? cDNA sequence? Protein translation? $\endgroup$
    – terdon
    Nov 20, 2021 at 11:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.