Skip to content

Commit

Permalink
Merge branch 'master' into go-site-2002-gorule-0000061-update-for-new…
Browse files Browse the repository at this point in the history
…-requirements
  • Loading branch information
mugitty committed Sep 14, 2023
2 parents 1943a88 + b8fdb36 commit c072412
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 135 deletions.
7 changes: 4 additions & 3 deletions README-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ git push --tags

> To ensure this is successful, make sure you have relevant permissions to Ontobio package on [PyPI](https://pypi.org/project/ontobio/)

Run the following commands:
Run the following commands (note, you will need a pypi token to do this work, see: https://pypi.org/help/#apitoken
and make a ~/.pypirc file to store your token):

```sh
make cleandist
python setup.py sdist bdist_wheel bdist_egg
twine upload --repository-url https://upload.pypi.org/legacy/ --username PYPI_USERNAME dist/*
python setup.py sdist bdist_wheel
twine upload --repository-url https://upload.pypi.org/legacy/ --username __token__ dist/*
```

****************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion ontobio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

__version__ = '2.8.11'
__version__ = '2.8.14'


from .ontol_factory import OntologyFactory
Expand Down
5 changes: 4 additions & 1 deletion ontobio/io/gafparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,10 @@ def to_association(gaf_line: List[str], report=None, group="unknown", dataset="u
return assocparser.ParseResult(source_line, [], True, report=report)

taxon = parsed_taxons_result.parsed[0]

if taxon.identity is None or taxon.identity == '0':
report.error(source_line, Report.INVALID_TAXON, parsed_taxons_result.original, parsed_taxons_result.message, taxon=parsed_taxons_result.original, rule=1)
return assocparser.ParseResult(source_line, [], True, report=report)

date = assocparser.parse_date(gaf_line[13], report, source_line)
if date is None:
return assocparser.ParseResult(source_line, [], True, report=report)
Expand Down
12 changes: 12 additions & 0 deletions ontobio/io/gpadparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ def from_1_2(gpad_line: List[str], report=None, group="unknown", dataset="unknow
if entity is not None:
subject = entity
taxon = subject.taxon

#Ensure taxon is valid, if we are reading from bioentity
if len(bio_entities.entities) > 0:
if taxon.identity is None or taxon.identity == '0':
report.error(source_line, Report.INVALID_TAXON, "None or 0", "Taxon is invalid", rule=1)
return assocparser.ParseResult(source_line, [], True, report=report)

go_term = association.Curie.from_str(gpad_line[3])
if go_term.is_error():
Expand Down Expand Up @@ -425,6 +431,12 @@ def from_2_0(gpad_line: List[str], report=None, group="unknown", dataset="unknow
# If we found a subject entity, then set `subject` to the found entity
subject = entity
taxon = subject.taxon

#Ensure taxon is valid, if we are reading from bioentity
if len(bio_entities.entities) > 0:
if taxon.identity is None or taxon.identity == '0':
report.error(source_line, Report.INVALID_TAXON, "None or 0", "Taxon is invalid", rule=1)
return assocparser.ParseResult(source_line, [], True, report=report)

negated = gpad_line[1] == "NOT"

Expand Down
12 changes: 12 additions & 0 deletions ontobio/io/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,17 @@ def test(self, annotation: association.GoAssociation, config: assocparser.AssocP

return result

class GoRule51(GoRule):

def __init__(self):
super().__init__("GORULE:0000051", "Some GO terms require a value in the Annotation Extension field", FailMode.SOFT)

def test(self, annotation: association.GoAssociation, config: assocparser.AssocParserConfig, group=None) -> TestResult:

term = str(annotation.object.id)
no_extensions = (annotation.object_extensions is None or len(annotation.object_extensions) == 0)
fails = (term == "GO:0005488" or term == "GO:0005515") and no_extensions
return self._result(not fails)

class GoRule55(GoRule):

Expand Down Expand Up @@ -919,6 +930,7 @@ def test(self, annotation: association.GoAssociation, config: assocparser.AssocP
"GoRule43": GoRule43(),
"GoRule46": GoRule46(),
"GoRule50": GoRule50(),
"GoRule51": GoRule51(),
"GoRule55": GoRule55(),
"GoRule57": GoRule57(),
"GoRule58": GoRule58(),
Expand Down
290 changes: 163 additions & 127 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/resources/errors.gaf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!
! bad GO ID
PomBase SPAC25B8.17 ypf1 BAD_GO_ID GO_REF:0000024 ISO SGD:S000001583 C intramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted) ppp81 protein taxon:4896 20150305 PomBase
! No gene symbol
! No gene symbol, fail since gene symbol is a required field
PomBase SPAC977.10 GO:1990578 PMID:19171118 IDA C plasma membrane sodium ion/proton antiporter Nhe1/Sod2 sod2 protein taxon:4896 20151201 PomBase
! Blank lines

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gafparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_errors_gaf():
n_invalid_idspace += 1
assert len(msgs) == 13
assert n_invalid_idspace == 1
assert len(assocs) == 2
assert len(assocs) == 1

w = GafWriter()
w.write(assocs)
Expand Down
78 changes: 78 additions & 0 deletions tests/test_gpad_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from ontobio.model import association
from ontobio.model.association import ConjunctiveSet, ExtensionUnit, Curie
from ontobio.ontol_factory import OntologyFactory
from ontobio.model import collections
from ontobio.model.association import Curie, Subject

import yaml

Expand Down Expand Up @@ -252,3 +254,79 @@ def test_unmapped_eco_to_gaf_codes():
vals[5] = "ECO:0006003" # indirectly maps to IDA via gaf-eco-mapping-derived.txt
result = parser.parse_line("\t".join(vals))
assert len(result.associations) == 1

def test_gpi_check():
report = assocparser.Report(group="unknown", dataset="unknown")
vals = [
"ZFIN",
"ZDB-GENE-070117-1552",
"acts_upstream_of_or_within",
"GO:0045601",
"PMID:17531218",
"ECO:0000307",
"",
"",
"20080326",
"ZFIN",
"",
"creation-date=2020-09-17|modification-date=2020-09-17|contributor-id=http://orcid.org/0000-0003-2689-5511"
]

bioentities = {'ZFIN:ZDB-GENE-070117-1552' : {
'id': "ZDB-GENE-070117-1552",
'label': "ZDB-GENE-070117-1552",
'full_name': "fullnames",
'synonyms': "synonyms",
'type': "gene_product",
'taxon': "taxon:0"
}
}

bioentities = collections.BioEntities({
Curie("ZFIN", "ZDB-GENE-070117-1552"): Subject(Curie.from_str("ZFIN:ZDB-GENE-070117-1552"), "ste4", ["adaptor protein Ste4"], [], ["protein"], Curie.from_str("taxon:0"))
})



result = to_association(list(vals), report=report, version="1.2", bio_entities=bioentities)
assert result.skipped == True
assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 1
assert len(result.associations) == 0

vals = [
"ZFIN:ZDB-GENE-070117-1552",
"ZFIN:ZDB-GENE-070117-1552",
"RO:12345",
"GO:0045601",
"PMID:17531218",
"ECO:0000307",
"",
"",
"2008-03-26",
"ZFIN",
"",
"creation-date=2020-09-17|modification-date=2020-09-17|contributor-id=http://orcid.org/0000-0003-2689-5511"
]
result = to_association(list(vals), report=report, version="2.0", bio_entities=bioentities)
assert result.skipped == True
assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 2
assert len(result.associations) == 0


bioentities = collections.BioEntities({"bla": 'blabla'})

result = to_association(list(vals), report=report, version="2.0", bio_entities=bioentities)
assert result.skipped == True
assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 3
assert len(result.associations) == 0

bioentities = collections.BioEntities({
Curie("ZFIN", "ZDB-GENE-070117-1552"): Subject(Curie.from_str("ZFIN:ZDB-GENE-070117-1552"), "ste4", ["adaptor protein Ste4"], [], ["protein"], Curie.from_str("NCBITaxon:12345"))
})

result = to_association(list(vals), report=report, version="2.0", bio_entities=bioentities)
assert result.skipped == 0
assert len([m for m in result.report.messages if m["level"] == "ERROR"]) == 3
assert len(result.associations) == 1


12 changes: 11 additions & 1 deletion tests/test_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ def test_gorule50():
assoc.evidence.type = Curie.from_str(iea_eco)
test_result = qc.GoRule50().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.PASS

def test_gorule51():
assoc = make_annotation(goid="GO:0005515", extension="has_input(GO:0003674),occurs_in(CL:123456)").associations[0]

test_result = qc.GoRule51().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.PASS

assoc = make_annotation(goid="GO:0005488").associations[0]
test_result = qc.GoRule51().test(assoc, all_rules_config())
assert test_result.result_type == qc.ResultType.WARNING

def test_gorule55():
a = ["blah"] * 15
Expand Down Expand Up @@ -727,7 +737,7 @@ def test_all_rules():
assoc = gafparser.to_association(a).associations[0]

test_results = qc.test_go_rules(assoc, config).all_results
assert len(test_results.keys()) == 24
assert len(test_results.keys()) == 25
assert test_results[qc.GoRules.GoRule26.value].result_type == qc.ResultType.PASS
assert test_results[qc.GoRules.GoRule29.value].result_type == qc.ResultType.PASS

Expand Down

0 comments on commit c072412

Please sign in to comment.