How to use the goatools.gosubdag.rpt.write_hierarchy.WrHierGO function in goatools

To help you get started, we’ve selected a few goatools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tanghaibao / goatools / tests / test_write_hier.py View on Github external
def write_hier_all(gosubdag, out):
    """write_hier.py: Prints the entire mini GO hierarchy, with counts of children."""
    out.write('\nTEST ALL: Print all hierarchies:\n')
    objwr = WrHierGO(gosubdag)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert set(gos_printed) == set(objwr.gosubdag.go2nt)
github tanghaibao / goatools / tests / test_optional_fields.py View on Github external
Prints the 'entire hierarchy' of GO:0000005 the 1st time seen:

           ---     1 GO:0000005    L-02    D-02
           ----     0 GO:0000010   L-03    D-04

         Prints just GO:0000005 (ommit child GO:10) the 2nd time seen:

           ===     1 GO:0000005    L-02    D-02

         '=' is used in hierarchy mark to indicate that the pathes
             below the marked term have already been printed.
    """
    out.write('\nTEST {NAME} {GO}: Print branches just once:\n'.format(
        NAME=name, GO=go_id))
    #### dag.write_hier(go_id, out, num_child=True, short_prt=True)
    WrHierGO(gosubdag, concise=True).prt_hier_down(go_id, out)
    out.write("GOTerm: {}\n".format(gosubdag.go2obj[go_id]))
github tanghaibao / goatools / tests / test_write_hier.py View on Github external
def write_hier_mrk_dct(gosubdag, out):
    """Print all paths, but mark GO Terms of interest. """
    mark_dct = {'GO:0000001':'a', 'GO:0000003':'b', 'GO:0000006':'c',
                'GO:0000008':'d', 'GO:0000009':'e'}
    out.write('\nTEST MARK DICT: 01->03->06->08->09:\n')
    objwr = WrHierGO(gosubdag, item_marks=mark_dct, sortby=lambda o: o.item_id)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert gos_printed == ['GO:0000001', 'GO:0000002', 'GO:0000005', 'GO:0000010',
                           'GO:0000003', 'GO:0000004', 'GO:0000007', 'GO:0000009',
                           'GO:0000005', 'GO:0000010', 'GO:0000006', 'GO:0000008',
                           'GO:0000009', 'GO:0000010']
github tanghaibao / goatools / tests / test_optional_fields.py View on Github external
def test_write_hier_lim(gosubdag, out):
    """Limits hierarchy list to GO Terms specified by user."""
    # - GO:0000001      BP     9 L00 D00 top
    # -- GO:0000002     BP     2 L01 D01 B
    # -- GO:0000003     BP     7 L01 D01 A
    # --- GO:0000004    BP     2 L02 D02 b
    # ---- GO:0000007   BP     1 L03 D03 b1
    # ----- GO:0000009  BP     0 L04 D04 ab
    # --- GO:0000006    BP     3 L02 D02 a
    # ---- GO:0000008   BP     2 L03 D03 a1
    # ----- GO:0000009  BP     0 L04 D04 ab
    go_omit = ['GO:0000005']
    go_ids = [go_id for go_id in gosubdag.go2nt.keys() if go_id not in go_omit]
    out.write('\nTEST {NAME} OMIT: 05->10:\n'.format(NAME="MINI"))
    objwr = WrHierGO(gosubdag, include_only=go_ids, sortby=lambda o: o.item_id)
    gos_prtd = objwr.prt_hier_down("GO:0000001", out)
    print(gos_prtd)
    assert gos_prtd == ['GO:0000001', 'GO:0000002', 'GO:0000003', 'GO:0000004', 'GO:0000007',
                        'GO:0000009', 'GO:0000006', 'GO:0000008', 'GO:0000009', 'GO:0000010']
github tanghaibao / goatools / tests / test_write_hier.py View on Github external
"""Shortens hierarchy report by only printing branches once.

         Prints the 'entire hierarchy' of GO:0000005 the 1st time seen:

           ---     1 GO:0000005    L-02    D-02
           ----     0 GO:0000010   L-03    D-04

         Prints just GO:0000005 (ommit child GO:10) the 2nd time seen:

           ===     1 GO:0000005    L-02    D-02

         '=' is used in hierarchy mark to indicate that the pathes
             below the marked term have already been printed.
    """
    out.write('\nTEST ALL: Print branches just once:\n')
    objwr = WrHierGO(gosubdag, concise=True, sortby=lambda o: o.item_id)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert set(gos_printed) == set(objwr.gosubdag.go2nt)
    assert gos_printed == ['GO:0000001', 'GO:0000002', 'GO:0000005', 'GO:0000010',
                           'GO:0000003', 'GO:0000004', 'GO:0000007', 'GO:0000009',
                           'GO:0000005', 'GO:0000006', 'GO:0000008', 'GO:0000009',
                           'GO:0000010']
github tanghaibao / goatools / tests / test_optional_fields.py View on Github external
def test_write_hier_all(name, go_id, gosubdag, out):
    """test_optional_fields.py: Prints the entire mini GO hierarchy, with counts of children."""
    out.write('\nTEST {NAME} {GO}: Print all hierarchies:\n'.format(
        NAME=name, GO=go_id))
    #### dag.write_hier(go_id, out, num_child=True)
    WrHierGO(gosubdag).prt_hier_down(go_id, out)
    out.write("GOTerm: {}\n".format(gosubdag.go2obj[go_id].__repr__()))
github tanghaibao / goatools / tests / test_write_hier.py View on Github external
def write_hier_mrk_lst(gosubdag, out):
    """Print all paths, but mark GO Terms of interest. """
    mark_lst = ['GO:0000001', 'GO:0000003', 'GO:0000006', 'GO:0000008', 'GO:0000009']
    out.write('\nTEST MARK LIST: 01->03->06->08->09:\n')
    objwr = WrHierGO(gosubdag, item_marks=mark_lst, sortby=lambda o: o.item_id)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert gos_printed == ['GO:0000001', 'GO:0000002', 'GO:0000005', 'GO:0000010',
                           'GO:0000003', 'GO:0000004', 'GO:0000007', 'GO:0000009',
                           'GO:0000005', 'GO:0000010', 'GO:0000006', 'GO:0000008',
                           'GO:0000009', 'GO:0000010']
github tanghaibao / goatools / tests / test_write_hier.py View on Github external
def write_hier_lim(gosubdag, out):
    """Limits hierarchy list to GO Terms specified by user."""
    go_omit = ['GO:0000005', 'GO:0000010']
    go_ids = [go_id for go_id in gosubdag.go2obj if go_id not in go_omit]
    out.write('\nTEST OMIT: 05 and 10:\n')
    objwr = WrHierGO(gosubdag, include_only=go_ids, sortby=lambda o: o.item_id)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert not set(gos_printed).intersection(go_omit), "SHOULD NOT PRINT {GOs}".format(GOs=go_omit)
    assert gos_printed == ['GO:0000001', 'GO:0000002', 'GO:0000003', 'GO:0000004',
                           'GO:0000007', 'GO:0000009', 'GO:0000006', 'GO:0000008',
                           'GO:0000009']
github tanghaibao / goatools / goatools / cli / wr_hierarchy.py View on Github external
def prt_hier(self, prt=sys.stdout):
        """Write hierarchy below specfied GO IDs."""
        objwr = WrHierGO(self.gosubdag, **self.kws)
        assert self.goids, "NO VALID GO IDs WERE PROVIDED"
        if 'up' not in objwr.usrset:
            for goid in self.goids:
                objwr.prt_hier_down(goid, prt)
        else:
            objwr.prt_hier_up(self.goids, prt)