from __future__ import with_statement
import os, glob
mypath = '/home/sb/bioinfo/test/'
AACharge = {"C":-.045,"D":-.999,"E":-.998,
            "H":.091,"K":1,"R":1,"Y":-.001}
for x in glob.glob(mypath+'*.fas'):
    with open(os.path.join(mypath,x),'U') as fh:
        name = fh.readline()[1:-1]
        seq = ""
        for line in fh:
            seq += line[:-1].upper()
    charge = -0.002
    for aa in seq:
        charge += AACharge.get(aa,0)
    with open(os.path.join(mypath,'netvalue.txt'),'a') as fh:
        fh.write("%s,%s\n"%(name,charge))

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