ontology_loader
Project description
ontology_loader
Suite of tools to configure and load an ontology from the OboFoundary into the data object for OntologyClass as specified by NMDC schema.
Development Environment
Pre-requisites
-
=Python 3.9
- Poetry
- Docker
- MongoDB
- NMDC materialized schema
- ENV variable for MONGO_PASSWORD (or pass it in via the cli/runner itself directly)
% docker pull mongo
% docker run -d --name mongodb-container -p 27018:27017 mongo
Basic mongosh commands
% docker ps
% docker exec -it [mongodb-container-id] bash
% mongosh mongodb://admin:root@mongo:27017/nmdc?authSource=admin
% show dbs
% use nmdc
% db.ontology_class_set.find().pretty()
% db.ontology_relation_set.find().pretty()
Command line
% poetry install
% poetry run ontology_loader --help
% poetry run ontology_loader --source-ontology "envo"
% poetry run ontology_loader --source-ontology "go"
Running the tests
% make test
Running the linter
% make lint
python example usage
pip install nmdc-ontology-loader
from nmdc_ontology_loader.ontology_loader import OntologyLoader
import tempfile
def test_load_ontology():
"""Test the load_ontology method."""
ontology_loader = OntologyLoader(
source_ontology="envo",
output_directory=tempfile.gettempdir(),
generate_reports=True,
)
ontology_loader.load_ontology()
assert ontology_loader.ontology_class_set
assert ontology_loader.ontology_relation_set
assert ontology_loader.ontology_class_set.count() > 0
assert ontology_loader.ontology_relation_set.count() > 0
Testing CRUD operations in a live MongoDB
If you want to test the CRUD operations in a live MongoDB instance, you need to set two environment variables: MONGO_PASSWORD="your_valid_password" ENABLE_DB_TESTS=true
This will allow you to run tests to actually insert/update/delete records in your MongoDB tests instance instead of simply mocking the calls. You can then run the tests with the following command:
make test
The same test command will run without the environment variables, but it will only mock the calls to the database. This is intended to help prevent accidental data loss or corruption in a live database environment and to ensure that MONGO_PASSWORD is not hardcoded in the codebase.
Reset collections in dev
% docker exec -it mongodb-container bash
% mongosh mongodb://admin:root@mongo:27017/nmdc?authSource=admin
% db.ontology_class_set.find({}).pretty()
% db.ontology_relation_set.find({}).pretty()
% db.biosample_set.find({}).pretty()
% db.ontology_class_set.drop()
% db.ontology_relation_set.drop()
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 ontology_loader-0.1.9.tar.gz.
File metadata
- Download URL: ontology_loader-0.1.9.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d20e046124b110b584f9e4be2c1007012c9e3b92c348b71f11f999fce14a18
|
|
| MD5 |
5247ef98ee31eff073a1667d2f98fb8e
|
|
| BLAKE2b-256 |
cf7a3f0b16d76ca3f0703b6ee4a00a0cc9b59b89a4f60f8ef9e27c4671dcb809
|
File details
Details for the file ontology_loader-0.1.9-py3-none-any.whl.
File metadata
- Download URL: ontology_loader-0.1.9-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
258203ba772fc591ffbeba772a44d6faa07467f70ab8b1c48c972e4b0629ef11
|
|
| MD5 |
a2876f6d04f326f4aa7afb5063ae5147
|
|
| BLAKE2b-256 |
55948bfadbc9870bbcca4c61d79275ccd6934b1377b0d3216b9bd3864a4c8b5e
|