-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afae190
commit 40ea710
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Test that a Gene Ontology Enrichement Analysis can be run quietly""" | ||
|
||
import os | ||
from goatools.goea.go_enrichment_ns import GOEnrichmentStudyNS | ||
from goatools.anno.idtogos_reader import IdToGosReader | ||
from goatools.base import get_godag | ||
|
||
__copyright__ = "Copyright (C) 2010-present, H Tang et al., All rights reserved." | ||
|
||
REPO = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") | ||
|
||
|
||
def test_goea_quiet(): | ||
"""Test that a Gene Ontology Enrichement Analysis can be run quietly""" | ||
goeaobj = _get_goeaobj() | ||
study_fin = "{REPO}/tests/data/small_study".format(REPO=REPO) | ||
study_ids = [line.rstrip() for line in open(study_fin)] | ||
print('\nTEST 1: GOEA run_study(study_ids)') | ||
goea_results1 = goeaobj.run_study(study_ids) | ||
print('{N} GOEA results for verbose GOEA'.format(N=len(goea_results1))) | ||
|
||
print('\nTEST 2: GOEA run_study(study_ids, prt=None)') | ||
goea_results2 = goeaobj.run_study(study_ids, prt=None) | ||
print('{N} GOEA results for quiet GOEA'.format(N=len(goea_results2))) | ||
|
||
# Original keyword is 'log' | ||
print('\nTEST 3: GOEA run_study(study_ids, log=None)') | ||
goea_results3 = goeaobj.run_study(study_ids, log=None) | ||
print('{N} GOEA results for quiet GOEA'.format(N=len(goea_results3))) | ||
|
||
|
||
_chk_results(goea_results1, goea_results2) | ||
_chk_results(goea_results1, goea_results3) | ||
|
||
|
||
def _get_goeaobj(methods=None): | ||
"""Test GOEA with method, fdr.""" | ||
# REad GODag | ||
obo_fin = os.path.join(REPO, "go-basic.obo") | ||
obo_dag = get_godag(obo_fin, loading_bar=None) | ||
# Read association | ||
fin_assc = "{REPO}/tests/data/small_association".format(REPO=REPO) | ||
objanno = IdToGosReader(fin_assc, godag=obo_dag) | ||
ns2assc = objanno.get_ns2assc() | ||
popul_fin = "{REPO}/tests/data/small_population".format(REPO=REPO) | ||
popul_ids = [line.rstrip() for line in open(popul_fin)] | ||
goeaobj = GOEnrichmentStudyNS(popul_ids, ns2assc, obo_dag, methods=methods) | ||
return goeaobj | ||
|
||
def _chk_results(results1, results2): | ||
"""Check that results match""" | ||
# pylint: disable=line-too-long | ||
for res1, res2 in zip(results1, results2): | ||
assert res1.GO == res2.GO, '\nRES1: {R1}\nRES2: {R2}\n\n'.format(R1=res1, R2=res2) | ||
assert res1.p_bonferroni == res2.p_bonferroni, '\nRES1: {R1}\nRES2: {R2}\n\n'.format(R1=res1, R2=res2) | ||
assert res1.p_sidak == res2.p_sidak, '\nRES1: {R1}\nRES2: {R2}\n\n'.format(R1=res1, R2=res2) | ||
assert res1.p_holm == res2.p_holm, '\nRES1: {R1}\nRES2: {R2}\n\n'.format(R1=res1, R2=res2) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_goea_quiet() | ||
|
||
# Copyright (C) 2010-present, H Tang et al., All rights reserved. |
Just a quick recommendation, it may sometimes be cleaner to do it through the
logging
module and then control the logging level globally through the API.