Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCKAN-248 feat: Update from_entities when applicable #223

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions backend/composer/services/cs_ingestion/neurondm_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import rdflib
from neurondm import orders
from neurondm.core import Config, graphBase, log
from neurondm.core import Config, graphBase
from neurondm.core import OntTerm, OntId, RDFL
from pyontutils.core import OntGraph, OntResIri, OntResPath
from pyontutils.namespaces import rdfs, ilxtr

from composer.services.cs_ingestion.exceptions import NeuronDMInconsistency
from composer.services.cs_ingestion.helpers import VALIDATION_ERRORS, DESTINATIONS, VIAS, ORIGINS
from composer.services.cs_ingestion.logging_service import LoggerService, AXIOM_NOT_FOUND, INCONSISTENT_AXIOMS
from composer.services.cs_ingestion.logging_service import LoggerService, AXIOM_NOT_FOUND
from composer.services.cs_ingestion.models import NeuronDMVia, NeuronDMOrigin, NeuronDMDestination, LoggableAnomaly, \
AxiomType, ValidationErrors, Severity

Expand Down Expand Up @@ -95,6 +95,9 @@ def get_connections(n, lpes):
origins = merge_origins(tmp_origins)
vias = merge_vias(tmp_vias)
destinations = merge_destinations(tmp_destinations)

origins, vias, destinations = update_from_entities(origins, vias, destinations)

return origins, vias, destinations, validation_errors


Expand Down Expand Up @@ -333,6 +336,24 @@ def merge_destinations_by_from_entities(destinations: List[NeuronDMDestination])
return list(merged_destinations.values())


def update_from_entities(origins: NeuronDMOrigin, vias: List[NeuronDMVia], destinations: List[NeuronDMDestination]):
# Step 1: Initialize "previous anatomical entities" with origins
previous_anatomical_entities = origins.anatomical_entities

# Step 2: Process vias
for via in sorted(vias, key=lambda v: v.order):
if via.from_entities == previous_anatomical_entities:
via.from_entities = set()
previous_anatomical_entities = via.anatomical_entities

# Step 3: Process destinations
for destination in destinations:
if destination.from_entities == previous_anatomical_entities:
destination.from_entities = set()

return origins, vias, destinations


## Based on:
## https://github.com/tgbugs/pyontutils/blob/30c415207b11644808f70c8caecc0c75bd6acb0a/neurondm/docs/composer.py#L668-L698
def main(local=False, logger_service_param=Optional[LoggerService]):
Expand Down
Loading