def load_mzml_file(files, start_time, stop_time): """Load MS1 scans from MZML files""" t0 = timer.time() ScanList = {} ms1ScanList = {} profiles = {} for file_iter in files: parser = mspy.parseMZML(path + file_iter + ".mzML") parser.load() ScanList[file_iter] = parser.scanlist() ms1ScanList[file_iter] = [] profiles[file_iter] = {} for key, scan_info in ScanList[file_iter].iteritems(): if ( scan_info["msLevel"] == 1 and scan_info["retentionTime"] >= start_time and scan_info["retentionTime"] <= stop_time ): ms1ScanList[file_iter].append(key) profiles[file_iter][key] = parser.scan(key).profile t1 = timer.time() - t0 print "Extracted data in %s " % t1 return [ScanList, ms1ScanList, profiles]
def load_mzml_file(self): """Load MS1 scans from MZML files""" t0 = timer.time() self.parser = mspy.parseMZML(self.filename + '.mzML') self.parser.load() self.scan_list = self.parser.scanlist() self.ms1_indices = [] self.profiles = {} for key, scan_info in self.scan_list.iteritems(): if scan_info['msLevel'] == 1 \ and scan_info['retentionTime'] >= self.start_time \ and scan_info['retentionTime'] <= self.stop_time: self.ms1_indices.append(key) self.profiles[key] = self.parser.scan(key).profile t1 = timer.time() - t0 print 'Loaded MS1 spectra in %s ' % t1
def export_html(): tmpDir = '' reportPath = os.path.join('test.html') reportHTML=REPORT_HEADER with open('d3.v3.min.js','r') as d3file: reportHTML += d3file.read() reportHTML += '</script>\n<body><div id="graph" class="aGraph" style="position:absolute;top:0px;left:0; float:left;"></div>' mzfile = mspy.parseMZML('t0r3t1.mzML') mzfile.load() print 'Loaded MZML file' scanlist = mzfile.scanlist() relevant_scans_20 = [] for i_scan in scanlist.keys(): if scanlist[i_scan]['filterString'] == u'FTMS + p ESI sid=35.00 Full ms2 [email protected] [500.00-1600.00]' and scanlist[i_scan]['retentionTime'] > 300 and scanlist[i_scan]['retentionTime'] < 480: relevant_scans_20.append(i_scan) av_scan_20 = None for i_scan in relevant_scans_20: if av_scan_20 == None: av_scan_20 = mzfile.scan(i_scan) else: av_scan_20 += mzfile.scan(i_scan) av_scan_20.profile = mspy.filter(av_scan_20.profile, 0.002) reportHTML += '<script>\ndata_x = [' reportHTML += ','.join(map(str,av_scan_20.profile.T[0])) reportHTML += '];\n' reportHTML += 'data_y = [' reportHTML += ','.join(map(str,av_scan_20.profile.T[1])) reportHTML += '];\n' reportHTML += GRAPH_SCRIPT reportHTML += '</script>' reportHTML += '</body>' reportFile = file(reportPath, 'w') reportFile.write(reportHTML.encode("utf-8")) reportFile.close()