Skip to content

Commit

Permalink
Merge pull request #28 from dvklopfenstein/master
Browse files Browse the repository at this point in the history
Added a new test to find error. Test can be run by cd-ing into tests and...
  • Loading branch information
tanghaibao committed Mar 19, 2015
2 parents f7dedfa + b6ab6fc commit 66ba804
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Tools for Gene Ontology
Kenta Sato (`bicycle1885 <http://github.com/bicycle1885>`_),
Chris Mungall (`cmungall <https://github.com/cmungall>`_),
Greg Stupp (`stuppie <https://github.com/stuppie>`_),
Debra Klopfenstein
Debra Klopfenstein(`dvklopfenstein <https://github.com/dvklopfenstein>`_)
:Email: tanghaibao@gmail.com
:License: BSD

Expand Down
3 changes: 3 additions & 0 deletions goatools/go_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def run_study(self, study):

pop_n, study_n = len(self.pop), len(study)

#Uncomment these to cause tests/test_enrichment_fdr.py to pass:
#study_count = 0
#pop_count = 0
for term, study_count in list(term_study.items()):
pop_count = self.term_pop[term]
p = fisher.pvalue_population(study_count, study_n,
Expand Down
10 changes: 9 additions & 1 deletion scripts/find_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def check_bad_args(args):
"Bonferroni but slower)")
p.add_option('--indent', dest='indent', default=False,
action='store_true', help="indent GO terms")
p.add_option('--obo', default="go-basic.obo", type="string",
help="Specifies location and name of the obo file"
"[default: %default]")

(opts, args) = p.parse_args()
bad = check_bad_args(args)
Expand All @@ -114,12 +117,17 @@ def check_bad_args(args):
study_fn, pop_fn, assoc_fn = args
study, pop = read_geneset(study_fn, pop_fn, compare=opts.compare)
assoc = read_associations(assoc_fn)
#print("{}".format(assoc))
#print("{}".format(study))
#print("{}".format(pop))

methods = ["bonferroni", "sidak", "holm"]
if opts.fdr:
methods.append("fdr")

obo_dag = GODag(obo_file="go-basic.obo")
obo_dag = GODag(obo_file=opts.obo)
g = GOEnrichmentStudy(pop, assoc, obo_dag, alpha=opts.alpha,
study=study, methods=methods)
g.print_summary(min_ratio=min_ratio, indent=opts.indent, pval=opts.pval)
print('pval={}'.format(opts.pval))
print('min_ratio={}'.format(min_ratio))
2 changes: 2 additions & 0 deletions tests/data/study_unknown
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AT2G00000
AT4G00001
25 changes: 25 additions & 0 deletions tests/test_enrichment_fdr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import os

def test():
"""Test to find this error below.
Traceback (most recent call last):
File "../scripts/find_enrichment.py", line 130, in <module>
study=study, methods=methods)
File "../scripts/../goatools/go_enrichment.py", line 93, in __init__
self.run_study(study)
File "../scripts/../goatools/go_enrichment.py", line 129, in run_study
p_val_distribution = calc_qval(study_count, study_n,
UnboundLocalError: local variable 'study_count' referenced before assignment
"""
os.system("python {SCR} --alpha=0.05 {STUDY} {POP} {ASSN} --fdr --obo={OBO}".format(
SCR="../scripts/find_enrichment.py",
OBO="../go-basic.obo",
STUDY="data/study_unknown",
POP="../data/population",
ASSN="../data/association"))

if __name__ == '__main__':
test()

0 comments on commit 66ba804

Please sign in to comment.