#!/usr/bin/env python
from mod_python import apache
from mod_python.util import FieldStorage

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

def handler(req):
    req.content_type='text/html'
    fs = dict(FieldStorage(req))
    charge,pvalue = chargeandprop(fs['seq'])
    req.write("<html><body>Job title:"+fs['title']+"<br/>"+
              "Your sequence is:<br/>"+fs['seq']+"<br/>"+
              "Net charge:"+str(charge)+"<br/>")
    if fs['prop']=="y":
        req.write("Proportion of charged AA: %.2f "
                   %pvalue)
    req.write("<br/></body></html>")
    return apache.OK

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