def peakcros(args, xargs): with open(args.peakfile) as fin: peaks = map(lambda t: t.split(), fin) peaks = peakset(map(lambda t: [float(t[0]), float(t[1]), t[2]], peaks)) lrbt = [args.bleft, args.bright, args.bbottom, args.btop] for sample in eval(args.holonums): holo = hsqc(os.path.join(args.folder, str(sample) + ".nv")) holopeaks = peakset( holo.xyzconv(holo.peak_search(args.num_peaks, lrbt))) print "Sample #" + str(sample).ljust( 3) + ": %d peaks matched" % holopeaks.matchcount( peaks, args.dcutoff, args.scutoff)
def peakwindow(data, num=50, box=None, apfname=None, *args, **kwds): fig = figure(FigureClass=PeakWindow) fig.build_mplgui() fig.set_box(box) fig.set_hsqc(data if data.__class__ is hsqc else hsqc(data)) fig.set_max_peaknum(num) fig.peak_search() fig.plot() if apfname is not None: fig.loadapeaks(apfname) fig.canvas.mpl_connect('key_press_event', fig.onkeypress) if 'shift_globally' in kwds: fig.shift_globally = kwds['shift_globally'] return fig
def autocros(args, xargs): apo = hsqc(os.path.join(args.folder, str(args.aponum) + ".nv")) lrbt = [args.bleft, args.bright, args.bbottom, args.btop] apo_peakdata = apo.peak_search(args.num_peaks, lrbt) apo_peaks = peakset(apo_peakdata) pmv = [] for sample in eval(args.controls): ctrl_apo = hsqc(os.path.join(args.folder, str(sample) + ".nv")) ctrl_peaks = peakset(ctrl_apo.peak_search(args.num_peaks, lrbt)) pmv.append(apo_peaks.matchsignal(ctrl_apo, True)) pmv = array(pmv) apo_good = [] for (i, value) in enumerate(pmv.min(0)): if value > args.vcutoff: apo_good.append(apo_peakdata[i]) print "Found %d good peaks in set of %d" % (len(apo_good), 160) good_peaks = peakset(array(apo_good)) for sample in eval(args.holonums): holo = hsqc(os.path.join(args.folder, str(sample) + ".nv")) x = good_peaks.matchsignal(holo, True) print "Sample #" + str(sample).ljust(3) + ": " + " ".join( map(lambda x: "%5.2f" % x, map(lambda p: scoreatpercentile(x, p), range(0, 100 + 10, 10))))
def peakmatch(args, xargs): with open(args.peakfile) as fin: peaks = map(lambda t: t.split(), fin) Np = len(peaks) peaks = peakset(map(lambda t: [float(t[0]), float(t[1]), t[2]], peaks)) lrbt = [args.bleft, args.bright, args.bbottom, args.btop] allpms, hps = [], [] for sample in eval(args.holonums): holo = hsqc(os.path.join(args.folder, str(sample) + ".nv")) holopeaks = peakset( holo.xyzconv(holo.peak_search(args.num_peaks, lrbt))) samplenum = str(sample).ljust(3) print "Sample #" + samplenum + " processed" pms = holopeaks.peakmatch(peaks) allpms.append(list(pms[1])) hps.append(holopeaks) x = array(allpms).flatten() x.sort() N = len(x) n = arange(1, N).astype(float) sigmaD = sqrt(0.5 * x[:N / 2]**2 / log(N / (N - n[:N / 2]))).mean() print "Estimated peak position noise level %.3f" % (sigmaD) zcut = bonferroni(args.zcutoff, Np) print "Requested Z-score cutoff (%.2f) adjusted to %.2f (Bonferroni correction)" % ( args.zcutoff, zcut) dcut = zcut * sigmaD print "Peak mismatch cutoff set to %.3f ppm" % dcut for (i, sample) in enumerate(eval(args.holonums)): holopeaks = hps[i] pms = holopeaks.peakmatch(peaks) samplenum = str(sample).ljust(3) print "Sample #" + samplenum + ": %d peaks shifted" % ( Np - holopeaks.matchcount(peaks, dcut, args.scutoff)) if args.print_peakmatch: pms = sorted(zip(*(pms + [list(zip(*peaks.peaks)[2])])), key=lambda x: x[1], reverse=True) print '\n'.join( map(lambda x: samplenum + "%7.3f %6.2f %s" % x[1:], filter(lambda xx: xx[1] >= dcut, pms)))
def peakmxy(args, xargs): with open(args.peakfile) as fin: peaks = map(lambda t: t.split(), fin) Np = len(peaks) peaks = peakset(map(lambda t: [float(t[0]), float(t[1]), t[2]], peaks)) lrbt = [args.bleft, args.bright, args.bbottom, args.btop] allxy, hps = [], [] for sample in eval(args.holonums): holo = hsqc(os.path.join(args.folder, str(sample) + ".nv")) holopeaks = peakset( holo.xyzconv(holo.peak_search(args.num_peaks, lrbt))) hps.append(holopeaks) allxy.append(holopeaks.peakmxy(peaks)) samplenum = str(sample).ljust(3) sys.stderr.write("Sample #" + samplenum + " processed\n") xx, yy = array(allxy).T sx, sy = iqr_sigma(xx), iqr_sigma(yy) sys.stderr.write("Estimated peak position variations %.3f %.3f\n" % (sx, sy)) zcut = bonferroni(args.zcutoff, Np) sys.stderr.write( "Requested Z-score cutoff (%.2f) adjusted to %.2f (Bonferroni correction)\n" % (args.zcutoff, zcut)) xcut, ycut = zcut * sx, zcut * sy sys.stderr.write("Peak mismatch cutoffs set to %.3f / %.3f ppm\n" % (xcut, ycut)) for (i, sample) in enumerate(eval(args.holonums)): holopeaks = hps[i] pms = holopeaks.peakmatch(peaks) Nm, indm, xm, ym = holopeaks.matchcut_xy(peaks, xcut, ycut) samplenum = str(sample).ljust(3) print "Sample #" + samplenum + ": %d peaks shifted" % Nm if args.print_peakmatch: for (j, flag) in enumerate(indm): if flag or args.print_full: print samplenum + " %7.3f %7.3f %s %7.3f %7.3f" % ( holopeaks.peaks[pms[0][j]][0], holopeaks.peaks[ pms[0][j]][1], peaks.peaks[j][2], xm[j], ym[j])
def onkeypress(self, event): PeakWindow.onkeypress(self, event) if event.key == 'A': self.set_apo_peaks(self.peaks) print str(len(self.peaks)) + " apo-peaks stored" if event.key == 'H': self.load_current_holohsqc() self.peak_search() self.plot() self.apoplot() if event.key == 'N': self.curholo = min(len(self.holonums) - 1, self.curholo + 1) print "Now loading sample #" + str(self.holonums[self.curholo]) self.load_current_holohsqc() self.peak_search() self.plot() self.apoplot() print " ".join( map(lambda x: "%5.2f" % x, peakset(self.peaks).matchperc(peakset(self.apo_peaks)))) if event.key == 'P': self.curholo = max(0, self.curholo - 1) print "Now loading sample #" + str(self.holonums[self.curholo]) self.load_current_holohsqc() self.peak_search() self.plot() self.apoplot() print " ".join( map(lambda x: "%5.2f" % x, peakset(self.peaks).matchperc(peakset(self.apo_peaks)))) if event.key == ']': self.acounter += 1 self.limit_acounter() self.onapozoom(event) if event.key == '[': self.acounter -= 1 self.limit_acounter() self.onapozoom(event) if event.key == 'I': apox = peakset(self.apo_peaks) x = apox.matchsignal(self.dataset, True) print "Sample #" + str( self.holonums[self.curholo]).ljust(3) + ": " + " ".join( map( lambda x: "%5.2f" % x, map(lambda p: scoreatpercentile(x, p), range(0, 100 + 10, 10)))) if event.key == 'D': apox = peakset(self.apo_peaks) f = apox.matchsignal(self.dataset, True) with open(str(self.holonums[self.curholo]) + ".out", 'w') as fout: fout.write("RPH: " + " ".join(map(lambda x: "%6.3f" % x, f)) + '\n') if event.key == 'Q': apox = peakset(self.apo_peaks) with open("holall.dat", 'w') as fout: for sample in self.holonums: holo = hsqc(str(sample) + ".nv") f = apox.matchsignal(holo, True) fout.write("RPHI " + str(sample).ljust(3) + " :" + " ".join(map(lambda x: "%6.3f" % x, f)) + '\n') fout.write("RPHD " + str(sample).ljust(3) + " :" + " ".join( map( lambda x: "%5.2f" % x, map(lambda p: scoreatpercentile(f, p), range(0, 100 + 10, 10)))) + '\n') print "RPHD " + str(sample).ljust(3) + " :" + " ".join( map( lambda x: "%5.2f" % x, map(lambda p: scoreatpercentile(f, p), range(0, 100 + 10, 10))))
def load_current_holohsqc(self): self.set_hsqc(hsqc(str(self.holonums[self.curholo]) + '.nv'))
def load_apo_hsqc(self): self.set_hsqc(hsqc(self.apo_hsqc))
def file_or_data(data): return data if data.__class__ is hsqc else hsqc(data)