1
$\begingroup$

I want to do a systematic literature review of genetic variant annotation. As part of this I am interested in all the databases available to annotate genetic variants.

I want to export all the references cited by the article with PubMed ID 35943817 (https://pubmed.ncbi.nlm.nih.gov/35943817/), because many of these references are relevant to my review. I can see that they number 93. I want them in a CSV table with their PubMed ID, Title, etc., similar to CSV tables obtained in a search after clicking "Save citations to file", Format "CSV".

$\endgroup$
2
  • $\begingroup$ Hi @CristianRiccio, your question is fine, but I am not sure this is 'bioinformatics'. The nearest bioinformatics solution is NCBI's Entrez, often used for sequence retrieval, but will retrieve citations from Pubmed - so if you parse the titles in the paper, e.g. Pdfminer you can use those to obtain this data in Entrez, e.g. within Biopython. $\endgroup$
    – M__
    Commented Apr 4, 2023 at 13:27
  • $\begingroup$ You're posting this as a bioinformatics question, which suggests you want code for this. Given that it's only 93 citations, it sounds like you only need to do this once, and they're all in a standard format in the paper. Is there any reason why copying the references from the paper and manually inserting field separators would not be appropriate? $\endgroup$
    – gringer
    Commented Apr 5, 2023 at 20:04

1 Answer 1

2
$\begingroup$

Something like this will work, it did just now for me. You might want to extract different info from the records though.
This exports to a table (bibliography.tsv) columns containing:

  • pmid
  • authors
  • title
  • journal
  • year
max_attempts = 5
def fetch_pubmed_data(pmid):
    Entrez.email = "[email protected]"  # Replace with your email address    
    handle = Entrez.efetch(db="pubmed", id=pmid, rettype="xml", retmode="text")
    record = Entrez.read(handle)
    time.sleep(1)
    return record


def extract_cited_articles(pmid):
    
    record = fetch_pubmed_data(pmid)
    cited_pmids = []

    record_article = record['PubmedArticle']

    if "PubmedData" in record_article[0] and "ReferenceList" in record_article[0]["PubmedData"]:
        for reference in record_article[0]["PubmedData"]["ReferenceList"][0]["Reference"]:
            if "ArticleIdList" in reference and len(reference["ArticleIdList"]) > 0:
                cited_pmids.append(reference["ArticleIdList"][0])

    return cited_pmids


def extract_bibliographic_info(pmid_list, max_attempts):
    bibliographic_info = {}
    bibliographic_info_ls = []

    for pmid in pmid_list:

        authors = title = journal = year = ""
        record = {}

        for attempt in range(max_attempts):
            try:
                record = fetch_pubmed_data(pmid)
                break

            except:
                time.sleep(5)

        if 'PubmedArticle' in record:
            if len(record['PubmedArticle']) >0:
                article = record['PubmedArticle'][0]["MedlineCitation"]["Article"]

                if "AuthorList" in article:
                    authors = ", ".join([f"{author['LastName']} {author['Initials']}" for author in article["AuthorList"] if 'LastName' in author and 'Initials' in author])
                    title = article["ArticleTitle"]
                    journal = article["Journal"]["Title"]
                    year = article["Journal"]["JournalIssue"]["PubDate"]["Year"]


        print (pmid, authors, title, journal, year)
        bibliographic_info_ls.append([pmid, authors, title, journal, year])

    return bibliographic_info_ls


def main():
    pmid = input("Enter the PubMed article ID: ")
    cited_pmids = extract_cited_articles(pmid)
    bibliographic_info_ls = extract_bibliographic_info(cited_pmids, max_attempts)

    df = pd.DataFrame(bibliographic_info_ls, columns=["pmid", "authors", "title", "journal", "year"])
    df.to_csv("bibliography.tsv", sep="\t", index=False)
    return df
    
if __name__ == "__main__":
    df = main()
$\endgroup$
1
  • $\begingroup$ Really amazing code. Thank you very much. I just had to change to change cited_pmids.append(reference["ArticleIdList"][0]) to cited_pmids.append(reference["ArticleIdList"][-1]) to get the PMIDs instead of the PMCIDs! Thank you! $\endgroup$ Commented Apr 10, 2023 at 12:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.