コード例 #1
0
ファイル: workingfile.py プロジェクト: Aluriak/GBI
def pipeline_degree(g, essential_proteins):
    thresholds = (1, 2)  # TODO
    protein_count_total     = []  # number of proteins with a degree >= threshold
    protein_count_essential = []  # same for essential proteins
    degrees = centrality_degree(g)
    for threshold in thresholds:
        protein_count_total.append(0)
        protein_count_essential.append(0)
        for vertex, degree in degrees:
            if degree >= threshold:
                if vertex.attributes()['name'] in essential_proteins:
                    protein_count_essential[-1] += 1
                protein_count_total[-1] += 1
    # plotting proportions
    plot_stats(
        protein_count_total,
        protein_count_essential,
        thresholds,
    )
    # hypergeometric test
    pvalues = []
    for index, threshold in enumerate(thresholds):
        protein_count = len(g.vs)
        # total number of protein: protein_count,
        # subset of proteins: protein_count_total[index]
        # total number of essential proteins: len(essential_proteins)
        # number of essential proteins in subset: protein_count_essential[index]
        pvalues.append(phyper(
            protein_count, len(essential_proteins),
            protein_count_total[index],
            protein_count_essential[index]
        ))
    # plotting p-value evolution
    plot_phyper(pvalues, thresholds)
コード例 #2
0
ファイル: workingfile_correction.py プロジェクト: Aluriak/GBI
def pipeline_degree(g, essential_proteins, centrality, thresholds):
    # thresholds = (1, 2, 5, 8, 12, 20)  # TODO
    # thresholds = range(1, 20)  # TODO
    protein_count_total     = []  # number of proteins with a degree >= threshold
    protein_count_essential = []  # same for essential proteins
    # degrees = centrality_degree(g)
    degrees = [(v, centrality(v)) for v in g.vs]
    for threshold in thresholds:
        protein_count_total.append(0)
        protein_count_essential.append(0)
        for vertex, degree in degrees:
            if degree >= threshold:
                if vertex.attributes()['name'] in essential_proteins:
                    protein_count_essential[-1] += 1
                protein_count_total[-1] += 1
    # plotting proportions
    plot_stats(
        protein_count_total,
        protein_count_essential,
        thresholds,
    )
    # hypergeometric test
    pvalues = []
    for index, threshold in enumerate(thresholds):
        protein_count = len(g.vs)
        # total number of protein: protein_count,
        # subset of proteins: protein_count_total[index]
        # total number of essential proteins: len(essential_proteins)
        # number of essential proteins in subset: protein_count_essential[index]
        pvalues.append(phyper(
            protein_count, len(essential_proteins),
            protein_count_total[index],
            protein_count_essential[index]
        ))
    # plotting p-value evolution
    plot_phyper(pvalues, thresholds)
