PEATDB/Ekin/Titration.py
def makepKasTable(cls, pkainfo=None, outfile=None, primary=False):
        """make table of pka fit/analysis results"""
        if outfile != None:
            saveout = sys.stdout
            fsock = open(outfile, 'w')
            sys.stdout = fsock

        kys = sorted(pkainfo.keys())
        resinfo = {}
        #for r in cls.titratable:
        for r in cls.residue_names.keys():
            resinfo[r] = {}

        print '<table id="summary" width=80% align=center cellspacing="0">'
        row=1;c=1
        print '<th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th>'\
                    % ('protein', 'dataset', 'res type', 'resnum', 'atom', '&Delta&delta', '&Delta&delta err', 'pKa', 'pKa err', 'model')
        print '<tr>'

        for name in kys:
            for d in pkainfo[name]:
                PI = pkainfo[name][d]
                resnum = PI['resnum']
                res = PI['res']
                atom = PI['atom']
                model = PI['model']
                for p in PI:
                    if not 'pK' in p: continue
                    pka = PI[p][p]
                    span = PI[p]['span']

                    if primary == True and not '1 pKa' in model:
                        continue
                    if pkainfo[name][d][p].has_key('pkaerror'):
                        pkaerr = pkainfo[name][d][p]['pkaerror']
                        spanerr = pkainfo[name][d][p]['spanerror']
                    else:
                        pkaerr = 0
                        spanerr=0

                    if not resinfo[res].has_key(atom):
                        resinfo[res][atom]={}
                        resinfo[res][atom]['pkas']=[]
                        resinfo[res][atom]['pkaerrs']=[]
                        resinfo[res][atom]['spans']=[]
                        resinfo[res][atom]['spanerrs']=[]
                    resinfo[res][atom]['pkas'].append(pka)
                    resinfo[res][atom]['pkaerrs'].append(pkaerr)
                    resinfo[res][atom]['spans'].append(span)
                    resinfo[res][atom]['spanerrs'].append(spanerr)
                    #print name, res, resnum, atom, span, spanerr, pka, pkaerr, model
                    if pka != None:
                        print '<td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%s</td>'  \
                                    % (name, d, res, resnum, atom, span, spanerr, pka, pkaerr, model)
                        print '</tr>'
        print '</table>'
        print '<br>'
        #summary table for average pKas per residue
        print '<h2>Average pKa and &Delta&delta per atom/residue</h2><br\Delta'
        print '<table id="summary" width=60% align=center cellspacing="0">'
        print '<tr><td>Residue</td> <td>atom</td> <td>average &Delta&delta</td> <td>average &Delta&delta err</td> <td>average pKa</td> <td>av pKa error</td> <td>no. curves</td></tr>'
        for r in resinfo:
            allpkas=[]
            allspans=[]
            allpkaerrs=[]
            for a in resinfo[r]:
                numcurves = len(resinfo[r][a]['pkas'])
                averagepka = numpy.mean(resinfo[r][a]['pkas'])
                averagepkaerr = numpy.mean(resinfo[r][a]['pkaerrs'])
                averagespan = numpy.mean(resinfo[r][a]['spans'])
                averagespanerr = numpy.mean(resinfo[r][a]['spanerrs'])
                minpka = min(resinfo[r][a]['pkas'])
                maxpka = min(resinfo[r][a]['pkas'])
                print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.2f</td> <td>%s</td></tr>' \
                    %(r, a, averagespan, averagespanerr, averagepka, averagepkaerr, numcurves)
                allpkas += resinfo[r][a]['pkas']
                allpkaerrs += resinfo[r][a]['pkaerrs']
                allspans += resinfo[r][a]['spans']

            finalpkaerr = numpy.sqrt(sum(numpy.square(allpkaerrs)))
            print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.1f</td> <td>%s</td></tr>' \
                %(r, 'All', numpy.average(allspans), numpy.std(allspans), numpy.average(allpkas), numpy.std(allpkas), len(allpkas))

        print '</table>'
        print '<br>'
        if outfile != None:
            sys.stdout.flush()
            sys.stdout = saveout
            fsock.close()
        return
