def setasref(self): L = self.filesTable.selectedItems() if len(L[0:len(L) / 2]) >= 2: msgBox = QMessageBox() msgBox.setText("Only one item can be selected.") msgBox.exec_() elif len(L[0:len(L) / 2]) == 1: if '&' in self.filesTable.item(0, 0).text(): msgBox = QMessageBox() msgBox.setText("The ref has existed.") msgBox.exec_() else: self.filesTable.insertRow(0) fn = L[0].text() file = QtCore.QFile(self.currentDir.absoluteFilePath(fn)) size = QtCore.QFileInfo(file).size() fileNameItem = QtGui.QTableWidgetItem('&' + fn) fileNameItem.setFlags(fileNameItem.flags() ^ QtCore.Qt.ItemIsEditable) sizeItem = QtGui.QTableWidgetItem("%d KB" % (int( (size + 1023) / 1024))) sizeItem.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight) sizeItem.setFlags(sizeItem.flags() ^ QtCore.Qt.ItemIsEditable) self.filesTable.setItem(0, 0, fileNameItem) self.filesTable.setItem(0, 1, sizeItem) ncr = netcdf_reader(self.currentDir.absoluteFilePath(fn), bmmap=False) self.emit(SIGNAL("ref_ncr"), ncr) self.updata_files()
def get_R2(bass=None): # pkl_file = open('standardn3') pkl_file = open('PD6--RM---') data = pickle.load(pkl_file) msrt = data['MSRT'] # fn = "F:\MARS\data_save\STDAND/zhi10-5vs1.CDF" fn = "F:\MARS\data_save\D6/73.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] mss = msrt['ms'] mz = msrt['mz'] segno = msrt['segno'] results = data['results'] inds = [75] tzs = results[0]['tzs'][inds, :] RG = np.arange(np.min(tzs), np.max(tzs)) dd = np.zeros((len(RG), len(mz))) xx = ncr.mat(int(RG[0]), int(RG[-1]), 1) for j in inds: newd = np.zeros((len(RG), len(mz))) tz, seg, x, segx, maxpos, irr = findTZ(ncr, rts[j], np.array(mss[j], ndmin=2), pw, w, 'RM') c, vsel, pc = gridsearch(x, maxpos, 6, irr) chrom, area, heig, d = polyfitting(c, x, vsel, np.array(mss[j], ndmin=2)) re = np.searchsorted(RG, [tz[0], tz[1]]) newd[re[0]:re[1], :] = d dd = dd + newd xx1 = ncr.mat(int(RG[0]) - 8, int(RG[-1]) + 8, 1) seg = np.array([[0, 8], [xx1['d'].shape[0] - 8, xx1['d'].shape[0]]]) fit, bas = backremv(xx1['d'], seg) bbas = bas[8:xx1['d'].shape[0] - 8, :] if bass == 'baseline': xxo = xx['d'] - bbas resn = xx['d'] - bbas - dd else: xxo = xx['d'] resn = xx['d'] - dd un = np.sum((np.power(resn, 2))) sstn = np.sum(np.power(xxo, 2)) R2 = (sstn - un) / sstn print(R2) plt.plot(np.sum(xx1['d'], axis=1), 'b') # plt.plot(range(8,xx1['d'].shape[0]-8),np.sum(dd,axis=0),'r') t = range(8, xx1['d'].shape[0] - 8) plt.plot(t, np.sum(dd, axis=1), 'r') plt.plot(np.sum(bas, axis=1), 'k') plt.show()
def plot_compara1(): pkl_file = open('PD6--RM--') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/75.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] mz = msrt['mz'] # com = [79] com = range(22, 27) rttic = ncr.tic()['rt'] plt.figure() ax = plt.subplot(111) rang = [] colors = ['r', 'g', 'c', 'y', 'm'] for ii, i in enumerate(com): tz, seg2, x, segx, maxpos, irr = findTZ(ncr, rts[i], np.array(ms[i], ndmin=2), pw, w, mth='RM') rang.extend(tz) c, vsel, pc = gridsearch(x, maxpos, 6, irr) chrom, area, heig, d = polyfitting(c, x, vsel, np.array(ms[i], ndmin=2)) # plt.subplot(111) # plt.plot(np.sum(x, axis=1)) plt.plot(rttic[range(tz[0], tz[1])], chrom, color=colors[ii], linewidth=3.0, label='c' + str(ii + 1)) plt.plot( rttic[range(tz[0], tz[1])], chrom, color='m', ) segx = ncr.mat(min(rang), max(rang) - 1, 1) rtseg = rttic[range(min(rang), max(rang))] plt.plot(rtseg, np.sum(segx['d'], axis=1), color='b', linewidth=3.0, label='raw') ax.set_xlim((min(rtseg), max(rtseg))) ax.set_xlabel('retention time (min)') ax.set_ylabel('intensity') # plt.legend(loc='upper left') plt.show()
def updata_inputs(self, pdata, path): self.results = [] self.idents = [] self.seleno = 0 self.refflag = QString() self.ticflag = QString() self.selefiles = str() self.msrtflag = str() self.massflag = str() self.MSRT = pdata['MSRT'] self.files = pdata['files'] files = [] if not os.path.isdir(self.files['dir']): dir = str(self.fileWidget.directoryComboBox.currentText()) else: dir = self.files['dir'] for fn in self.files['fn']: if '&' in fn: fnl = fn[1:] else: fnl = fn if os.path.isfile(dir + '/' + fnl): files.append(dir + '/' + fnl) if len(files) == len(self.files['files']): self.files['dir'] = dir self.files['files'] = files elif len(files): msgBox = QMessageBox() msgBox.setText("CDF Files not complete") msgBox.exec_() return else: msgBox = QMessageBox() msgBox.setText("CDF Files not exist in Dir") msgBox.exec_() return self.options = pdata['options'] self.results = pdata['results'] self.finish_files = pdata['finish_files'] ref_seg = pdata['ref_seg'] segments = pdata['segments'] resu_results = pdata['resu_results'] ncr = netcdf_reader(self.files['files'][0], bmmap=False) finished = pdata['finished'] self.fileWidget.loading(self.files) self.segtable.loading(segments, resu_results) self.refplot.loading(ref_seg, ncr, self.files['fn'][0]) self.msrttable.loading(self.MSRT, finished) self.ticplot.loading() self.resoluset.loading(segments, ncr) self.massdlg.loading() self.mcralsmass.loading() self.setmarsdlg.loading(self.options)
def mainaddresol(self, num, row): rt = self.MSRT['rt'][num] ms = self.MSRT['ms'][num] mz = self.MSRT['mz'] chrom = {} if num in self.msrttable.finished: nnum = np.searchsorted(self.msrttable.finished, num) if row >= 0: res = self.results[row - 1] file = self.files['files'][row] rts = netcdf_reader(file, bmmap=False).tic() tz = res['tzs'][nnum, :] seg = res['segs'][nnum, :] tzs = rts['rt'][tz[0]:tz[1]] segs = rts['rt'][seg[0]:seg[1]] orc = res['orc'][nnum] chr = res['chrs'][nnum] chrom = {'rts': tzs, 'chrom': chr, 'segs': segs, 'orc': orc} self.massdlg.addresolmass(rt, ms, mz, num, chrom, self.ticflag)
def ticfig(self, fn, row): file = self.files['files'][row] ncr = netcdf_reader(file, bmmap=False) # self.refflag = str(fn) if '&' in fn: self.refplot.add_tic(ncr, fn) self.refflag = fn self.resoluset.update_ncr(ncr) else: self.ticplot.add_tic(ncr, fn) self.ticflag = fn massplot = self.massdlg.massplot files = self.files['fn'] row = files.index(self.ticflag) rtitems = self.msrttable.get_rtitem() if len(massplot): num = rtitems.index(massplot) rt = self.MSRT['rt'][num] self.mainaddresol(num, row)
starttime_t = datetime.datetime.now() COMs = [1, 2, 3, 4, 5] work_path = 'C:/Users/admin/Desktop/DeepResolution2_upload' model_size = 128 data_path = 'F:/GCMS/male infertility plasma' result_path = work_path + '/resultpath' mkdir(result_path) pathDir = os.listdir(data_path) for file in pathDir: data_file = os.path.join(data_path, file) print('Data file: ' + str(file) + ' start...') ncr = netcdf_reader(data_file, bmmap=False) m = ncr.mat(1, 8774, 1) ######################### U-Net4S ################################ tf.keras.backend.clear_session() ops.reset_default_graph() starttime = datetime.datetime.now() y_DeepSeg, ind_st_DeepSeg, ind_en_DeepSeg = UNet4S(work_path, m, model_size, distance=5, threshold=15) endtime = datetime.datetime.now()
tiab.extend(x[tt, i]) reg.extend(np.arange(seg[j][0], seg[j][1])) rm = reg - np.mean(reg) tm = tiab - np.mean(tiab) b = np.dot(np.dot(float(1) / np.dot(rm.T, rm), rm.T), tm) s = np.mean(tiab) - np.dot(np.mean(reg), b) b_est = s + b * np.arange(mn[0]) bak2[:, i] = x[:, i] - b_est bak = x - bak2 return bak2, bak if __name__ == '__main__': filename = 'F:\MARS\data_save\D6/73.CDF' ncr = netcdf_reader(filename, True) options = {'chrom': ['fnnls', 'average'], 'mass': ['fnnls']} x = ncr.mat(1850, 1890, 1) # ax = plt.figure() # ax.add_subplot(111) # ax.show() plt.plot(x['d']) plt.show() ### test MCR_ALS pures = pure(x['d'].T, 3, 10) # RESU = MCRALS(x, 3, pures['SP'], options) # moptions = {'pw':80, 'w':3, 'thres':0.8} # MSRT = {'ms': RESU['spec'], 'rt': RESU['rt']}
# vsel90 = vse[np.where(np.array(SI) >= 0.90)[0]] # vsel95 = vse[np.where(np.array(SI) >= 0.95)[0]] # # plt.plot(x[:, vsel95]) # # plt.show() # return vsel90, vsel95 if __name__ == '__main__': # pkl_file = open('heye12-4.pkl') pkl_file = open('PD6--RM--') # pkl_file = open('standardn2') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/73.CDF" # fn = "F:\MARS\data_save\STDAND/zhi50-5vs1.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] com = 48 tz, seg, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, mth='RM') # RM = reverse_match(x, ms[com]) # plt.plot(RM)
"select peakindex,peakintensity from catalog where id=%d" % (self.corrs_top10[i][0])) temp = self.cur.fetchall() masstemp = np.frombuffer(temp[0][0], dtype=np.int) intensitytemp = np.frombuffer(temp[0][1], dtype=np.int) temp2 = (self.corrs_top10[i][0], corrcoef_ms(masstemp, intensitytemp, self.ms_search['mz'], self.ms_search['val'])) self.corrs.append(temp2) self.corrs.sort(key=lambda d: d[1], reverse=True) if __name__ == "__main__": from NetCDF import netcdf_reader import time filename = 'E:\MARS\data_save\D6/73.CDF' ncr = netcdf_reader(filename) ms = binMS(ncr.mz_rt(20.50)) ms_bg = binMS(ncr.mz_rt(20.60)) ms['val'] = np.abs(ms['val'] - ms_bg['val']) # background correction t = time.time() nist = NISTSearch(NIST_DBPath) nist.top10_screen(ms) nist.corr() print nist.corrs print time.time() - t
def get_feature(): pkl_file = open('PD6--RM--') # pkl_file = open('standardn2') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/73.CDF" # fn = "F:\MARS\data_save\STDAND/zhi50-5vs1.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] com = 49 tz, seg, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, thre) c, vsel, pc = gridsearch(x, maxpos, 6, irr) c0 = ittfa(x, maxpos, 1) c1 = ittfa(x, maxpos, 2) c2 = ittfa(x, maxpos, 3) c3 = ittfa(x, maxpos, 4) c4 = ittfa(x, maxpos, 5) c5 = ittfa(x, maxpos, 11) # # fig1 = plt.figure(321) plt.subplot(322) plt.plot(x, color='k', linewidth=1.5, alpha=0.35) plt.subplot(324) plt.plot(c0, 'k') # plt.plot(c2, 'y') # plt.plot(c3, 'c') # plt.plot(c4, 'k') plt.plot(c5, 'b') plt.plot(c1, 'r') chrom, area, heig, d = polyfitting(c, x, vsel, np.array(ms[com], ndmin=2)) ax2 = plt.subplot(326) plt.plot(np.sum(x, axis=1)) plt.plot(chrom, 'r') ax2.set_xlabel('scans') com = 48 tz, seg, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, thre) c, vsel, pc = gridsearch(x, maxpos, 6, irr) c0 = ittfa(x, maxpos, 1) c1 = ittfa(x, maxpos, 2) c2 = ittfa(x, maxpos, 3) c3 = ittfa(x, maxpos, 4) c4 = ittfa(x, maxpos, 5) c5 = ittfa(x, maxpos, 11) # # fig1 = plt.figure(321) plt.subplot(321) plt.plot(x, color='k', linewidth=1.5, alpha=0.35) plt.subplot(323) # plt.plot(c0, 'g') plt.plot(c1, 'k') # plt.plot(c2, 'y') # plt.plot(c3, 'c') plt.plot(c5, 'b') plt.plot(c4, 'r') chrom, area, heig, d = polyfitting(c, x, vsel, np.array(ms[com], ndmin=2)) ax1 = plt.subplot(325) plt.plot(np.sum(x, axis=1)) plt.plot(chrom, 'r') ax1.set_xlabel('scans') plt.subplots_adjust(left=0.08, right=0.95, bottom=0.1, top=0.9, hspace=0.35) plt.show()
def plot_fig5(): pkl_file = open('PD6--RM--') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/73.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] mz = msrt['mz'] com = 23 d = ncr.mat(1845, 1895, 1) rttic = ncr.tic()['rt'] rts = rttic[range(1845, 1896)] pos = np.searchsorted(rts, [12.753]) plt.plot(d['d'][pos[0], :]) plt.show() map = np.argsort(d['d'][pos[0], :])[::-1][0:10] print(map) mzs = d['mz'] mz1 = mzs[123] mz2 = mzs[265] mz3 = mzs[170] ax1 = plt.subplot(211) plt.plot(rts, d['d'], color='k', linewidth=1.5, alpha=0.35) plt.plot(rts, d['d'][:, 123], color='k', linewidth=1.5, alpha=0.35, label='raw') plt.plot(rts, d['d'][:, 123], color='g', label='m/z=' + str(int(mz1))) plt.plot(rts, d['d'][:, 265], color='r', label='m/z=' + str(int(mz2))) plt.plot(rts, d['d'][:, 170], color='b', label='m/z=' + str(int(mz3))) ax1.set_xlim((min(rts), max(rts))) ax1.set_xlabel('retention time (min)') ax1.set_ylabel('intensity') plt.legend(loc='upper right') pkl_file = open('standard') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\STDAND/zhi10-5vs1.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) d = ncr.mat(1470, 1506, 1) rttic = ncr.tic()['rt'] rts = rttic[range(1470, 1507)] # pos = np.searchsorted(rts, [12.753]) # plt.plot(d['d'][pos[0], :]) # plt.show() # map = np.argsort(d['d'][pos[0], :])[::-1][0:10] # print(map) mzs = d['mz'] ax2 = plt.subplot(212) plt.plot(rts, d['d'], color='k', linewidth=1.5, alpha=0.35) ax2.set_xlim((min(rts), max(rts))) ax2.set_ylim((0, 400000)) ax2.set_xlabel('retention time (min)') ax2.set_ylabel('intensity') plt.legend(loc='upper right') plt.show()
def plot_compara2(): pkl_file = open('PD6--RM--') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/73.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] mz = msrt['mz'] com = 23 rttic = ncr.tic()['rt'] plt.figure() ax = plt.subplot(111) colors = ['r', 'g', 'c', 'y', 'm'] tz, seg2, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, mth='RM') # c1, vsel1 = gridsearch(x, maxpos, 6, irr) c1 = ittfa(x, maxpos, 3) vsel2, vsel99 = count99(x, c1) chrom1, area, heig, d = polyfitting(c1, x, vsel2, np.array(ms[com], ndmin=2)) print(len(vsel99)) # c2 = ittfa(x, maxpos, 2) c2, vsel1, pc = gridsearch(x, maxpos, 6, irr) vsel2, vsel99 = count99(x, c2) chrom2, area, heig, d = polyfitting(c2, x, vsel2, np.array(ms[com], ndmin=2)) print(len(vsel99)) plt.plot(rttic[range(tz[0], tz[1])], chrom1, color=colors[0], linewidth=3.0, label='com number =' + str(3)) plt.plot(rttic[range(tz[0], tz[1])], chrom2, color=colors[1], linewidth=3.0, label='com number =' + str(4)) plt.plot(rttic[range(tz[0], tz[1])], np.sum(x, axis=1), color='b', linewidth=3.0, label='raw') ax.set_xlim((min(rttic[range(tz[0], tz[1])]), max(rttic[range(tz[0], tz[1])]))) ax.set_xlabel('retention time (min)') ax.set_ylabel('intensity') plt.legend(loc='upper left') plt.show()
S[:, j] = a #S = np.dot(np.linalg.pinv(C), X) Res = X - np.dot(C, S) S = S.T return C, S, Res if __name__ == "__main__": from NetCDF import netcdf_reader from pylab import plot, show, figure, scatter, xlabel, ylabel, hist, ylim, axhline, vlines, subplot import sys filename = 'C:/Users/admin/Desktop/DeepResolution/CDF/zhi10-5vs1.CDF' ncr = netcdf_reader(filename, bmmap=False) m = ncr.mat(0, ncr.scan_acquisition_time.shape[0] - 1, 1) m = m['d'] plot(m) show() #Pures = SelectPureChromatogram(m, 0.0001, 10) # t = [6, 7, 8,13]#[0, 8, 12,14,16,20] #[9, 12, 15,20] # C, S, Res = iskss(m, t) # plot(C) # show() # # for i in range(0, C.shape[1]): # plot(np.dot(C[:, i:i+1],S[:,i:i+1].T))
def getmars_results(self): if len(self.MSRT) == 0: msgBox = QMessageBox() msgBox.setText("Please input MSRT.") msgBox.exec_() elif len(self.files) == 0: msgBox = QMessageBox() msgBox.setText("Please loading files.") msgBox.exec_() else: if len(self.results) == 0: MSRT = self.MSRT files = self.files fns = self.files['fn'] flag = 0 fflag = 0 else: if len(self.MSRT['rt']) == len(self.results[0]['tzs']): MSRT = self.MSRT flag = 0 else: flag = 1 new_rt = [] new_ms = [] vsel = [] for i in range(0, len(self.MSRT['rt'])): if i not in self.msrttable.finished: vsel.append(i) new_rt.append(self.MSRT['rt'][i]) new_ms.append(self.MSRT['ms'][i]) MSRT = {'ms': new_ms, 'rt': new_rt} if self.files['fn'] == self.finish_files: fils = self.files['files'] fns = self.files['fn'] fflag = 0 else: fflag = 1 fns = [] fils = [] for i, fn in enumerate(self.files['fn']): if str(fn) not in self.finish_files: fns.append(fn) fils.append(self.files['files'][i]) if flag == 0 and fflag == 0: return dir = self.files['dir'] files = {'fn': fns, 'files': fils, 'dir': dir} progressDialog = QProgressDialog(self) progressDialog.setWindowModality(Qt.WindowModal) progressDialog.setMinimumDuration(1) progressDialog.setWindowTitle('waiting...') progressDialog.setCancelButtonText('cancle') progressDialog.setRange(1, len(self.files['files'])) if flag == 1 and fflag == 1: results1 = [] results2 = [] for ind, fn in enumerate(self.files['files']): QApplication.processEvents() # progressDialog.setLabelText(str(ind+1)+'/' + str(len(self.files['files']))+'th files processing') # progressDialog.setValue(ind + 1) if '&' not in self.files['fn'][ind]: ncr = netcdf_reader(fn, bmmap=False) if str(self.files['fn'][ind]) in self.finish_files: result = mars(ncr, MSRT, self.options) results1.append(result) else: result = mars(ncr, self.MSRT, self.options) results2.append(result) print(ind) QApplication.processEvents() progressDialog.setLabelText( str(ind + 1) + '/' + str(len(self.files['files'])) + 'th files processing') progressDialog.setValue(ind + 1) if progressDialog.wasCanceled(): return self.results = self.combine_result(results1, vsel) self.results.extend(results2) else: results = [] for ind, fn in enumerate(files['files']): QApplication.processEvents() progressDialog.setLabelText( str(ind + 1) + '/' + str(len(fns)) + 'th files processing') progressDialog.setValue(ind + 1) if '&' not in files['fn'][ind]: ncr = netcdf_reader(fn, bmmap=False) result = mars(ncr, MSRT, self.options) results.append(result) print(ind) QApplication.processEvents() progressDialog.setLabelText( str(ind + 1) + '/' + str(len(fns)) + 'th files processing') progressDialog.setValue(ind + 1) if progressDialog.wasCanceled(): return if flag == 1 and fflag == 0: self.results = self.combine_result(results, vsel) elif flag == 0: self.results.extend(results) self.finish_files = self.files['fn'] self.msrttable.update_resulist(self.results)
def plot_RM(): pkl_file = open('PD6--RM--') data = pickle.load(pkl_file) msrt = data['MSRT'] fn = "F:\MARS\data_save\D6/73.CDF" options = data['options'] ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] mz = msrt['mz'] com = 33 rttic = ncr.tic()['rt'] tz, seg1, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, mth='MSWFA') resp1, eig1, ir = MSWFA(segx, np.array(ms[com], ndmin=2), 5, w, mth='MSWFA') tz, seg2, x, segx, maxpos, irr = findTZ(ncr, rts[com], np.array(ms[com], ndmin=2), pw, w, mth='RM') resp2, eig2, ir = MSWFA(segx, np.array(ms[com], ndmin=2), 5, w, mth='RM') po = rttic[tz] x1 = rttic[range(seg1[0], seg1[1])] x2 = rttic[range(seg2[0], seg2[1])] pos = np.searchsorted(x2, po) plt.figure() ax1 = plt.subplot(211) ax1.plot(x1, eig1, color='r', label='MSWFA') ax1.plot(x2, eig2, color='b', label='RM') ax1.scatter(np.array(po), np.array(eig2)[pos], s=45, marker='^', color='black') maxpos = np.argmax(eig2) maxrt = rttic[np.arange(seg1[0], seg1[1])[maxpos]] ax1.scatter(np.array([maxrt]), np.array(eig2)[maxpos], s=45, marker='o', color='blue') ax1.set_xlim((min(x1), max(x1))) ax1.set_ylim((0, 1.02)) plt.subplots_adjust(bottom=0.1, top=0.95, hspace=0.25) ax1.set_ylabel('score') ax1.set_xlabel('retention time (min)') plt.legend(loc='upper left') ax = plt.subplot(212) ii = 12 y1 = x[ii, :] / norm(x[ii, :]) ax.vlines(mz, np.zeros((len(mz), )), y1, color='b', linestyles='solid', label='R') y2 = ms[com] / norm(ms[com]) ind = np.argsort(y2)[::-1][1:20] yy = y2[ind] mz1 = mz[ind] ax.vlines(mz1, np.zeros((len(mz1), )), -yy, color='r', linestyles='solid', label='E') ax.plot(range(0, len(mz)), np.zeros(len(mz)), color='k') ax.set_xlim((min(mz), 350)) ax.set_ylim((-0.25, 0.25)) ax.set_xlabel('m/z') ax.set_ylabel('intensity') plt.legend(loc='lower left') plt.show()
pkl_file = open('PD6--RM--') data = pickle.load(pkl_file) msrt = data['MSRT'] # fn = "F:\MARS\data_save\D6/75.CDF" options = data['options'] # ncr = netcdf_reader(fn, bmmap=False) pw = options['pw'] w = options['w'] thre = options['thres'] rts = msrt['rt'] ms = msrt['ms'] mz = msrt['mz'] files = data['files']['files'] # fn = files[0] ncr = netcdf_reader("F:\\MARS\\data_save\\D6/73.CDF", bmmap=False) # sics = [] # times = [] # pcs = [] # R2 = [] # nums = [] # # tt1 = time.time() # for i, m in enumerate(ms): # # t1 = time.time() # tz1, seg1, x1, segx1, maxpos1, irr1 = findTZ(ncr, rts[i], np.array(ms[i], ndmin=2), pw, w, mth='MSWFA') # t2 = time.time() # dt1 = t2-t1 #