How to get the corresponding PMCID from PMID with python?
3
0
Entering edit mode
5.8 years ago

Hi, I'm new here and I need help.

I have an array with all the PMIDs I get as my query in pubmed using Entrez.esearch, but I need the PMCID to after then access the full article. Can someone help me?

Pubmed PMCID PMID • 4.8k views
ADD COMMENT
0
Entering edit mode

it would help if you post example PMIDs. Try NCBI eutils and here is a shell solution:

output:

while read line; do efetch -db pubmed -id $line -format xml | xtract -pattern ArticleIdList -element ArticleId ; done   < pmid.txt 

29900339    10.1016/j.dib.2018.05.056   S2352-3409(18)30562-6   PMC5997901
29897644    10.1002/anie.201805074

input:

cat pmid.txt 
29900339
29897644
ADD REPLY
2
Entering edit mode
5.8 years ago

You'll need to use eUtils, specifically eLink. You can re-use this Python script that I've written (tested in Python 2.7), called PMIDtoPMCID.py

import sys    
import argparse
from Bio import Entrez

parser = argparse.ArgumentParser(description="Looks up PMCID with OMID")
parser.add_argument("-e", action="store", dest="EmailAddress", required=True, help="Entrez requires your email address.")
parser.add_argument("-i", action="store", dest="SearchTerm", required=True, help="PMID.")

arguments = parser.parse_args()

Entrez.email = arguments.EmailAddress

SearchTerm = arguments.SearchTerm

handle = Entrez.elink(dbfrom="pubmed", db="pmc", linkname="pubmed_pmc", id=SearchTerm, retmode="text")

print(handle.read())

handle.close()

Now try it:

python PMIDtoPMCID.py -e MyWine@chardonnay.com -i 21990379


https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20101123/elink.dtd">
<eLinkResult>

  <LinkSet>
    <DbFrom>pubmed</DbFrom>
    <IdList>
      <Id>21990379</Id>
    </IdList>
    <LinkSetDb>
      <DbTo>pmc</DbTo>
      <LinkName>pubmed_pmc</LinkName>

        <Link>
                <Id>3266030</Id>
            </Link>

    </LinkSetDb>
  </LinkSet>
</eLinkResult>

I'll have to leave it to you to parse the output. The PMCID is 3266030

Kevin

ADD COMMENT
1
Entering edit mode
5.7 years ago

In case this is useful, Europe PMC (PubMed Central partner) provides a file with PMID-PMCID-DOI mappings that you can download via FTP: ftp://ftp.ebi.ac.uk/pub/databases/pmc/DOI/ Disclaimer: I work for Europe PMC

ADD COMMENT
0
Entering edit mode
9 months ago

Here is a complete solution. you need to pass an email for Entrez API requests and obviously the pmid which you need to cenvert

from Bio import Entrez
import xml.etree.ElementTree as ET

def pmid2pmcid(email, pmid):
    Entrez.email = email

    handle = Entrez.elink(dbfrom="pubmed", db="pmc", linkname="pubmed_pmc", id=pmid, retmode="text")

    handle_read = handle.read()
    handle.close()

    root = ET.fromstring(handle_read)

    pmcid = ""

    for link in root.iter('Link'):
        for id in link.iter('Id'):
            pmcid = id.text
    return pmcid 
ADD COMMENT

Login before adding your answer.

Traffic: 1940 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6