コード例 #3
0
ファイル: lib.py プロジェクト: Aluriak/GBI
def figure1Ning():

    g = ig.Graph()

    g.add_vertex('S. Townsendii')
    g.add_vertex('R. Eofficinalis')
    g.add_vertex('A. Vera')
    g.add_vertex('S. Alterniflora')
    g.add_vertex('A. Millefolium')

    g.add_edge(0, 1, weight=2.5)
    g.add_edge(1, 2, weight=2.0)
    g.add_edge(2, 3, weight=1.0)
    g.add_edge(3, 4, weight=4.0)
    g.add_edge(1, 3, weight=2.5)
    g.add_edge(0, 4, weight=5.0)
    g.add_edge(0, 3, weight=1.5)

    visual_style = {
        'vertex_label': g.vs['name'],
        'edge_label'  : g.es['weight'],
        'layout'      : g.layout_circle(),
        'margin'      : 150,
        'autocurve'   : False,
    }
    ig.plot(g, **visual_style)

    exit()

    # plot_stats(
        # [3000, 2000, 1000],
        # [ 300,  200,  100],
        # [  10,   20,   30],
    # )
    plot_phyper(
        (0.23, 0.42, 0.2),
        (3, 4, 8),
    )
    exit()
    plot_dumb_stats()

    g = ig.Graph(directed=False)
    # i.plot(g)
    # print(help(g.add_vertex))
    for i in range(1, 6):
        g.add_vertex(i, label='node ' + str(i))
    # print(help(g.add_edge))
    g.es["weight"] = 1.0  # make the graph a weighed one
    g[0, 1] = 2.5
    g[0, 1] = 2.5
    # g[1, 2] = 2.0  # equivalent to g.add_edge(1, 2, weight=2.0)
    g.add_edge(1, 2, weight=2.0, color='green')
    g[2, 3] = 1.0
    g[3, 4] = 4.0
    g[0, 4] = 5.0
    g[0, 3] = 1.5
    g[1, 3] = 2.5


    # CENTRALITY
    for vertex in g.vs:
        print('VERTEX:', vertex)
        print('\tdegree:', vertex.degree())
        print('\tbetweenness:', vertex.betweenness())
        print('\tcloseness:', vertex.closeness())

    # PLOT
    visual_style = {
        'vertex_label': g.vs['label'],
        'edge_label'  : g.es['weight'],
        'layout'      : g.layout_circle(),
        'margin'      : 150,
    }
    ig.plot(g, **visual_style)

    rnn = RkNN(g, k=2)
    rnn_visual_style = {
        'vertex_label': rnn.vs['label'],
        'edge_label'  : rnn.es['weight'],
        'layout'      : rnn.layout_kamada_kawai(),
        'margin'      : 150,
        'autocurve'  : False,
    }
    ig.plot(rnn, **rnn_visual_style)
コード例 #4
0
def figure1Ning():

    g = ig.Graph()

    g.add_vertex('S. Townsendii')
    g.add_vertex('R. Eofficinalis')
    g.add_vertex('A. Vera')
    g.add_vertex('S. Alterniflora')
    g.add_vertex('A. Millefolium')

    g.add_edge(0, 1, weight=2.5)
    g.add_edge(1, 2, weight=2.0)
    g.add_edge(2, 3, weight=1.0)
    g.add_edge(3, 4, weight=4.0)
    g.add_edge(1, 3, weight=2.5)
    g.add_edge(0, 4, weight=5.0)
    g.add_edge(0, 3, weight=1.5)

    visual_style = {
        'vertex_label': g.vs['name'],
        'edge_label': g.es['weight'],
        'layout': g.layout_circle(),
        'margin': 150,
        'autocurve': False,
    }
    ig.plot(g, **visual_style)

    exit()

    # plot_stats(
    # [3000, 2000, 1000],
    # [ 300,  200,  100],
    # [  10,   20,   30],
    # )
    plot_phyper(
        (0.23, 0.42, 0.2),
        (3, 4, 8),
    )
    exit()
    plot_dumb_stats()

    g = ig.Graph(directed=False)
    # i.plot(g)
    # print(help(g.add_vertex))
    for i in range(1, 6):
        g.add_vertex(i, label='node ' + str(i))
    # print(help(g.add_edge))
    g.es["weight"] = 1.0  # make the graph a weighed one
    g[0, 1] = 2.5
    g[0, 1] = 2.5
    # g[1, 2] = 2.0  # equivalent to g.add_edge(1, 2, weight=2.0)
    g.add_edge(1, 2, weight=2.0, color='green')
    g[2, 3] = 1.0
    g[3, 4] = 4.0
    g[0, 4] = 5.0
    g[0, 3] = 1.5
    g[1, 3] = 2.5

    # CENTRALITY
    for vertex in g.vs:
        print('VERTEX:', vertex)
        print('\tdegree:', vertex.degree())
        print('\tbetweenness:', vertex.betweenness())
        print('\tcloseness:', vertex.closeness())

    # PLOT
    visual_style = {
        'vertex_label': g.vs['label'],
        'edge_label': g.es['weight'],
        'layout': g.layout_circle(),
        'margin': 150,
    }
    ig.plot(g, **visual_style)

    rnn = RkNN(g, k=2)
    rnn_visual_style = {
        'vertex_label': rnn.vs['label'],
        'edge_label': rnn.es['weight'],
        'layout': rnn.layout_kamada_kawai(),
        'margin': 150,
        'autocurve': False,
    }
    ig.plot(rnn, **rnn_visual_style)