Skip to content

Commit

Permalink
Merge pull request #603 from biolink/issue-602-obsolete-with-from
Browse files Browse the repository at this point in the history
Return empty list for with/from if no term
  • Loading branch information
kltm committed Feb 23, 2022
2 parents 152b6a0 + 5f576b5 commit a0478e4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ontobio/io/assocparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ def _unroll_withfrom_and_replair_obsoletes(self, line: SplitLine, gaf_or_gpad: s
for element_individual in filter(None, element_set.split(",")): # parse the | and ,
if element_individual.startswith("GO:"):
fixed_element_individual = self._validate_ontology_class_id(str(element_individual), line)
if fixed_element_individual is None:
return None
else:
fixed_element_individual = element_individual
if grouped_fixed_elements == '':
Expand All @@ -691,7 +693,10 @@ def _unroll_withfrom_and_replair_obsoletes(self, line: SplitLine, gaf_or_gpad: s
regrouped_fixed_elements = grouped_fixed_elements
else:
regrouped_fixed_elements = regrouped_fixed_elements + "|" + grouped_fixed_elements
return association.ConjunctiveSet.str_to_conjunctions(regrouped_fixed_elements)
if regrouped_fixed_elements:
return association.ConjunctiveSet.str_to_conjunctions(regrouped_fixed_elements)
else:
return []

# check the term id is in the ontology, and is not obsolete
def _validate_ontology_class_id(self, id, line: SplitLine, subclassof=None):
Expand All @@ -715,7 +720,7 @@ def _validate_ontology_class_id(self, id, line: SplitLine, subclassof=None):
taxon=line.taxon, rule=20)
id = rb[0]
else:
self.report.warning(line.line, Report.OBSOLETE_CLASS_NO_REPLACEMENT, id, msg="Violates GORULE:0000020",
self.report.error(line.line, Report.OBSOLETE_CLASS_NO_REPLACEMENT, id, msg="Violates GORULE:0000020",
taxon=line.taxon, rule=20)
id = None
else:
Expand Down
5 changes: 4 additions & 1 deletion ontobio/io/gafparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ def parse_line(self, line):
validated = self.validate_curie_ids(wf.elements, split_line)
if validated is None:
return assocparser.ParseResult(line, [], True)
assoc.evidence.with_support_from = self._unroll_withfrom_and_replair_obsoletes(split_line, 'gaf')
with_support_from = self._unroll_withfrom_and_replair_obsoletes(split_line, 'gaf')
if with_support_from is None:
return assocparser.ParseResult(line, [], True)
assoc.evidence.with_support_from = with_support_from
# validation
self._validate_symbol(assoc.subject.label, split_line)

Expand Down
57 changes: 57 additions & 0 deletions tests/resources/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,63 @@
},
"type" : "CLASS",
"lbl" : "ferric iron import across cell outer membrane"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_0016458",
"meta" : {
"definition" : {
"val" : "OBSOLETE. Any process carried out at the cellular level that results in either long-term transcriptional repression via action on chromatin structure or RNA mediated, post-transcriptional repression of gene expression.",
"xrefs" : [ "GOC:dos", "GOC:dph", "GOC:jid", "GOC:tb" ]
},
"comments" : [ "This term was obsoleted because its definition was too broad, and not distinct from 'GO:0045814 negative regulation of gene expression, epigenetic'." ],
"xrefs" : [ {
"val" : "Wikipedia:Gene_silencing"
} ],
"basicPropertyValues" : [ {
"pred" : "http://purl.obolibrary.org/obo/IAO_0000233",
"val" : "https://github.com/geneontology/go-ontology/issues/22202"
}, {
"pred" : "http://www.geneontology.org/formats/oboInOwl#hasOBONamespace",
"val" : "biological_process"
}, {
"pred" : "http://www.geneontology.org/formats/oboInOwl#consider",
"val" : "GO:0010629"
}, {
"pred" : "http://www.geneontology.org/formats/oboInOwl#consider",
"val" : "GO:0031507"
} ],
"deprecated" : true
},
"type" : "CLASS",
"lbl" : "obsolete gene silencing"
}, {
"id" : "http://purl.obolibrary.org/obo/GO_0005634",
"meta" : {
"definition" : {
"val" : "A membrane-bounded organelle of eukaryotic cells in which chromosomes are housed and replicated. In most cells, the nucleus contains all of the cell's chromosomes except the organellar chromosomes, and is the site of RNA synthesis and processing. In some species, or in specialized cell types, RNA metabolism or DNA replication may be absent.",
"xrefs" : [ "GOC:go_curators" ]
},
"subsets" : [ "http://purl.obolibrary.org/obo/go#goslim_generic", "http://purl.obolibrary.org/obo/go#goslim_yeast", "http://purl.obolibrary.org/obo/go#goslim_agr", "http://purl.obolibrary.org/obo/go#goslim_candida", "http://purl.obolibrary.org/obo/go#goslim_plant", "http://purl.obolibrary.org/obo/go#goslim_pir", "http://purl.obolibrary.org/obo/go#goslim_flybase_ribbon", "http://purl.obolibrary.org/obo/go#goslim_drosophila", "http://purl.obolibrary.org/obo/go#goslim_aspergillus", "http://purl.obolibrary.org/obo/go#goslim_metagenomics", "http://purl.obolibrary.org/obo/go#goslim_chembl", "http://purl.obolibrary.org/obo/go#goslim_mouse" ],
"xrefs" : [ {
"val" : "NIF_Subcellular:sao1702920020"
}, {
"val" : "Wikipedia:Cell_nucleus"
} ],
"synonyms" : [ {
"pred" : "hasNarrowSynonym",
"val" : "horsetail nucleus",
"xrefs" : [ "GOC:al", "GOC:mah", "GOC:vw", "PMID:15030757" ]
}, {
"pred" : "hasExactSynonym",
"val" : "cell nucleus",
"xrefs" : [ ]
} ],
"basicPropertyValues" : [ {
"pred" : "http://www.geneontology.org/formats/oboInOwl#hasOBONamespace",
"val" : "cellular_component"
} ]
},
"type" : "CLASS",
"lbl" : "nucleus"
}, {
"id" : "http://www.geneontology.org/formats/oboInOwl#hasAlternativeId",
"type" : "PROPERTY",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_gafparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ def test_obsolete_replair_of_withfrom():
assocs = p.parse(open(ZFIN_GAF, "r"), skipheader=True)
assert assocs[0].evidence.with_support_from == [ConjunctiveSet(elements=[Curie(namespace='GO', identity='0005912')])]

# Reset parser report
p = GafParser(config=assocparser.AssocParserConfig(
ontology=OntologyFactory().create(OBSOLETE_ONT)))
p.version = "2.2"
obsolete_no_replacement_line = "FB\tFBgn0003334\tScm\tlocated_in\tGO:0005634\tFB:FBrf0179383|PMID:15280237\tIC\tGO:0016458\tC\tSex comb on midleg\tCG9495|SCM|Sex Comb on Midleg|Sex Comb on the Midleg|Sex combs on midleg|Sex combs on midlegs|Su(z)302|l(3)85Ef|scm|sex comb on midleg\tprotein\ttaxon:7227\t20050203\tUniProt\t\t"
assoc_result = p.parse_line(obsolete_no_replacement_line)
assert assoc_result.associations == []
assert p.report.to_report_json()["messages"]["gorule-0000020"][0]["obj"] == "GO:0016458"


def test_subject_extensions_bad_curie():
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_local_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ def test_obsolete():
assert ont.replaced_by('GO:1') == ['GO:2']
assert ont.replaced_by('GO:4') == ['GO:3']
assert ont.replaced_by('GO:0005913') == ['GO:0005912']
assert n_obs == 3
assert n_obs == 4

0 comments on commit a0478e4

Please sign in to comment.