Exemple #1
0
 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);
         }
     }
 }
Exemple #2
0
        protected new void outputWithOrder(Hashtable table, BlockIndex index)
        {
            ArrayList keys = new ArrayList(table.Keys);

            keys.Sort();
            foreach (int key in keys)
            {
                TempScan tempScan = (TempScan)table[key];
                addToIndex(index, tempScan);
            }
        }
Exemple #3
0
 //注意:本函数会操作startPosition这个全局变量
 protected new void addToIndex(BlockIndex index, TempScan ts)
 {
     index.nums.Add(ts.num);
     index.rts.Add(ts.rt);
     index.mzs.Add(startPosition);
     index.ints.Add(startPosition + ts.mzArrayBytes.Length);
     index.cvList.Add(ts.cvs);
     startPosition = startPosition + ts.mzArrayBytes.Length + ts.intArrayBytes.Length;
     index.endPtr  = startPosition;
     airdStream.Write(ts.mzArrayBytes, 0, ts.mzArrayBytes.Length);
     airdStream.Write(ts.intArrayBytes, 0, ts.intArrayBytes.Length);
 }
Exemple #4
0
        //处理MS2,由于每一个MS1只跟随少量的MS2光谱图,因此DDA采集模式下MS2的压缩模式仍然使用Aird ZDPD的压缩算法
        private void doWithMS2Block()
        {
            jobInfo.log("Start Processing MS2 List");
            ArrayList keys = new ArrayList(ms2Table.Keys);

            keys.Sort();
            foreach (int key in keys)
            {
                List <TempIndex> tempIndexList = ms2Table[key] as List <TempIndex>;
                //为每一组key创建一个Block
                BlockIndex blockIndex = new BlockIndex();
                blockIndex.level    = 2;
                blockIndex.startPtr = startPosition;
                blockIndex.num      = key;
                //创建这一个block中每一个ms2的窗口序列
                List <WindowRange> ms2Ranges = new List <WindowRange>();
                jobInfo.log(null, "MS2:" + progress + "/" + ms2Table.Keys.Count);
                progress++;

                foreach (TempIndex index in tempIndexList)
                {
                    WindowRange range = new WindowRange(index.mzStart, index.mzEnd, index.mz);
                    if (index.charge != 0)
                    {
                        range.charge = index.charge;
                    }
                    ms2Ranges.Add(range);
                    TempScan ts = new TempScan(index.num, index.rt, index.tic);
                    if (jobInfo.jobParams.includeCV)
                    {
                        ts.cvs = index.cvList;
                    }
                    compress(spectrumList.spectrum(index.num, true), ts);
                    blockIndex.nums.Add(ts.num);
                    blockIndex.rts.Add(ts.rt);
                    blockIndex.tics.Add(ts.tic);
                    if (jobInfo.jobParams.includeCV)
                    {
                        blockIndex.cvList.Add(ts.cvs);
                    }
                    blockIndex.mzs.Add(ts.mzArrayBytes.Length);
                    blockIndex.ints.Add(ts.intArrayBytes.Length);
                    startPosition = startPosition + ts.mzArrayBytes.Length + ts.intArrayBytes.Length;
                    airdStream.Write(ts.mzArrayBytes, 0, ts.mzArrayBytes.Length);
                    airdStream.Write(ts.intArrayBytes, 0, ts.intArrayBytes.Length);
                }

                blockIndex.rangeList = ms2Ranges;
                blockIndex.endPtr    = startPosition;
                indexList.Add(blockIndex);
            }
        }
Exemple #5
0
        private void scan(int i)
        {
            Spectrum spectrum = spectrumList.spectrum(i, true);

            //忽略所有MS1的谱图
            if (spectrum.cvParamChild(CVID.MS_ms_level).value.ToString().Equals(MsLevel.MS1))
            {
                return;
            }
            double    targetMz = getPrecursorIsolationWindowParams(spectrum, CVID.MS_isolation_window_target_m_z);
            ArrayList ms2List  = null;

            if (rangeMap.Contains(targetMz))
            {
                ms2List = (ArrayList)ms2Map[targetMz];
            }
            else
            {
                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);

                WindowRange range    = new WindowRange(mz - lowerOffset, mz + upperOffset, mz);
                BlockIndex  addIndex = new BlockIndex();
                addIndex.setWindowRange(range);
                rangeMap.Add(targetMz, addIndex);
                ms2Map.Add(targetMz, ArrayList.Synchronized(new ArrayList()));
                ms2List = (ArrayList)ms2Map[targetMz];
            }

            if (spectrum.scanList.scans.Count != 1)
            {
                return;
            }
            try
            {
                TempScan ts = new TempScan(i, parseRT(spectrum.scanList.scans[0]), parseTIC(spectrum));
                if (jobInfo.jobParams.includeCV)
                {
                    ts.cvs = CV.trans(spectrum);
                }
                compress(spectrum, ts);
                ms2List.Add(ts);
            }
            catch (Exception exception)
            {
                jobInfo.log(exception.Message);
                return;
            }
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        //注意:本函数会操作startPosition这个全局变量
        public void addToIndex(BlockIndex index, object tempScan)
        {
            if (jobInfo.jobParams.useStackZDPD())
            {
                TempScanSZDPD ts = (TempScanSZDPD)tempScan;

                index.nums.AddRange(ts.nums);
                index.rts.AddRange(ts.rts);
                index.tics.AddRange(ts.tics);
                if (jobInfo.jobParams.includeCV)
                {
                    index.cvList.AddRange(ts.cvs);
                }
                index.mzs.Add(ts.mzArrayBytes.Length);
                index.ints.Add(ts.intArrayBytes.Length);
                index.tags.Add(ts.tagArrayBytes.Length);
                startPosition = startPosition + ts.mzArrayBytes.Length + ts.tagArrayBytes.Length + ts.intArrayBytes.Length;
                airdStream.Write(ts.mzArrayBytes, 0, ts.mzArrayBytes.Length);
                airdStream.Write(ts.tagArrayBytes, 0, ts.tagArrayBytes.Length);
                airdStream.Write(ts.intArrayBytes, 0, ts.intArrayBytes.Length);
            }
            else
            {
                TempScan ts = (TempScan)tempScan;

                index.nums.Add(ts.num);
                index.rts.Add(ts.rt);
                index.tics.Add(ts.tic);
                if (jobInfo.jobParams.includeCV)
                {
                    index.cvList.Add(ts.cvs);
                }
                index.mzs.Add(ts.mzArrayBytes.Length);
                index.ints.Add(ts.intArrayBytes.Length);
                startPosition = startPosition + ts.mzArrayBytes.Length + ts.intArrayBytes.Length;
                airdStream.Write(ts.mzArrayBytes, 0, ts.mzArrayBytes.Length);
                airdStream.Write(ts.intArrayBytes, 0, ts.intArrayBytes.Length);
            }
        }
