https://github.com/cthoyt/umls_downloader
Don't worry about UMLS, RxNorm, SNOMED, or SemMedDB licensing - write code that knows how to download it automatically
https://github.com/cthoyt/umls_downloader
python reproducibility reproducible-research rxnorm semmeddb snomed snomed-ct umls
Last synced: about 2 months ago
JSON representation
Don't worry about UMLS, RxNorm, SNOMED, or SemMedDB licensing - write code that knows how to download it automatically
- Host: GitHub
- URL: https://github.com/cthoyt/umls_downloader
- Owner: cthoyt
- License: mit
- Created: 2021-11-21T16:53:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-02T08:03:37.000Z (about 1 year ago)
- Last Synced: 2025-03-12T23:18:04.260Z (2 months ago)
- Topics: python, reproducibility, reproducible-research, rxnorm, semmeddb, snomed, snomed-ct, umls
- Language: Python
- Homepage: https://umls-downloader.readthedocs.io
- Size: 54.7 KB
- Stars: 38
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UMLS DownloaderDon't worry about [UMLS Terminology Services (UTS)](https://uts.nlm.nih.gov/uts/)
licensing and distribution rules - just use
`umls_downloader` to write code that knows how to download content and use it
automatically from the following (non-exhaustive) list of resources:- [UMLS](https://www.nlm.nih.gov/research/umls/licensedcontent/umlsknowledgesources.html)
- [RxNorm](https://www.nlm.nih.gov/research/umls/rxnorm/docs/rxnormfiles.html)
- [SemMedDB](https://lhncbc.nlm.nih.gov/ii/tools/SemRep_SemMedDB_SKR/SemMedDB_download.html)
- [SNOMED-CT](https://www.nlm.nih.gov/healthit/snomedct/international.html)
- potentially more in the futureor any content that can be downloaded through
the [UTS ticket granting](https://documentation.uts.nlm.nih.gov/automating-downloads.html)
system. There's no centralized list of content available through the UTS so
suggestions for additional resources are welcome through
the [issue tracker](https://github.com/cthoyt/umls_downloader/issues).Full documentation are available at [umls-downloader.readthedocs.io](https://umls-downloader.readthedocs.io).
## Installation
```bash
$ pip install umls_downloader
```## Download A Specific Version of UMLS
```python
import os
from umls_downloader import download_umls# Get this from https://uts.nlm.nih.gov/uts/edit-profile
api_key = ...path = download_umls(version="2021AB", api_key=api_key)
# This is where it gets downloaded: ~/.data/bio/umls/2021AB/umls-2021AB-mrconso.zip
expected_path = os.path.join(
os.path.expanduser("~"), ".data", "umls", "2021AB",
"umls-2021AB-mrconso.zip",
)
assert expected_path == path.as_posix()
```After it's been downloaded once, it's smart and doesn't need to download again.
It gets stored using [`pystow`](https://github.com/cthoyt/pystow) automatically
in the `~/.data/bio/umls` directory.A full list of functions is available in the
[documentation](https://umls-downloader.readthedocs.io).## Automating Configuration of UTS Credentials
There are two ways to automatically set the username and password so you don't
have to worry about getting it and passing it around in your python code:1. Set `UMLS_API_KEY` in the environment
2. Create `~/.config/umls.ini` and set in the `[umls]` section a `api_key` key.```python
from umls_downloader import download_umls# Same path as before
path = download_umls(version="2021AB")
```## Download the Latest Version
First, you'll have to
install [`bioversions`](https://github.com/cthoyt/bioversions)
with `pip install bioversions`, whose job it is to look up the latest version of
many databases. Then, you can modify the previous code slightly by omitting
the `version` keyword argument:```python
from umls_downloader import download_umls# Same path as before (as of November 21st, 2021)
path = download_umls()
```## Download and open the file
The UMLS file is zipped, so it's usually accompanied with the following
boilerplate code:```python
import zipfile
from umls_downloader import download_umlspath = download_umls()
with zipfile.ZipFile(path) as zip_file:
with zip_file.open("MRCONSO.RRF", mode="r") as file:
for line in file:
...
```This exact code is wrapped with the `open_umls()` using Python's context manager
so it can more simply be written as:```python
from umls_downloader import open_umlswith open_umls() as file:
for line in file:
...
```The `version` and `api_key` arguments also apply here.
## Why not an API?
The UMLS provides an [API](https://documentation.uts.nlm.nih.gov/rest/home.html)
for access to tiny bits of data at a time. There are even two recent (last 5
years) packages [`umls-api`](https://pypi.org/project/umls-api)
[`connect-umls`](https://pypi.org/project/connect-umls) that provide a wrapper
around them. However, API access is generally rate limited, difficult to use in
bulk, and slow. For working with UMLS (or any other database, for that matter)in
bulk, it's necessary to download full database dumps.## 👋 Attribution
### ⚖️ License
The code in this package is licensed under the MIT License.
### 🍪 Cookiecutter
This package was created
with [@audreyfeldroy](https://github.com/audreyfeldroy)'s
[cookiecutter](https://github.com/cookiecutter/cookiecutter) package
using [@cthoyt](https://github.com/cthoyt)'s
[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack)
template.