Completed
Push — master ( ca146f...1b2584 )
by
unknown
53s
created

test_plotgosubdag()   A

Complexity

Conditions 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 29
rs 9.184
c 3
b 0
f 0
1
#!/usr/bin/env python
2
"""Test creation of GoSubDag's rcntobj data member."""
3
4
from __future__ import print_function
5
6
__copyright__ = "Copyright (C) 2016-2018, DV Klopfenstein, H Tang. All rights reserved."
7
__author__ = "DV Klopfenstein"
8
9
import os
10
from goatools.base import get_godag
11
from goatools.gosubdag.gosubdag import GoSubDag
12
from goatools.gosubdag.plot.gosubdag_plot import GoSubDagPlot
13
14
REPO = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../")
15
16
17
def test_plotgosubdag():
18
    """Test creation of GoSubDag's rcntobj data member."""
19
    objrun = Run("../goatools/tests/data/mini_obo.obo")
20
    #objrun.prt_goids_all(prt)
21
    in_exp = [
22
        (["GO:0000002"], set(["GO:0000001", "GO:0000002"]), {}),
23
        (["GO:0000002"], set(["GO:0000001", "GO:0000002",
24
                              "GO:0000003", "GO:0000005",
25
                              "GO:0000006", "GO:0000008",
26
                              "GO:0000010",             ]), {'children':True}),
27
        (["GO:0000002"], set(["GO:0000001", "GO:0000002"]), {'children':0}),
28
        (["GO:0000002"], set(["GO:0000001", "GO:0000002",
29
                              "GO:0000003", "GO:0000005",
30
                              "GO:0000006", "GO:0000008",
31
                              "GO:0000010",             ]), {'children':1}),
32
        (["GO:0000008"], set(["GO:0000001", "GO:0000003",
33
                              "GO:0000006", "GO:0000008"]), {}),
34
        (["GO:0000008"], set(["GO:0000001", "GO:0000003",
35
                              "GO:0000006", "GO:0000008"]), {'children':False}),
36
        (["GO:0000008"], set(["GO:0000001", "GO:0000003",
37
                              "GO:0000006", "GO:0000008"]), {'children':None}),
38
        (["GO:0000008"], set(["GO:0000001", "GO:0000003",
39
                              "GO:0000006", "GO:0000008",
40
                              "GO:0000002", "GO:0000005",
41
                              "GO:0000004", "GO:0000007",
42
                              "GO:0000009", "GO:0000010"]), {'children':True}),
43
    ]
44
    for in_goids, exp_goids, kws in in_exp:
45
        objrun.run(in_goids, exp_goids, **kws)
46
    # objrun.plt_goids("mini_obo.png", None)
47
48
49
class Run(object):
50
    """Printing GO IDs and Plotting; GODag from obo using GoSubDag."""
51
52
    def __init__(self, obo):
53
        self.go2obj_all = get_godag(os.path.join(REPO, obo))
54
        self.gosubdag_all = GoSubDag(None, self.go2obj_all)
55
        self.prtfmt = self.gosubdag_all.prt_attr['fmta']
56
57
    def prt_goids_all(self, prt):
58
        """Print all GO IDs, including alternate GO IDs, in GODag."""
59
        self.gosubdag_all.prt_goids(prtfmt=self.prtfmt, prt=prt)
60
61
    def plt_goids(self, fout_img, go_sources):
62
        """Plot GO IDs."""
63
        # % src/bin/go_plot.py GOs --obo=../goatools/data/i86.obo --outfile=t00.jpg --mark_alt_id
64
        gosubdag = GoSubDag(go_sources, self.go2obj_all)
65
        objplt = GoSubDagPlot(gosubdag, mark_alt_id=True)
66
        objplt.plt_dag(os.path.join(REPO, fout_img))
67
68
    def run(self, go_sources, exp_gos, **kws):
69
        """Create GoSubDag using specified GO sources."""
70
        print("\nSRCS: {GOs}".format(GOs=go_sources))
71
        gosubdag = GoSubDag(go_sources, self.go2obj_all, **kws)
72
        gosubdag.prt_goids(gosubdag.go2nt)
73
        assert set(gosubdag.go2nt) == exp_gos, "ACT({}) != EXP({})\n{} {}".format(
74
            sorted(gosubdag.go2nt), sorted(exp_gos), go_sources, kws)
75
76
77
if __name__ == '__main__':
78
    test_plotgosubdag()
79
80
# Copyright (C) 2016-2018, DV Klopfenstein, H Tang. All rights reserved.
81