skimgpt 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- skimgpt-1.0.0/.github/workflows/release.yml +63 -0
- skimgpt-1.0.0/Dockerfile +88 -0
- skimgpt-1.0.0/MANIFEST.in +16 -0
- skimgpt-1.0.0/PKG-INFO +187 -0
- skimgpt-1.0.0/README.md +147 -0
- skimgpt-1.0.0/VERSION +1 -0
- skimgpt-1.0.0/__init__.py +70 -0
- skimgpt-1.0.0/config_template.json +92 -0
- skimgpt-1.0.0/input_lists/FDA_approved_ProductsActiveIngredientOnly_DupsRemovedCleanedUp.txt +2449 -0
- skimgpt-1.0.0/input_lists/genes_no_syn.txt +17545 -0
- skimgpt-1.0.0/main.py +539 -0
- skimgpt-1.0.0/main_wrapper.py +232 -0
- skimgpt-1.0.0/pyproject.toml +83 -0
- skimgpt-1.0.0/requirements.txt +4 -0
- skimgpt-1.0.0/setup.cfg +4 -0
- skimgpt-1.0.0/skimgpt.egg-info/PKG-INFO +187 -0
- skimgpt-1.0.0/skimgpt.egg-info/SOURCES.txt +43 -0
- skimgpt-1.0.0/skimgpt.egg-info/dependency_links.txt +1 -0
- skimgpt-1.0.0/skimgpt.egg-info/entry_points.txt +3 -0
- skimgpt-1.0.0/skimgpt.egg-info/requires.txt +16 -0
- skimgpt-1.0.0/skimgpt.egg-info/top_level.txt +1 -0
- skimgpt-1.0.0/src/__init__.py +57 -0
- skimgpt-1.0.0/src/__pycache__/__init__.cpython-310.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/__init__.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/abstract_comprehension.cpython-310.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/abstract_comprehension.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/few_shot_library.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/get_pubmed_text.cpython-310.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/get_pubmed_text.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/prompt_library.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/scoring_guidelines.cpython-311.pyc +0 -0
- skimgpt-1.0.0/src/__pycache__/skim_and_km_api.cpython-310.pyc +0 -0
- skimgpt-1.0.0/src/classifier.py +616 -0
- skimgpt-1.0.0/src/cost_estimator.py +325 -0
- skimgpt-1.0.0/src/eval_JSON_results.py +137 -0
- skimgpt-1.0.0/src/htcondor_helper.py +348 -0
- skimgpt-1.0.0/src/jobs.py +25 -0
- skimgpt-1.0.0/src/prompt_library.py +397 -0
- skimgpt-1.0.0/src/pubmed_fetcher.py +346 -0
- skimgpt-1.0.0/src/relevance.py +593 -0
- skimgpt-1.0.0/src/run.sh +16 -0
- skimgpt-1.0.0/src/scoring_guidelines.py +378 -0
- skimgpt-1.0.0/src/skim_and_km_api.py +415 -0
- skimgpt-1.0.0/src/utils.py +586 -0
- skimgpt-1.0.0/wrapper_result_merger.py +141 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: Release – TestPyPI on merge to main
|
|
2
|
+
|
|
3
|
+
# Publish to TestPyPI on pushes to main, and to production PyPI on version tags (e.g. v1.2.3)
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
tags:
|
|
8
|
+
- 'v*.*.*'
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish-testpypi:
|
|
13
|
+
name: Build & publish package to TestPyPI
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
environment: test
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write # OIDC trusted publishing
|
|
18
|
+
contents: read
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: '3.11'
|
|
26
|
+
|
|
27
|
+
- name: Build wheel & sdist
|
|
28
|
+
run: |
|
|
29
|
+
python -m pip install --upgrade pip build
|
|
30
|
+
python -m build
|
|
31
|
+
|
|
32
|
+
- name: Publish to TestPyPI via OIDC
|
|
33
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
34
|
+
with:
|
|
35
|
+
repository-url: https://test.pypi.org/legacy/
|
|
36
|
+
skip-existing: true
|
|
37
|
+
|
|
38
|
+
# New production publish job – runs only for version tags
|
|
39
|
+
publish-pypi:
|
|
40
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
41
|
+
name: Build & publish package to PyPI (production)
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
environment: prod
|
|
44
|
+
permissions:
|
|
45
|
+
id-token: write # OIDC trusted publishing
|
|
46
|
+
contents: read
|
|
47
|
+
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
|
+
|
|
51
|
+
- uses: actions/setup-python@v5
|
|
52
|
+
with:
|
|
53
|
+
python-version: '3.11'
|
|
54
|
+
|
|
55
|
+
- name: Build wheel & sdist
|
|
56
|
+
run: |
|
|
57
|
+
python -m pip install --upgrade pip build
|
|
58
|
+
python -m build
|
|
59
|
+
|
|
60
|
+
- name: Publish to PyPI via OIDC
|
|
61
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
62
|
+
with:
|
|
63
|
+
skip-existing: true
|
skimgpt-1.0.0/Dockerfile
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Use NVIDIA CUDA base image with Python 3.10
|
|
2
|
+
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
|
|
3
|
+
|
|
4
|
+
# Set environment variables
|
|
5
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
6
|
+
ENV PYTHONUNBUFFERED=1
|
|
7
|
+
ENV CUDA_VISIBLE_DEVICES=0
|
|
8
|
+
|
|
9
|
+
# Install system dependencies including Python 3.10
|
|
10
|
+
RUN apt-get update && apt-get install -y \
|
|
11
|
+
python3.10 \
|
|
12
|
+
python3-pip \
|
|
13
|
+
python3.10-dev \
|
|
14
|
+
python3.10-distutils \
|
|
15
|
+
git \
|
|
16
|
+
wget \
|
|
17
|
+
curl \
|
|
18
|
+
build-essential \
|
|
19
|
+
cmake \
|
|
20
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
21
|
+
|
|
22
|
+
# Create symbolic links for python3.10
|
|
23
|
+
RUN ln -sf /usr/bin/python3.10 /usr/bin/python3
|
|
24
|
+
RUN ln -sf /usr/bin/python3.10 /usr/bin/python
|
|
25
|
+
|
|
26
|
+
# Install pip for Python 3.10
|
|
27
|
+
RUN python3.10 -m pip install --upgrade pip
|
|
28
|
+
|
|
29
|
+
# Set working directory
|
|
30
|
+
WORKDIR /app
|
|
31
|
+
|
|
32
|
+
# Install dependencies from PyPI first to avoid TestPyPI issues
|
|
33
|
+
RUN pip install --no-cache-dir \
|
|
34
|
+
pandas>=1.3.0 \
|
|
35
|
+
numpy>=1.21.0 \
|
|
36
|
+
openai>=1.0.0 \
|
|
37
|
+
biopython>=1.79 \
|
|
38
|
+
requests>=2.25.0 \
|
|
39
|
+
tiktoken>=0.7.0 \
|
|
40
|
+
vllm>=0.6.0 \
|
|
41
|
+
htcondor>=24.0.0
|
|
42
|
+
|
|
43
|
+
# Build argument for skimgpt version
|
|
44
|
+
ARG SKIMGPT_VERSION=0.1.9
|
|
45
|
+
# Try to install skimgpt from TestPyPI (may need to skip broken dependencies)
|
|
46
|
+
RUN pip install --no-cache-dir --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ --no-deps skimgpt==${SKIMGPT_VERSION} || \
|
|
47
|
+
echo "Warning: Could not install skimgpt from TestPyPI, installing from PyPI instead" && \
|
|
48
|
+
pip install --no-cache-dir skimgpt==${SKIMGPT_VERSION}
|
|
49
|
+
|
|
50
|
+
# Verify the installation and entry point
|
|
51
|
+
RUN skimgpt-relevance --help || echo "Entry point verification failed, but package may still work"
|
|
52
|
+
|
|
53
|
+
# Install additional dependencies that might be needed
|
|
54
|
+
RUN pip install --no-cache-dir \
|
|
55
|
+
torch \
|
|
56
|
+
transformers \
|
|
57
|
+
accelerate \
|
|
58
|
+
xformers
|
|
59
|
+
|
|
60
|
+
# Create directories for data and output
|
|
61
|
+
RUN mkdir -p /app/input_lists /app/output /app/debug /app/token
|
|
62
|
+
|
|
63
|
+
# Copy configuration file if it exists (will be volume mounted in production)
|
|
64
|
+
COPY config.json ./
|
|
65
|
+
|
|
66
|
+
# Set environment variables for vLLM
|
|
67
|
+
ENV VLLM_USE_MODELSCOPE=False
|
|
68
|
+
ENV VLLM_WORKER_MULTIPROC_METHOD=spawn
|
|
69
|
+
|
|
70
|
+
# Expose port if needed
|
|
71
|
+
EXPOSE 5081
|
|
72
|
+
|
|
73
|
+
# Create entrypoint script
|
|
74
|
+
RUN echo '#!/bin/bash\n\
|
|
75
|
+
# Check for GPU availability\n\
|
|
76
|
+
if ! nvidia-smi > /dev/null 2>&1; then\n\
|
|
77
|
+
echo "Warning: No GPU detected. vLLM will run on CPU (much slower)"\n\
|
|
78
|
+
fi\n\
|
|
79
|
+
\n\
|
|
80
|
+
# Run the application\n\
|
|
81
|
+
exec "$@"' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh
|
|
82
|
+
|
|
83
|
+
# Set the entrypoint
|
|
84
|
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
85
|
+
|
|
86
|
+
# Default command
|
|
87
|
+
CMD ["skimgpt-relevance", "--help"]
|
|
88
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include requirements.txt
|
|
3
|
+
include config_template.json
|
|
4
|
+
include main.py
|
|
5
|
+
include main_wrapper.py
|
|
6
|
+
include wrapper_result_merger.py
|
|
7
|
+
include run_multiple_analyses.sh
|
|
8
|
+
recursive-include src *.py
|
|
9
|
+
recursive-include src *.sh
|
|
10
|
+
recursive-include input_lists *.txt
|
|
11
|
+
exclude test/*
|
|
12
|
+
exclude .git*
|
|
13
|
+
exclude .pytest_cache
|
|
14
|
+
exclude __pycache__
|
|
15
|
+
exclude *.pyc
|
|
16
|
+
exclude .ipynb_checkpoints
|
skimgpt-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: skimgpt
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Biomedical Knowledge Mining with co-occurrence modeling and LLMs
|
|
5
|
+
Author-email: Ron Stewart <rstewart@morgridge.org>, Rob Millikin <rmillikin@morgridge.org>, Kevin George <kshinegeorge@morgridge.org>, Jack Freeman <jfreeman@morgridge.org>
|
|
6
|
+
Maintainer-email: Ron Stewart <rstewart@morgridge.org>, Rob Millikin <rmillikin@morgridge.org>, Kevin George <kshinegeorge@morgridge.org>, Jack Freeman <jfreeman@morgridge.org>
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/stewart-lab/skimgpt
|
|
9
|
+
Project-URL: Repository, https://github.com/stewart-lab/skimgpt.git
|
|
10
|
+
Project-URL: Documentation, https://github.com/stewart-lab/skimgpt#readme
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/stewart-lab/skimgpt/issues
|
|
12
|
+
Keywords: biomedical,nlp,co-occurrence,knowledge-mining,LLMs,literature-analysis,skim
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: pandas>=1.3.0
|
|
26
|
+
Requires-Dist: numpy>=1.21.0
|
|
27
|
+
Requires-Dist: openai>=1.0.0
|
|
28
|
+
Requires-Dist: biopython>=1.79
|
|
29
|
+
Requires-Dist: requests>=2.25.0
|
|
30
|
+
Requires-Dist: vllm>=0.6.0
|
|
31
|
+
Requires-Dist: tiktoken>=0.7.0
|
|
32
|
+
Requires-Dist: htcondor>=24.6.1
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
35
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
36
|
+
Requires-Dist: flake8>=3.8; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=0.910; extra == "dev"
|
|
38
|
+
Requires-Dist: build>=0.7.0; extra == "dev"
|
|
39
|
+
Requires-Dist: twine>=3.4.0; extra == "dev"
|
|
40
|
+
|
|
41
|
+
# Evaluating hypotheses using SKiM-GPT (Note: Must be on Mir-81)
|
|
42
|
+
This repository provides tools to SKIM through PubMed abstracts to evalaute hypotheses.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- Python 3.9^
|
|
48
|
+
- Libraries specified in `requirements.txt`
|
|
49
|
+
- OpenAI API key
|
|
50
|
+
- Pubmed API key
|
|
51
|
+
- CHTC auth token
|
|
52
|
+
- Rstewart2 access
|
|
53
|
+
|
|
54
|
+
## Getting Started
|
|
55
|
+
|
|
56
|
+
1. **Setup**:
|
|
57
|
+
Clone the repository to your machine and change to its top level directory.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone <repository_url>
|
|
61
|
+
cd <repository_directory>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
2. **Install Dependencies (with conda)**
|
|
65
|
+
Install the required packages using pip:
|
|
66
|
+
```bash
|
|
67
|
+
conda create --name {myenv} python=3.9
|
|
68
|
+
conda activate {myenv}
|
|
69
|
+
pip install -r requirements.txt
|
|
70
|
+
```
|
|
71
|
+
3. **Get CHTC auth token**
|
|
72
|
+
Log onto CHTC's submit node (ap2002.chtc.wisc.edu) and get you auth token using:
|
|
73
|
+
```bash
|
|
74
|
+
condor_token_fetch -file my_token
|
|
75
|
+
```
|
|
76
|
+
Copy the token to set youe environment variable back on rstewart2
|
|
77
|
+
|
|
78
|
+
3. **Environment Variables**
|
|
79
|
+
Before running the script, ensure you have set up your environment variables. We recommend setting in your shell profile. You must source your shell profile after setting
|
|
80
|
+
the environment variables (Jack has our OpenAI and Pubmed keys in his .bashrc on the server FYI):
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
export OPENAI_API_KEY=your_api_key_here
|
|
84
|
+
export PUBMED_API_KEY=your_api_key_here
|
|
85
|
+
export HTCONDOR_TOKEN=your_token_here
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
4. **Configuring Parameters**
|
|
89
|
+
The `config.json` file includes global parameters as well as several job types, each with unique paramenters. Please view the [`config` Module Overview](#config-overview) to help set up your job.
|
|
90
|
+
|
|
91
|
+
5. **Running the script**
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
|
|
95
|
+
python main.py
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
99
|
+
<a name="config-overview"></a>
|
|
100
|
+
# `config` Module Overview
|
|
101
|
+
|
|
102
|
+
This configuration file contains various settings for different job types. Below are descriptions of each parameter:
|
|
103
|
+
|
|
104
|
+
## General Parameters
|
|
105
|
+
|
|
106
|
+
- `JOB_TYPE`: Specifies the type of job to be executed, e.g., `km_with_gpt` or `skim_with_gpt`.
|
|
107
|
+
- `KM_hypothesis`: Hypothesis template for KM analysis, using f-string format like `{a_term}` and `{b_term}` (e.g., `"Treatment with {b_term} will have no effect on {a_term} patient outcomes."`).
|
|
108
|
+
- `SKIM_hypotheses`: A dictionary of hypothesis templates for SKIM analysis (Must use f-string format).
|
|
109
|
+
- `AB`: Relevance hyopthesis between `{a_term}` and `{b_term}` (e.g., `"There exists an interaction between the organ {a_term} and the gene {b_term}."`).
|
|
110
|
+
- `BC`: Relevance hyopthesis between`{c_term}` and `{b_term}` (e.g., `"There exists an interaction between the disease {c_term} and the gene {b_term}."`).
|
|
111
|
+
- `rel_AC`: Relevance hyopthesis between `{c_term}` and `{a_term}` (e.g., `"There exists an interaction between the disease {c_term} and the organ {a_term}."`).
|
|
112
|
+
- `ABC`: Evaluation hypothesis (e.g., `"The gene {b_term} links the organ {a_term} to the disease {c_term}."`).
|
|
113
|
+
- `AC`: Evaluation hypothesis (e.g., `"The gene {a_term} influences the disease {c_term}."`).
|
|
114
|
+
- `Evaluate_single_abstract`: Boolean flag to evaluate a single abstract (e.g., `false`).
|
|
115
|
+
|
|
116
|
+
## Global Settings
|
|
117
|
+
|
|
118
|
+
- `A_TERM`: The primary term of interest, such as an organ (e.g., `"Thymus"`).
|
|
119
|
+
- `A_TERM_SUFFIX`: Optional suffix for the `A_TERM` (e.g., `""`).
|
|
120
|
+
- `TOP_N_ARTICLES_MOST_CITED`: Number of top-cited articles to consider (e.g., `300`).
|
|
121
|
+
- `TOP_N_ARTICLES_MOST_RECENT`: Number of most recent articles to consider (e.g., `0`).
|
|
122
|
+
- `POST_N`: Number of articles to process after relevance filtering (e.g., `20`).
|
|
123
|
+
- `MIN_WORD_COUNT`: Minimum word count for an abstract to be considered (e.g., `98`).
|
|
124
|
+
- `MODEL`: Machine learning model used for processing (e.g., `"gpt-4o-2024-08-06"`).
|
|
125
|
+
- `MAX_TOKENS`: Maximum number of tokens per API request (e.g., `1000`).
|
|
126
|
+
- `API_URL`: URL for the API endpoint (e.g., `"http://localhost:5099/skim/api/jobs"`).
|
|
127
|
+
- `PORT`: Port number for the API service (e.g., `"5081"`).
|
|
128
|
+
- `RATE_LIMIT`: Maximum number of requests allowed per time unit (e.g., `3`).
|
|
129
|
+
- `DELAY`: Time in seconds to wait before making a new request (e.g., `10`).
|
|
130
|
+
- `MAX_RETRIES`: Maximum number of retry attempts after a failed request (e.g., `10`).
|
|
131
|
+
- `RETRY_DELAY`: Delay in seconds before retrying a failed request (e.g., `5`).
|
|
132
|
+
|
|
133
|
+
## Abstract Filter Settings
|
|
134
|
+
|
|
135
|
+
- `MODEL`: Model used for abstract filtering (e.g., `"lexu14/porpoise1"`).
|
|
136
|
+
- `TEMPERATURE`: Sampling temperature for model inference (e.g., `0`).
|
|
137
|
+
- `TOP_K`: Number of highest-probability vocabulary tokens to keep for top-k-filtering (e.g., `20`).
|
|
138
|
+
- `TOP_P`: Cumulative probability for nucleus sampling (e.g., `0.95`).
|
|
139
|
+
- `MAX_COT_TOKENS`: Maximum tokens for Chain-of-Thought reasoning (e.g., `500`).
|
|
140
|
+
- `DEBUG`: Boolean flag to enable debug mode (e.g., `false`).
|
|
141
|
+
- `TEST_LEAKAGE`: Boolean flag to test for data leakage (e.g., `false`).
|
|
142
|
+
- `TEST_LEAKAGE_TYPE`: Type of data leakage test (e.g., `"empty"`).
|
|
143
|
+
|
|
144
|
+
## Job-Specific Settings
|
|
145
|
+
|
|
146
|
+
### km_with_gpt
|
|
147
|
+
|
|
148
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
149
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
150
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/test/km_a.txt"`).
|
|
151
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/leakage_b_terms.txt"`).
|
|
152
|
+
- `SORT_COLUMN`: Column used for sorting A-B relationships (e.g., `"ab_sort_ratio"`).
|
|
153
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider after sorting (e.g., `25`).
|
|
154
|
+
- `km_with_gpt`:
|
|
155
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `1`).
|
|
156
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `2024`).
|
|
157
|
+
|
|
158
|
+
### skim_with_gpt
|
|
159
|
+
|
|
160
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
161
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
162
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/exercise3/skim_a.txt"`).
|
|
163
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/genes_no_syn.txt"`).
|
|
164
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider (e.g., `20000`).
|
|
165
|
+
- `C_TERMS_FILE`: File path for the `C` terms list (e.g., `"../input_lists/down_syndrome.txt"`).
|
|
166
|
+
- `SORT_COLUMN`: Column used for sorting B-C relationships (e.g., `"bc_sort_ratio"`).
|
|
167
|
+
- `skim`:
|
|
168
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `0.1`).
|
|
169
|
+
- `bc_fet_threshold`: Fisher Exact Test threshold for B-C relationships (e.g., `0.5`).
|
|
170
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `2024`).
|
|
171
|
+
- `top_n`: Number of top items to consider after AB linkage (e.g., `300`).
|
|
172
|
+
|
|
173
|
+
### km_with_gpt_direct_comp
|
|
174
|
+
|
|
175
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
176
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
177
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/test/km_a.txt"`).
|
|
178
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/scrapie_b_terms_ProteinvsVI_directlyForNewCode.txt"`).
|
|
179
|
+
- `SORT_COLUMN`: Column used for sorting A-B relationships (e.g., `"ab_sort_ratio"`).
|
|
180
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider (e.g., `25`).
|
|
181
|
+
- `km_with_gpt_direct_comp`:
|
|
182
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `1`).
|
|
183
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `1990`).
|
|
184
|
+
|
|
185
|
+
This configuration is critical for tailoring the behavior of the system to specific job types and requirements. Ensure all file paths and parameters are correctly set before execution to avoid runtime errors.
|
|
186
|
+
## Contributions
|
|
187
|
+
Feel free to contribute to this repository by submitting a pull request or opening an issue for suggestions and bugs.
|
skimgpt-1.0.0/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Evaluating hypotheses using SKiM-GPT (Note: Must be on Mir-81)
|
|
2
|
+
This repository provides tools to SKIM through PubMed abstracts to evalaute hypotheses.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Python 3.9^
|
|
8
|
+
- Libraries specified in `requirements.txt`
|
|
9
|
+
- OpenAI API key
|
|
10
|
+
- Pubmed API key
|
|
11
|
+
- CHTC auth token
|
|
12
|
+
- Rstewart2 access
|
|
13
|
+
|
|
14
|
+
## Getting Started
|
|
15
|
+
|
|
16
|
+
1. **Setup**:
|
|
17
|
+
Clone the repository to your machine and change to its top level directory.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone <repository_url>
|
|
21
|
+
cd <repository_directory>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2. **Install Dependencies (with conda)**
|
|
25
|
+
Install the required packages using pip:
|
|
26
|
+
```bash
|
|
27
|
+
conda create --name {myenv} python=3.9
|
|
28
|
+
conda activate {myenv}
|
|
29
|
+
pip install -r requirements.txt
|
|
30
|
+
```
|
|
31
|
+
3. **Get CHTC auth token**
|
|
32
|
+
Log onto CHTC's submit node (ap2002.chtc.wisc.edu) and get you auth token using:
|
|
33
|
+
```bash
|
|
34
|
+
condor_token_fetch -file my_token
|
|
35
|
+
```
|
|
36
|
+
Copy the token to set youe environment variable back on rstewart2
|
|
37
|
+
|
|
38
|
+
3. **Environment Variables**
|
|
39
|
+
Before running the script, ensure you have set up your environment variables. We recommend setting in your shell profile. You must source your shell profile after setting
|
|
40
|
+
the environment variables (Jack has our OpenAI and Pubmed keys in his .bashrc on the server FYI):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
export OPENAI_API_KEY=your_api_key_here
|
|
44
|
+
export PUBMED_API_KEY=your_api_key_here
|
|
45
|
+
export HTCONDOR_TOKEN=your_token_here
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4. **Configuring Parameters**
|
|
49
|
+
The `config.json` file includes global parameters as well as several job types, each with unique paramenters. Please view the [`config` Module Overview](#config-overview) to help set up your job.
|
|
50
|
+
|
|
51
|
+
5. **Running the script**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
|
|
55
|
+
python main.py
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
59
|
+
<a name="config-overview"></a>
|
|
60
|
+
# `config` Module Overview
|
|
61
|
+
|
|
62
|
+
This configuration file contains various settings for different job types. Below are descriptions of each parameter:
|
|
63
|
+
|
|
64
|
+
## General Parameters
|
|
65
|
+
|
|
66
|
+
- `JOB_TYPE`: Specifies the type of job to be executed, e.g., `km_with_gpt` or `skim_with_gpt`.
|
|
67
|
+
- `KM_hypothesis`: Hypothesis template for KM analysis, using f-string format like `{a_term}` and `{b_term}` (e.g., `"Treatment with {b_term} will have no effect on {a_term} patient outcomes."`).
|
|
68
|
+
- `SKIM_hypotheses`: A dictionary of hypothesis templates for SKIM analysis (Must use f-string format).
|
|
69
|
+
- `AB`: Relevance hyopthesis between `{a_term}` and `{b_term}` (e.g., `"There exists an interaction between the organ {a_term} and the gene {b_term}."`).
|
|
70
|
+
- `BC`: Relevance hyopthesis between`{c_term}` and `{b_term}` (e.g., `"There exists an interaction between the disease {c_term} and the gene {b_term}."`).
|
|
71
|
+
- `rel_AC`: Relevance hyopthesis between `{c_term}` and `{a_term}` (e.g., `"There exists an interaction between the disease {c_term} and the organ {a_term}."`).
|
|
72
|
+
- `ABC`: Evaluation hypothesis (e.g., `"The gene {b_term} links the organ {a_term} to the disease {c_term}."`).
|
|
73
|
+
- `AC`: Evaluation hypothesis (e.g., `"The gene {a_term} influences the disease {c_term}."`).
|
|
74
|
+
- `Evaluate_single_abstract`: Boolean flag to evaluate a single abstract (e.g., `false`).
|
|
75
|
+
|
|
76
|
+
## Global Settings
|
|
77
|
+
|
|
78
|
+
- `A_TERM`: The primary term of interest, such as an organ (e.g., `"Thymus"`).
|
|
79
|
+
- `A_TERM_SUFFIX`: Optional suffix for the `A_TERM` (e.g., `""`).
|
|
80
|
+
- `TOP_N_ARTICLES_MOST_CITED`: Number of top-cited articles to consider (e.g., `300`).
|
|
81
|
+
- `TOP_N_ARTICLES_MOST_RECENT`: Number of most recent articles to consider (e.g., `0`).
|
|
82
|
+
- `POST_N`: Number of articles to process after relevance filtering (e.g., `20`).
|
|
83
|
+
- `MIN_WORD_COUNT`: Minimum word count for an abstract to be considered (e.g., `98`).
|
|
84
|
+
- `MODEL`: Machine learning model used for processing (e.g., `"gpt-4o-2024-08-06"`).
|
|
85
|
+
- `MAX_TOKENS`: Maximum number of tokens per API request (e.g., `1000`).
|
|
86
|
+
- `API_URL`: URL for the API endpoint (e.g., `"http://localhost:5099/skim/api/jobs"`).
|
|
87
|
+
- `PORT`: Port number for the API service (e.g., `"5081"`).
|
|
88
|
+
- `RATE_LIMIT`: Maximum number of requests allowed per time unit (e.g., `3`).
|
|
89
|
+
- `DELAY`: Time in seconds to wait before making a new request (e.g., `10`).
|
|
90
|
+
- `MAX_RETRIES`: Maximum number of retry attempts after a failed request (e.g., `10`).
|
|
91
|
+
- `RETRY_DELAY`: Delay in seconds before retrying a failed request (e.g., `5`).
|
|
92
|
+
|
|
93
|
+
## Abstract Filter Settings
|
|
94
|
+
|
|
95
|
+
- `MODEL`: Model used for abstract filtering (e.g., `"lexu14/porpoise1"`).
|
|
96
|
+
- `TEMPERATURE`: Sampling temperature for model inference (e.g., `0`).
|
|
97
|
+
- `TOP_K`: Number of highest-probability vocabulary tokens to keep for top-k-filtering (e.g., `20`).
|
|
98
|
+
- `TOP_P`: Cumulative probability for nucleus sampling (e.g., `0.95`).
|
|
99
|
+
- `MAX_COT_TOKENS`: Maximum tokens for Chain-of-Thought reasoning (e.g., `500`).
|
|
100
|
+
- `DEBUG`: Boolean flag to enable debug mode (e.g., `false`).
|
|
101
|
+
- `TEST_LEAKAGE`: Boolean flag to test for data leakage (e.g., `false`).
|
|
102
|
+
- `TEST_LEAKAGE_TYPE`: Type of data leakage test (e.g., `"empty"`).
|
|
103
|
+
|
|
104
|
+
## Job-Specific Settings
|
|
105
|
+
|
|
106
|
+
### km_with_gpt
|
|
107
|
+
|
|
108
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
109
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
110
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/test/km_a.txt"`).
|
|
111
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/leakage_b_terms.txt"`).
|
|
112
|
+
- `SORT_COLUMN`: Column used for sorting A-B relationships (e.g., `"ab_sort_ratio"`).
|
|
113
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider after sorting (e.g., `25`).
|
|
114
|
+
- `km_with_gpt`:
|
|
115
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `1`).
|
|
116
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `2024`).
|
|
117
|
+
|
|
118
|
+
### skim_with_gpt
|
|
119
|
+
|
|
120
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
121
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
122
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/exercise3/skim_a.txt"`).
|
|
123
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/genes_no_syn.txt"`).
|
|
124
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider (e.g., `20000`).
|
|
125
|
+
- `C_TERMS_FILE`: File path for the `C` terms list (e.g., `"../input_lists/down_syndrome.txt"`).
|
|
126
|
+
- `SORT_COLUMN`: Column used for sorting B-C relationships (e.g., `"bc_sort_ratio"`).
|
|
127
|
+
- `skim`:
|
|
128
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `0.1`).
|
|
129
|
+
- `bc_fet_threshold`: Fisher Exact Test threshold for B-C relationships (e.g., `0.5`).
|
|
130
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `2024`).
|
|
131
|
+
- `top_n`: Number of top items to consider after AB linkage (e.g., `300`).
|
|
132
|
+
|
|
133
|
+
### km_with_gpt_direct_comp
|
|
134
|
+
|
|
135
|
+
- `position`: Boolean flag to consider positional data (e.g., `false`).
|
|
136
|
+
- `A_TERM_LIST`: Boolean to indicate if a list of `A` terms is used (e.g., `false`).
|
|
137
|
+
- `A_TERMS_FILE`: File path for the `A` terms list (e.g., `"../input_lists/test/km_a.txt"`).
|
|
138
|
+
- `B_TERMS_FILE`: File path for the `B` terms list (e.g., `"../input_lists/scrapie_b_terms_ProteinvsVI_directlyForNewCode.txt"`).
|
|
139
|
+
- `SORT_COLUMN`: Column used for sorting A-B relationships (e.g., `"ab_sort_ratio"`).
|
|
140
|
+
- `NUM_B_TERMS`: Number of `B` terms to consider (e.g., `25`).
|
|
141
|
+
- `km_with_gpt_direct_comp`:
|
|
142
|
+
- `ab_fet_threshold`: Fisher Exact Test threshold for A-B relationships (e.g., `1`).
|
|
143
|
+
- `censor_year`: Year for data censoring or time-slicing (e.g., `1990`).
|
|
144
|
+
|
|
145
|
+
This configuration is critical for tailoring the behavior of the system to specific job types and requirements. Ensure all file paths and parameters are correctly set before execution to avoid runtime errors.
|
|
146
|
+
## Contributions
|
|
147
|
+
Feel free to contribute to this repository by submitting a pull request or opening an issue for suggestions and bugs.
|
skimgpt-1.0.0/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
skimgpt - Scientific Knowledge Mining with GPT
|
|
3
|
+
|
|
4
|
+
A biomedical literature analysis tool for knowledge discovery and hypothesis evaluation.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.9"
|
|
8
|
+
__author__ = "Jack Freeman"
|
|
9
|
+
__email__ = "jfreeman@morgridge.org"
|
|
10
|
+
|
|
11
|
+
"""Top-level package initialisation for *skimgpt*.
|
|
12
|
+
|
|
13
|
+
Only very lightweight, dependency-free modules should be imported eagerly here.
|
|
14
|
+
Heavier sub-modules (those that need BioPython, torch, vllm …) are imported
|
|
15
|
+
lazily the first time they are accessed. This allows the submission wrapper
|
|
16
|
+
to run on a minimal Python environment while the GPU container provides the
|
|
17
|
+
full scientific stack at runtime.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from importlib import import_module
|
|
21
|
+
from types import ModuleType
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
25
|
+
# Metadata
|
|
26
|
+
# ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
# These names are exposed. Everything except ``src`` will be loaded lazily.
|
|
29
|
+
_EXPOSED = {
|
|
30
|
+
"src", # the sub-package itself (lightweight)
|
|
31
|
+
"utils", # lightweight (numpy/pandas)
|
|
32
|
+
"classifier", # depends on openai but no GPU
|
|
33
|
+
"pubmed_fetcher", # depends on BioPython → may be missing on submit host
|
|
34
|
+
"relevance", # heavy GPU / vLLM dependencies – container only
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# What *import skimgpt as s; dir(s)* should show
|
|
38
|
+
__all__ = list(_EXPOSED)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# ---------------------------------------------------------------------------
|
|
42
|
+
# Lazy loader
|
|
43
|
+
# ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
def __getattr__(name: str) -> Any: # noqa: D401 – single-line docstring ok
|
|
46
|
+
"""Dynamically import sub-modules on first access.
|
|
47
|
+
|
|
48
|
+
This is executed only when an attribute that does not yet exist is
|
|
49
|
+
requested from the *skimgpt* package. It tries to import the matching
|
|
50
|
+
module from *skimgpt.src* and caches it in ``globals()`` so subsequent
|
|
51
|
+
look-ups are fast.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
if name not in _EXPOSED:
|
|
55
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
|
56
|
+
|
|
57
|
+
# Map attribute → real module path
|
|
58
|
+
mod_path = "skimgpt" if name == "src" else f"skimgpt.src.{name}"
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
module: ModuleType = import_module(mod_path)
|
|
62
|
+
except ImportError as exc:
|
|
63
|
+
# Provide a clearer message for optional heavy dependencies
|
|
64
|
+
raise AttributeError(
|
|
65
|
+
f"Sub-module '{name}' could not be imported – missing optional "
|
|
66
|
+
f"dependency? Original error: {exc}"
|
|
67
|
+
) from exc
|
|
68
|
+
|
|
69
|
+
globals()[name] = module # cache for future access
|
|
70
|
+
return module
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"JOB_TYPE": "",
|
|
3
|
+
"KM_hypothesis": "",
|
|
4
|
+
"KM_direct_comp_hypothesis": "",
|
|
5
|
+
"SKIM_hypotheses": {
|
|
6
|
+
"BC": "",
|
|
7
|
+
"AB": "",
|
|
8
|
+
"rel_AC": "",
|
|
9
|
+
"AC": "",
|
|
10
|
+
"ABC": ""
|
|
11
|
+
},
|
|
12
|
+
"Evaluate_single_abstract": false,
|
|
13
|
+
"GLOBAL_SETTINGS": {
|
|
14
|
+
"A_TERM": "",
|
|
15
|
+
"A_TERM_SUFFIX": "",
|
|
16
|
+
"TOP_N_ARTICLES_MOST_CITED": 50,
|
|
17
|
+
"TOP_N_ARTICLES_MOST_RECENT": 50,
|
|
18
|
+
"POST_N": 5,
|
|
19
|
+
"MIN_WORD_COUNT": 98,
|
|
20
|
+
"MODEL": "o1-preview",
|
|
21
|
+
"REASONING_EFFORT": "medium",
|
|
22
|
+
"API_URL": "http://localhost:5099/skim/api/jobs",
|
|
23
|
+
"PORT": "5081",
|
|
24
|
+
"RATE_LIMIT": 3,
|
|
25
|
+
"DELAY": 10,
|
|
26
|
+
"MAX_RETRIES": 10,
|
|
27
|
+
"RETRY_DELAY": 5,
|
|
28
|
+
"LOG_LEVEL": "INFO",
|
|
29
|
+
"OUTDIR_SUFFIX": "",
|
|
30
|
+
"iterations": 3
|
|
31
|
+
},
|
|
32
|
+
"HTCONDOR": {
|
|
33
|
+
"collector_host": "cm.chtc.wisc.edu",
|
|
34
|
+
"submit_host": "ap2002.chtc.wisc.edu",
|
|
35
|
+
"request_gpus": "1",
|
|
36
|
+
"request_cpus": "1",
|
|
37
|
+
"request_memory": "24GB",
|
|
38
|
+
"request_disk": "50GB",
|
|
39
|
+
"docker_image": "docker://lexu27/kmgpt_filter:v0.6"
|
|
40
|
+
},
|
|
41
|
+
"abstract_filter": {
|
|
42
|
+
"MODEL": "lexu14/porpoise1",
|
|
43
|
+
"TEMPERATURE": 0,
|
|
44
|
+
"TOP_K": 20,
|
|
45
|
+
"TOP_P": 0.95,
|
|
46
|
+
"MAX_COT_TOKENS": 500,
|
|
47
|
+
"DEBUG": false,
|
|
48
|
+
"TEST_LEAKAGE": false,
|
|
49
|
+
"TEST_LEAKAGE_TYPE": "empty"
|
|
50
|
+
},
|
|
51
|
+
"JOB_SPECIFIC_SETTINGS": {
|
|
52
|
+
"km_with_gpt": {
|
|
53
|
+
"position": false,
|
|
54
|
+
"A_TERM_LIST": false,
|
|
55
|
+
"A_TERMS_FILE": "../input_lists/test/km_a.txt",
|
|
56
|
+
"B_TERMS_FILE": "../input_lists/hpv.txt",
|
|
57
|
+
"SORT_COLUMN": "ab_sort_ratio",
|
|
58
|
+
"NUM_B_TERMS": 25,
|
|
59
|
+
"km_with_gpt": {
|
|
60
|
+
"ab_fet_threshold": 1,
|
|
61
|
+
"censor_year": 1980
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"km_with_gpt_direct_comp": {
|
|
65
|
+
"position": false,
|
|
66
|
+
"A_TERM_LIST": false,
|
|
67
|
+
"A_TERMS_FILE": "./input_lists/test/km_a.txt",
|
|
68
|
+
"B_TERMS_FILE": "./input_lists/cervicalCancer_b_terms_HPVvsHSV_directlyForNewCode.txt",
|
|
69
|
+
"SORT_COLUMN": "ab_sort_ratio",
|
|
70
|
+
"NUM_B_TERMS": 25,
|
|
71
|
+
"km_with_gpt_direct_comp": {
|
|
72
|
+
"ab_fet_threshold": 1,
|
|
73
|
+
"censor_year": 1990
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"skim_with_gpt": {
|
|
77
|
+
"position": true,
|
|
78
|
+
"A_TERM_LIST": true,
|
|
79
|
+
"A_TERMS_FILE": "../input_lists/exercise3/skim_a.txt",
|
|
80
|
+
"B_TERMS_FILE": "../input_lists/exercise3/skim_b.txt",
|
|
81
|
+
"NUM_B_TERMS": 20000,
|
|
82
|
+
"C_TERMS_FILE": "../input_lists/exercise3/skim_c.txt",
|
|
83
|
+
"SORT_COLUMN": "bc_sort_ratio",
|
|
84
|
+
"skim_with_gpt": {
|
|
85
|
+
"ab_fet_threshold": 0.1,
|
|
86
|
+
"bc_fet_threshold": 0.5,
|
|
87
|
+
"censor_year": 2024,
|
|
88
|
+
"top_n": 300
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|