def show_specific(self): """Show datasets for an individual cell, depends on fieldtype""" protein = self.form.getfirst('protein') rectype = self.form.getfirst('rectype') col = self.form.getfirst('column') sys.stdout.flush() DB = self.DB = self.connect() ptmodel = PEATTableModel(DB) ekincols = ptmodel.ekintypes fieldtype = DB['userfields'][col]['field_type'] protname = DB[protein]['name'] self.showHeader(title=str(protname+': '+col), menu=1) print '<div><a>Protein: %s </a><br>' %protname print 'Column data: %s </div>' %col from PEATDB.Ekin.Web import EkinWeb if fieldtype in ekincols: fieldtype = 'ekindata' #plot ekin data curves, if fieldtype is ekindata if fieldtype == 'ekindata': E = DB[protein][col] EW = EkinWeb() EW.showEkinPlots(project=E, datasets='ALL', path=self.plotsdir, imgpath=self.imagepath) print '</table>' #save the pdb structure to a file and provide url link to it elif fieldtype == 'structure': recdata = DB[protein][col] for k in recdata: print '<br><a> %s</a>' %str(k) elif fieldtype == 'Notes': recdata = DB[protein][col] print '<br><a> %s</a>' %recdata['text'] elif fieldtype == 'File': recdata = DB[protein][col] print '<p> This record contains a data file. Click link to open.' print '<a href="http://peat.ucd.ie/titration_db/%s">Open link</a>' %recdata['location'] else: print '<br>Sorry, no handler for this data right now..</br>' self.footer() return
def estimateExpUncertainty(ekindata, fitdata, xuncert=0, yuncert=0, runs=10, doplots=False, callback=None, guess=True, **kwargs): """Chresten's method for estimating the error on each parameter due to the effect of the exp uncertainty, which is user provided. If the datapoints have x or y error values, we use that instead""" '''we iterate over runs and re-fit the data, each time adjusting x-y points then accumulate a fit val for each parameter and get mean/stdev. Note: errors are added +/- values''' from PEATDB.Ekin.Dataset import EkinDataset grad = 1e-6 conv = 1e-6 for k in kwargs: if k == 'conv': conv = kwargs[k] if k == 'grad': grad = kwargs[k] if fitdata == None or len(fitdata) == 0: return None model = fitdata['model'] F = getFitter(model=model) try: varnames = F.getVarNames() except: return None fitvars = {} for v in varnames: fitvars[v] = [] #group lists by variable name xd, yd, a, xerrs, yerrs = ekindata.getAll() estdata = {} estdata['__datatabs_fits__'] = {} for r in range(runs): mut_x = [] mut_y = [] #if the datapoint has x or y error values, we use that instead for i in range(len(xd)): if xerrs != None and xerrs[i] > 0: mut_x.append(xd[i] + random.uniform(-xerrs[i], xerrs[i])) else: mut_x.append(xd[i] + random.uniform(-xuncert, xuncert)) if yerrs != None and yerrs[i] > 0: mut_y.append(yd[i] + random.uniform(-yerrs[i], yerrs[i])) else: mut_y.append(yd[i] + random.uniform(-yuncert, yuncert)) ek = EkinDataset(xy=[mut_x, mut_y], active=a) fitres, X = doFit(ek, model=model, fitdata=fitdata, grad=1e-6, conv=1e-6, silent=True, guess=guess, noiter=100) vrs = X.getVariables() for n in range(len(varnames)): fitvars[varnames[n]].append(vrs[n]) estdata[str(r)] = ek estdata['__datatabs_fits__'][str(r)] = fitres if callback != None: fitstats = {} for v in varnames: fitstats[v] = numpy.mean(fitvars[v]), numpy.std(fitvars[v]) callback(r, fitstats) fitstats = {} for v in varnames: #print fitvars[v] err = numpy.std(fitvars[v]) / 2 #print v, numpy.mean(fitvars[v]), err #we store the final error as +/- half the stdev. fitstats[v] = numpy.mean(fitvars[v]), err if doplots == True: from PEATDB.Ekin.Web import EkinWeb ew = EkinWeb() ew.showEkinPlots(ekindata=estdata, outfile='est_exp_err.html', columns=3, normalise=False, showfitvars=True, imgpath='.') return fitstats
def estimateExpUncertainty(ekindata, fitdata, xuncert=0, yuncert=0, runs=10, doplots=False, callback=None, guess=True, **kwargs): """Chresten's method for estimating the error on each parameter due to the effect of the exp uncertainty, which is user provided. If the datapoints have x or y error values, we use that instead""" '''we iterate over runs and re-fit the data, each time adjusting x-y points then accumulate a fit val for each parameter and get mean/stdev. Note: errors are added +/- values''' from PEATDB.Ekin.Dataset import EkinDataset grad=1e-6; conv=1e-6 for k in kwargs: if k=='conv': conv=kwargs[k] if k=='grad': grad=kwargs[k] if fitdata == None or len(fitdata) == 0: return None model = fitdata['model'] F = getFitter(model=model) try: varnames = F.getVarNames() except: return None fitvars = {} for v in varnames: fitvars[v] = [] #group lists by variable name xd,yd,a,xerrs,yerrs = ekindata.getAll() estdata={}; estdata['__datatabs_fits__']={} for r in range(runs): mut_x=[];mut_y=[] #if the datapoint has x or y error values, we use that instead for i in range(len(xd)): if xerrs != None and xerrs[i] > 0: mut_x.append(xd[i] + random.uniform(-xerrs[i], xerrs[i])) else: mut_x.append(xd[i] + random.uniform(-xuncert, xuncert)) if yerrs != None and yerrs[i] > 0: mut_y.append(yd[i] + random.uniform(-yerrs[i], yerrs[i])) else: mut_y.append(yd[i] + random.uniform(-yuncert,yuncert)) ek = EkinDataset(xy=[mut_x,mut_y],active=a) fitres, X = doFit(ek, model=model, fitdata=fitdata, grad=1e-6, conv=1e-6, silent=True, guess=guess, noiter=100) vrs = X.getVariables() for n in range(len(varnames)): fitvars[varnames[n]].append(vrs[n]) estdata[str(r)] = ek estdata['__datatabs_fits__'][str(r)] = fitres if callback != None: fitstats = {} for v in varnames: fitstats[v] = numpy.mean(fitvars[v]), numpy.std(fitvars[v]) callback(r, fitstats) fitstats = {} for v in varnames: #print fitvars[v] err = numpy.std(fitvars[v])/2 #print v, numpy.mean(fitvars[v]), err #we store the final error as +/- half the stdev. fitstats[v] = numpy.mean(fitvars[v]), err if doplots == True: from PEATDB.Ekin.Web import EkinWeb ew = EkinWeb() ew.showEkinPlots(ekindata=estdata, outfile='est_exp_err.html', columns=3, normalise=False, showfitvars=True, imgpath='.') return fitstats
def show_datasets(self): """Show single or multiple dataset plot from search results""" plotoption = self.form.getfirst('plotoption') norm = bool(self.form.getfirst('normalise')) logx = bool(self.form.getfirst('logx')) logy = bool(self.form.getfirst('logy')) legend = bool(self.form.getfirst('legend')) DB = self.DB = self.connect() from PEATDB.Ekin.Web import EkinWeb ekincols = DB.ekintypes self.showHeader(menu=1) self.menu() sys.stdout.flush() #get dataset name(s) from form residuefield = self.form.getvalue('residue') if not isinstance(residuefield, list): residuefield = [residuefield] #prepare data, if more than one dataset from seperate proteins, print '</div>' print '<table id="mytable" cellspacing=0>' print '<tr><th>' print 'plotoption:', plotoption print 'norm:', str(norm) print 'log-x', logx print 'log-y', logy print 'legend', legend print '</table>' ekindata={} ekindata['__datatabs_fits__']={} ekindata['__meta_data__']={} #extracting seperate datasets and put them in ekindata for r in residuefield: fields = r.split('$') protein = fields[0] col = fields[1] d = fields[2] E = DB[protein][col] fits = E.__datatabs_fits__ meta = E.__meta_data__ protname = DB[protein]['name'] ekindata['__datatabs_fits__'][d+'_'+col+'_'+protname] = fits[d] ekindata['__meta_data__'][d+'_'+col+'_'+protname] = meta[d] ekindata[d+'_'+col+'_'+protname] = E.getDataset(d) if plotoption == None: plotoption = 1 else: plotoption = 3 EW = EkinWeb() EW.showEkinPlots(ekindata, 'ALL', path=self.plotsdir, imgpath=self.imagepath, plotoption=plotoption, normalise=norm, legend=legend, logx=logx, logy=logy) return
def plotpKDCalcs(self, calcs, Ed=None, option=1): """Do pKD calcs with exp data plots""" from PEATDB.Ekin.Web import EkinWeb from PEATDB.Ekin.Base import EkinProject from PEATDB.Ekin.Convert import EkinConvert from PEATDB.Ekin.Titration import TitrationAnalyser import PEATDB.Ekin.Utils as Utils t = TitrationAnalyser() c=calcs EW = EkinWeb() if option == '2': print '<a>Just showing experimental data</a>' EW.showEkinPlots(project=Ed, datasets='ALL', path=self.plotsdir, imgpath=self.imagepath) return #create ekin proj from pKD titcurves Ec = EkinProject() for r in c.keys(): xd=[];yd=[] for i in c[r]: if type(i) is types.StringType: continue xd.append(i) yd.append(c[r][i]) edata=EkinConvert.xy2ekin([xd,yd]) Ec.insertDataset(edata, r) print '<a>Please wait, fitting calcated curves...</a>' sys.stdout.flush() Ec.fitDatasets(models=['1 pKa 2 Chemical shifts'], silent=True) if option == '3': print '<a>Just showing pKD data</a>' EW.showEkinPlots(project=Ec, datasets='ALL', path=self.plotsdir, imgpath=self.imagepath) return #transform exp data names to match pKD ones s=':' usechainid = True #if pKD names have no chain id, we don't need one for exp names if Ec.datasets[0].startswith(':'): usechainid=False for d in Ed.datasets[:]: r = Ed.getMetaData(d) if r != None: if r['chain_id'] == None or usechainid == False: chain = '' else: chain = r['chain_id'] new = chain+s+Utils.leadingZeros(r['res_num'],4)+s+r['residue'] if new in Ed.datasets: atom = r['atom'] new = new + '_' + atom Ed.renameDataset(d, new) #now we overlay the same datasets in Ed and Ec #also handles cases where same residue multiple times for diff atoms in exp data for d in Ed.datasets: if d in Ec.datasets: Ep = EkinProject() cdata = Ec.getDataset(d) Ep.insertDataset(cdata, d+'_pKD') Ep.setFitData(d+'_pKD', Ec.getFitData(d)) ddata = Ed.getDataset(d) Ep.insertDataset(ddata, d+'_exp') Ep.setFitData(d+'_exp', Ed.getFitData(d)) EW.showEkinPlots(project=Ep, datasets='ALL', plotoption=3, normalise=True, legend=True, path=self.plotsdir, imgpath=self.imagepath) return