Esempio n. 1
0
def index(req):

    try:
        species1 = req.form.getfirst('sp1')
        species2 = req.form.getfirst('sp2')
    except:
        return "<font color='red'>Please select species from both lists.</font>"

    if species1 > species2:
        species1, species2 = species2, species1

    header = "block_no,block_score,e_value,locus_1,locus_2,ka,ks"
    sql1 = "SELECT %s from block WHERE note='%s_%s' AND chr_1 is not NULL AND chr_2 is not NULL" % (header, species1, species2)
    results = myconnect(sql1)
    if results==-1: return DB_FAIL_MSG

    # write to intermediate file
    os.chdir("/var/www/duplication/usr/")
    file_name = "%s_%s_block.csv.gz" % (species1, species2)

    if not os.path.exists(file_name):
        import gzip 
        f = gzip.open(file_name, "wb")
        f.write(header + "\n")
        for r in results:
            f.write(",".join(str(x) for x in r) + "\n")
        f.close()

    return "%d records found. Transferring data ..." % len(results)
Esempio n. 2
0
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from pylab import * 

sys.path.insert(0, op.join(op.dirname(__file__), ".."))
from preferences import myconnect

import itertools
import os


# generate data file
sql = "SELECT note, ks FROM block"
results = list(myconnect(sql))
results.sort()

fontdict = {"color":"b", "fontweight":"bold", "size":10}

def my_hist(l, interval, max_r, c):
    n = []; p = []
    total_len = len(l)
    if total_len==0: return 0
    for i in arange(0, max_r, interval):
        xmin, xmax = i-.5*interval, i+.5*interval
        nx = [x for x in l if xmin<=x<xmax]
        n.append(i)
        p.append(len(nx)*100./total_len)
    ax.set_xlabel('Synonymous substitutions per site (Ks)', fontdict)
    ax.set_ylabel('Percentage of %d gene pairs'%total_len, fontdict)
Esempio n. 3
0
def index(req):
    q = req.form.getfirst("term")
    query = "SELECT locus FROM loci WHERE locus LIKE '%s%%' ORDER by locus limit 5" % q
    res = myconnect(query)
    return json.dumps([x[0] for x in res])