PEATDB/Ekin/Titration.py
def analysepKas(cls, pkainfo, satoms='all', path=None, exclude=[],
                        silent=False, prefix=''):
        """Read in the pkainfo dict from extractpkas method and do
          additional analyses, makes plots for titdb"""

        if path==None:
            path=os.getcwd()
        aminoacids = cls.residue_names.keys()
        titratable = cls.titratable

        titrspans = {}      #histogram of reliable spans, for titr groups
        primaryspans = {}   #primary spans, for titr groups
        allspans = {}       #histogram of all spans for all groups
        titravgshfts = {}   #histogram of average shifts
        atomshfts = {}      #store per atom
        spansbyres = {}     #sort out spans by residue

        for t in aminoacids:
            titravgshfts[t]=[]
            atomshfts[t]={}
        for t in titratable:
            titrspans[t]=[]
            primaryspans[t]=[]
            spansbyres[t]={}

        for t in aminoacids:
            allspans[t] = []

        if silent == False:
            print
            print 'Analysing pKa info..'

        count=0
        titrcount = 0
        for name in pkainfo.keys():
            for d in pkainfo[name].keys():
                PI = pkainfo[name][d]
                res = PI['res']
                atom = PI['atom']
                model = PI['model']
                for p in PI:
                    #print p, d, '<p>'
                    if 'pK' in p:
                        count += 1
                        pval = PI[p][p]
                        sp = PI[p]['span']

                        #print  d, p, pval,  sp
                        #change atom if handling HB2/3 in ASP, HIS and GLU, so
                        #we group them together as HB* for the stats

                        #move to extract??
                        if res in ['ASP','GLU','HIS'] and atom in ['HB2', 'HB3']:
                            atom = 'HB*'
                        elif res == 'GLU' and atom in ['HG2','HG3']:
                            atom = 'HG*'

                        if model == '1 pKa 2 Chemical shifts' and res in titratable:
                            primaryspans[res].append(sp)
                        elif res in titratable:
                            titrspans[res].append(sp)
                            titrcount+=1
                        else:
                            allspans[res].append(sp)

                        #assign spans by atom

                        if not atomshfts[res].has_key(atom):
                            atomshfts[res][atom] = []
                        if satoms != 'all' and not atom in satoms:
                            if silent == False:
                                print 'excluding atom', atom
                                continue
                        else:
                            atomshfts[res][atom].append(sp)

            '''if allpkas != None:
                for s in allsp:
                    if s >= maxspan:
                        continue
                    allspans[res].append(s)
                    if res in titratable:
                        spansbyres[res][s] = prot+'__'+d'''

        #lenallspans=Utils.getlenDict(allspans)

        lentitrspans=Utils.getlenDict(titrspans)
        lenprimaryspans=Utils.getlenDict(primaryspans)
        #lentitrallspans=Utils.getlenDict(allspans, keys=titratable)

        #remove primary from allspans to get leftover ones
        otherspans = {}
        for k in titrspans:
            otherspans[k] = list( set(allspans[k]) - set(titrspans[k]) )
            #otherspans[k] = list( set(allspans[k]) - (set(titrspans[k]) | set(primaryspans[k])))

        print '<div>'
        print 'Total residues: %s <br>' %count
        print 'of which titratable grps: %s <br>' %titrcount
        #print 'All pkas: %s <br>' %lenallspans
        print 'Titratable "reliable" pkas: %s <br>' %(lentitrspans + lenprimaryspans)
        print 'Titratable "primary" pkas: %s <br>' %lenprimaryspans
        #print 'Titratable all pkas: %s <br>' %lentitrallspans
        print '</div>'
        print '<br>'

        '''for r in atomshfts:
            print r
            for a in atomshfts[r]:
                print a, len(atomshfts[r][a])'''

        pylab.rc("font", family="serif")
        pylab.rc("font", size=10)
        pylab.rc('text', usetex=True)

        fig1 = pylab.figure(1,figsize=(10,6))
        fig1.text(0.5, 0.95, 'Distribution of $\Delta\delta$ of extracted pKas: '+prefix, horizontalalignment='center',
                            fontproperties=FontProperties(size=18))

        #plot multiple histograms together in multiple subplots
        hdata = {}
        for k in titrspans:
            hdata[k] = {'primary':primaryspans[k], 'reliable':titrspans[k], 'other':otherspans[k]}

        cls.doMultipleHistograms(fig1, hdata, bins=30, xlabel='$\Delta\delta$ (ppm)',
                                ylabel='no. datasets', xticks=False, yticks=False)
        img1 = prefix+'deltashifts_dist.png'
        fig1.savefig(os.path.join(path,img1), dpi=100)
        '''pylab.clf()
        fig6 = pylab.figure(6,figsize=(10,6))
        fig6.text(0.5, 0.95, 'Distribution: $\Delta\delta$ by atom: '+prefix, horizontalalignment='center',
                            fontproperties=FontProperties(size=18))

        cls.doMultipleHistograms(fig6, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img2 = prefix+'deltashifts_byatom.png'
        fig6.savefig(os.path.join(path,img2) ,dpi=100)'''

        '''fig7 = pylab.figure(7,figsize=(10,6))
        cls.do3DHistograms(fig7, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img3 = prefix+'deltashifts_3d.png'
        fig7.savefig(os.path.join(path,img3) ,dpi=100)'''
        #pylab.show()
        pylab.clf()
        return img1
