PEATDB/plugins/VantHoffAnalysis.py
def fitDifferentialCurve(self, E=None, d=None, xy=None,smooth=0,
                                invert=False,show=True,figname=None):
        """Derive differential denaturation curve and fit to get deltaH
           We smooth the unfolding curve and then differentiate and finally
           fit to a 3 parameter equation.
           See http://www.ncbi.nlm.nih.gov/pubmed/10933511"""

        if E !=None:
            ek = E.getDataset(d)
            x,y,a, xerr,yerr = ek.getAll()
        elif xy!=None:
            x,y = xy
        else:
            return
        if invert == True:
            y = [max(y)-i for i in y[:]]

        leg=[]; lines=[]
        f=plt.figure(figsize=(10,5))
        ax=f.add_subplot(121)
        p=ax.plot(x,y,'x',color='black',mew=3,alpha=0.5)
        leg.append(p); lines.append('original')
        #smooth
        if smooth == 0:
            smooth=int(len(x)/15.0)
        s=self.smoothListGaussian(y,smooth)
        p=ax.plot(x[:len(s)-1],s[:-1],lw=3)
        leg.append(p); lines.append('smoothed')
        ax.set_title("original data")
        ax.set_xlabel('T')
        ax1=f.add_subplot(122)
        #differentiate
        dx,ds = self.differentiate(x[:len(s)],s)
        #ds = [i/max(ds) for i in ds]
        ds = [i*10 for i in ds]
        cw=csv.writer(open('diffcd.csv','w'))
        for row in zip(dx,ds):
            cw.writerow(row)
        p=ax1.plot(dx,ds,'-',lw=1.5,alpha=0.7,color='black')
        leg.append(p); lines.append('differential')
        ax1.set_title("differential denaturation")
        ax1.set_xlabel('T'); ax1.set_ylabel('dsignal/dT')

        A,X=Fitting.doFit(expdata=zip(dx,ds),model='diffDenaturation',grad=1e-9,conv=1e-10)
        fity = X.getFitLine(dx)
        p=ax1.plot(dx,fity,'r',lw=2)
        leg.append(p); lines.append('fit')
        t=X.getFitDict()
        self.drawParams(ax1,t)
        dHkcal=t['deltaH']/4.184
        f.suptitle('Method 3 - deltaH: %2.2f kJ/mol (%2.2f kcal) Tm: %2.2f' %(t['deltaH'],dHkcal,t['Tm']),size=18)
        ax.legend(leg,lines,loc='best',prop=FontProperties(size="smaller"))
        #f.subplots_adjust(hspace=0.8)
        if show == True:
            self.showTkFigure(f)
        if figname != None:
            figname = figname.replace('.','_')
            f.savefig(figname+'m3',dpi=300)
            plt.close()
        if E!=None:
            fdata = Fitting.makeFitData(X.name,vrs=X.variables)
            E.insertDataset(xydata=[dx,ds], newname=d+'_diff',replace=True,fit=fdata)
            #E.saveProject()
        return t['deltaH'],t['Tm']
Derive differential denaturation curve and fit to get deltaH
           We smooth the unfolding curve and then differentiate and finally
           fit to a 3 parameter equation.
           See http://www.ncbi.nlm.nih.gov/pubmed/10933511
Derive differential denaturation curve and fit to get deltaH
We smooth the unfolding curve and then differentiate and finally
fit to a 3 parameter equation.
Derive differential denaturation curve and fit to get deltaH We smooth the unfolding curve and then differentiate and finally fit to a 3 parameter equation .
def fitDifferentialCurve(self, E=None, d=None, xy=None,smooth=0,
                                invert=False,show=True,figname=None):
        if E !=None:
            ek = E.getDataset(d)
            x,y,a, xerr,yerr = ek.getAll()
        elif xy!=None:
            x,y = xy
        else:
            return
        if invert == True:
            y = [max(y)-i for i in y[:]]
        leg=[]; lines=[]
        f=plt.figure(figsize=(10,5))
        ax=f.add_subplot(121)
        p=ax.plot(x,y,'x',color='black',mew=3,alpha=0.5)
        leg.append(p); lines.append('original')
        if smooth == 0:
            smooth=int(len(x)/15.0)
        s=self.smoothListGaussian(y,smooth)
        p=ax.plot(x[:len(s)-1],s[:-1],lw=3)
        leg.append(p); lines.append('smoothed')
        ax.set_title("original data")
        ax.set_xlabel('T')
        ax1=f.add_subplot(122)
        dx,ds = self.differentiate(x[:len(s)],s)
        ds = [i*10 for i in ds]
        cw=csv.writer(open('diffcd.csv','w'))
        for row in zip(dx,ds):
            cw.writerow(row)
        p=ax1.plot(dx,ds,'-',lw=1.5,alpha=0.7,color='black')
        leg.append(p); lines.append('differential')
        ax1.set_title("differential denaturation")
        ax1.set_xlabel('T'); ax1.set_ylabel('dsignal/dT')
        A,X=Fitting.doFit(expdata=zip(dx,ds),model='diffDenaturation',grad=1e-9,conv=1e-10)
        fity = X.getFitLine(dx)
        p=ax1.plot(dx,fity,'r',lw=2)
        leg.append(p); lines.append('fit')
        t=X.getFitDict()
        self.drawParams(ax1,t)
        dHkcal=t['deltaH']/4.184
        f.suptitle('Method 3 - deltaH: %2.2f kJ/mol (%2.2f kcal) Tm: %2.2f' %(t['deltaH'],dHkcal,t['Tm']),size=18)
        ax.legend(leg,lines,loc='best',prop=FontProperties(size="smaller"))
        if show == True:
            self.showTkFigure(f)
        if figname != None:
            figname = figname.replace('.','_')
            f.savefig(figname+'m3',dpi=300)
            plt.close()
        if E!=None:
            fdata = Fitting.makeFitData(X.name,vrs=X.variables)
            E.insertDataset(xydata=[dx,ds], newname=d+'_diff',replace=True,fit=fdata)
        return t['deltaH'],t['Tm']