Exemple #8
0
        public void compress(Spectrum spectrum, TempScan ts)
        {
            BinaryDataDouble mzData  = spectrum.getMZArray().data;
            BinaryDataDouble intData = spectrum.getIntensityArray().data;
            var dataCount            = mzData.Count;

            int[]   mzArray        = new int[dataCount];
            float[] intensityArray = new float[dataCount];
            int     j = 0;

            for (int t = 0; t < dataCount; t++)
            {
                if (jobInfo.jobParams.ignoreZeroIntensity && intData[t] == 0)
                {
                    continue;
                }
                int mz = Convert.ToInt32(mzData[t] * mzPrecision);
                mzArray[j] = mz;

                if (jobInfo.jobParams.log2)
                {
                    intensityArray[j] = Convert.ToSingle(Math.Round(Math.Log(intData[t]) / log2, 3)); //取log10并且精确到小数点后3位
                }
                else
                {
                    intensityArray[j] = Convert.ToSingle(Math.Round(intData[t], 1)); //精确到小数点后一位
                }
                j++;
            }
            int[] mzSubArray = new int[j];
            Array.Copy(mzArray, mzSubArray, j);
            float[] intensitySubArray = new float[j];
            Array.Copy(intensityArray, intensitySubArray, j);

            int[] compressedMzArray = CompressUtil.fastPforEncoder(mzSubArray);
            ts.mzArrayBytes  = CompressUtil.zlibEncoder(compressedMzArray);
            ts.intArrayBytes = CompressUtil.zlibEncoder(intensitySubArray);
        }
Exemple #9
0
        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);
                }
            }
        }
Exemple #10
0
        //解析MS1和MS2谱图
        protected void doProgress()
        {
            var ms1Index = new BlockIndex(1);
            var ms2Index = new BlockIndex(2);

            jobInfo.log("Preprocessing:" + totalSize, "Preprocessing");
            if (jobInfo.jobParams.threadAccelerate)
            {
                var ms1Table = Hashtable.Synchronized(new Hashtable());
                var ms2Table = Hashtable.Synchronized(new Hashtable());
                //使用多线程处理数据提取与压缩
                Parallel.For(0, totalSize, (i, ParallelLoopState) =>
                {
                    jobInfo.log(null, progress + "/" + totalSize);
                    progress++;
                    var spectrum = spectrumList.spectrum(i, true);
                    if (spectrum.scanList.scans.Count != 1)
                    {
                        ParallelLoopState.Break();
                        return;
                    }

                    var scan = spectrum.scanList.scans[0];
                    var ts   = new TempScan(i, parseRT(scan), parseTIC(spectrum));
                    if (jobInfo.jobParams.includeCV)
                    {
                        ts.cvs = CV.trans(spectrum);
                    }
                    compress(spectrum, ts);
                    var msLevel = parseMsLevel(spectrum);
                    if (msLevel.Equals(MsLevel.MS1))
                    {
                        ms1Table.Add(i, ts);
                    }
                    else
                    {
                        if (activator == null)
                        {
                            parseActivator(spectrum.precursors[0].activation);
                        }
                        ms2Table.Add(i, ts);
                    }
                });

                outputWithOrder(ms1Table, ms1Index);
                outputWithOrder(ms2Table, ms2Index);
            }
            else
            {
                for (var i = 0; i < totalSize; i++)
                {
                    var spectrum = spectrumList.spectrum(i, true);
                    if (spectrum.scanList.scans.Count != 1)
                    {
                        continue;
                    }
                    var scan = spectrum.scanList.scans[0];
                    var ts   = new TempScan(i, parseRT(scan), parseTIC(spectrum));
                    if (jobInfo.jobParams.includeCV)
                    {
                        ts.cvs = CV.trans(spectrum);
                    }
                    compress(spectrum, ts);
                    var msLevel = parseMsLevel(spectrum);
                    if (msLevel.Equals(MsLevel.MS1))
                    {
                        addToIndex(ms1Index, ts);
                    }
                    else
                    {
                        addToIndex(ms2Index, ts);
                    }
                }
            }

            indexList.Add(ms1Index);
            indexList.Add(ms2Index);
        }