Read in the pkainfo dict from extractpkas method and do
          additional analyses, makes plots for titdb
Read in the pkainfo dict from extractpkas method and do
additional analyses, makes plots for titdb
Read in the pkainfo dict from extractpkas method and do additional analyses makes plots for titdb
def analysepKas(cls, pkainfo, satoms='all', path=None, exclude=[],
                        silent=False, prefix=''):
        if path==None:
            path=os.getcwd()
        aminoacids = cls.residue_names.keys()
        titratable = cls.titratable
        titrspans = {}      
        primaryspans = {}   
        allspans = {}       
        titravgshfts = {}   
        atomshfts = {}      
        spansbyres = {}     
        for t in aminoacids:
            titravgshfts[t]=[]
            atomshfts[t]={}
        for t in titratable:
            titrspans[t]=[]
            primaryspans[t]=[]
            spansbyres[t]={}
        for t in aminoacids:
            allspans[t] = []
        if silent == False:
            print
            print 'Analysing pKa info..'
        count=0
        titrcount = 0
        for name in pkainfo.keys():
            for d in pkainfo[name].keys():
                PI = pkainfo[name][d]
                res = PI['res']
                atom = PI['atom']
                model = PI['model']
                for p in PI:
                    if 'pK' in p:
                        count += 1
                        pval = PI[p][p]
                        sp = PI[p]['span']
                        if res in ['ASP','GLU','HIS'] and atom in ['HB2', 'HB3']:
                            atom = 'HB*'
                        elif res == 'GLU' and atom in ['HG2','HG3']:
                            atom = 'HG*'
                        if model == '1 pKa 2 Chemical shifts' and res in titratable:
                            primaryspans[res].append(sp)
                        elif res in titratable:
                            titrspans[res].append(sp)
                            titrcount+=1
                        else:
                            allspans[res].append(sp)
                        if not atomshfts[res].has_key(atom):
                            atomshfts[res][atom] = []
                        if satoms != 'all' and not atom in satoms:
                            if silent == False:
                                print 'excluding atom', atom
                                continue
                        else:
                            atomshfts[res][atom].append(sp)
        lentitrspans=Utils.getlenDict(titrspans)
        lenprimaryspans=Utils.getlenDict(primaryspans)
        otherspans = {}
        for k in titrspans:
            otherspans[k] = list( set(allspans[k]) - set(titrspans[k]) )
        print '<div>'
        print 'Total residues: %s <br>' %count
        print 'of which titratable grps: %s <br>' %titrcount
        print 'Titratable "reliable" pkas: %s <br>' %(lentitrspans + lenprimaryspans)
        print 'Titratable "primary" pkas: %s <br>' %lenprimaryspans
        print '</div>'
        print '<br>'
        pylab.rc("font", family="serif")
        pylab.rc("font", size=10)
        pylab.rc('text', usetex=True)
        fig1 = pylab.figure(1,figsize=(10,6))
        fig1.text(0.5, 0.95, 'Distribution of $\Delta\delta$ of extracted pKas: '+prefix, horizontalalignment='center',
                            fontproperties=FontProperties(size=18))
        hdata = {}
        for k in titrspans:
            hdata[k] = {'primary':primaryspans[k], 'reliable':titrspans[k], 'other':otherspans[k]}
        cls.doMultipleHistograms(fig1, hdata, bins=30, xlabel='$\Delta\delta$ (ppm)',
                                ylabel='no. datasets', xticks=False, yticks=False)
        img1 = prefix+'deltashifts_dist.png'
        fig1.savefig(os.path.join(path,img1), dpi=100)
        pylab.clf()
        return img1
