Skip to content

Commit

Permalink
Ensure multivalued slots appear in YAML serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pkalita-lbl committed Sep 13, 2024
1 parent 1ad5d2a commit ce29e89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/gocam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def fetch(model_ids, format):

for model_id in model_ids:
model = wrapper.fetch_model(model_id)
model_dict = model.model_dump(exclude_none=True, exclude_unset=True)
model_dict = model.model_dump(exclude_none=True, exclude_defaults=True)

if format == "json":
click.echo(json.dumps(model_dict, indent=2))
Expand Down
10 changes: 3 additions & 7 deletions src/gocam/translation/minerva_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def _annotations_multivalued(obj: Dict) -> Dict[str, List[str]]:

def _setattr_with_warning(obj, attr, value):
if getattr(obj, attr, None) is not None:
logger.warning(f"Overwriting {attr} for {obj.id if hasattr(obj, 'id') else obj}")
logger.warning(
f"Overwriting {attr} for {obj.id if hasattr(obj, 'id') else obj}"
)
setattr(obj, attr, value)


Expand Down Expand Up @@ -320,8 +322,6 @@ def _iter_activities_by_fact_subject(
for activity, term, evs in _iter_activities_by_fact_subject(
fact_property=HAS_INPUT
):
if activity.has_input is None:
activity.has_input = []
activity.has_input.append(MoleculeAssociation(term=term, evidence=evs))

for activity, term, evs in _iter_activities_by_fact_subject(
Expand All @@ -333,8 +333,6 @@ def _iter_activities_by_fact_subject(
for activity, term, evs in _iter_activities_by_fact_subject(
fact_property=HAS_OUTPUT
):
if activity.has_output is None:
activity.has_output = []
activity.has_output.append(MoleculeAssociation(term=term, evidence=evs))

for activity, term, evs in _iter_activities_by_fact_subject(
Expand Down Expand Up @@ -368,8 +366,6 @@ def _iter_activities_by_fact_subject(
downstream_activity=object_activity.id,
evidence=evs,
)
if not subject_activity.causal_associations:
subject_activity.causal_associations = []
subject_activity.causal_associations.append(rel)

annotations = _annotations(obj)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_translation/test_minerva_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def test_multivalued_input_and_output():
minerva_object = json.load(f)
model = mw.minerva_object_to_model(minerva_object)

cs_activity = next(a for a in model.activities if a.molecular_function.term == "GO:0004108")
cs_activity = next(
a for a in model.activities if a.molecular_function.term == "GO:0004108"
)
assert len(cs_activity.has_input) == 3
assert len(cs_activity.has_output) == 2

0 comments on commit ce29e89

Please sign in to comment.