Skip to content

Commit

Permalink
new grouper test
Browse files Browse the repository at this point in the history
  • Loading branch information
dvklopfenstein committed Jun 27, 2018
1 parent 6972248 commit e0b8313
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 190 deletions.
190 changes: 0 additions & 190 deletions goatools/test_data/sections_gjoneska.py

This file was deleted.

1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ clobber:
# tests/test_gosubdag_children.py \
NOSETESTS := \
tests/test_grpr_get_sections_2d.py \
tests/test_sorter.py \
tests/test_gosubdag_relationships.py \
tests/test_gosubdag_mk.py \
Expand Down
59 changes: 59 additions & 0 deletions tests/test_grpr_get_sections_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
"""Test function, get_sections_2d, in the Grouper class.
The method, get_sections_2d should, return hdrgos used for
the user GO IDs in the same order as the 2-d sections list
provided when a Grouper object is initialized.
"""

import sys
from goatools.test_data.gjoneska_goea_consistent_increase import goea_results
from goatools.test_data.sections.gjoneska_pfenning import SECTIONS
from goatools.grouper.grprdflts import GrouperDflts
from goatools.grouper.hdrgos import HdrgosSections
from goatools.grouper.grprobj import Grouper

PRT = sys.stdout

def test_fnc():
"""Test function, get_sections_2d, in the Grouper class."""
usrgo2nt = {getattr(nt, 'GO'):nt for nt in goea_results if getattr(nt, 'p_fdr_bh') < 0.05}
usrgos = usrgo2nt.keys()
grprdflt = GrouperDflts()
hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=SECTIONS, hdrgos=None)
grprobj = Grouper("test", usrgos, hdrobj, grprdflt.gosubdag, go2nt=usrgo2nt)
assert set(usrgos) == grprobj.usrgos
sections_act = grprobj.get_sections_2d()
chk_results(sections_act, grprobj)

def chk_results(sections_act, grprobj):
"""Get expected results."""
hdrgos_act = grprobj.get_hdrgos()
hdrgos_sec_act = set([g for _, gs in sections_act for g in gs])
assert hdrgos_act == hdrgos_sec_act
num_gos_orig = sum([len(gs) for _, gs in SECTIONS])
PRT.write("{N} of {M} Sections Header GOs for {U} user GOs, {H} headers\n".format(
N=len(hdrgos_sec_act), M=num_gos_orig, U=len(grprobj.usrgos), H=len(hdrgos_act)))
sections_act_dict = {s:hs for s, hs in sections_act}
# Check that order of actual header GOs is the same as found in the sections 2-d list
for section_name, hdrgos_all in SECTIONS:
hdrgos_act = sections_act_dict.get(section_name, None)
if hdrgos_act is not None:
h2i = {h:i for i, h in enumerate(hdrgos_act)}
idx_act = None
for hdrgo in hdrgos_all:
idx = h2i.get(hdrgo, "")
PRT.write("ORIG {I:2} {S} {H}\n".format(S=section_name, H=hdrgo, I=idx))
if idx != "":
assert idx == 0 and idx_act is None or idx_act == idx - 1
idx_act = idx
idx_act = None
for hdrgo in hdrgos_act:
idx = h2i.get(hdrgo, "")
PRT.write("ACT {I:2} {S} {H}\n".format(S=section_name, H=hdrgo, I=idx))
assert idx == 0 and idx_act is None or idx_act == idx - 1
idx_act = idx

if __name__ == '__main__':
test_fnc()

0 comments on commit e0b8313

Please sign in to comment.