def analysepKas ( cls , pkainfo , satoms = 'all' , path = None , exclude = [ ] , silent = False , prefix = '' ) : if path == None : path = os . getcwd ( ) aminoacids = cls . residue_names . keys ( ) titratable = cls . titratable titrspans = { } primaryspans = { } allspans = { } titravgshfts = { } atomshfts = { } spansbyres = { } for t in aminoacids : titravgshfts [ t ] = [ ] atomshfts [ t ] = { } for t in titratable : titrspans [ t ] = [ ] primaryspans [ t ] = [ ] spansbyres [ t ] = { } for t in aminoacids : allspans [ t ] = [ ] if silent == False : print print 'Analysing pKa info..' count = 0 titrcount = 0 for name in pkainfo . keys ( ) : for d in pkainfo [ name ] . keys ( ) : PI = pkainfo [ name ] [ d ] res = PI [ 'res' ] atom = PI [ 'atom' ] model = PI [ 'model' ] for p in PI : if 'pK' in p : count += 1 pval = PI [ p ] [ p ] sp = PI [ p ] [ 'span' ] if res in [ 'ASP' , 'GLU' , 'HIS' ] and atom in [ 'HB2' , 'HB3' ] : atom = 'HB*' elif res == 'GLU' and atom in [ 'HG2' , 'HG3' ] : atom = 'HG*' if model == '1 pKa 2 Chemical shifts' and res in titratable : primaryspans [ res ] . append ( sp ) elif res in titratable : titrspans [ res ] . append ( sp ) titrcount += 1 else : allspans [ res ] . append ( sp ) if not atomshfts [ res ] . has_key ( atom ) : atomshfts [ res ] [ atom ] = [ ] if satoms != 'all' and not atom in satoms : if silent == False : print 'excluding atom' , atom continue else : atomshfts [ res ] [ atom ] . append ( sp ) '''if allpkas != None:
                for s in allsp:
                    if s >= maxspan:
                        continue
                    allspans[res].append(s)
                    if res in titratable:
                        spansbyres[res][s] = prot+'__'+d''' lentitrspans = Utils . getlenDict ( titrspans ) lenprimaryspans = Utils . getlenDict ( primaryspans ) otherspans = { } for k in titrspans : otherspans [ k ] = list ( set ( allspans [ k ] ) - set ( titrspans [ k ] ) ) print '<div>' print 'Total residues: %s <br>' % count print 'of which titratable grps: %s <br>' % titrcount print 'Titratable "reliable" pkas: %s <br>' % ( lentitrspans + lenprimaryspans ) print 'Titratable "primary" pkas: %s <br>' % lenprimaryspans print '</div>' print '<br>' '''for r in atomshfts:
            print r
            for a in atomshfts[r]:
                print a, len(atomshfts[r][a])''' pylab . rc ( "font" , family = "serif" ) pylab . rc ( "font" , size = 10 ) pylab . rc ( 'text' , usetex = True ) fig1 = pylab . figure ( 1 , figsize = ( 10 , 6 ) ) fig1 . text ( 0.5 , 0.95 , 'Distribution of $\Delta\delta$ of extracted pKas: ' + prefix , horizontalalignment = 'center' , fontproperties = FontProperties ( size = 18 ) ) hdata = { } for k in titrspans : hdata [ k ] = { 'primary' : primaryspans [ k ] , 'reliable' : titrspans [ k ] , 'other' : otherspans [ k ] } cls . doMultipleHistograms ( fig1 , hdata , bins = 30 , xlabel = '$\Delta\delta$ (ppm)' , ylabel = 'no. datasets' , xticks = False , yticks = False ) img1 = prefix + 'deltashifts_dist.png' fig1 . savefig ( os . path . join ( path , img1 ) , dpi = 100 ) '''pylab.clf()
        fig6 = pylab.figure(6,figsize=(10,6))
        fig6.text(0.5, 0.95, 'Distribution: $\Delta\delta$ by atom: '+prefix, horizontalalignment='center',
                            fontproperties=FontProperties(size=18))

        cls.doMultipleHistograms(fig6, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img2 = prefix+'deltashifts_byatom.png'
        fig6.savefig(os.path.join(path,img2) ,dpi=100)''' '''fig7 = pylab.figure(7,figsize=(10,6))
        cls.do3DHistograms(fig7, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img3 = prefix+'deltashifts_3d.png'
        fig7.savefig(os.path.join(path,img3) ,dpi=100)''' pylab . clf ( ) return img1
