Example #1
0
        private List <int> FindPeakIdx(float[] argMZAry, int argTargetIdx, int argCharge, float argPPM)
        {
            List <int> Peak       = new List <int>();
            float      Interval   = 1 / (float)argCharge;
            float      FirstMZ    = argMZAry[argTargetIdx];
            int        CurrentIdx = argTargetIdx;

            Peak.Add(argTargetIdx);
            //Forward  Peak
            for (int i = argTargetIdx - 1; i >= 0; i--)
            {
                if (argMZAry[argTargetIdx] - argMZAry[i] >= Interval * 10)
                {
                    break;
                }
                List <int> ClosedPeaks = MassUtility.GetClosestMassIdxsWithinPPM(argMZAry, argMZAry[CurrentIdx] - Interval, argPPM);
                if (ClosedPeaks.Count == 1)
                {
                    CurrentIdx = ClosedPeaks[0];
                    Peak.Insert(0, ClosedPeaks[0]);
                }
                else if (ClosedPeaks.Count > 1)
                {
                    double minPPM    = 100;
                    int    minPPMIdx = 0;
                    for (int j = 0; j < ClosedPeaks.Count; j++)
                    {
                        if (MassUtility.GetMassPPM(argMZAry[ClosedPeaks[j]], argMZAry[CurrentIdx] - Interval) < minPPM)
                        {
                            minPPMIdx = ClosedPeaks[j];
                            minPPM    = MassUtility.GetMassPPM(argMZAry[ClosedPeaks[j]], argMZAry[CurrentIdx] + Interval);
                        }
                    }
                    CurrentIdx = minPPMIdx;
                    Peak.Insert(0, CurrentIdx);
                }
            }
            //Backward  Peak
            CurrentIdx = argTargetIdx;
            for (int i = argTargetIdx + 1; i < argMZAry.Length; i++)
            {
                if (argMZAry[i] - argMZAry[argTargetIdx] >= Interval * 10)
                {
                    break;
                }
                List <int> ClosedPeaks = MassUtility.GetClosestMassIdxsWithinPPM(argMZAry, argMZAry[CurrentIdx] + Interval, argPPM);
                if (ClosedPeaks.Count == 1)
                {
                    CurrentIdx = ClosedPeaks[0];
                    Peak.Add(ClosedPeaks[0]);
                }
                else if (ClosedPeaks.Count > 1)
                {
                    double minPPM    = 100;
                    int    minPPMIdx = 0;
                    for (int j = 0; j < ClosedPeaks.Count; j++)
                    {
                        if (MassUtility.GetMassPPM(argMZAry[ClosedPeaks[j]], argMZAry[CurrentIdx] + Interval) < minPPM)
                        {
                            minPPMIdx = ClosedPeaks[j];
                            minPPM    = MassUtility.GetMassPPM(argMZAry[ClosedPeaks[j]], argMZAry[CurrentIdx] + Interval);
                        }
                    }
                    CurrentIdx = minPPMIdx;
                    Peak.Add(CurrentIdx);
                }
            }

            return(Peak);
        }
