def plot_go_vs_p(list_name):
    """
    A function to plot GO Term vs P-value with label of gene count on each bar
    ================================================
    example:

        >>>from intermine import query_manager as qm
        >>>b.plot_go_vs_p("PL_obesityMonogen_ORahilly09")

    """
    link = "http://registry.intermine.org/service/instances/" + mine
    r = requests.get(link)

    dict = json.loads(r.text)
    url = dict["instance"]["url"]
    service = Service(url)

    lm = service.list_manager()
    store = lm.get_list(name=list_name)
    r = store.calculate_enrichment(widget="go_enrichment_for_gene")

    gene_count = []
    identifier = []
    p_value = []
    object_count = 0
    for i in r:
        if object_count < 5:
            gene_count.append(i.matches)
            identifier.append(i.identifier)
            p_value.append(i.p_value)
            object_count = object_count + 1
        else:
            if object_count >= 5:
                break
    y = pd.Series(p_value)
    x = identifier
    # Plot the figure.

    ax = y.plot(kind='bar')
    ax.set_title('GO Term vs p-value (Label: Gene count)')
    ax.set_xlabel('GO Term')
    ax.set_ylabel('p_value')
    ax.set_xticklabels(x, rotation='horizontal')

    rects = ax.patches

    def autolabel(rects, ax):
        i = 0
        for rect in rects:
            x = rect.get_x() + rect.get_width()/2.
            y = rect.get_height()
            ax.annotate(gene_count[i], (x, y), xytext=(0, 5),
                        textcoords="offset points",
                        ha='center', va='bottom')
            i = i+1

    autolabel(ax.patches, ax)

    ax.margins(y=0.1)
    plt.show()
Esempio n. 2
0
    def attack(self):
        username = "******".format(self.ident)
        password = "******"

        try:
            s = Service(self.service.root, username, password)
            s.deregister(s.get_deregistration_token())
            self.counter.add(3)
        except:
            pass

        s = self.service.register(username, password)
        self.LOG.debug("Registered user " + username)
        self.counter.add(1)

        c = 0
        classes = s.model.classes.values()
        self.counter.add(1)

        classkeys = s._get_json('/classkeys')['classes']
        self.counter.add(1)

        while c == 0:
            table = random.choice(classes)
            if not (table.has_id and table.name in classkeys):
                continue
            query = s.query(table.name).select(classkeys[table.name][0])

            c = query.count()
            self.counter.add(1)

        n = random.randint(1, min(100, c))
        members = random.sample(map(lambda r: r[0], query.rows()), n)
        self.counter.add(1)

        self.LOG.debug("Will construct list of %s with: %r", table.name, members)

        with s.list_manager() as lm:
            l = lm.create_list(members, table.name)
            self.LOG.debug('Created list %s, size: %d', l.name, l.size)
            self.counter.add(1)

        try:
            s.deregister(s.get_deregistration_token())
            self.counter.add(2)
        except:
            pass
Esempio n. 3
0
def plot_go_vs_p(list_name):
    """
    A function to plot GO Term vs P-value with label of gene count on each bar
    ================================================
    example:

        >>>from intermine import query_manager as qm
        >>>b.plot_go_vs_p("PL_obesityMonogen_ORahilly09")

    """
    link = "http://registry.intermine.org/service/instances/" + mine
    r = requests.get(link)

    dict = json.loads(r.text)
    url = dict["instance"]["url"]
    service = Service(url)

    lm = service.list_manager()
    store = lm.get_list(name=list_name)
    r = store.calculate_enrichment(widget="go_enrichment_for_gene")

    gene_count = []
    identifier = []
    p_value = []
    object_count = 0
    for i in r:
        if object_count < 5:
            gene_count.append(i.matches)
            identifier.append(i.identifier)
            p_value.append(i.p_value)
            object_count = object_count + 1
        else:
            if object_count >= 5:
                break
    y = pd.Series(p_value)
    x = identifier
    # Plot the figure.

    ax = y.plot(kind='bar')
    ax.set_title('GO Term vs p-value (Label: Gene count)')
    ax.set_xlabel('GO Term')
    ax.set_ylabel('p_value')
    ax.set_xticklabels(x, rotation='horizontal')

    rects = ax.patches

    def autolabel(rects, ax):
        i = 0
        for rect in rects:
            x = rect.get_x() + rect.get_width() / 2.
            y = rect.get_height()
            ax.annotate(gene_count[i], (x, y),
                        xytext=(0, 5),
                        textcoords="offset points",
                        ha='center',
                        va='bottom')
            i = i + 1

    autolabel(ax.patches, ax)

    ax.margins(y=0.1)
    plt.show()