Skip to content

Commit

Permalink
Merge pull request #51 from biolink/obo-obsolete
Browse files Browse the repository at this point in the history
handing of obsoletion
  • Loading branch information
cmungall committed Jun 28, 2017
2 parents c9bf28e + c585948 commit bad1244
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 6 deletions.
57 changes: 56 additions & 1 deletion ontobio/io/assocwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,59 @@ class GafWriter(AssocWriter):
"""
Writes Associations in GAF format. Not yet implemented
"""
pass
def __init__(self, file=None):
self.file = file

def write_assoc(self, assoc):
"""
Write a single association to a line in the output file
"""
subj = assoc['subject']

db, db_object_id = self._split_prefix(subj)

rel = assoc['relation']
qualifier = rel['id']
if assoc['negated']:
qualifier = 'NOT|' + qualifier

goid = assoc['object']['id']

ev = assoc['evidence']
evidence = ev['type']
withfrom = "|".join(ev['with_support_from'])
reference = "|".join(ev['has_supporting_reference'])

date = assoc['date']
assigned_by = assoc['provided_by']

annotation_xp = '' # TODO
annotation_properties = '' # TODO
interacting_taxon_id = '' ## TODO
gene_product_isoform = '' ## TODO

aspect = None
taxon = None
if 'taxon' in subj:
taxon = subj['taxon']['id']

vals = [db,
db_object_id,
subj.get('label'),
qualifier,
goid,
reference,
evidence,
withfrom,
aspect,
subj.get('full_name'),
subj.get('synonyms'),
subj.get('type'),
taxon,
date,
assigned_by,
annotation_xp,
gene_product_isoform]

self._write_row(vals)

9 changes: 7 additions & 2 deletions ontobio/obograph_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def add_obograph_digraph(og, digraph, node_type=None, predicates=None, xref_grap
if 'lbl' in n:
digraph.node[id]['label'] = n['lbl']
if parse_meta and 'meta' in n:
meta = n['meta']
meta = transform_meta(n['meta'])
if xref_graph is not None and 'xrefs' in meta:
for x in meta['xrefs']:
xref_graph.add_edge(contract_uri_wrap(x['val']), id, source=id)
Expand Down Expand Up @@ -71,7 +71,12 @@ def add_obograph_digraph(og, digraph, node_type=None, predicates=None, xref_grap
contract_uri_wrap(x['fillerId'])) for x in a['restrictions'] if x is not None])
logical_definitions.append(ld)


def transform_meta(m):
if 'basicPropertyValues' in m:
for x in m['basicPropertyValues']:
x['pred'] = contract_uri_wrap(x['pred'])
x['val'] = contract_uri_wrap(x['val'])
return m

def convert_json_file(obographfile, **args):
"""
Expand Down
10 changes: 7 additions & 3 deletions ontobio/ontol.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,15 @@ def _get_meta(self, nid):
return None

def _get_basic_property_values(self, nid):
return self._get_meta_prop(nid, 'basicPropertyValues')
r = self._get_meta_prop(nid, 'basicPropertyValues')
if r is None:
return []
else:
return r

def _get_basic_property_value(self, nid, prop):
bpvs = self._get_basic_property_values()
return [x['val'] for x in bpvs in x['pred'] == prop]
bpvs = self._get_basic_property_values(nid)
return [x['val'] for x in bpvs if x['pred'] == prop]

def is_obsolete(self, nid):
"""
Expand Down
73 changes: 73 additions & 0 deletions tests/resources/obsolete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"graphs" : [ {
"nodes" : [ {
"id" : "http://purl.obolibrary.org/obo/IAO_0100001",
"type" : "PROPERTY",
"lbl" : "term replaced by"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_2",
"meta" : {
"basicPropertyValues" : [ {
"pred" : "http://purl.obolibrary.org/obo/IAO_0100001",
"val" : "http://purl.obolibrary.org/obo/GO_1"
}, {
"pred" : "http://purl.obolibrary.org/obo/IAO_0000231",
"val" : "http://purl.obolibrary.org/obo/IAO_0000227"
} ],
"deprecated" : true
},
"type" : "CLASS"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_1",
"meta" : {
"basicPropertyValues" : [ {
"pred" : "http://www.geneontology.org/formats/oboInOwl#hasAlternativeId",
"val" : "GO:2"
} ]
},
"type" : "CLASS",
"lbl" : "x1"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_4",
"meta" : {
"basicPropertyValues" : [ {
"pred" : "http://www.geneontology.org/formats/oboInOwl#consider",
"val" : "GO:1"
} ],
"deprecated" : true
},
"type" : "CLASS",
"lbl" : "x4"
}, {
"id" : "http://www.geneontology.org/formats/oboInOwl#consider",
"type" : "PROPERTY",
"lbl" : "consider"
}, {
"id" : "http://www.geneontology.org/formats/oboInOwl#hasAlternativeId",
"type" : "PROPERTY",
"lbl" : "has_alternative_id"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_3",
"meta" : {
"basicPropertyValues" : [ {
"pred" : "http://purl.obolibrary.org/obo/IAO_0100001",
"val" : "GO:1"
} ],
"deprecated" : true
},
"type" : "CLASS",
"lbl" : "x3"
} ],
"edges" : [ ],
"id" : "http://purl.obolibrary.org/obo/test-obsolete.owl",
"meta" : {
"subsets" : [ ],
"xrefs" : [ ],
"basicPropertyValues" : [ ]
},
"equivalentNodesSets" : [ ],
"logicalDefinitionAxioms" : [ ],
"domainRangeAxioms" : [ ],
"propertyChainAxioms" : [ ]
} ]
}
21 changes: 21 additions & 0 deletions tests/test_local_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,24 @@ def test_subontology():
ancs = subont.ancestors(PERM)
print(str(ancs))
assert len(ancs) > 0

def test_obsolete():
"""
Test obsoletion metadata
"""
factory = OntologyFactory()
print("Creating ont")
ont = factory.create('tests/resources/obsolete.json')
print("ONT NODES: {}".format(ont.nodes()))
n_obs = 0
for nid in ont.nodes():
is_obs = ont.is_obsolete(nid)
if is_obs:
print("OBS: {} {}".format(nid, ont.label(nid)))
n_obs += 1
rb = ont.replaced_by(nid)
if rb is not None:
print("REPLACED BY: {} {}".format(rb, ont.label(rb)))
assert ont.replaced_by('GO:2') == 'GO:1'
assert ont.replaced_by('GO:3') == 'GO:1'
assert n_obs == 3

0 comments on commit bad1244

Please sign in to comment.