Medical Literature Analysis and Annotation System with LLM-powered automation
Project description
MedLitAnno: Medical Literature Annotation System
MedLitAnno is a powerful tool for automated annotation of medical literature, designed to extract structured information about bacteria-disease relationships from scientific texts. It also includes MRAgent, an innovative automated agent for causal knowledge discovery in disease research via Mendelian Randomization (MR).
๐ Features
Medical Literature Annotation
- Multi-model Support: Use OpenAI, DeepSeek, DeepSeek Reasoner, or Qianwen models
- Robust Processing: Breakpoint resume and error retry mechanisms
- Comprehensive Annotation: Entity recognition, relation extraction, evidence detection
- Batch Processing: Process entire directories of Excel files
- Progress Monitoring: Track annotation progress and manage batch processing
- Format Conversion: Export to Label Studio compatible format
MRAgent: Causal Knowledge Discovery
- Automated Literature Analysis: Scans scientific literature to discover potential exposure-outcome pairs
- Causal Inference: Performs Mendelian Randomization using GWAS data
- Knowledge Discovery Mode: Autonomously identifies potential causal factors for diseases
- Causal Validation Mode: Validates specific causal hypotheses
- GWAS Integration: Seamless integration with OpenGWAS database
๐ Installation
From PyPI (Recommended)
pip install medlitanno
From Source
# Clone the repository
git clone https://github.com/chenxingqiang/medlitanno.git
cd medlitanno
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install the package
pip install -e .
โ๏ธ API Key Configuration
Set your API keys as environment variables:
# For DeepSeek models
export DEEPSEEK_API_KEY="your-deepseek-api-key"
# For Qianwen models
export QIANWEN_API_KEY="your-qianwen-api-key"
# For OpenAI models (optional)
export OPENAI_API_KEY="your-openai-api-key"
# For MR analysis (optional)
export OPENGWAS_JWT="your-opengwas-jwt-token"
๐ Usage
Medical Literature Annotation
Command Line Interface
# Annotate medical literature
medlitanno annotate --data-dir datatrain --model deepseek-chat
Python API
from medlitanno.annotation import MedicalAnnotationLLM
import os
# Initialize the annotator
annotator = MedicalAnnotationLLM(
api_key=os.environ.get("DEEPSEEK_API_KEY"),
model="deepseek-chat",
model_type="deepseek"
)
# Annotate text
text = "Helicobacter pylori infection is associated with gastric cancer."
result = annotator.annotate_text(text)
# Print results
print(f"Entities: {result.entities}")
print(f"Relations: {result.relations}")
print(f"Evidences: {result.evidences}")
MRAgent: Causal Knowledge Discovery
Command Line Interface
# Knowledge Discovery mode
medlitanno mr --outcome "back pain" --model gpt-4o
# Causal Validation mode
medlitanno mr --exposure "osteoarthritis" --outcome "back pain" --mode causal
Python API
from medlitanno.mragent import MRAgent, MRAgentOE
import os
# Knowledge Discovery mode
agent = MRAgent(
outcome="back pain",
AI_key=os.environ.get("OPENAI_API_KEY"),
LLM_model="gpt-4o",
gwas_token=os.environ.get("OPENGWAS_JWT")
)
agent.run()
# Causal Validation mode
agent_oe = MRAgentOE(
exposure="osteoarthritis",
outcome="back pain",
AI_key=os.environ.get("OPENAI_API_KEY"),
LLM_model="gpt-4o",
gwas_token=os.environ.get("OPENGWAS_JWT")
)
agent_oe.run()
๐ Output Format
Annotation System
The annotation system extracts:
- Entities: Bacteria and Disease mentions
- Relations: Connections between entities with relation types
- Evidences: Text spans supporting the relations
Relation Types
contributes_to: Bacteria contributes to disease developmentameliorates: Bacteria improves or alleviates diseasecorrelated_with: Bacteria and disease show correlationbiomarker_for: Bacteria serves as a biomarker for disease
MRAgent System
MRAgent provides:
- Literature Analysis: Summary of relevant scientific papers
- Potential Exposures: List of potential causal factors
- MR Results: Statistical evidence for causal relationships
- Visualizations: Forest plots and other visual representations
- Recommendations: Insights for further research
๐ Performance
- Annotation Speed: ~30-60 seconds per document (depends on model and text length)
- MR Analysis: Processes hundreds of articles and GWAS datasets efficiently
- Accuracy: Comparable to manual annotation and analysis in controlled tests
๐ช Stability
- Breakpoint Resume: Automatically continues from the last processed file
- Error Retry: Automatically retries failed operations
- Progress Monitoring: Track progress in real-time
๐ Project Structure
medlitanno/
โโโ src/ # Source code
โ โโโ medlitanno/ # Main package
โ โโโ annotation/ # Annotation system
โ โโโ common/ # Shared utilities
โ โโโ mragent/ # MR analysis (optional)
โโโ docs/ # Documentation
โ โโโ images/ # Documentation images
โ โโโ ...
โโโ examples/ # Example scripts
โโโ tests/ # Unit tests
โโโ scripts/ # Utility scripts
โโโ config/ # Configuration files
โโโ ...
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ง Contact
For questions or feedback, please contact chenxingqiang@gmail.com.
Note: This package incorporates technology from MRAgent, an innovative automated agent for causal knowledge discovery in disease research via Mendelian Randomization.
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 medlitanno-1.1.0.tar.gz.
File metadata
- Download URL: medlitanno-1.1.0.tar.gz
- Upload date:
- Size: 1.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
508b319c9a8d2c873db11c3efa6d5031a457894c448848f9ab6c521225117781
|
|
| MD5 |
f05ad21a517fb70da8dfc7ea3776fdf5
|
|
| BLAKE2b-256 |
990582c58a93c2d0e8fb5d01c93ab94f1d959a541d3630f86d3ab22233bc488e
|
File details
Details for the file medlitanno-1.1.0-py3-none-any.whl.
File metadata
- Download URL: medlitanno-1.1.0-py3-none-any.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cc9edb733bdc17fb1d8e94ccfc7d149003db60562b2a2527d6558011d36141d
|
|
| MD5 |
5f81dd205de6a4136b0e13663665a7af
|
|
| BLAKE2b-256 |
6d8f281e9e722fc0ca611242a37ce1f86b48ef2e92bb93c7f799f1518255a791
|