def gpad2gocams(ctx, gpad_path, gpi_path, target, ontology, ttl): # NOTE: Validation on GPAD not included here since it's currently baked into produce() above. # Multi-param to accept multiple ontology files, then merge to one (this will make a much smaller ontology # with only what we need, i.e. GO, RO, GOREL) ontology_graph = OntologyFactory().create(ontology[0], ignore_cache=True) for ont in ontology[1:]: ontology_graph.merge( [OntologyFactory().create(ont, ignore_cache=True)]) parser_config = assocparser.AssocParserConfig(ontology=ontology_graph, gpi_authority_path=gpi_path) extractor = AssocExtractor(gpad_path, parser_config=parser_config) assocs_by_gene = extractor.group_assocs() absolute_target = os.path.abspath(target) gpad_basename = os.path.basename(gpad_path) gpad_basename_root, gpad_ext = os.path.splitext(gpad_basename) output_basename = "{}.nq".format(gpad_basename_root) report_basename = "{}.gocamgen.report".format(gpad_basename_root) output_path = os.path.join(absolute_target, output_basename) report_path = os.path.join(absolute_target, report_basename) builder = GoCamBuilder(parser_config=parser_config) for gene, associations in assocs_by_gene.items(): if ttl: builder.make_model_and_write_out(gene, annotations=associations, output_directory=absolute_target) else: builder.make_model_and_add_to_store(gene, annotations=associations) if not ttl: builder.write_out_store_to_nquads(filepath=output_path) builder.write_report(report_filepath=report_path)
import pytest import datetime from ontobio.io import assocparser from ontobio.io.gpadparser import to_association 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" ) # Placeholder ontology to instantiate models GO_ONTO.merge([ OntologyFactory().create("tests/resources/ro-gp2term-20210723.json") ]) # Truncated RO PARSER_CONFIG = assocparser.AssocParserConfig( ontology=GO_ONTO, gpi_authority_path="tests/resources/mgi2.test_entities.gpi") def test_evidence_max_date(): ev1 = gocamgen.GoCamEvidence(code="ECO:0000314", references=["PMID:12345"], date="2008-08-14") ev2 = gocamgen.GoCamEvidence(code="ECO:0000314", references=["PMID:12345"], date="2011-04-12") ev3 = gocamgen.GoCamEvidence(code="ECO:0000314", references=["PMID:12345"], date="2021-03-01") max_date = gocamgen.GoCamEvidence.sort_date([ev1, ev2, ev3])[-1] assert max_date == "2021-03-01"