From 90e284d1e1cb883ce428d6b069210dc75890cda9 Mon Sep 17 00:00:00 2001 From: dosumis Date: Mon, 9 Mar 2020 22:42:38 +0000 Subject: [PATCH 1/7] Partial fix. New core method needed to add reciprocal. --- src/uk/ac/ebi/vfb/neo4j/KB_tools.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py index 212db325..7c488779 100644 --- a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py +++ b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py @@ -671,7 +671,8 @@ def __init__(self, endpoint, usr, pwd): 'in register with': 'http://purl.obolibrary.org/obo/RO_0002026', 'is specified output of': 'http://purl.obolibrary.org/obo/OBI_0000312', 'hasDbXref': 'http://www.geneontology.org/formats/oboInOwl#hasDbXref', - 'has_source': 'http://purl.org/dc/terms/source' + 'has_source': 'http://purl.org/dc/terms/source', + 'is exemplar of': 'http://purl.obolibrary.org/obo/c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0' # This really needs to be using RO!!! } self.class_lookup = { @@ -694,6 +695,7 @@ def add_anatomy_image_set(self, start, template, anatomical_type='', + is_exemplar=False, anon_anatomical_types=None, index=False, center=(), @@ -714,6 +716,8 @@ def add_anatomy_image_set(self, If your image does not fit into these types, please post a ticket to request the list of supported types be extended. anatomical_type: classification of anatomical entity, + if is_exemplar is True - then individual is registered as exemplar + of type specified in 'anatomical_type' arg. anon_anatomical_types: list of r,o) tuples specifying anon anatomical types, where subject is the anatomical individual being created template: channel ID of the template to which the image is registered @@ -817,8 +821,9 @@ def add_anatomy_image_set(self, o='VFBext_0000014', match_on='short_form') + # Imaging modality - currently works on internal lookup in script. + # Should probably be dynamic with DB - # Imaging modality - currently works on internal lookup in script. Should probably be dynamic with DB self.ew.add_anon_type_ax(s=channel_id['iri'], r=self.relation_lookup['is specified output of'], o=self.class_lookup[imaging_type]) @@ -828,6 +833,14 @@ def add_anatomy_image_set(self, o=anatomical_type, match_on=match_on, edge_annotations=type_edge_annotations) + + if is_exemplar: + self.ew.add_anon_type_ax(s=anat_id['iri'], + r=self.relation_lookup['is exemplar of'], + o=anatomical_type, + match_on='iri', + ) + # Also add reciprocal? # Add facts # This takes no vars so match_on can be fixed. From 53b039e68eef8589f382c16cdb78e71df2a0bc50 Mon Sep 17 00:00:00 2001 From: dosumis Date: Mon, 9 Mar 2020 22:51:22 +0000 Subject: [PATCH 2/7] reciprocal added. relation lookup needs short_forms (minor refactor rqd) --- src/uk/ac/ebi/vfb/neo4j/KB_tools.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py index 7c488779..f1a6cb07 100644 --- a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py +++ b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py @@ -376,6 +376,13 @@ def add_anon_subClassOf_ax(self, s, r, o, edge_annotations=None, edge_annotations = edge_annotations, match_on = match_on, safe_label_edge=safe_label_edge) + + def add_value_restriction(self, s, r, o, edge_annotations=None, + match_on="iri", safe_label_edge=False): + self._add_related_edge(s, r, o, stype=":Class", otype=":Individual", + edge_annotations=edge_annotations, + match_on=match_on, + safe_label_edge=safe_label_edge) def add_named_subClassOf_ax(self, s, o, match_on="iri"): """Add OWL named type axiom to statement stack. @@ -835,12 +842,18 @@ def add_anatomy_image_set(self, edge_annotations=type_edge_annotations) if is_exemplar: + # Is this direction needed? self.ew.add_anon_type_ax(s=anat_id['iri'], r=self.relation_lookup['is exemplar of'], o=anatomical_type, match_on='iri', ) - # Also add reciprocal? + self.ew.add_value_restriction(s=anatomical_type, + r=self.relation_lookup['has exemplar'], + o=anat_id[match_on], + match_on=match_on) # Relation lookup needs short_forms! + + # Also add reciprocal? # Add facts # This takes no vars so match_on can be fixed. From c29223e43e89683ede278195d39c61092397f0be Mon Sep 17 00:00:00 2001 From: dosumis Date: Wed, 11 Mar 2020 19:07:42 +0000 Subject: [PATCH 3/7] exemplar value restriction now follows / --- src/uk/ac/ebi/vfb/neo4j/KB_tools.py | 69 +++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py index f1a6cb07..9a1437a6 100644 --- a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py +++ b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py @@ -674,20 +674,53 @@ def __init__(self, endpoint, usr, pwd): # Adding a dict of common classes and properties. (Should really just use KB lookup...) self.relation_lookup = { - 'depicts': 'http://xmlns.com/foaf/0.1/depicts', - 'in register with': 'http://purl.obolibrary.org/obo/RO_0002026', - 'is specified output of': 'http://purl.obolibrary.org/obo/OBI_0000312', - 'hasDbXref': 'http://www.geneontology.org/formats/oboInOwl#hasDbXref', - 'has_source': 'http://purl.org/dc/terms/source', - 'is exemplar of': 'http://purl.obolibrary.org/obo/c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0' # This really needs to be using RO!!! + 'depicts': { + 'iri': 'http://xmlns.com/foaf/0.1/depicts', + 'short_form': 'depicts' + }, + 'in register with': { + 'iri': 'http://purl.obolibrary.org/obo/RO_0002026', + 'short_form': 'RO_0002026' + }, + 'is specified output of': { + 'iri': 'http://purl.obolibrary.org/obo/OBI_0000312', + 'short_form': 'OBI_0000312' + }, + 'hasDbXref': { + 'iri': 'http://www.geneontology.org/formats/oboInOwl#hasDbXref', + 'short_form': 'hasDbXref' + }, + 'has_source': { + 'iri': 'http://purl.org/dc/terms/source', + 'short_form': 'source' + }, + 'is exemplar of': { + 'iri': 'http://purl.obolibrary.org/obo/c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0', + 'short_form' : 'c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0' # This really needs to be using RO!!! + } } self.class_lookup = { - 'computer graphic': 'http://purl.obolibrary.org/obo/FBbi_00000224', - 'channel': 'http://purl.obolibrary.org/obo/fbbt/vfb/VFBext_0000014', - 'confocal microscopy': 'http://purl.obolibrary.org/obo/FBbi_00000251', - 'SB-SEM': 'http://purl.obolibrary.org/obo/FBbi_00000585', - 'TEM': 'http://purl.obolibrary.org/obo/FBbi_00000258' + 'computer graphic': { + 'iri': 'http://purl.obolibrary.org/obo/FBbi_00000224', + 'short_form': 'FBbi_00000224' + }, + 'channel': { + 'iri': 'http://purl.obolibrary.org/obo/fbbt/vfb/VFBext_0000014', + 'short_form': 'VFBext_0000014' + }, + 'confocal microscopy': { + 'iri': 'http://purl.obolibrary.org/obo/FBbi_00000251', + 'short_form': 'FBbi_00000251' + }, + 'SB-SEM': { + 'iri': 'http://purl.obolibrary.org/obo/FBbi_00000585', + 'short_form': 'FBbi_00000585' + }, + 'TEM': { + 'iri': 'http://purl.obolibrary.org/obo/FBbi_00000258', + 'short_form': 'FBbi_00000258' + } } def commit(self, ni_chunk_length=5000, ew_chunk_length=2000, verbose=False): @@ -832,8 +865,8 @@ def add_anatomy_image_set(self, # Should probably be dynamic with DB self.ew.add_anon_type_ax(s=channel_id['iri'], - r=self.relation_lookup['is specified output of'], - o=self.class_lookup[imaging_type]) + r=self.relation_lookup['is specified output of']['iri'], + o=self.class_lookup[imaging_type]['iri']) if anatomical_type: self.ew.add_named_type_ax(s=anat_id[match_on], @@ -844,21 +877,21 @@ def add_anatomy_image_set(self, if is_exemplar: # Is this direction needed? self.ew.add_anon_type_ax(s=anat_id['iri'], - r=self.relation_lookup['is exemplar of'], + r=self.relation_lookup['is exemplar of']['iri'], o=anatomical_type, match_on='iri', ) self.ew.add_value_restriction(s=anatomical_type, - r=self.relation_lookup['has exemplar'], + r=self.relation_lookup['has exemplar'][match_on], o=anat_id[match_on], - match_on=match_on) # Relation lookup needs short_forms! + match_on=match_on) # Relation lookup needs short_forms! # Also add reciprocal? # Add facts # This takes no vars so match_on can be fixed. self.ew.add_fact(s=channel_id['iri'], - r=self.relation_lookup['depicts'], + r=self.relation_lookup['depicts']['iri'], o=anat_id['iri']) edge_annotations = {} @@ -869,7 +902,7 @@ def add_anatomy_image_set(self, # if template == 'self': # template = channel_iri self.ew.add_fact(s=channel_id['short_form'], - r=get_sf(self.relation_lookup['in register with']), + r=get_sf(self.relation_lookup['in register with']['iri']), o=template, edge_annotations=edge_annotations, match_on='short_form', From 6b841fa2ae153ebcba4b071144db1a3010ca088f Mon Sep 17 00:00:00 2001 From: dosumis Date: Wed, 11 Mar 2020 19:11:54 +0000 Subject: [PATCH 4/7] Added (v.limited!) test --- src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py b/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py index 9531e529..197e6a8a 100644 --- a/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py +++ b/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py @@ -270,6 +270,7 @@ def testAddAnatomyImageSet(self): template='template_of_dave', anatomical_type='lobulobus', dbxrefs={'fu': 'bar'}, + is_exemplar=True, anon_anatomical_types=([('part_of', 'brain')]), start=100 ) From aea72df3433b73ca870362410d2b10fef887b70d Mon Sep 17 00:00:00 2001 From: dosumis Date: Wed, 11 Mar 2020 19:26:06 +0000 Subject: [PATCH 5/7] Fixed test setup - following changes to lookups --- src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py b/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py index 197e6a8a..64819ff4 100644 --- a/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py +++ b/src/uk/ac/ebi/vfb/neo4j/test/KB_tools_test.py @@ -226,16 +226,14 @@ def setUp(self): 'http://localhost:7474', 'neo4j', 'neo4j') statements = [] for k,v in self.kpw.relation_lookup.items(): - short_form = re.split('[/#]', v)[-1] statements.append("MERGE (p:Property { iri : '%s', label: '%s', " "short_form : '%s' }) " % - (v, k, short_form)) + (v['iri'], k, v['short_form'])) for k,v in self.kpw.class_lookup.items(): - short_form = re.split('[/#]', v)[-1] statements.append("MERGE (p:Class { iri : '%s', " "label: '%s', short_form : '%s' }) " % - (v, k, short_form)) + (v['iri'], k, v['short_form'])) self.nc.commit_list(statements) statements = [] From 2ad59a632323bc90be4ebb1129a50c4aed563812 Mon Sep 17 00:00:00 2001 From: dosumis Date: Wed, 11 Mar 2020 19:42:04 +0000 Subject: [PATCH 6/7] added has exemplar to lookup. Silly not to use an iri function for all this, but still... --- src/uk/ac/ebi/vfb/neo4j/KB_tools.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py index 9a1437a6..32ccafd2 100644 --- a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py +++ b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py @@ -697,6 +697,10 @@ def __init__(self, endpoint, usr, pwd): 'is exemplar of': { 'iri': 'http://purl.obolibrary.org/obo/c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0', 'short_form' : 'c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0' # This really needs to be using RO!!! + }, + 'has examplar': { + 'iri': 'http://purl.obolibrary.org/obo/C888C3DB-AEFA-447F-BD4C-858DFE33DBE7', + 'short_form': 'C888C3DB-AEFA-447F-BD4C-858DFE33DBE7' } } From e655884694a55be707e4581259fd074f353051e4 Mon Sep 17 00:00:00 2001 From: dosumis Date: Mon, 30 Mar 2020 13:08:50 +0100 Subject: [PATCH 7/7] Fixed type in relation name' --- src/uk/ac/ebi/vfb/neo4j/KB_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py index 32ccafd2..93ec3829 100644 --- a/src/uk/ac/ebi/vfb/neo4j/KB_tools.py +++ b/src/uk/ac/ebi/vfb/neo4j/KB_tools.py @@ -698,7 +698,7 @@ def __init__(self, endpoint, usr, pwd): 'iri': 'http://purl.obolibrary.org/obo/c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0', 'short_form' : 'c099d9d6-4ef3-11e3-9da7-b1ad5291e0b0' # This really needs to be using RO!!! }, - 'has examplar': { + 'has exemplar': { 'iri': 'http://purl.obolibrary.org/obo/C888C3DB-AEFA-447F-BD4C-858DFE33DBE7', 'short_form': 'C888C3DB-AEFA-447F-BD4C-858DFE33DBE7' }