Skip to content

Commit

Permalink
Merge pull request #387 from sierra-moxon/mkg_qualifiers
Browse files Browse the repository at this point in the history
Adding qualifiers to MetaEdge fixes #342
  • Loading branch information
edeutsch authored Mar 3, 2023
2 parents dac8437 + f478dc2 commit 31895eb
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
41 changes: 40 additions & 1 deletion TranslatorReasonerAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ info:
url: https://github.com/NCATSTranslator/translator_extensions/blob/\
production/x-translator/
x-trapi:
version: 1.3.0
version: 1.4.0-dev
asyncquery: REPLACE-WITH-true-IF-/asyncquery-IS-IMPLEMENTED-ELSE-false
operations:
- LIST-ALL-SUPPORTED-OPERATION-IDS-HERE-OR-REMOVE-THIS-SECTION
Expand Down Expand Up @@ -1273,11 +1273,50 @@ components:
items:
$ref: '#/components/schemas/MetaAttribute'
nullable: true
qualifiers:
description: >-
Qualifiers that are possible to be found on this edge type.
items:
$ref: '#/components/schemas/MetaQualifier'
nullable: true
type: array
association:
type: object
$ref: '#/components/schemas/BiolinkEntity'
description: >-
The Biolink association type (entity) that this edge represents.
Associations are classes in Biolink
that represent a relationship between two entities.
For example, the association 'gene interacts with gene'
is represented by the Biolink class,
'biolink:GeneToGeneAssociation'. If association
is filled out, then the testing harness can
help validate that the qualifiers are being used
correctly.
example: biolink:ChemicalToGeneAssociation
required:
- subject
- predicate
- object
additionalProperties: false
MetaQualifier:
type: object
properties:
qualifier_type_id:
$ref: '#/components/schemas/CURIE'
description: >-
The CURIE of the qualifier type.
example: biolink:subject_aspect_qualifier
nullable: false
applicable_values:
type: array
description: >-
The list of values that are possible for this qualifier.
items:
type: string
example: [expression, activity, abundance, degradation]
required:
- qualifier_type_id
MetaAttribute:
type: object
properties:
Expand Down
61 changes: 61 additions & 0 deletions examples/MetaKnowledgeGraph/metaedge_with_qualifiers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"nodes": {
"biolink:MolecularActivity": {
"id_prefixes": [
"RHEA",
"REACT",
"GO",
"UMLS"
]
},
"biolink:SmallMolecule": {
"id_prefixes": [
"CHEBI",
"CHEMBL.COMPOUND",
"UMLS",
"UNII",
"PUBCHEM.COMPOUND",
"DRUGBANK",
"MESH",
"KEGG.COMPOUND",
"HMDB",
"CAS",
"KEGG.DRUG"
]
}
},
"edges": [
{
"subject": "biolink:ChemicalEntity",
"predicate": "biolink:affects",
"object": "biolink:Gene",
"knowledge_types": [
"lookup"
],
"association": "biolink:ChemicalToGeneAssociation",
"qualifiers": [
{
"qualifier_type_id": "biolink:subject_aspect_qualifier",
"applicable_values": [
"expression",
"abundance"
]
},
{
"qualifier_type_id": "biolink:subject_aspect_qualifier",
"applicable_values": [
"expression",
"abundance",
"activity"
]
},
{
"qualifier_type_id": "biolink:qualified_predicate",
"applicable_values": [
"biolink:causes"
]
}
]
}
]
}
31 changes: 30 additions & 1 deletion tests/test_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def test_valid():
jsonschema.validate(spec, openapi_schema)


def test_examples():
def test_message_examples():
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, '..', 'TranslatorReasonerAPI.yaml')) as f:
spec = yaml.load(f, Loader=yaml.SafeLoader)
print(spec)
dir_path_json = os.path.join(dir_path, '../examples/Message')
for filename in os.listdir(dir_path_json):
full_path = os.path.join(dir_path_json, filename)
Expand All @@ -36,6 +37,7 @@ def test_examples():
example = json.load(f)
trapi_version_locally = spec['info']['x-trapi']['version']
validator = TRAPISchemaValidator(trapi_version=trapi_version_locally)
print(validator.trapi_version)
try:
validator.validate(
instance=example,
Expand All @@ -45,3 +47,30 @@ def test_examples():
print(validator.to_dict(), file=stderr)
raise ValueError('TRAPI example is not valid against the trapi_version specified!')


def metakg_examples(): # def test_metakg_examples():
mtest_directory('../examples/MetaKnowledgeGraph', 'MetaKnowledgeGraph')
mtest_directory('../examples/Message', 'Message')


def mtest_directory(json_path, object_to_validate):
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, '..', 'TranslatorReasonerAPI.yaml')) as f:
spec = yaml.load(f, Loader=yaml.SafeLoader)
dir_path_json = os.path.join(dir_path, json_path)
for filename in os.listdir(dir_path_json):
full_path = os.path.join(dir_path_json, filename)
file_extension = pathlib.Path(full_path).suffix
if file_extension == '.json':
with open(full_path) as f:
example = json.load(f)
trapi_version_locally = spec['info']['x-trapi']['version']
validator = TRAPISchemaValidator(trapi_version=trapi_version_locally)
try:
validator.validate(
instance=example,
component=object_to_validate
)
except ValidationError:
print(validator.to_dict(), file=stderr)
raise ValueError('TRAPI example is not valid against the trapi_version specified!')

0 comments on commit 31895eb

Please sign in to comment.