The ohcrn-lei tool takes a PDF or TXT file of a clinical report and extracts desired information from it, which will be output in json format.
Project description
🌺🌺🌺🌺🌺🌺 OHCRN-LEI 🌺🌺🌺🌺🌺🌺
The Ontario Hereditary Cancer Research Network - LLM-based Extraction of Information
Overview • Getting started • Contributing • Citation
Status
Overview
The ohcrn-lei processes PDF or TXT files of clinical reports and extracts desired information from it, which will be output in json format.
LEI currently supports the following built-in extraction tasks:
- Report: Extracts the following data:
- "report_date" (Collected On, Received On, etc in "YYYY-MM-DD" format).
- "report_type": Type of report.
- "testing_context": Purpose of the testing (clinical or research).
- "ordering_clinic": Name of the lab that ordered the test.
- "testing/laboratory": Name of the lab that conducted the test.
- Molecular test:
- Sequencing Scope: Gene panel, Targeted variant testing, Whole exome sequencing (WES), Whole genome sequencing (WGS), Whole transcriptome sequencing (WTS).
- Tested Genes
- Sample Type: Amplified DNA, ctDNA, Other DNA enrichments, Other RNA fractions, polyA+ RNA, Ribo-Zero RNA, Total DNA, Total RNA.
- Analysis Type: Variant analysis, Microarray, Repeat expansion analysis, Karyotyping, Fusion analysis, Methylation analysis.
- Variants:
- Variant Identifiers: e.g OMIM, Clinvar, dbSNP, etc
- Gene Symbol
- Transcript ID: NCBI or LRG.
- Variant descriptor in genomic context (gHGVS):
- Variant descriptor in coding sequence context (cHGVS)
- Amino Acid Change (pHGVS)
- Chromosome: The chromosome identifier.
- Exon: The exon number
- Reference genome build: ("GRCh37","GRCh38")
In addition to the built-in extraction tasks, additional tasks can also be provided via a task definition file (via the -t option). See below for the task definition file format requirements.
Getting started
Prerequisites
OpenAI account
OHCRN-LEI uses GPT4o and thus requires an OpenAI account token. If you do not have an account, please create one on the OpenAI webpage. After verifying your account, log in, navigate to the API Keys section in your dashboard, and click on "Create new secret key" to generate your key.
Copy the key and store it in an environment variable named OPENAI_API_KEY. To do so, open your .bashrc (or .zshenv if you use zsh) and add the following entry:
export OPENAI_API_KEY=your-api-key-here
Poppler
OHCRN-LEI requires poppler to be installed. If you don't have poppler installed already, you can do so as follows:
MacOS (via homewbrew):
$ brew install poppler
Ubuntu/Debian:
$ sudo apt install poppler-utils
UV
We also recommend uv for a faster and easier installation process. (It only takes seconds!)
MacOS (via homewbrew):
$ brew install uv
Linux:
$ curl -LsSf https://astral.sh/uv/install.sh | sh
Installation
Preliminarily:
Install directly from github via uv:
$ uv tool install "ohcrn-lei @ git+https://github.com/courtotlab/ohcrn_lei"
Usage
After installation, you can run the ohcrn-lei in your command line. For example, to run the report extraction task on the file example.pdf, run:
ohrcn-lei --task report -outfile output.json example.pdf
Currently, the report, molecular_test and variant task are supported out-of-the-box. However, you can also create your own custom tasks.
The full set of parameters can be found below:
usage: ohcrn-lei [-h] [-b PAGE_BATCH] [-t TASK] [-o OUTFILE]
[--mock-LLM] [--no-ocr]
filename
Extract data from report file.
positional arguments:
filename Path to the report file to process.
options:
-h, --help show this help message and exit
-b, --page-batch PAGE_BATCH
Number of pages to be processed at a given
time. Default=2
-t, --task TASK Specify the extraction task. This can either be
a pre-defined task
('report','molecular_test','variant')or a plain
*.txt file with a task definition. See
documentationfor the task definition file
format specification.Default: report
-o, --outfile OUTFILE
Output file or '-' for stdout (default)
--mock-LLM Don't make real LLM call, produce mock output
instead.
--no-ocr Disable OCR processing.
Creating custom tasks
To create a new extraction task from scratch, you can create a new task definition file. The task definition file follows the following format
##### START PROMPT #####
Enter your LLM prompt here. Must instruct the LLM to generate a JSON dictionary output.
##### END PROMPT #####
##### START PLUGINS #####
json_key=plugin_name
...
##### END PLUGINS #####
The following plugins are supported:
- trie_hgnc : Extracts HGNC gene symbols and aliases using a Trie search algorithm.
- regex_hgvsg : Extracts genomic HGVS strings using a regular expression search.
- regex_hgvsc : Extracts coding sequence HGVS strings using a regular expression search.
- regex_hgvsp : Extracts protein-level HGVS strings using a regular expression search.
- regex_variants : Extracts variant IDs (OMIM,dbSNP,etc.) using a regular expression search.
- regex_chromosome : Extracts chromosome identifiers using a regular expression search.
Contributing
Build process
To build the project from source, use uv
$ git clone https://github.com/courtotlab/ohcrn_lei.git
$ cd ohcrn_lei
$ uv build
The resulting .whl file will be n the dist/ directory.
Code quality
Unit tests are located in the tests/ directory. To run them use
$ uv run pytest
You can lint and format the code with ruff:
$ uv run ruff check
$ uv run ruff format
Pull requests
If you are an outside contributor, you'll want to fork the repo first. Members of the Courtot Lab can create a branch on this repo instead.
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Test
- Open a pull request.
Authors
Citation
Coming soon.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ohcrn_lei-0.3.0.tar.gz.
File metadata
- Download URL: ohcrn_lei-0.3.0.tar.gz
- Upload date:
- Size: 110.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be63b9ffc42bd671cd0662427cf19441a39362da743271992ff80d30dfc28aa0
|
|
| MD5 |
f11094399685b6da200db2872db86b9e
|
|
| BLAKE2b-256 |
118b907b18ea3db080484fd0191620c2fb84836e7aa86c0eaf40700a57e364ea
|
File details
Details for the file ohcrn_lei-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ohcrn_lei-0.3.0-py3-none-any.whl
- Upload date:
- Size: 39.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6baf372e7ae00a0c02b684ba1f24110cb85e2db60efb1da31e447997a639c575
|
|
| MD5 |
23699c6b5cff10a1a913cde1512e2bbe
|
|
| BLAKE2b-256 |
310aa4f735a5ee3294b2a10e37bb3155f9c85e25b7f547136ef87df6b3e96251
|