Skip to main content

Medical Literature Analysis and Annotation System with LLM-powered automation

Project description

MedLitAnno: Medical Literature Annotation System

GitHub Python PyPI CI

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:

  1. Entities: Bacteria and Disease mentions
  2. Relations: Connections between entities with relation types
  3. Evidences: Text spans supporting the relations

Relation Types

  • contributes_to: Bacteria contributes to disease development
  • ameliorates: Bacteria improves or alleviates disease
  • correlated_with: Bacteria and disease show correlation
  • biomarker_for: Bacteria serves as a biomarker for disease

MRAgent System

MRAgent provides:

  1. Literature Analysis: Summary of relevant scientific papers
  2. Potential Exposures: List of potential causal factors
  3. MR Results: Statistical evidence for causal relationships
  4. Visualizations: Forest plots and other visual representations
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medlitanno-1.1.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medlitanno-1.1.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

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

Hashes for medlitanno-1.1.0.tar.gz
Algorithm Hash digest
SHA256 508b319c9a8d2c873db11c3efa6d5031a457894c448848f9ab6c521225117781
MD5 f05ad21a517fb70da8dfc7ea3776fdf5
BLAKE2b-256 990582c58a93c2d0e8fb5d01c93ab94f1d959a541d3630f86d3ab22233bc488e

See more details on using hashes here.

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

Hashes for medlitanno-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7cc9edb733bdc17fb1d8e94ccfc7d149003db60562b2a2527d6558011d36141d
MD5 5f81dd205de6a4136b0e13663665a7af
BLAKE2b-256 6d8f281e9e722fc0ca611242a37ce1f86b48ef2e92bb93c7f799f1518255a791

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page