def run(self): self.br=BGrate.calcBGrate(self.dbname,20,400,T0=600.0) self.burst=BurstSearch.findBurst(self.br,self.dbname,["All"]) self.burstSeff, self.burstFRET,self.wei,self.H,self.xedges, \ self.yedges=fretAndS.FretAndS(self.dbname,self.burst,(27,27),self.br) #self.timer.stop() self.viewbox.canvas.drawHist(self.H,self.xedges,self.yedges) if self.mainui is not None: print ("copy burst") self.mainui.burst=copy.deepcopy(self.burst) print(self.mainui.burst["SyncResolution"])
def main(comm, dbname, n_states, Sth): rank = comm.Get_rank() clsize = comm.Get_size() #print("============size=====",clsize) if rank == 0: br = BGrate.calcBGrate(dbname, 20, 400) burst = BurstSearch.findBurst(br, dbname, ["All"]) burstSeff, burstFRET, wei, H, xedges, yedges = fretAndS.FretAndS( dbname, burst, (27, 27), br) n_burst = len(burst["All"]['chl']) if n_burst < clsize: clsize = n_burst chunkLists = list(chunks(range(n_burst), clsize)) #gsml=GS_MLE(burst,0.891) #gsml.n_states=2 #gsml.MaxLikehood([0.3,0.7,0.2, 3,3,3, 3,3,3]) #endtime = datetime.datetime.now() #print (endtime - starttime) else: burst = dict() chunkLists = list() clsize = comm.bcast(clsize, root=0) burst = comm.bcast(burst, root=0) burstIdxRange = comm.scatter(chunkLists, root=0) #print(burstIdxRange,rank) gsml = GS_MLE(burst, comm, burstIdxRange, Sth) gsml.n_states = n_states params = [0.38, 0.6, 675.0, 325.0, 3, 3, 3, 3, 3] params = params[:n_states * n_states] #print(params) stop = [0] if rank == 0: gsml.MaxLikehood(params) #gsml.lnLikelihood(params,stop) else: while stop[0] == 0: gsml.lnLikelihood(params, stop)
return None matP = np.empty([n, 1]) ap = 0 for i in range(n): ap += matK[i, i] for i in range(n): matP[i, 0] = matK[i, i] / ap return matP if __name__ == '__main__': import matplotlib import datetime starttime = datetime.datetime.now() dbname = '/home/liuk/sf/oc/data/38.sqlite' dbname = 'E:/liuk/proj/ptu/data/55.sqlite' #dbname='E:/sf/oc/data/38.sqlite' dbname = "E:/dbox/sf/oc/data/1min.sqlite" br = BGrate.calcBGrate(dbname, 20, 400) burst = BurstSearch.findBurst(br, dbname, ["All"]) burstSeff, burstFRET, wei, H, xedges, yedges = fretAndS.FretAndS( dbname, burst, (27, 27), br) #matplotlib.pyplot.plot(burst["All"].s) gsml = GS_MLE(burst, 0.891) gsml.n_states = 3 gsml.MaxLikehood([0.3, 0.7, 0.2, 3, 3, 3, 3, 3, 3]) endtime = datetime.datetime.now() print(endtime - starttime)
def FretZ(dbname, burst, bins=(25, 25), bgrate=None): #conn = sqlite3.connect(dbname) #c = conn.cursor() lenburst = len(burst["All"]['chl']) print("lenburst:", lenburst) burstFRET = array("d") #np.zeros(lenburst) burstSeff = array("d") #np.zeros(lenburst) burstZ = array("d") wei = array("d") #np.zeros(lenburst) #fw = np.zeros(lenburst) for i in range(lenburst): # c.execute("select Dtime,ch from fretData_All where TimeTag>=? and TimeTag<= ?", # (burst["All"].stag[i],burst["All"].etag[i])) # data=c.fetchall() data = burst["All"]['chl'][i] if bgrate != None: tt = burst["All"]['timetag'][i] #print(tt) backgT = burst["All"]['burstW'][i] / 2 + tt.iloc[0] * bgrate[ "SyncResolution"] #中点时刻 bgAA = BurstSearch.getBGrateAtT(bgrate, "AexAem", backgT) bgDD = BurstSearch.getBGrateAtT(bgrate, "DexDem", backgT) bgDA = BurstSearch.getBGrateAtT(bgrate, "DexAem", backgT) w = len(data) #print(w) nda = 0 #ch1 ndd = 0 #ch2 naa = 0 #ch3 nad = 0 #ch4 for d in data: if d == 1: nda += 1 elif d == 2: ndd += 1 elif d == 3: naa += 1 elif d == 4: nad += 1 if bgrate != None: naa = naa - bgAA * burst["All"]['burstW'][i] ndd = ndd - bgDD * burst["All"]['burstW'][i] nda = nda - bgDA * burst["All"]['burstW'][i] if naa < bgAA * burst["All"]['burstW'][i] or ndd < 0 or nda < 0: continue wei.append(w) gamma = 0.31 beta = 1.42 if ndd == 0: zp = np.log(nda / (gamma * 0.001)) burstZ.append(zp) burst["All"]['z'][i] = zp else: zp = np.log(nda / (gamma * ndd)) burst["All"]['z'][i] = zp burstZ.append(zp) if (nda + ndd) == 0: burstFRET.append(1) burst["All"]['e'][i] = 1 else: burstFRET.append((nda) / (nda + gamma * ndd)) burst["All"]['e'][i] = (nda) / (nda + gamma * ndd) if (nda + ndd + naa) == 0: burstSeff.append(1) burst["All"]['s'][i] = 1 else: burstSeff.append( (nda + gamma * ndd) / (nda + gamma * ndd + naa / beta)) burst["All"]['s'][i] = (nda + gamma * ndd) / (nda + gamma * ndd + naa / beta) H, xedges, yedges = np.histogram2d(burstFRET, burstSeff, bins=bins, weights=wei) #conn.close() #fig, ax = plt.subplots() #plt.subplots_adjust(bottom=0.15) #im=plt.imshow(H.transpose()[::-1], interpolation='bessel', # cmap=cm.jet,extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]]) #plt.colorbar(im) #rs=RectSect(ax,xedges,yedges) #toggle_selector(rs.toggle_selectorRS,plt) #RectBuilder(ax,xedges,yedges,rs.toggle_selectorRS) #callback = MaxLikehood(ax,burstSeff, burstFRET,burst) #axMLH = plt.axes([0.1, 0.02, 0.1, 0.05]) #bnMLH = Button(axMLH, 'calc ML') #bnMLH.on_clicked(callback.calc) #import seaborn as sns #g = sns.JointGrid(x=burstFRET, y=burstSeff) #g.plot_marginals(sns.distplot) #g.plot_joint(plt.hist2d) return burstSeff, burstFRET, burstZ, wei, H, xedges, yedges