Skip to main content

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.drop()
% db.ontology_relation_set.drop()

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

ontology_loader-0.1.8.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

ontology_loader-0.1.8-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file ontology_loader-0.1.8.tar.gz.

File metadata

  • Download URL: ontology_loader-0.1.8.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for ontology_loader-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b79760c16fcd48772957c0b87d032ad29f4110040b009b729b8772742f121ba1
MD5 dad1f78fda15facdd484f43fb747069f
BLAKE2b-256 bdf376a2c5a8aab90a23f91e055e463e88a868b735c139290c51e2652a71c36d

See more details on using hashes here.

File details

Details for the file ontology_loader-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for ontology_loader-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 17e6c2c513130d01d3f4c8e1db36df4e88ae40bfaaf15eb2fcd43f4b4d60b682
MD5 0fe2bc63aae71d40a55917793dbce1a2
BLAKE2b-256 392a5ce435bd1a1ff8c3de549070a3ec0167788a53b9e781a90d567b69ec1001

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