#!/usr/bin/env python

from selector import Selector
from yaro import Yaro

rootdir = '/var/www/mywebsite/htdocs/'

def index(req):
    return open(rootdir+'form.html').read()

def _chargeandprop(AAseq):
    protseq = AAseq.upper()
    charge = -0.002
    cp = 0
    AACharge = {"C":-.045,"D":-.999,"E":-.998,"H":.091,
    for aa in protseq:
        charge += AACharge.get(aa,0)
        if aa in AACharge:
            cp += 1
    prop = 100.*cp/len(AAseq)
    return (charge,prop)

def netc(req):
    seq = req.form.get('seq','')
    title = req.form.get('title','')
    prop = req.form.get('prop','')
    charge,propval = _chargeandprop(seq)
    yield "<html><body>Job title: %s<br/>"%title+\
          "Your sequence is:<br/>%s<br/>"%seq+\
          "Net charge: %s<br/>"%charge
    if prop=="y":
        yield "Proportion of charged AA: %.2f"%propval
    yield "<br/></body></html>"

s = Selector(wrap=Yaro)
s.add('/', GET=index)
s.add('/netc', POST=netc)
application = s    

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.