A modular command-line interface and GUI for mapping and enriching ontologies using BioPortal and OLS APIs.
This tool provides a simple, user-friendly interface for ontology concept lookup and mapping across multiple biomedical ontologies. It supports both command-line interface (CLI) and graphical user interface (GUI) modes.
- Multi-ontology support: 24+ ontologies including MONDO, HP, NCIT, DOID, CHEBI, GO, SNOMEDCT, and more
- Dual API integration: BioPortal and OLS APIs with intelligent fallback
- Multiple input formats: Read Turtle, JSON-LD, RDF/XML, N-Triples, N3, TriG, N-Quads with auto-detection
- Multiple output formats: Export to Turtle, JSON-LD, RDF/XML, N-Triples, CSV, TSV, SSSOM, and more
- Format conversion: Convert between any supported RDF format
- Intelligent caching: In-memory and persistent caching for faster repeated queries
- Interactive search: Real-time concept lookup with user-friendly selection
- Flexible file processing: Parse and enrich ontology files in any supported format
- Batch processing: Handle multiple concepts efficiently
- GUI interface: User-friendly graphical interface for non-technical users with format selection
- Result comparison: Compare results from different ontology services
- Python 3.8 or higher
- pip package manager
# Clone the repository
git clone https://github.com/your-username/ontology-mapping-tool.git
cd ontology-mapping-tool
# Install dependencies
pip install -r requirements.txt
# Install the package
pip install -e .-
Copy the environment template:
cp .env.template .env
-
Edit
.envand add your API keys:- Get a BioPortal API key from: https://bioportal.bioontology.org/account
- (Optional) Get a UMLS API key from: https://uts.nlm.nih.gov/uts/profile
-
(Optional) Configure caching settings in
.env:CACHE_ENABLED: Enable/disable caching (default: true)CACHE_TTL: Cache time-to-live in seconds (default: 86400 = 24 hours)CACHE_PERSISTENT: Enable persistent file-based cache (default: true)CACHE_DIR: Cache directory location (default: ~/.ontology_mapper_cache)CACHE_MAX_SIZE_MB: Maximum cache size in MB (default: 100)
python main.py --single-word "breast cancer"# Process a Turtle file
python main.py ontology.ttl --output enriched_ontology.ttl
# Process a JSON-LD file
python main.py ontology.jsonld --output enriched_ontology.jsonld
# Process an RDF/XML file with explicit format
python main.py ontology.rdf --input-format xml --output enriched_ontology.ttl# List available input formats
python main.py --list-input-formats
# Parse JSON-LD input
python main.py data.jsonld --input-format json-ld
# Parse RDF/XML input
python main.py data.rdf --input-format xml
# Auto-detect input format from extension
python main.py ontology.jsonld # Automatically detects JSON-LD
python main.py ontology.rdf # Automatically detects RDF/XML- turtle/ttl (default): Turtle - Human-readable RDF format
- json-ld: JSON-LD - JSON format for linked data
- xml/rdf-xml/rdf: RDF/XML - Traditional RDF XML format
- nt/ntriples: N-Triples - Simple line-based RDF format
- n3: Notation3 - Superset of Turtle with rules
- trig: TriG - Turtle with named graphs
- nquads: N-Quads - N-Triples with named graphs
# List available output formats (both input and output)
python main.py --list-formats
# Export as JSON-LD
python main.py ontology.ttl --output result.jsonld --format json-ld
# Export as RDF/XML
python main.py --single-word "diabetes" --output result.rdf --format xml
# Export as N-Triples
python main.py ontology.ttl --output result.nt --format nt
# Export as SSSOM mapping
python main.py ontology.ttl --output mappings.sssom.tsv --format sssom
# Auto-detect format from file extension
python main.py --single-word "cancer" --output result.jsonld
# Convert between formats
python main.py ontology.jsonld --input-format json-ld --output ontology.ttl --format turtle- turtle/ttl (default): Turtle - Human-readable RDF format
- json-ld: JSON-LD - JSON format for linked data
- xml/rdf-xml: RDF/XML - Traditional RDF XML format
- nt/ntriples: N-Triples - Simple line-based RDF format
- n3: Notation3 - Superset of Turtle with rules
- trig: TriG - Turtle with named graphs
- nquads: N-Quads - N-Triples with named graphs
- csv: CSV - Comma-separated values (tabular export)
- tsv: TSV - Tab-separated values (tabular export)
- sssom: SSSOM TSV - Simple Standard for Sharing Ontology Mappings
# View cache statistics
python main.py --cache-stats
# Clear all cached data
python main.py --clear-cache
# Disable cache for a single run
python main.py --single-word "diabetes" --no-cachepython main.py --batch concepts.txt --output results.jsonThe tool includes an intelligent caching mechanism to reduce API calls and improve performance:
- In-memory caching: Fast access to recently queried results
- Persistent caching: Results saved to disk and reused across sessions
- Configurable TTL: Set cache expiration time (default 24 hours)
- Automatic cleanup: Old entries are removed when size limit is reached
- Cache statistics: Monitor hit rates and cache performance
- Per-service caching: Separate caches for BioPortal and OLS
- 50%+ reduction in API calls for repeated queries
- Faster response times for cached results
- Reduced load on API servers
- Works seamlessly across CLI and GUI
- Respects API rate limits
Cache is enabled by default. Configure it via environment variables in .env:
# Enable/disable caching
CACHE_ENABLED=true
# Cache time-to-live (24 hours)
CACHE_TTL=86400
# Enable persistent disk cache
CACHE_PERSISTENT=true
# Maximum cache size in MB
CACHE_MAX_SIZE_MB=100View cache statistics:
python main.py --cache-statsClear cache:
python main.py --clear-cacheDisable cache for a single run:
python main.py --single-word "query" --no-cacheLaunch the GUI:
python gui/launch_gui.pyOr use the demo interface:
python gui/demo_gui.pyThe tool supports lookup across 24+ major biomedical ontologies:
- MONDO: Monarch Disease Ontology
- HP: Human Phenotype Ontology
- NCIT: National Cancer Institute Thesaurus
- DOID: Disease Ontology
- CHEBI: Chemical Entities of Biological Interest
- GO: Gene Ontology
- SNOMEDCT: Systematized Nomenclature of Medicine Clinical Terms
- ICD10CM, ICD11: International Classification of Diseases
- LOINC: Logical Observation Identifiers Names and Codes
- OMIM: Online Mendelian Inheritance in Man
- ORDO: Orphanet Rare Disease Ontology
- And many more...
The tool is organized into modular components:
ontology-mapping-tool/
├── cli/ # Command-line interface
│ ├── main.py # Main CLI entry point
│ └── interface.py # CLI interface logic
├── core/ # Core functionality
│ ├── parser.py # TTL file parsing
│ ├── lookup.py # Concept lookup orchestration
│ └── generator.py # Output generation
├── services/ # API services
│ ├── bioportal.py # BioPortal API client
│ ├── ols.py # OLS API client
│ └── comparator.py # Result comparison
├── config/ # Configuration
│ └── ontologies.py # Ontology definitions
├── utils/ # Utilities
│ ├── helpers.py # Helper functions
│ └── loading.py # Loading animations
└── gui/ # Graphical interface
├── launch_gui.py # GUI launcher
├── bioportal_gui.py # Main GUI application
└── demo_gui.py # Demo interface
python main.py --search "diabetes mellitus"python main.py --input disease_ontology.ttl --output enhanced_ontology.ttlCreate a file concepts.txt:
breast cancer
diabetes mellitus
hypertension
Then run:
python main.py --batch concepts.txt --output results.jsonMain class for performing concept lookups across multiple ontologies.
Client for interacting with the BioPortal API.
Client for interacting with the OLS (Ontology Lookup Service) API.
Parser for TTL (Turtle) ontology files.
Generator for creating ontologies with alignments. Supports multiple output formats:
- RDF formats via rdflib (Turtle, JSON-LD, RDF/XML, N-Triples, etc.)
- Custom formats (CSV, TSV, SSSOM)
python main.py --single-word "diabetes" --output result.ttlProduces human-readable RDF in Turtle format with prefixes and namespaces.
python main.py --single-word "diabetes" --output result.jsonld --format json-ldProduces JSON format suitable for web APIs and JavaScript applications.
python main.py --single-word "diabetes" --output result.rdf --format xmlProduces traditional RDF/XML format compatible with older tools.
python main.py --single-word "diabetes" --output result.nt --format ntProduces simple line-based format, one triple per line.
python main.py --single-word "diabetes" --output result.csv --format csvProduces tabular format with columns: Subject, Predicate, Object, Object Type.
python main.py --single-word "diabetes" --output mappings.sssom.tsv --format sssomProduces SSSOM (Simple Standard for Sharing Ontology Mappings) format for interoperability with mapping tools.
Edit config/ontologies.py to customize:
- Supported ontologies
- API endpoints
- Search strategies
- Result filtering
BIOPORTAL_API_KEY: Your BioPortal API key (required)UMLS_API_KEY: Your UMLS API key (optional)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Run the test suite:
python -m pytest tests/This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or contributions:
- Open an issue on GitHub
- Check the documentation in the
docs/directory - Review the example scripts in
examples/
- BioPortal team for providing the ontology API
- OLS team for the Ontology Lookup Service
- The broader biomedical ontology community
If you use this tool in your research, please cite:
[Your citation information here]
Note: This tool is designed to complement existing ontology mapping frameworks like SSSOM-py by providing a simple, user-friendly interface for concept lookup and initial mapping tasks.
helpers.py: Common helper functions (text cleaning, deduplication, etc.)
ontologies.py: Ontology definitions, mappings, and search strategies
interface.py: Main CLI interface and argument parsingmain.py: CLI entry point and error handling
# List available ontologies
python run_cli.py --list-ontologies
# Query a single term
python run_cli.py --single-word "fatigue" --ontologies "HP,NCIT"
# Process a TTL file
python run_cli.py ontology.ttl --output improved.ttl
# Batch processing with pre-selected choices
python run_cli.py ontology.ttl --batch-mode selections.json--ontologies: Specify ontologies to search (e.g., "HP,NCIT,MONDO")--max-results: Maximum results per search (default: 5)--disable-ols: Use only BioPortal--disable-bioportal: Use only OLS--comparison-only: Run comparison without generating output--terminal-only: Print results without creating files
Set your BioPortal API key:
export BIOPORTAL_API_KEY="your_api_key_here"Or use the --api-key argument.
The tool supports 24+ ontologies including:
- MONDO: Monarch Disease Ontology
- HP: Human Phenotype Ontology
- DOID: Disease Ontology
- ORDO: Orphanet Rare Disease Ontology
- SNOMEDCT: SNOMED Clinical Terms
- ICD10/ICD11: International Classification of Diseases
- LOINC: Logical Observation Identifiers Names and Codes
- CPT: Current Procedural Terminology
- GO: Gene Ontology
- CHEBI: Chemical Entities of Biological Interest
- PRO: Protein Ontology
- UBERON: Anatomical structures
python run_cli.py --single-word "cancer" --ontologies "MONDO,HP,DOID,NCIT,ORDO"python run_cli.py --single-word "headache" --ontologies "HP,SYMP,NCIT"python run_cli.py --single-word "aspirin" --ontologies "CHEBI,RXNORM,NCIT"ontology_mapping/
├── bioportal_cli.py # Original monolithic file (kept for reference)
├── run_cli.py # Convenient wrapper script
├── main.py # Main entry point
├── cli/
│ ├── __init__.py
│ ├── interface.py # CLI interface and argument parsing
│ └── main.py # CLI entry point
├── core/
│ ├── __init__.py
│ ├── parser.py # TTL file parsing
│ ├── lookup.py # Concept lookup orchestration
│ └── generator.py # Ontology generation
├── services/
│ ├── __init__.py
│ ├── bioportal.py # BioPortal API client
│ ├── ols.py # OLS API client
│ └── comparator.py # Result comparison
├── utils/
│ ├── __init__.py
│ ├── loading.py # Loading animations
│ └── helpers.py # Helper functions
└── config/
├── __init__.py
└── ontologies.py # Ontology configurations
rdflib: RDF graph processingrequests: HTTP API callsargparse: Command-line argument parsingthreading: Loading bar animationsjson: Configuration and batch processing
The original bioportal_cli.py (1185+ lines) has been split into focused modules:
- Services separated: BioPortal and OLS clients are now independent
- Core logic isolated: Parsing, lookup, and generation are distinct
- Configuration centralized: All ontology definitions in one place
- CLI decoupled: Interface separated from business logic
- Utilities extracted: Common functions in dedicated modules
This modular approach improves:
- Maintainability: Easier to update individual components
- Testability: Each module can be tested independently
- Reusability: Components can be imported and used elsewhere
- Readability: Smaller, focused files are easier to understand
The modular structure makes it easy to add:
- New ontology services
- Additional output formats
- Enhanced comparison algorithms
- Batch processing improvements
- Web interface components