Package: pubmed-mapper
pubmed-mapper: A Python Library that map PubMed XML to Python object中文文档1. Philosophyview UMLProgrammatically access PubMed article is a common task for me.
Luckily, with the help ofeutils,
we can access full article data in XML format.
What I need is Python objects, not just XML strings, so pubmed-mapper was born.2. Installationpipinstallpubmed-mapper3. Usage3.1 use as library3.1.1 parse a PubMed IDfrompubmed_mapperimportArticlearticle=Article.parse_pmid('32329900')# PubMed IDprint(article.pmid)# 32329900# idsprint(article.ids)# [pubmed: 32329900, doi: 10.1111/jgs.16467]print(article.ids[1].id_type)# doiprint(article.ids[1].id_value)# 10.1111/jgs.16467# titleprint(article.title)# Associations of Coffee...# abstractprint(article.abstract)# <p><strong>Background: </strong>Coffee and tea...# keywordsprint(article.keywords)# ['aging', 'coffee; diet; longevity', 'tea']# MeSH headingsprint(article.mesh_headings)# ['Aged', 'Body Mass Index', '...']# authorsprint(article.authors)# [hadyab AH Aladdin H, Manson JE JoAnn E, ...]print(article.authors[0].last_name)# Shadyabprint(article.authors[0].forename)# Aladdin Hprint(article.authors[0].initials)# AHprint(article.authors[0].affiliation)# Department of Family...# journalprint(article.journal)# Journal of the American Geriatrics Societyprint(article.journal.issn)# 1532-5415print(article.journal.issn_type)# Electronicprint(article.journal.title)# Journal of the American Geriatrics Societyprint(article.journal.abbr)# J Am Geriatr Soc# volumeprint(article.volume)# 68# issueprint(article.issue)# 9# referencesprint(article.references)# [n. 2013;129:643-659....]print(article.references[0].citation)# Lotfield E, Freedman ND...print(article.references[0].ids)# []# pubdateprint(article.pubdate)# 2020-09-013.1.2 parse a downloaded XML filefromlxmlimportetreefrompubmed_mapperimportArticleinfile='xxx.xml'withopen(infile)asfp:root=etree.parse(fp)articles=[]forpubmed_article_elementinroot.xpath('/PubmedArticleSet/PubmedArticle'):article=Article.parse_element(pubmed_article_element)articles.append(article)3.2 use as command line software3.2.1 parse PubMed IDpubmed-mapper pmid -p 323299003.2.2 parse single PubMed XML filepubmed-mapper file -i data/pubmed21n0001.xml -o output/pubmed21n0001.jl3.2.3 parse a directory who contains multiple PubMed XML filespubmed-mapper directory -i data/ -o output/pubmed-mapper.jl4. FAQs4.1 There many types of PubMed article publication date, how do you convert it to datetime.date object?Parse publication date is a hard work, until now pubmed-mapper can't parse all types of them.
The types pubmed-mapper can be parsed and the parsed value are:typevalue2021-03-132021-03-132021-032021-03-012021 Spring2021-04-0120212021-01-012021 Jan-Feb2021-01-012021 Mar 13-152021-03-132021 Mar-2022 Jan2021-03-012021-20222021-01-012021 Mar 13-Dec 152021-03-131976-1977 Winter1976-01-011977-1978 Fall-Winter1977-10-014.2 What is pubmed-mapper.log generated by pubmed-mapper?pubmed-mapper.log is the default log file generate by pubmed-mapper,
you can change the file by using--log-fileoptions:pubmed-mapper --log-file my-custom.log file -i data/pubmed21n0001.xml -o output/pubmed21n0001.jlYou can go to this log file to find out more parsing details.4.3 I want log detail message in my log file?Using--log-levelcan log more detail message:pubmed-mapper --log-file my-custom.log --log-level DEBUG file -i data/pubmed21n0001.xml -o output/pubmed21n0001.jl