Skip to content

Commit

Permalink
Gocamgen reports: Logical def errors and GO rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dustine32 committed Mar 22, 2021
1 parent f4bbefa commit 7494f32
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
11 changes: 8 additions & 3 deletions bin/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,11 @@ def gpad2gocams(ctx, gpad_path, gpi_path, target, ontology, ttl):
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)
parse_report_basename = "{}.parser.report".format(gpad_basename_root)
model_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)
parse_report_path = os.path.join(absolute_target, parse_report_basename)
model_report_path = os.path.join(absolute_target, model_report_basename)

builder = GoCamBuilder(parser_config=parser_config)

Expand All @@ -580,7 +582,10 @@ def gpad2gocams(ctx, gpad_path, gpi_path, target, ontology, ttl):
if not ttl:
builder.write_out_store_to_nquads(filepath=output_path)

builder.write_report(report_filepath=report_path)
# Reports
builder.write_report(report_filepath=model_report_path)
with open(parse_report_path, 'w') as prp:
prp.write(extractor.gpad_parser.report.to_markdown())


@cli.command()
Expand Down
14 changes: 13 additions & 1 deletion ontobio/rdfgen/gocamgen/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from ontobio.rdfgen.gocamgen import collapsed_assoc


class GocamgenException(Exception):
def __init__(self, message):
def __init__(self, message: str):
self.message = message

def __str__(self):
Expand All @@ -14,6 +17,15 @@ class ShexException(GocamgenException):
pass


class CollapsedAssocGocamgenException(GocamgenException):
def __init__(self, message: str, assoc: collapsed_assoc.CollapsedAssociation):
self.message = message
self.assoc = assoc

def __str__(self):
return "{}\n{}".format(self.message, "\n".join([l.source_line for l in self.assoc.lines]))


class GeneErrorSet:
def __init__(self):
self.errors = {}
Expand Down
6 changes: 4 additions & 2 deletions ontobio/rdfgen/gocamgen/gocam_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def make_model(self, gene, annotations: List[GoAssociation], output_directory=No
model.write(out_filename)
logger.info("Model for {} written to {} in {} sec".format(gene, out_filename,
(time.time() - start_time)))
for err in model.errors:
self.errors.add_error(gene, err)
return model
except GocamgenException as ex:
self.errors.add_error(gene, ex)
Expand Down Expand Up @@ -156,13 +158,13 @@ def parse_gpi(gpi_file):
class AssocExtractor:
def __init__(self, gpad_file, parser_config: AssocParserConfig):
self.assocs = []
gpad_parser = gpadparser.GpadParser(config=parser_config)
self.gpad_parser = gpadparser.GpadParser(config=parser_config)
with open(gpad_file) as sg:
lines = sum(1 for line in sg)

with open(gpad_file) as gf:
click.echo("Making products...")
with click.progressbar(iterable=gpad_parser.association_generator(file=gf, skipheader=True),
with click.progressbar(iterable=self.gpad_parser.association_generator(file=gf, skipheader=True),
length=lines) as associations:
self.assocs = list(associations)

Expand Down
5 changes: 4 additions & 1 deletion ontobio/rdfgen/gocamgen/gocamgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def __init__(self, modeltitle, assocs: List[GoAssociation], config: AssocParserC
self.provided_bys = set()
self.graph.bind("GOREL", GOREL) # Because GOREL isn't in context.jsonld's
self.gpi_entities = gpi_entities
self.errors: List[errors.GocamgenException] = []
ncbi_taxon = self.taxon_id_from_entity(str(assocs[0].subject.id))
# Emit model-level in_taxon triple from ncbi_taxon
if ncbi_taxon:
Expand Down Expand Up @@ -615,7 +616,9 @@ def translate(self):
ext_target_n = annot_subgraph.add_instance_of_class(ext_target)
annot_subgraph.add_edge(regulated_term_n, chained_rel, ext_target_n)
else:
logger.warning("Couldn't get regulates relation from LD of: {}".format(term))
err_msg = "Couldn't get regulates relation from LD of: {}".format(term)
logger.warning(err_msg)
self.errors.append(errors.CollapsedAssocGocamgenException(err_msg, a))
elif ext_relation in HAS_REGULATION_TARGET_RELATIONS:
if aspect == 'P':
# For BP annotations, translate 'has regulation target' to 'has input'.
Expand Down

0 comments on commit 7494f32

Please sign in to comment.