pythonpubmedpubmed-api

Is there a way to add filters such as article type ("only show meta-analyses") to a PubMed/Entrez esearch API search?


Thanks for taking the time to read this. I would like to know if it is possible to filter results from the PubMed API by e.g. article type (only show meta analysis/clinical trial/etc) or use the additional filters such as species

My code:

import requests
import json
db = 'pubmed'
domain = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils'  
query = "cancer"
retmode='json'

queryLinkSearch = f'{domain}/esearch.fcgi?db={db}&retmode={retmode}&term={query}&sort=relevance'  
response = requests.get(queryLinkSearch)
pubmedJson = response.json()

print(pubmedJson)

It works and is giving me a list of IDs. What I would like to do is add a filter now, e.g. to only show meta-analyses.

I didn't see anything regarding filtering in the API docs. When I check the link of the website it adds the following filter:

https://pubmed.ncbi.nlm.nih.gov/?term=cancer**&filter=pubt.meta-analysis**

But when I try to add this filter to my query I get the error:

{'ERROR': 'Invalid filter key: pubt.meta-analysis'}}

Does somebody know if this is possible? Thank you!


Solution

  • I am using the metapub implementation of NCBI's E-utilities search tool. Here is how I am constructing my query for that:

    from metapub import PubMedFetcher     
    fetch = PubMedFetcher()
    
    keywords = '''
    ("journal article" [Publication Type]) AND 
    ("1995/01/01" [Date - Publication] : "2023/07/14" [Date - Publication]) AND 
    ("english" [Language]) AND 
    (("human" [Other Term]) OR ("mouse" [Other Term]) OR ("rat" [Other Term]) OR ("yeast" [Other Term])) AND
    ((“tandem affinity purification" [MeSH Terms]) OR 
    (“complex isolation" [Text Word]) OR 
    (“complex isolation and purification" [Text Word]) OR 
    ("complex characterisation" [Text Word]) OR 
    ("coimmunoprecipitated proteins" [Text Word]) OR 
    (“coimmunoprecipitated specifically" [Text Word]) OR 
    (“coimmunoprecipitates" [Text Word]) OR 
    (“coimmunoprecipitating proteins" [Text Word]) OR 
    (“coimmunoprecipitation" [Text Word]) OR
    ("quaternary" [Other Term]))
    '''
    
    num_of_articles = 500
    pmids = fetch.pmids_for_query(keywords,
                                      retmax=num_of_articles,
                                      pmc_only= True)
    

    You can find out a lot about the terms playing around with their interactive advanced search and use their field autocomplete tool to search the annotation DB. The documentation for their term mapping is also available here.