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

Handle GPI label merge for geneontology/go-releases#50 #648

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions ontobio/model/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ class BioEntities:
def merge(self, other):
"""
Merge another BioEntity set into this one. The `other` set will
override any collisions in this BioEntities
override any collisions in this BioEntities except for
any specific fields (e.g., label) handled below
"""
self.entities.update(other.entities)
# self.entities.update(other.entities)
for ent in other.entities:
if ent in self.entities:
# Handle specific field merges here
merged_ent = other.entities[ent]

# Carry forward existing label if other label is blank string or None
if not merged_ent.label:
merged_ent.label = self.entities[ent].label
self.entities[ent] = merged_ent
else:
self.entities[ent] = other.entities[ent]
return self

def get(self, entity_id: Curie) -> Optional[Subject]:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def test_bioentities_merge():
Curie("BAR", "987"): Subject(Curie("BAR", "987"), "goodbye", "world", [], "protien", Curie("NCBITaxon", "999"))
})

# Test that blank label does not overwrite existing label
p = collections.BioEntities({
Curie("BAR", "987"): Subject(Curie("BAR", "987"), "", "world", [], "protien", Curie("NCBITaxon", "999"))
})

assert o.merge(p) == collections.BioEntities({
Curie("BAR", "987"): Subject(Curie("BAR", "987"), "goodbye", "world", [], "protien", Curie("NCBITaxon", "999"))
})

def test_bioentities_merge_clobber():
e = collections.BioEntities({
Curie("FOO", "123"): Subject(Curie("FOO", "123"), "hello", "world", [], "protien", Curie("NCBITaxon", "12345"))
Expand Down
Loading