public void compressMS2(List <TempIndex> tempIndexList, BlockIndex index) { if (converter.jobInfo.jobParams.threadAccelerate) { Hashtable table = Hashtable.Synchronized(new Hashtable()); //使用多线程处理数据提取与压缩 Parallel.For(0, tempIndexList.Count, (i, ParallelLoopState) => { TempIndex tempIndex = tempIndexList[i]; TempScan ts = new TempScan(tempIndex.num, tempIndex.rt, tempIndex.tic); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = tempIndex.cvList; } converter.compress(converter.spectrumList.spectrum(tempIndex.num, true), ts); table.Add(i, ts); }); converter.outputWithOrder(table, index); } else { foreach (TempIndex tempIndex in tempIndexList) { TempScan ts = new TempScan(tempIndex.num, tempIndex.rt, tempIndex.tic); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = tempIndex.cvList; } converter.compress(converter.spectrumList.spectrum(tempIndex.num, true), ts); converter.addToIndex(index, ts); } } }
//建立Ms1Scan的索引 new private TempIndex parseMS1(Spectrum spectrum, int index) { TempIndex ms1 = new TempIndex(); ms1.level = 1; ms1.num = index; if (spectrum.scanList.scans.Count != 1) { return(ms1); } Scan scan = spectrum.scanList.scans[0]; if (jobInfo.jobParams.includeCV) { ms1.cvList = CV.trans(spectrum); if (scan.cvParams != null) { ms1.cvList.AddRange(CV.trans(scan.cvParams)); } } ms1.rt = parseRT(scan); ms1.tic = parseTIC(spectrum); if (msType == null) { parseMsType(spectrum); } if (polarity == null) { parsePolarity(spectrum); } return(ms1); }
protected TempIndex parseMS2(Spectrum spectrum, int index, int parentIndex) { TempIndex ms2 = new TempIndex(); ms2.level = 2; ms2.pNum = parentIndex; ms2.num = index; try { double mz = getPrecursorIsolationWindowParams(spectrum, CVID.MS_isolation_window_target_m_z); double lowerOffset = getPrecursorIsolationWindowParams(spectrum, CVID.MS_isolation_window_lower_offset); double upperOffset = getPrecursorIsolationWindowParams(spectrum, CVID.MS_isolation_window_upper_offset); int charge = getPrecursorCharge(spectrum); ms2.charge = charge; ms2.mz = mz; ms2.mzStart = mz - lowerOffset; ms2.mzEnd = mz + upperOffset; ms2.wid = lowerOffset + upperOffset; } catch (Exception e) { jobInfo.log("ERROR:SpectrumIndex:" + spectrum.index) .log("ERROR:SpectrumId:" + spectrum.id) .log("ERROR: mz:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_target_m_z).value) .log("ERROR: lowerOffset:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_lower_offset).value) .log("ERROR: upperOffset:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_upper_offset).value); throw e; } if (activator == null) { parseActivator(spectrum.precursors[0].activation); } if (spectrum.scanList.scans.Count != 1) { return(ms2); } Scan scan = spectrum.scanList.scans[0]; if (jobInfo.jobParams.includeCV) { ms2.cvList = CV.trans(spectrum); if (scan.cvParams != null) { ms2.cvList.AddRange(CV.trans(scan.cvParams)); } } ms2.rt = parseRT(scan); ms2.tic = parseTIC(spectrum); return(ms2); }
new private void addToMS2Map(TempIndex ms2Index) { if (ms2Table.Contains(ms2Index.pNum)) { (ms2Table[ms2Index.pNum] as List <TempIndex>).Add(ms2Index); } else { List <TempIndex> indexList = new List <TempIndex>(); indexList.Add(ms2Index); ms2Table.Add(ms2Index.pNum, indexList); } }
protected void addToMS2Map(TempIndex ms2Index) { if (ms2Table.Contains(ms2Index.mz)) { (ms2Table[ms2Index.mz] as List <TempIndex>).Add(ms2Index); } else { List <TempIndex> indexList = new List <TempIndex>(); indexList.Add(ms2Index); ms2Table.Add(ms2Index.mz, indexList); } }
private void parseAndStoreMS2Block() { jobInfo.log("Start Processing MS2 List"); foreach (double key in ms2Table.Keys) { List <TempIndex> tempIndexList = ms2Table[key] as List <TempIndex>; //为每一个key组创建一个SwathBlock BlockIndex swathIndex = new BlockIndex(); swathIndex.level = 2; swathIndex.startPtr = startPosition; //顺便创建一个WindowRanges,用以让Propro服务端快速获取全局的窗口数目和mz区间 WindowRange range = new WindowRange(tempIndexList[0].mzStart, tempIndexList[0].mzEnd, key); swathIndex.setWindowRange(range); ranges.Add(range); jobInfo.log(null, "MS2:" + progress + "/" + ms2Table.Keys.Count); progress++; if (jobInfo.jobParams.threadAccelerate) { Hashtable table = Hashtable.Synchronized(new Hashtable()); //使用多线程处理数据提取与压缩 Parallel.For(0, tempIndexList.Count, (i, ParallelLoopState) => { TempIndex index = tempIndexList[i]; TempScan ts = new TempScan(index.num, index.rt, index.tic); compress(spectrumList.spectrum(index.num, true), ts); table.Add(i, ts); }); outputWithOrder(table, swathIndex); } else { foreach (TempIndex index in tempIndexList) { TempScan ts = new TempScan(index.pNum, index.rt, index.tic); compress(spectrumList.spectrum(index.num, true), ts); addToIndex(swathIndex, ts); } } swathIndex.endPtr = startPosition; indexList.Add(swathIndex); jobInfo.log("MS2 Group Finished:" + progress + "/" + ms2Table.Keys.Count); } }
private static string GetDeleteRootSql(DataTable table) { List <string> sqls = new List <string>(); using (var temp = TempIndex.Borrow()) { var index = temp.Item; FillDeleteByRootIdSql(table, sqls, index); } StringBuilder code = new StringBuilder(); foreach (var sql in sqls) { code.AppendLine(sql); } return(code.ToString().Trim()); }
public void compressMS1(BlockIndex index) { if (converter.jobInfo.jobParams.threadAccelerate) { Hashtable table = Hashtable.Synchronized(new Hashtable()); //使用多线程处理数据提取与压缩 Parallel.For(0, converter.ms1List.Count, (i, ParallelLoopState) => { converter.jobInfo.log(null, "MS1:" + i + "/" + converter.ms1List.Count); TempIndex scanIndex = converter.ms1List[i]; TempScan ts = new TempScan(scanIndex.num, scanIndex.rt, scanIndex.tic); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = scanIndex.cvList; } converter.compress(converter.spectrumList.spectrum(scanIndex.num, true), ts); table.Add(i, ts); }); converter.outputWithOrder(table, index); } else { for (int i = 0; i < converter.ms1List.Count; i++) { converter.jobInfo.log(null, "MS1:" + i + "/" + converter.ms1List.Count); TempIndex scanIndex = converter.ms1List[i]; TempScan ts = new TempScan(scanIndex.num, scanIndex.rt, scanIndex.tic); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = scanIndex.cvList; } converter.compress(converter.spectrumList.spectrum(scanIndex.num, true), ts); converter.addToIndex(index, ts); } } }
private static void FillDeleteByRootIdSql(DataTable table, List <string> sqls, TempIndex index) { foreach (var child in table.BuildtimeChilds) { if (!index.TryAdd(child)) { continue; //已处理过 } if (child.Type == DataTableType.AggregateRoot) { continue; //不删除引用的外部根表 } FillDeleteByRootIdSql(child, sqls, index); if (child.Middle != null) { FillDeleteByRootIdSql(child.Middle, sqls, index); } } var selfSql = GetDeleteByRootIdSql(table); if (!sqls.Contains(selfSql)) { sqls.Add(selfSql); } }
//建立Ms2Scan的索引 new private TempIndex parseMS2(Spectrum spectrum, int index, int parentIndex) { TempIndex ms2 = new TempIndex(); ms2.level = 2; ms2.pNum = parentIndex; ms2.num = index; try { float mz = (float)double.Parse(spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_target_m_z).value.ToString()); //兼容Agilent的DDA数据格式中可能出现的lower offset和upper offset为空的情况 string lowerOffsetStr = spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_lower_offset).value.ToString(); string upperOffsetStr = spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_upper_offset).value.ToString(); float lowerOffset = 0f; if (!lowerOffsetStr.IsNullOrEmpty()) { lowerOffset = (float)double.Parse(lowerOffsetStr); } float upperOffset = 0f; if (!upperOffsetStr.IsNullOrEmpty()) { upperOffset = (float)double.Parse(upperOffsetStr); } ms2.charge = getPrecursorCharge(spectrum); ms2.mz = mz; ms2.mzStart = mz - lowerOffset; ms2.mzEnd = mz + upperOffset; ms2.wid = lowerOffset + upperOffset; } catch (Exception e) { jobInfo.log("ERROR:SpectrumIndex:" + spectrum.index) .log("ERROR:SpectrumId:" + spectrum.id) .log("ERROR: mz:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_target_m_z).value) .log("ERROR: lowerOffset:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_lower_offset).value) .log("ERROR: upperOffset:" + spectrum.precursors[0].isolationWindow .cvParamChild(CVID.MS_isolation_window_upper_offset).value); throw e; } if (spectrum.scanList.scans.Count != 1) { return(ms2); } Scan scan = spectrum.scanList.scans[0]; if (jobInfo.jobParams.includeCV) { ms2.cvList = CV.trans(spectrum); if (scan.cvParams != null) { ms2.cvList.AddRange(CV.trans(scan.cvParams)); } } ms2.rt = parseRT(scan); ms2.tic = parseTIC(spectrum); if (activator == null) { parseActivator(spectrum.precursors[0].activation); } return(ms2); }
public void compressMS1(BlockIndex index) { int layers = (int)Math.Pow(2, converter.jobInfo.jobParams.digit); //计算堆叠层数 int iter = converter.ms1List.Count % layers == 0 ? (converter.ms1List.Count / layers) : (converter.ms1List.Count / layers + 1); //计算循环周期 if (converter.jobInfo.jobParams.threadAccelerate) { Hashtable table = Hashtable.Synchronized(new Hashtable()); //使用多线程处理数据提取与压缩 Parallel.For(0, iter, (i, ParallelLoopState) => { converter.jobInfo.log(null, "MS1:" + i + "/" + iter); List <float> rts = new List <float>(); List <int> nums = new List <int>(); List <long> tics = new List <long>(); List <List <CV> > cvs = new List <List <CV> >(); List <Spectrum> spectrumGroup = new List <Spectrum>(); for (int k = 0; k < layers; k++) { int realNum = i * layers + k; if (realNum >= converter.ms1List.Count) { break; } TempIndex scanIndex = converter.ms1List[realNum]; rts.Add(scanIndex.rt); nums.Add(scanIndex.num); tics.Add(scanIndex.tic); if (converter.jobInfo.jobParams.includeCV) { cvs.Add(scanIndex.cvList); } spectrumGroup.Add(converter.spectrumList.spectrum(scanIndex.num, true)); } TempScanSZDPD ts = new TempScanSZDPD(nums, rts, tics); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = cvs; } converter.compress(spectrumGroup, ts); table.Add(i, ts); }); converter.outputWithOrder(table, index); } else { for (int i = 0; i < iter; i++) { converter.jobInfo.log(null, "MS1:" + i + "/" + iter); List <float> rts = new List <float>(); List <int> nums = new List <int>(); List <long> tics = new List <long>(); List <List <CV> > cvs = new List <List <CV> >(); List <Spectrum> spectrumGroup = new List <Spectrum>(); for (int k = 0; k < layers; k++) { int realNum = i * layers + k; if (realNum >= converter.ms1List.Count) { break; } TempIndex scanIndex = converter.ms1List[realNum]; rts.Add(scanIndex.rt); nums.Add(scanIndex.num); tics.Add(scanIndex.tic); if (converter.jobInfo.jobParams.includeCV) { cvs.Add(scanIndex.cvList); } spectrumGroup.Add(converter.spectrumList.spectrum(scanIndex.num, true)); } TempScanSZDPD ts = new TempScanSZDPD(nums, rts, tics); if (converter.jobInfo.jobParams.includeCV) { ts.cvs = cvs; } converter.compress(spectrumGroup, ts); converter.addToIndex(index, ts); } } }