Retrieve article records from NCBI via E-utilities
Project description
ncbiutils
Making retrieval of records from National Center for Biotechnology Information (NCBI) E-Utilities simpler.
Installation
Set up a virtual environment. Here, we use miniconda to create an environment named testenv
:
$ conda create --name testenv python=3.8
$ conda activate testenv
Then install the package in the testenv
environment:
$ pip install ncbiutils
Usage
The ncbiutils
module exposes a PubMedFetch
class that provides an easy to configure and use wrapper for the EFetch E-Utility. By default, PubMedFetch
will retrieve PubMed article records, each indicated by its PubMed identifier (PMID).
from ncbiutils.ncbiutils import PubMedFetch
# Initalize a list of PubMed identifiers for those records we wish to retrieve
uids = ['16186693', '29083299']
# Create an instance, optionally provide an E-Utility API key
pubmed_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 results
for chunk in chunks:
# 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 chunk
error, citations, ids = chunk
# Citation class can be represented as a dict
print(citations[0].dict())
Options
Configure the PubMedFetch
instance through its constructor:
- retmax : int
- Maximum number of records to return in a chunk (default/max 10000)
- api_key : str
- API key for NCBI E-Utilities
Testing
As this project was built with poetry, you'll need to install poetry to get this project's development dependencies.
Once installed, clone this GitHub remote:
$ git clone https://github.com/PathwayCommons/ncbiutils
$ cd ncbiutils
Install the project:
$ poetry install
Run the test script:
$ ./test.sh
Under the hood, the tests are run with pytest. The test script also does a lint check with flake8 and type check with mypy.
Publishing a release
A GitHub workflow will automatically version and release this package to PyPI following a push directly to main
or when a pull request is merged into main
. A push/merge to main
will automatically bump up the patch version.
We use Python 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 with semver.
For a patch bump:
$ git commit -m "fix(ncbiutils): some comment for this patch version"
For a minor bump:
$ git commit -m "feat(ncbiutils): some comment for this minor version bump"
For a release:
$ git commit -m "feat(mod_plotting): some comment for this release\n\nBREAKING CHANGE: other footer text."
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ncbiutils-0.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9cde1d5a2f28024004148b3e2f6f1d577d855b8f3bc4c7d6dfde43e135ad9aa |
|
MD5 | b7b440be56792183ae304695d43c72ec |
|
BLAKE2b-256 | 2c9d2ace0c67a5f88eaf509a0c69663180f7adfac0a91771f17590fca2990a7f |