Example #2
0
        private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)//, float argPPM = 6, int argMinPeakCount=3)
        {
            int mslevel = GetMsLevel(argScanNo);

            tolSN = argMinSN;
            MSScan scan = new MSScan(argScanNo);

            scan.MsLevel    = GetMsLevel(argScanNo);
            scan.Time       = GetRetentionTime(argScanNo);
            scan.ScanHeader = GetScanDescription(argScanNo);



            double[,] peakData;
            if (GetMzAnalyzer(argScanNo) == ThermoMzAnalyzer.ITMS)     //Low Res
            {
                object massList          = null;
                object peakFlags         = null;
                int    arraySize         = -1;
                double centroidPeakWidth = double.NaN;
                _rawConnection.GetMassListFromScanNum(ref argScanNo, null, 0, 0, 0, 0, ref centroidPeakWidth, ref massList, ref peakFlags, ref arraySize);
                peakData = (double[, ])massList;
            }
            else
            {
                object labels = null;
                object flags  = null;
                _rawConnection.GetLabelData(ref labels, ref flags, ref argScanNo);
                peakData = (double[, ])labels;
            }
            scan.RawMZs         = new float[peakData.GetLength(1)];
            scan.RawIntensities = new float[peakData.GetLength(1)];
            if (mslevel == 1)
            {
                List <float> MzsAboveSN        = new List <float>();
                List <float> IntensitysAboveSN = new List <float>();


                for (int i = 0; i < peakData.GetLength(1); i++)
                {
                    scan.RawMZs[i]         = Convert.ToSingle(peakData[(int)RawLabelDataColumn.MZ, i]);
                    scan.RawIntensities[i] = Convert.ToSingle(peakData[(int)RawLabelDataColumn.Intensity, i]);
                    if (peakData.GetLength(0) >= 4)     //Data contain SN
                    {
                        double Noise = peakData[(int)RawLabelDataColumn.NoiseLevel, i];
                        double SN    = 0;
                        if (Noise.Equals(0))
                        {
                            SN = float.NaN;
                        }
                        else
                        {
                            SN = scan.RawIntensities[i] / Noise;
                        }
                        if (SN >= tolSN)
                        {
                            MzsAboveSN.Add(scan.RawMZs[i]);
                            IntensitysAboveSN.Add(scan.RawIntensities[i]);
                        }
                    }
                    else
                    {
                        MzsAboveSN.Add(scan.RawMZs[i]);
                        IntensitysAboveSN.Add(scan.RawIntensities[i]);
                    }
                }
                scan.MZs         = MzsAboveSN.ToArray();
                scan.Intensities = IntensitysAboveSN.ToArray();
            }
            else // MS/MS
            {
                scan.MZs         = new float[peakData.GetLength(1)];
                scan.Intensities = new float[peakData.GetLength(1)];
                for (int i = 0; i < peakData.GetLength(1); i++)
                {
                    scan.MZs[i]         = Convert.ToSingle(peakData[(int)RawLabelDataColumn.MZ, i]);
                    scan.Intensities[i] = Convert.ToSingle(peakData[(int)RawLabelDataColumn.Intensity, i]);
                }
                scan.ParentScanNo = GetParentScanNumber(argScanNo);
                scan.ParentMZ     = GetPrecusorMz(argScanNo);
                scan.ParentCharge = GetPrecusorCharge(argScanNo);

                //Sometime get wrong value
                //scan.ParentMonoMz = Convert.ToSingle(GetExtraValue(argScanNo, "Monoisotopic M/Z:"));
                //Find in raw data
                scan.ParentMonoMz = GetPrecusorMz(argScanNo);
                MSScan parentScan = GetScanFromFile(scan.ParentScanNo);
                float  peakBefore = scan.ParentMZ - (1 / (float)scan.ParentCharge);
                float  foundPeak  = parentScan.RawMZs.OrderBy(x => Math.Abs(x - peakBefore)).ToList()[0];
                while (MassUtility.GetMassPPM(foundPeak, peakBefore) <= 10) //10PPM
                {
                    //Find another
                    scan.ParentMonoMz = foundPeak;
                    peakBefore        = foundPeak - (1 / (float)scan.ParentCharge);
                    foundPeak         = parentScan.MZs.OrderBy(x => Math.Abs(x - peakBefore)).ToList()[0];
                }
                scan.ParentBasePeak  = parentScan.MaxIntensity;
                scan.ParentIntensity = parentScan.RawIntensities[parentScan.RawMZs.ToList().IndexOf(scan.ParentMonoMz)];
            }


            scan.IsCIDScan = IsCIDScan(argScanNo);
            scan.IsHCDScan = IsHCDScan(argScanNo);
            scan.IsFTScan  = IsFTScan(argScanNo);
            return(scan);
        }