This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to convert data from NCBI E-utilities.efetch to python data object?

Hello, everyone! I want to use E-utilities to get all gene information. I already get all gene UIDs and next step is use E-utils.efetch get gene record. However I find it's hard to extract informations I need from the E-utils.efetch return data. Here is one example link getting gene records from E-utils, click to see the data returned:
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=gene&id=79669,10059,23548,8999
Return data looks like:

Entrezgene ::= {
  track-info {
    geneid 79669,
    status live,
    create-date std {
      year 2001,
      month 3,
      day 12
    },
    update-date std {
      year 2018,
      month 12,
      day 8
    }
  },
  type protein-coding,
  source {
    genome genomic,
    origin natural,
    org {
      taxname "Homo sapiens",
      common "human",
      db {
        {
          db "taxon", ...

The problem is I need to convert such data into python object(dict, list) to extract information I need, this is hard. I google and can't find any packages for such job. It's there some easy way? Otherwise I had to write scripts myself.

ncbi python

Hello MatthewP ,

the format of the return is called ASN.1. This format can be parsed and transformed in a dictionary using the ASN1.tools package for python. Have a look into the examples to see how it works.

fin swimmer

It would probably be worth your while to abandon ASN.1 style results, in favour of some of the more broadly applicable formats, as discussed here for instance.

1 answer

Hello, I find E-utils can return xml if you set retmode=xml. Example:
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=gene&id=79669,10059,23548,8999&retmode=xml
Here is all support retmode list:
https://www.ncbi.nlm.nih.gov/books/NBK25499/table/chapter4.T._valid_values_of__retmode_and/?report=objectonly
For some newbee like me.

Log in to answer this question.