Read in the pkainfo dict from extractpkas method and do
additional analyses, makes plots for titdb
Read in the pkainfo dict from extractpkas method and do additional analyses makes plots for titdb
"""Read in the pkainfo dict from extractpkas method and do
          additional analyses, makes plots for titdb""" #histogram of reliable spans, for titr groups #primary spans, for titr groups #histogram of all spans for all groups #histogram of average shifts #store per atom #sort out spans by residue #print p, d, '<p>' #print  d, p, pval,  sp #change atom if handling HB2/3 in ASP, HIS and GLU, so #we group them together as HB* for the stats #move to extract?? #assign spans by atom '''if allpkas != None:
                for s in allsp:
                    if s >= maxspan:
                        continue
                    allspans[res].append(s)
                    if res in titratable:
                        spansbyres[res][s] = prot+'__'+d''' #lenallspans=Utils.getlenDict(allspans) #lentitrallspans=Utils.getlenDict(allspans, keys=titratable) #remove primary from allspans to get leftover ones #otherspans[k] = list( set(allspans[k]) - (set(titrspans[k]) | set(primaryspans[k]))) #print 'All pkas: %s <br>' %lenallspans #print 'Titratable all pkas: %s <br>' %lentitrallspans '''for r in atomshfts:
            print r
            for a in atomshfts[r]:
                print a, len(atomshfts[r][a])''' #plot multiple histograms together in multiple subplots '''pylab.clf()
        fig6 = pylab.figure(6,figsize=(10,6))
        fig6.text(0.5, 0.95, 'Distribution: $\Delta\delta$ by atom: '+prefix, horizontalalignment='center',
                            fontproperties=FontProperties(size=18))

        cls.doMultipleHistograms(fig6, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img2 = prefix+'deltashifts_byatom.png'
        fig6.savefig(os.path.join(path,img2) ,dpi=100)''' '''fig7 = pylab.figure(7,figsize=(10,6))
        cls.do3DHistograms(fig7, atomshfts, bins=25, xlabel='$\Delta\delta$ (ppm)',
                                xticks=True, yticks=True)
        img3 = prefix+'deltashifts_3d.png'
        fig7.savefig(os.path.join(path,img3) ,dpi=100)''' #pylab.show()
cls
pkainfo
satoms
path
exclude
silent
prefix