Skip to content

Commit

Permalink
Added for testing GOEnrichmentStudy::print_results in issue #111
Browse files Browse the repository at this point in the history
  • Loading branch information
dvklopfenstein committed Oct 3, 2018
1 parent bacc42a commit 58db35e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion goatools/go_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_corrected_pval(self, nt_method, pvalue):
def __str__(self, indent=False):
field_data = [getattr(self, f, "n.a.") for f in self._fldsdefprt[:-1]] + \
[getattr(self, "p_{}".format(m.fieldname)) for m in self.method_flds] + \
[", ".join(sorted(getattr(self, self._fldsdefprt[-1], set())))]
[", ".join(str(e) for e in sorted(getattr(self, self._fldsdefprt[-1], set())))]
fldsdeffmt = self._fldsdeffmt
field_formatter = fldsdeffmt[:-1] + ["%.3g"]*len(self.method_flds) + [fldsdeffmt[-1]]
self._chk_fields(field_data, field_formatter)
Expand Down
37 changes: 37 additions & 0 deletions tests/test_print_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
"""Test GOEnrichmentStudy::print_results."""

import os
# from goatools.rpt.goea_nt_xfrm import MgrNtGOEAs # get_goea_nts_all
from goatools.test_data.genes_NCBI_10090_ProteinCoding import GENEID2NT as GeneID2nt_mus
from goatools.test_data.nature3102_goea import get_geneid2symbol, get_goeaobj

__copyright__ = "Copyright (C) 2016-2017, DV Klopfenstein, H Tang, All rights reserved."

REPO = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../")


def test_example():
"""Test GOEnrichmentStudy::print_results."""
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# Gene Ontology Enrichment Analysis (GOEA)
# --------------------------------------------------------------------
# --------------------------------------------------------------------
taxid = 10090 # Mouse study
# Load ontologies, associations, and population ids
geneids_pop = GeneID2nt_mus.keys()
geneids2symbol_study = get_geneid2symbol("nbt.3102-S4_GeneIDs.xlsx")
geneids_study = geneids2symbol_study.keys()
goeaobj = get_goeaobj("fdr_bh", geneids_pop, taxid)
# Run GOEA on study
goea_results_all = goeaobj.run_study(geneids_study)
goea_results_sig = [r for r in goea_results_all if r.p_fdr_bh < 0.05]
#goea_results_nt = MgrNtGOEAs(goea_results_sig).get_goea_nts_all()
goeaobj.print_results(goea_results_sig)


if __name__ == '__main__':
test_example()

# Copyright (C) 2016-2017, DV Klopfenstein, H Tang, All rights reserved.

0 comments on commit 58db35e

Please sign in to comment.