Skip to content

Commit

Permalink
remove equivalent class from node hierarchy (always empty) (#295)
Browse files Browse the repository at this point in the history
- Closes #257 

- [x] fix identical repetitive subclasses 
- [x] fix sql Association validation error (classic relations/primary
knowledge source madness)

---------

Co-authored-by: Kevin Schaper <[email protected]>
  • Loading branch information
glass-ships and kevinschaper authored Aug 29, 2023
1 parent cb45fff commit 3e099d5
Show file tree
Hide file tree
Showing 26 changed files with 741 additions and 329 deletions.
1 change: 0 additions & 1 deletion backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ class Node(Entity):
class NodeHierarchy(ConfiguredBaseModel):

super_classes: List[Entity] = Field(default_factory=list)
equivalent_classes: List[Entity] = Field(default_factory=list)
sub_classes: List[Entity] = Field(default_factory=list)


Expand Down
9 changes: 0 additions & 9 deletions backend/src/monarch_py/datamodels/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ classes:
NodeHierarchy:
slots:
- super_classes
- equivalent_classes
- sub_classes
Results:
abstract: true
Expand Down Expand Up @@ -261,12 +260,6 @@ slots:
the object or in the object closure, the direction is backwards.
range: AssociationDirectionEnum
required: true
equivalent_classes:
range: Entity
multivalued: true
inlined: true
inlined_as_list: true
required: true
evidence_count:
description: count of supporting documents, evidence codes, and sources supplying evidence
range: integer
Expand Down Expand Up @@ -371,8 +364,6 @@ slots:
multivalued: true
qualifiers:
multivalued: true
relation:
range: string
score:
range: float
sex_qualifier:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def get_entity(self, id: str, extra: bool) -> Union[Node, Entity]:

def _get_associated_entity(self, association: Association, this_entity: Entity) -> Entity:
"""Returns the id, name, and category of the other Entity in an Association given this_entity"""
if this_entity.id in association.subject_closure:
if this_entity.id == association.subject:
entity = Entity(
id=association.object,
name=association.object_label,
category=association.object_category,
)
elif this_entity.id in association.object_closure:
elif this_entity.id == association.object:
entity = Entity(
id=association.subject,
name=association.subject_label,
Expand Down Expand Up @@ -156,13 +156,15 @@ def _get_node_hierarchy(self, entity: Entity) -> NodeHierarchy:
NodeHierarchy: A NodeHierarchy object
"""

super_classes = self._get_associated_entities(entity, subject=entity.id, predicate="biolink:subclass_of")
equivalent_classes = self._get_associated_entities(entity, entity=entity.id, predicate="biolink:same_as")
sub_classes = self._get_associated_entities(entity, object=entity.id, predicate="biolink:subclass_of")
super_classes = self._get_associated_entities(
this_entity=entity, subject=entity.id, predicate="biolink:subclass_of"
)
sub_classes = self._get_associated_entities(
this_entity=entity, object=entity.id, predicate="biolink:subclass_of"
)

return NodeHierarchy(
super_classes=super_classes,
equivalent_classes=equivalent_classes,
sub_classes=sub_classes,
)

Expand Down
15 changes: 8 additions & 7 deletions backend/src/monarch_py/implementations/sql/sql_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ def _get_node_hierarchy(self, entity: Entity) -> NodeHierarchy:
NodeHierarchy: A NodeHierarchy object
"""

super_classes = self._get_associated_entities(entity, subject=entity.id, predicate="biolink:subclass_of")
equivalent_classes = self._get_associated_entities(entity, entity=entity.id, predicate="biolink:same_as")
sub_classes = self._get_associated_entities(entity, object=entity.id, predicate="biolink:subclass_of")
super_classes = self._get_associated_entities(
this_entity=entity, subject=entity.id, predicate="biolink:subclass_of"
)
sub_classes = self._get_associated_entities(
this_entity=entity, object=entity.id, predicate="biolink:subclass_of"
)

return NodeHierarchy(
super_classes=super_classes,
equivalent_classes=equivalent_classes,
sub_classes=sub_classes,
)

Expand Down Expand Up @@ -242,13 +244,12 @@ def get_associations(
"original_object": row["original_object"],
"category": row["category"],
"aggregator_knowledge_source": row["aggregator_knowledge_source"].split("|"),
"primary_knowledge_source": row["primary_knowledge_source"].split("|"),
"primary_knowledge_source": row["primary_knowledge_source"],
"publications": row["publications"].split("|"),
"qualifiers": row["qualifiers"].split("|"),
"provided_by": row["provided_by"],
"has_evidence": row["has_evidence"],
"has_evidence": row["has_evidence"].split("|"),
"stage_qualifier": row["stage_qualifier"],
"relation": row["relation"],
"negated": False if not row["negated"] else True,
"frequency_qualifier": row["frequency_qualifier"],
"onset_qualifier": row["onset_qualifier"],
Expand Down
18 changes: 15 additions & 3 deletions backend/tests/fixtures/association_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
def association_counts():
return {
"items": [
{"label": "Phenotypes", "count": 4011, "category": "biolink:DiseaseToPhenotypicFeatureAssociation"},
{"label": "Causal Genes", "count": 121, "category": "biolink:CausalGeneToDiseaseAssociation"},
{"label": "Correlated Genes", "count": 147, "category": "biolink:CorrelatedGeneToDiseaseAssociation"},
{
"label": "Phenotypes",
"count": 4011,
"category": "biolink:DiseaseToPhenotypicFeatureAssociation",
},
{
"label": "Causal Genes",
"count": 121,
"category": "biolink:CausalGeneToDiseaseAssociation",
},
{
"label": "Correlated Genes",
"count": 147,
"category": "biolink:CorrelatedGeneToDiseaseAssociation",
},
]
}
Loading

0 comments on commit 3e099d5

Please sign in to comment.