Package: ncbiutils
ncbiutilsMaking retrieval of records fromNational Center for Biotechnology Information (NCBI)E-Utilitiessimpler.InstallationSet up a virtual environment. Here, we useminicondato create an environment namedtestenv:$condacreate--nametestenvpython=3.8
$condaactivatetestenvThen install the package in thetestenvenvironment:$pipinstallncbiutilsUsageThencbiutilsmodule exposes aPubMedFetchclass that provides an easy to configure and use wrapper for theEFetchE-Utility. By default,PubMedFetchwill retrieve PubMed article records, each indicated by its PubMed identifier (PMID).fromncbiutils.ncbiutilsimportPubMedFetchimportjson# Initalize a list of PubMed identifiers for those records we wish to retrieveuids=['16186693','29083299']# Create an instance, optionally provide an E-Utility API keypubmed_fetch=PubMedFetch()# Retrieve the records# Returns a generator that yields results for a chunk of the input PMIDs (see Options)chunks=pubmed_fetch.get_citations(uids)# Iterate over the resultsforchunkinchunks:# A Chunk is a namedtuple with 3 fields:#   - error: Includes network errors as well as HTTP status >=400#   - citations: article records, each wrapped as a Citation#   - ids: input ids for chunkerror,citations,ids=chunk# Citation class can be represented as a dictprint(json.dumps(citations[0].dict()))# Output as JSON{"pmid":"16186693","pmc":"None","doi":"10.1159/000087186","title":"Searching the MEDLINE literature database through PubMed: a short guide.","abstract":"The Medline database from the National Library of Medicine (NLM) contains more than 12 million bibliographic citations from over 4,600 international biomedical journals...","author_list":[{"fore_name":"Edith","last_name":"Motschall","initials":"E","collective_name":"None","orcid":"None","affiliations":["Institut für Medizinische Biometrie und Medizinische Informatik, Universität Freiburg, Germany. motschall@mi.ukl.uni-freiburg.de"],"emails":["motschall@..."]},...],"journal":{"title":"Onkologie","issn":["0378-584X"],"volume":"28","issue":"10","pub_year":"2005","pub_month":"Oct","pub_day":"None"},"publication_type_list":["D016428","D016454"],"correspondence":[],"mesh_list":[{"descriptor_name":{"ui":"D003628","value":"Database Management Systems"}},{"descriptor_name":{"ui":"D016206","value":"Databases, Bibliographic"}},{"descriptor_name":{"ui":"D016247","value":"Information Storage and Retrieval"},"qualifier_name":[{"ui":"Q000379","value":"methods"}]},...]}OptionsConfigure thePubMedFetchinstance through its constructor:db: DbEnumSet the database to process either<!DOCTYPE pmc-articleset ...>or<!DOCTYPE PubmedArticleSet ...>(default)retmax : intMaximum number of records to return in a chunk (default/max 10000)api_key : strAPI key for NCBI E-UtilitiesAlso available is:PubMedDownloadthat can retrieve records from the PubMed FTP server for bothbaseline and daily updates.TestingAs this project was built withpoetry, you'll need toinstall poetryto get this project's development dependencies.Once installed, clone this GitHub remote:$gitclonehttps://github.com/PathwayCommons/ncbiutils
$cdncbiutilsInstall the project:$poetryinstallRun the test script:$./test.shUnder the hood, the tests are run withpytest. The test script also does a lint check withflake8and type check withmypy.Publishing a releaseA GitHub workflow will automatically version and release this package toPyPIfollowing a push directly tomainor when a pull request is merged intomain. A push/merge tomainwill automatically bump up the patch version.We usePython Semantic Release (PSR)to manage versioning. By making a commit with a well-defined message structure, PSR will scan commit messages and bump the version accordingly in accordance withsemver.For a patch bump:$gitcommit-m"fix(ncbiutils): some comment for this patch version"For a minor bump:$gitcommit-m"feat(ncbiutils): some comment for this minor version bump"For a release:$gitcommit-m"feat(mod_plotting): some comment for this release\n\nBREAKING CHANGE: other footer text."