def fitDifferentialCurve ( self , E = None , d = None , xy = None , smooth = 0 , invert = False , show = True , figname = None ) : if E != None : ek = E . getDataset ( d ) x , y , a , xerr , yerr = ek . getAll ( ) elif xy != None : x , y = xy else : return if invert == True : y = [ max ( y ) - i for i in y [ : ] ] leg = [ ] ; lines = [ ] f = plt . figure ( figsize = ( 10 , 5 ) ) ax = f . add_subplot ( 121 ) p = ax . plot ( x , y , 'x' , color = 'black' , mew = 3 , alpha = 0.5 ) leg . append ( p ) ; lines . append ( 'original' ) if smooth == 0 : smooth = int ( len ( x ) / 15.0 ) s = self . smoothListGaussian ( y , smooth ) p = ax . plot ( x [ : len ( s ) - 1 ] , s [ : - 1 ] , lw = 3 ) leg . append ( p ) ; lines . append ( 'smoothed' ) ax . set_title ( "original data" ) ax . set_xlabel ( 'T' ) ax1 = f . add_subplot ( 122 ) dx , ds = self . differentiate ( x [ : len ( s ) ] , s ) ds = [ i * 10 for i in ds ] cw = csv . writer ( open ( 'diffcd.csv' , 'w' ) ) for row in zip ( dx , ds ) : cw . writerow ( row ) p = ax1 . plot ( dx , ds , '-' , lw = 1.5 , alpha = 0.7 , color = 'black' ) leg . append ( p ) ; lines . append ( 'differential' ) ax1 . set_title ( "differential denaturation" ) ax1 . set_xlabel ( 'T' ) ; ax1 . set_ylabel ( 'dsignal/dT' ) A , X = Fitting . doFit ( expdata = zip ( dx , ds ) , model = 'diffDenaturation' , grad = 1e-9 , conv = 1e-10 ) fity = X . getFitLine ( dx ) p = ax1 . plot ( dx , fity , 'r' , lw = 2 ) leg . append ( p ) ; lines . append ( 'fit' ) t = X . getFitDict ( ) self . drawParams ( ax1 , t ) dHkcal = t [ 'deltaH' ] / 4.184 f . suptitle ( 'Method 3 - deltaH: %2.2f kJ/mol (%2.2f kcal) Tm: %2.2f' % ( t [ 'deltaH' ] , dHkcal , t [ 'Tm' ] ) , size = 18 ) ax . legend ( leg , lines , loc = 'best' , prop = FontProperties ( size = "smaller" ) ) if show == True : self . showTkFigure ( f ) if figname != None : figname = figname . replace ( '.' , '_' ) f . savefig ( figname + 'm3' , dpi = 300 ) plt . close ( ) if E != None : fdata = Fitting . makeFitData ( X . name , vrs = X . variables ) E . insertDataset ( xydata = [ dx , ds ] , newname = d + '_diff' , replace = True , fit = fdata ) return t [ 'deltaH' ] , t [ 'Tm' ]
Derive differential denaturation curve and fit to get deltaH
We smooth the unfolding curve and then differentiate and finally
fit to a 3 parameter equation.
Derive differential denaturation curve and fit to get deltaH We smooth the unfolding curve and then differentiate and finally fit to a 3 parameter equation .
"""Derive differential denaturation curve and fit to get deltaH
           We smooth the unfolding curve and then differentiate and finally
           fit to a 3 parameter equation.
           See http://www.ncbi.nlm.nih.gov/pubmed/10933511""" #smooth #differentiate #ds = [i/max(ds) for i in ds] #f.subplots_adjust(hspace=0.8) #E.saveProject()
self
E
d
xy
smooth
invert
show
figname