<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""
Evaluate the top X percent for enrichment for true positives.

"""

import os
import sys
import MySQLdb

c = MySQLdb.connect(host="localhost", port=3307, user="root", passwd="enter_your_password",db="project_aers").cursor()


table = 'psm_drug_events'
measure = 't_statistic'

arguments = {'table': table, 'measure': measure }

query = """
select count(*)
from %(table)s
join (select distinct stitch_id from gold_drug_ae_novartis) a using (stitch_id)
join (select distinct umls_id from gold_drug_ae_novartis) b using (umls_id)
""" % arguments
c.execute(query)
total_assoc = c.fetchall()[0][0]

query = """
select stitch_id, umls_id, gold is not null
from %(table)s
join (select distinct stitch_id from gold_drug_ae_novartis) a using (stitch_id)
join (select distinct umls_id from gold_drug_ae_novartis) b using (umls_id)
left join gold_drug_ae_novartis using (stitch_id, umls_id)
order by %(measure)s desc
""" % arguments
c.execute(query)

data = [row for row in c.fetchall()]

for top_x in range(0,101,5):
    if top_x == 0:
        top_x = 1
    
    top_n = int((top_x/100.0)*total_assoc)
    tp = sum([data[i][2] for i in range(top_n)])
    
    print &gt;&gt; sys.stderr, top_x, tp/float(top_n)
    


</pre></body></html>