Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Nov 14, 2024
1 parent 799ef44 commit 7d80152
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions tests/test_transformer/test_biolink_subsetting.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from pathlib import Path
from pprint import pprint
from typing import List

from linkml_runtime.dumpers import yaml_dumper
from linkml_runtime.utils.formatutils import camelcase, underscore
from linkml_runtime.utils.schemaview import SchemaView
from pytest import fixture

from linkml_runtime.dumpers import yaml_dumper
from linkml_map.datamodel.transformer_model import TransformationSpecification, ClassDerivation, SlotDerivation
from linkml_map.datamodel.transformer_model import (
ClassDerivation,
SlotDerivation,
TransformationSpecification,
)
from linkml_map.inference.schema_mapper import SchemaMapper
from linkml_map.session import Session
from linkml_runtime.utils.schemaview import SchemaView
from src.linkml_map.utils.loaders import load_specification
from linkml_runtime.utils.formatutils import camelcase, underscore
from pprint import pprint

REPO_ROOT = Path(__file__).resolve().parent.parent

Expand All @@ -25,10 +29,9 @@ def get_biolink_class_derivations(sv, subset_classes) -> dict:
"""
# Example implementation to fetch class definitions
# This should be replaced with the actual implementation
class_derivations ={}
class_derivations = {}
for class_name in subset_classes:
class_derivation = ClassDerivation(populated_from=class_name,
name=camelcase(class_name))
class_derivation = ClassDerivation(populated_from=class_name, name=camelcase(class_name))
induced_slots = sv.class_induced_slots(class_name)
for slot in induced_slots:
slot_derivation = SlotDerivation(populated_from=slot.name, name=underscore(slot.name))
Expand All @@ -49,13 +52,16 @@ def biolink_schema():
sv = SchemaView(schema_url)
return sv


def test_biolink_subsetting_manual(biolink_schema):
"""
Test to subset the Biolink schema manually
:param biolink_schema: Fixture to load Biolink schema
"""
transform_file = REPO_ROOT / "input/examples/biolink/transform/biolink-example-profile.transform.yaml"
transform_file = (
REPO_ROOT / "input/examples/biolink/transform/biolink-example-profile.transform.yaml"
)
# Initialize Session and SchemaBuilder
session = Session()

Expand All @@ -66,10 +72,11 @@ def test_biolink_subsetting_manual(biolink_schema):
mapper = SchemaMapper()
mapper.source_schemaview = biolink_schema

target_schema_obj = mapper.derive_schema(specification=tr_spec,
target_schema_id="biolink-profile",
target_schema_name="BiolinkProfile")

target_schema_obj = mapper.derive_schema(
specification=tr_spec,
target_schema_id="biolink-profile",
target_schema_name="BiolinkProfile",
)

yaml_dumper.dump(target_schema_obj, str("biolink-profile.yaml"))

Expand All @@ -95,14 +102,15 @@ def test_biolink_subset_auto(biolink_schema):
# Set the source schema in the session
session.set_source_schema(biolink_schema)

SUBSET_CLASSES = ["gene",
"disease",
"case to phenotypic feature association",
"gene to disease association",
"gene to phenotypic feature association",
"case",
"phenotypic feature",
]
SUBSET_CLASSES = [
"gene",
"disease",
"case to phenotypic feature association",
"gene to disease association",
"gene to phenotypic feature association",
"case",
"phenotypic feature",
]

class_derivations = get_biolink_class_derivations(biolink_schema, SUBSET_CLASSES)

Expand All @@ -111,9 +119,9 @@ def test_biolink_subset_auto(biolink_schema):
mapper = SchemaMapper()
mapper.source_schemaview = biolink_schema

target_schema_obj = mapper.derive_schema(specification=ts,
target_schema_id="biolink-profile",
target_schema_name="BiolinkProfile")
target_schema_obj = mapper.derive_schema(
specification=ts, target_schema_id="biolink-profile", target_schema_name="BiolinkProfile"
)

yaml_dumper.dump(target_schema_obj, str("biolink-subset.yaml"))

Expand All @@ -124,5 +132,3 @@ def test_biolink_subset_auto(biolink_schema):
print()
for slot_name in transformed_sv.all_slots():
print(slot_name)


0 comments on commit 7d80152

Please sign in to comment.