make table of pka fit/analysis results
make table of pka fit/analysis results
make table of pka fit / analysis results
def makepKasTable(cls, pkainfo=None, outfile=None, primary=False):
        if outfile != None:
            saveout = sys.stdout
            fsock = open(outfile, 'w')
            sys.stdout = fsock
        kys = sorted(pkainfo.keys())
        resinfo = {}
        for r in cls.residue_names.keys():
            resinfo[r] = {}
        print '<table id="summary" width=80% align=center cellspacing="0">'
        row=1;c=1
        print '<th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th>'\
                    % ('protein', 'dataset', 'res type', 'resnum', 'atom', '&Delta&delta', '&Delta&delta err', 'pKa', 'pKa err', 'model')
        print '<tr>'
        for name in kys:
            for d in pkainfo[name]:
                PI = pkainfo[name][d]
                resnum = PI['resnum']
                res = PI['res']
                atom = PI['atom']
                model = PI['model']
                for p in PI:
                    if not 'pK' in p: continue
                    pka = PI[p][p]
                    span = PI[p]['span']
                    if primary == True and not '1 pKa' in model:
                        continue
                    if pkainfo[name][d][p].has_key('pkaerror'):
                        pkaerr = pkainfo[name][d][p]['pkaerror']
                        spanerr = pkainfo[name][d][p]['spanerror']
                    else:
                        pkaerr = 0
                        spanerr=0
                    if not resinfo[res].has_key(atom):
                        resinfo[res][atom]={}
                        resinfo[res][atom]['pkas']=[]
                        resinfo[res][atom]['pkaerrs']=[]
                        resinfo[res][atom]['spans']=[]
                        resinfo[res][atom]['spanerrs']=[]
                    resinfo[res][atom]['pkas'].append(pka)
                    resinfo[res][atom]['pkaerrs'].append(pkaerr)
                    resinfo[res][atom]['spans'].append(span)
                    resinfo[res][atom]['spanerrs'].append(spanerr)
                    if pka != None:
                        print '<td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%s</td>'  \
                                    % (name, d, res, resnum, atom, span, spanerr, pka, pkaerr, model)
                        print '</tr>'
        print '</table>'
        print '<br>'
        print '<h2>Average pKa and &Delta&delta per atom/residue</h2><br\Delta'
        print '<table id="summary" width=60% align=center cellspacing="0">'
        print '<tr><td>Residue</td> <td>atom</td> <td>average &Delta&delta</td> <td>average &Delta&delta err</td> <td>average pKa</td> <td>av pKa error</td> <td>no. curves</td></tr>'
        for r in resinfo:
            allpkas=[]
            allspans=[]
            allpkaerrs=[]
            for a in resinfo[r]:
                numcurves = len(resinfo[r][a]['pkas'])
                averagepka = numpy.mean(resinfo[r][a]['pkas'])
                averagepkaerr = numpy.mean(resinfo[r][a]['pkaerrs'])
                averagespan = numpy.mean(resinfo[r][a]['spans'])
                averagespanerr = numpy.mean(resinfo[r][a]['spanerrs'])
                minpka = min(resinfo[r][a]['pkas'])
                maxpka = min(resinfo[r][a]['pkas'])
                print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.2f</td> <td>%s</td></tr>' \
                    %(r, a, averagespan, averagespanerr, averagepka, averagepkaerr, numcurves)
                allpkas += resinfo[r][a]['pkas']
                allpkaerrs += resinfo[r][a]['pkaerrs']
                allspans += resinfo[r][a]['spans']
            finalpkaerr = numpy.sqrt(sum(numpy.square(allpkaerrs)))
            print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.1f</td> <td>%s</td></tr>' \
                %(r, 'All', numpy.average(allspans), numpy.std(allspans), numpy.average(allpkas), numpy.std(allpkas), len(allpkas))
        print '</table>'
        print '<br>'
        if outfile != None:
            sys.stdout.flush()
            sys.stdout = saveout
            fsock.close()
        return
