Search code examples
pubmed

similar pubmed articles via pubmed api


Is it possible to obtain similar pubmed articles given a pmid. Example this link shows similar articles on the rights hand side.


Solution

  • You can do it with BioPython using the NCBI API. The command you are looking for is neighbor_score. Alternatively you can get the data directly via the URL.

    from Bio import Entrez
    
    Entrez.email = "Your.Name.Here@example.org"
    handle = Entrez.elink(db="pubmed", id="26998445", cmd="neighbor_score", rettype="xml")
    records = Entrez.read(handle)
    
    scores = sorted(records[0]['LinkSetDb'][0]['Link'], key=lambda k: int(k['Score']))
    #show the top 5 results
    for i in range(1, 6):
        handle = Entrez.efetch(db="pubmed", id=scores[-i]['Id'], rettype="xml")
        record = Entrez.read(handle)
        print(record)