Exemplo n.º 1
0
def write_hier_up(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'}
    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_up(["GO:0000005"], out)
    assert gos_printed == ['GO:0000001', 'GO:0000002', 'GO:0000005', 'GO:0000003', 'GO:0000005']
Exemplo n.º 2
0
def write_hier_mrk(gosubdag, out):
    """Print all paths, but mark GO Terms of interest. """
    mark_lst = [
        'GO:0000001', 'GO:0000003', 'GO:0000006', 'GO:0000008', 'GO:0000009'
    ]
    objwr = WrHierGO(gosubdag, go_marks=mark_lst)
    objwr.prt_hier_down("GO:0000001", out)
Exemplo n.º 3
0
def test_write_hier_mrk(gosubdag, out):
    """Print all paths, but mark GO Terms of interest. """
    # > - GO:0000001      BP     9 L00 D00 top
    #   -- GO:0000002     BP     2 L01 D01 B
    #   --- GO:0000005    BP     1 L02 D02 c
    #   ---- GO:0000010   BP     0 L03 D04 ac
    # > -- 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:0000005    BP     1 L02 D02 c
    #   ---- GO:0000010   BP     0 L03 D04 ac
    # > --- GO:0000006    BP     3 L02 D02 a
    # > ---- GO:0000008   BP     2 L03 D03 a1
    # > ----- GO:0000009  BP     0 L04 D04 ab
    #   ----- GO:0000010  BP     0 L03 D04 ac
    mark_lst = [
        'GO:0000001', 'GO:0000003', 'GO:0000006', 'GO:0000008', 'GO:0000009'
    ]
    out.write('\nTEST {NAME} MARK: 01->03->06->08->09:\n'.format(NAME="MINI"))
    objwr = WrHierGO(gosubdag, item_marks=mark_lst, sortby=lambda o: o.item_id)
    gos_prtd = objwr.prt_hier_down("GO:0000001", out)
    assert gos_prtd == [
        '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'
    ]
Exemplo n.º 4
0
def write_hier_mrk(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: 01->03->06->08->09:\n')
    objwr = WrHierGO(gosubdag, go_marks=mark_lst)
    objwr.prt_hier_down("GO:0000001", out)
Exemplo n.º 5
0
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)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert not gos_printed.intersection(go_omit), "SHOULD NOT PRINT {GOs}".format(GOs=go_omit)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
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']
Exemplo n.º 8
0
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']
Exemplo n.º 9
0
def extract_hier_all(gosubdag, out, root_term, go2geneids, prize_dictionary):
    """write_hier.py: Prints the entire mini GO hierarchy, with counts of children."""
    out.write('\nTEST EXTRACTION: Print all hierarchies:\n')
    objwr = WrHierGO(gosubdag,
                     go2geneids=go2geneids,
                     prize_dictionary=prize_dictionary,
                     G=nx.DiGraph())
    obj = objwr.ext_hier_down(root_term, out)
    seeds = prize_dictionary.keys()
    layer_i_nodes = linear_threshold(obj.G, seeds, steps=INFLUENCE_N_STEPS)
    return (obj.vertices, obj.edges, obj.G, layer_i_nodes)
Exemplo n.º 10
0
def write_hier_norep(gosubdag, out):
    """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)
    gos_printed = objwr.prt_hier_down("GO:0000001", out)
    assert gos_printed == set(objwr.gosubdag.go2nt)
Exemplo n.º 11
0
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__()))
Exemplo n.º 12
0
def test_write_hier_mrk(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 {NAME} MARK: 01->03->06->08->09:\n'.format(NAME="MINI"))
    # TBD: Add go_marks fnc to wr_hier
    #### dag.write_hier("GO:0000001", out, go_marks=mark_lst)
    WrHierGO(gosubdag).prt_hier_down("GO:0000001", out)
Exemplo n.º 13
0
def test_write_hier_bp_mf_cc():
    """Test that write hierarchy writes all: BP, MF, CC"""
    fin_anno = os.path.join(REPO, 'gene2go')
    fin_dag = os.path.join(REPO, "go-basic.obo")
    _dnld_anno(fin_anno)
    #godag = get_godag(os.path.join(REPO, 'go-basic.obo'), loading_bar=None)

    print('\nTEST STORING ONLY ONE SPECIES')
    #### obj = Gene2GoReader(fin_anno)
    godag = get_godag(fin_dag)
    gene2gos = read_annotations(namespace='ALL')
    tcntobj = TermCounts(godag, gene2gos) if gene2gos else None
    gosubdag = GoSubDag(godag.keys(),
                        godag,
                        relationships=False,
                        tcntobj=tcntobj,
                        children=True,
                        prt=sys.stdout)
    objwr = WrHierGO(gosubdag)

    # 2020 11:
    #     594,748 GO lines under GO:0008150
    #      23,199 GO lines under GO:0003674
    #       6,259 GO lines under GO:0005575
    #     624,206 items WROTE: tmp_test_wr_hier_BP_MF_CC.txt
    assert len(_wr_hier(['BP', 'MF', 'CC'], gosubdag.go2nt, objwr)) > 600000
    assert len(_wr_hier([
        'BP',
    ], gosubdag.go2nt, objwr)) > 500000
    assert len(_wr_hier([
        'MF',
    ], gosubdag.go2nt, objwr)) > 20000
    assert len(_wr_hier([
        'CC',
    ], gosubdag.go2nt, objwr)) > 5000
Exemplo n.º 14
0
def test_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.go2nt.keys() if go_id not in go_omit]
    out.write('\nTEST {NAME} OMIT: 05->10:\n'.format(NAME="MINI"))
    # TBD: Add include_only fnc to wr_hier
    #### dag.write_hier("GO:0000001", out, include_only=go_ids)
    WrHierGO(gosubdag).prt_hier_down("GO:0000001", out)
Exemplo n.º 15
0
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']
Exemplo n.º 16
0
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'
    ]
Exemplo n.º 17
0
def test_write_hier_mrk(gosubdag, out):
    """Print all paths, but mark GO Terms of interest. """
    # > - GO:0000001      BP     9 L00 D00 top
    #   -- GO:0000002     BP     2 L01 D01 B
    #   --- GO:0000005    BP     1 L02 D02 c
    #   ---- GO:0000010   BP     0 L03 D04 ac
    # > -- 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:0000005    BP     1 L02 D02 c
    #   ---- GO:0000010   BP     0 L03 D04 ac
    # > --- GO:0000006    BP     3 L02 D02 a
    # > ---- GO:0000008   BP     2 L03 D03 a1
    # > ----- GO:0000009  BP     0 L04 D04 ab
    #   ----- GO:0000010  BP     0 L03 D04 ac
    mark_lst = ['GO:0000001', 'GO:0000003', 'GO:0000006', 'GO:0000008', 'GO:0000009']
    out.write('\nTEST {NAME} MARK: 01->03->06->08->09:\n'.format(NAME="MINI"))
    objwr = WrHierGO(gosubdag, item_marks=mark_lst, sortby=lambda o: o.item_id)
    gos_prtd = objwr.prt_hier_down("GO:0000001", out)
    assert gos_prtd == ['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']
Exemplo n.º 18
0
def write_hier_norep(gosubdag, out):
    """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']
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
 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"
     # kws = {k:v for k, v in self.kws.items() if k in self.kws_dct_wr}
     # objwr.write_hier_all(prt=prt, **kws)
     # max_indent=None, num_child=None, short_prt=False):
     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)
Exemplo n.º 21
0
def test_write_hier_norep(name, go_id, gosubdag, out):
    """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 {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]))
Exemplo n.º 22
0
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)
Exemplo n.º 23
0
def extract_hier_all(gosubdag, out, root_term, go2geneids):
    """write_hier.py: Prints the entire mini GO hierarchy, with counts of children."""
    out.write('\nTEST EXTRACTION: Print all hierarchies:\n')
    objwr = WrHierGO(gosubdag, go2geneids=go2geneids)
    obj = objwr.ext_hier_down(root_term, out)
    return (obj.vertices, obj.edges)
Exemplo n.º 24
0
def write_hier_all(gosubdag, out, root_term):
    """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(root_term, out)
    print len(gos_printed)
Exemplo n.º 25
0
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)