def makepKasTable ( cls , pkainfo = None , outfile = None , primary = False ) : if outfile != None : saveout = sys . stdout fsock = open ( outfile , 'w' ) sys . stdout = fsock kys = sorted ( pkainfo . keys ( ) ) resinfo = { } for r in cls . residue_names . keys ( ) : resinfo [ r ] = { } print '<table id="summary" width=80% align=center cellspacing="0">' row = 1 ; c = 1 print '<th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th> <th>%s</th>' % ( 'protein' , 'dataset' , 'res type' , 'resnum' , 'atom' , '&Delta&delta' , '&Delta&delta err' , 'pKa' , 'pKa err' , 'model' ) print '<tr>' for name in kys : for d in pkainfo [ name ] : PI = pkainfo [ name ] [ d ] resnum = PI [ 'resnum' ] res = PI [ 'res' ] atom = PI [ 'atom' ] model = PI [ 'model' ] for p in PI : if not 'pK' in p : continue pka = PI [ p ] [ p ] span = PI [ p ] [ 'span' ] if primary == True and not '1 pKa' in model : continue if pkainfo [ name ] [ d ] [ p ] . has_key ( 'pkaerror' ) : pkaerr = pkainfo [ name ] [ d ] [ p ] [ 'pkaerror' ] spanerr = pkainfo [ name ] [ d ] [ p ] [ 'spanerror' ] else : pkaerr = 0 spanerr = 0 if not resinfo [ res ] . has_key ( atom ) : resinfo [ res ] [ atom ] = { } resinfo [ res ] [ atom ] [ 'pkas' ] = [ ] resinfo [ res ] [ atom ] [ 'pkaerrs' ] = [ ] resinfo [ res ] [ atom ] [ 'spans' ] = [ ] resinfo [ res ] [ atom ] [ 'spanerrs' ] = [ ] resinfo [ res ] [ atom ] [ 'pkas' ] . append ( pka ) resinfo [ res ] [ atom ] [ 'pkaerrs' ] . append ( pkaerr ) resinfo [ res ] [ atom ] [ 'spans' ] . append ( span ) resinfo [ res ] [ atom ] [ 'spanerrs' ] . append ( spanerr ) if pka != None : print '<td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%.2f</td> <td>%s</td>' % ( name , d , res , resnum , atom , span , spanerr , pka , pkaerr , model ) print '</tr>' print '</table>' print '<br>' print '<h2>Average pKa and &Delta&delta per atom/residue</h2><br\Delta' print '<table id="summary" width=60% align=center cellspacing="0">' print '<tr><td>Residue</td> <td>atom</td> <td>average &Delta&delta</td> <td>average &Delta&delta err</td> <td>average pKa</td> <td>av pKa error</td> <td>no. curves</td></tr>' for r in resinfo : allpkas = [ ] allspans = [ ] allpkaerrs = [ ] for a in resinfo [ r ] : numcurves = len ( resinfo [ r ] [ a ] [ 'pkas' ] ) averagepka = numpy . mean ( resinfo [ r ] [ a ] [ 'pkas' ] ) averagepkaerr = numpy . mean ( resinfo [ r ] [ a ] [ 'pkaerrs' ] ) averagespan = numpy . mean ( resinfo [ r ] [ a ] [ 'spans' ] ) averagespanerr = numpy . mean ( resinfo [ r ] [ a ] [ 'spanerrs' ] ) minpka = min ( resinfo [ r ] [ a ] [ 'pkas' ] ) maxpka = min ( resinfo [ r ] [ a ] [ 'pkas' ] ) print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.2f</td> <td>%s</td></tr>' % ( r , a , averagespan , averagespanerr , averagepka , averagepkaerr , numcurves ) allpkas += resinfo [ r ] [ a ] [ 'pkas' ] allpkaerrs += resinfo [ r ] [ a ] [ 'pkaerrs' ] allspans += resinfo [ r ] [ a ] [ 'spans' ] finalpkaerr = numpy . sqrt ( sum ( numpy . square ( allpkaerrs ) ) ) print '<tr><td>%s</td> <td>%s</td> <td>%.2f</td> <td>%.2f</td> <td>%.1f</td> <td>%.1f</td> <td>%s</td></tr>' % ( r , 'All' , numpy . average ( allspans ) , numpy . std ( allspans ) , numpy . average ( allpkas ) , numpy . std ( allpkas ) , len ( allpkas ) ) print '</table>' print '<br>' if outfile != None : sys . stdout . flush ( ) sys . stdout = saveout fsock . close ( ) return
make table of pka fit/analysis results
make table of pka fit / analysis results
"""make table of pka fit/analysis results""" #for r in cls.titratable: #print name, res, resnum, atom, span, spanerr, pka, pkaerr, model #summary table for average pKas per residue
cls
pkainfo
outfile
primary