#!/usr/local/bin/python3.3 import cgi import cgitb import pymysql import datetime from functions import get_cookies, phead, ptail, BEDintersect, BEDcopy cgitb.enable() #this is a test cookie = get_cookies() if cookie: print(cookie) fname = cookie["fname"].value lname = cookie["lname"].value name = " ".join((fname, lname)) admin = cookie["admin"].value uid = cookie["uid"].value uname = cookie["uname"].value form = cgi.FieldStorage() eid = form.getvalue('eid') qexname = "select title from Experiment where eid = '%s'" % eid data = [] #data should be in the order: user, passwd, host, db with open('./dbinfo.txt') as f: for line in f: line = line.strip('\n') data.append(line) info = [] for item in data: item = item.split(':') info.append(item) user=info[0][1] passwd=info[1][1] host=info[2][1] db=info[3][1] def runQuery(query, user, passwd): connection = pymysql.connect(host=host,db=db,user=user,passwd=passwd) cursor = connection.cursor() cursor.execute(query) res = cursor.fetchall() cursor.close() connection.close() return res def Copy(bid,name, location, des1, des2, des3, command, uname, cmid, wmid,stringency, source, eid): connection = pymysql.connect(host=host, user=user, db=db, passwd=passwd) cursor = connection.cursor() query1 = """INSERT INTO BEDfile (bid,name, location, description1, description2, description3, upload_date, bedtoolcommand, uploader, cmid, wmid,stringency, source) VALUES (%s, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", %s, %s,%s,%s) """%(int(bid),name, location, des1, des2, des3, str(datetime.datetime.now())[:-7], command, uname, int(cmid), int(wmid),stringency, source) query2 = """INSERT INTO ExperimentBEDfile (eid,bid) VALUES(%s,%s)"""%(bid,eid) cursor.execute(query1) cursor.execute(query2) connection.commit() cursor.close() connection.close() print("Content-type: text/html\n") phead(name, admin) print("""
Bedtools Intersect:
Note: You must be in a experiment to use this function!
All BED files:
') q1 = """ select bid, location, b.name, w.name, c.name, description1, description2, description3, uploader, upload_date, bedtoolcommand from BEDfile b join WetlabMethod w using(wmid) join ComputationalMethod c using(cmid) order by upload_date desc, b.name asc; """ elif admin == "1" and eid: exname = runQuery(qexname, user, passwd)[0][0] print('All BED files in experiment %s:
' % exname) q1 = """ select b.bid, location, b.name, w.name, c.name, description1, description2, description3, uploader, upload_date, bedtoolcommand from BEDfile b join ExperimentBEDfile using(bid) join WetlabMethod w using(wmid) join ComputationalMethod c using(cmid) where eid = "%s" order by upload_date desc, b.name asc; """ % eid elif admin == "0" and eid == None: print('All BED files:
') q1 = """ select bid, location, b.name, w.name, c.name, description1, description2, description3, uploader, upload_date, bedtoolcommand from BEDfile b join WetlabMethod w using(wmid) join ComputationalMethod c using(cmid) where uploader = "%s" order by upload_date desc, b.name asc; """ % uname else: exname = runQuery(qexname, user, passwd)[0][0] print('All BED files in experiment %s:
' % exname) q1 = """ select b.bid, location, b.name, w.name, c.name, description1, description2, description3, uploader, upload_date, bedtoolcommand from BEDfile b join ExperimentBEDfile using(bid) join WetlabMethod w using(wmid) join ComputationalMethod c using(cmid) where eid = "%s" and uploader = "%s" order by upload_date desc, b.name asc; """ % (eid,uname) res1 = runQuery(q1, user, passwd) if len(res1) > 0: print("""ID | BED file | Wetlab method | Computational method | Info1 | Info2 | Info3 | Uploader | Upload time | bedtools command | Download | """) for j in range(len(row)): if j == 0 or j == 2: print(""" | %s | """ % (str(row[0]),str(row[j]))) elif j == 1: pass else: print("%s | " % str(row[j])) print("""Download | """ % row[1]) print("") print("
---|
Copy the BEDfile: