Skip to content

Commit

Permalink
Merge pull request #575 from biolink/gocamgen-issue-90-modeltitle-fmt
Browse files Browse the repository at this point in the history
Gocamgen issue 90 modeltitle fmt
  • Loading branch information
dustine32 committed Jun 10, 2021
2 parents 4def878 + dc5aaa3 commit 2066457
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion ontobio/rdfgen/gocamgen/gocam_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ def __init__(self, parser_config: AssocParserConfig, modelstate=None):
self.modelstate = modelstate

def translate_to_model(self, gene, assocs: List[GoAssociation]):
if gene not in self.gpi_entities:
error_msg = "Gene ID '{}' missing from provided GPI. Skipping model translation.".format(gene)
raise GocamgenException(error_msg)
model_id = gene.replace(":", "_")
model = AssocGoCamModel(gene,
model_title = self.model_title(gene)
model = AssocGoCamModel(model_title,
assocs,
config=self.config,
store=self.store,
Expand Down Expand Up @@ -115,6 +119,14 @@ def write_report(self, report_filepath):
for ex in errs:
reportf.write(f"{type(ex).__name__} - {gene}: {ex}\n")

def model_title(self, gene_id: str) -> str:
entity = self.gpi_entities.get(gene_id)
if entity:
model_title = "{} ({})".format(entity["label"], gene_id)
else:
model_title = gene_id
return model_title

@staticmethod
def extract_relations_ontology(ontology_graph):
# TODO: This is probably all wrong - trying to reconstruct RO from broader ontology_graph
Expand Down
14 changes: 13 additions & 1 deletion tests/test_gocamgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from ontobio.ontol_factory import OntologyFactory
from ontobio.rdfgen.gocamgen import collapsed_assoc, gocam_builder, gocamgen

GO_ONTO = OntologyFactory().create("tests/resources/go-binding.json")
GO_ONTO = OntologyFactory().create("tests/resources/go-binding.json") # Placeholder ontology to instantiate models
PARSER_CONFIG = assocparser.AssocParserConfig(ontology=GO_ONTO,
gpi_authority_path="tests/resources/mgi2.test_entities.gpi")


def test_evidence_max_date():
Expand Down Expand Up @@ -83,3 +85,13 @@ def test_ref_picker():
test_refs = ["ZFIN:ZDB-PUB-170709-3"]
result = gocamgen.ReferencePreference.pick(test_refs)
assert result == "ZFIN:ZDB-PUB-170709-3"


def test_model_title():
builder = gocam_builder.GoCamBuilder(parser_config=PARSER_CONFIG, modelstate="test")
title = builder.model_title(gene_id="MGI:MGI:1915834")
assert title == "1110020C17Rik (MGI:MGI:1915834)"

# Fallback to gene_id as title if not found in GPI
title = builder.model_title(gene_id="FAKE:1915834")
assert title == "FAKE:1915834"

0 comments on commit 2066457

Please sign in to comment.