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);
        }
Example #3
0
        //private MSScan GetScanFromFile(int argScanNo)
        //{
        //    return GetScanFromFile(argScanNo);
        //}
        private MSScan GetScanFromFile(int argScanNo, float argMinSN = 2)//, float argPPM = 6, int argMinPeakCount=3)
        {
            MSDataScan DataScan = _raw.GetMsScan(argScanNo);

            tolSN = argMinSN;
            //tolMinPeakCount = argMinPeakCount;
            //tolPPM = argPPM;
            MZPeak[] peaks;
            List <ThermoLabeledPeak> TPeaks = new List <ThermoLabeledPeak>();

            peaks = DataScan.MassSpectrum.GetPeaks();

            //Start Read Scan
            MSScan scan = new MSScan(argScanNo);

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


            List <MSPeak> MSPsks = new List <MSPeak>();

            #region MSScan
            if (scan.MsLevel == 1)
            {
                float[] RawMz        = new float[peaks.Length];
                float[] RawIntensity = new float[peaks.Length];

                for (int i = 0; i < peaks.Length; i++)
                {
                    RawMz[i]        = Convert.ToSingle(peaks[i].MZ);
                    RawIntensity[i] = Convert.ToSingle(peaks[i].Intensity);
                    ThermoLabeledPeak TPeak = (ThermoLabeledPeak)peaks[i];
                    if (TPeak.SN >= tolSN)
                    {
                        TPeaks.Add(TPeak);
                    }
                }
                float[] Mz        = new float[TPeaks.Count];
                float[] Intensity = new float[TPeaks.Count];
                for (int i = 0; i < TPeaks.Count; i++)
                {
                    Mz[i]        = Convert.ToSingle(TPeaks[i].MZ);
                    Intensity[i] = Convert.ToSingle(TPeaks[i].Intensity);
                }
                scan.RawMZs         = RawMz;
                scan.RawIntensities = RawIntensity;
                scan.MZs            = Mz;
                scan.Intensities    = Intensity;
                //************************Peak Picking
                //scan.MSPeaks = MSPsks;
                //List<float> TPeaksMZ = new List<float>();
                //for (int i = 0; i < TPeaks.Count; i++)
                //{
                //    TPeaksMZ.Add(Convert.ToSingle(TPeaks[i].MZ));
                //}
                //do
                //{
                //    ThermoLabeledPeak BasePeak = TPeaks[0];
                //    List<ThermoLabeledPeak> clusterPeaks = new List<ThermoLabeledPeak>();
                //    List<int> RemoveIdx = new List<int>();
                //    RemoveIdx.Add(0);
                //    clusterPeaks.Add(BasePeak);
                //    double Interval = 1 / (double)BasePeak.Charge;
                //    double FirstMZ = BasePeak.MZ;
                //    for (int i = 1; i < TPeaks.Count; i++)
                //    {
                //        if (TPeaks[i].MZ - FirstMZ > Interval * 10)
                //        {
                //            break;
                //        }

                //        List<int> ClosePeaks = MassUtility.GetClosestMassIdxsWithinPPM(TPeaksMZ.ToArray(), Convert.ToSingle(BasePeak.MZ + Interval), argPPM);
                //        if (ClosePeaks.Count == 1 && TPeaks[ClosePeaks[0]].Charge == BasePeak.Charge)
                //        {
                //            BasePeak = TPeaks[i];
                //            clusterPeaks.Add(TPeaks[i]);
                //            RemoveIdx.Add(i);
                //        }
                //        else if (ClosePeaks.Count > 1)
                //        {
                //            double minPPM = 100;
                //            int minPPMIdx = 0;
                //            float maxIntensity = 0;
                //            int maxIntensityIdx = 0;
                //            for (int j = 0; j < ClosePeaks.Count; j++)
                //            {
                //                if (MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]) < minPPM)
                //                {
                //                    minPPMIdx = ClosePeaks[j];
                //                    minPPM = MassUtility.GetMassPPM(BasePeak.MZ + Interval, mz[ClosePeaks[j]]);
                //                }
                //                if (intensity[ClosePeaks[j]] > maxIntensity)
                //                {
                //                    maxIntensity = intensity[ClosePeaks[j]];
                //                    maxIntensityIdx = ClosePeaks[j];
                //                }
                //            }
                //            BasePeak = TPeaks[minPPMIdx];
                //            clusterPeaks.Add(TPeaks[minPPMIdx]);
                //            RemoveIdx.Add(minPPMIdx);
                //        }
                //    }
                //    if (clusterPeaks.Count < argMinPeakCount)
                //    {
                //        TPeaks.RemoveAt(RemoveIdx[0]);
                //        TPeaksMZ.RemoveAt(RemoveIdx[0]);
                //    }
                //    else
                //    {
                //        float MostIntenseMZ = 0.0f;
                //        double MostIntenseIntneisty = 0;
                //        double ClusterIntensity = 0;
                //        RemoveIdx.Reverse();
                //        for (int i = 0; i < RemoveIdx.Count; i++)
                //        {
                //            if (TPeaks[RemoveIdx[i]].Intensity > MostIntenseIntneisty)
                //            {
                //                MostIntenseIntneisty = TPeaks[RemoveIdx[i]].Intensity;
                //                MostIntenseMZ = Convert.ToSingle(TPeaks[RemoveIdx[i]].MZ);
                //            }
                //            ClusterIntensity = ClusterIntensity + TPeaks[RemoveIdx[i]].Intensity;
                //            TPeaks.RemoveAt(RemoveIdx[i]);
                //            TPeaksMZ.RemoveAt(RemoveIdx[i]);
                //        }
                //        scan.MSPeaks.Add(new MSPeak(
                //                                                                 Convert.ToSingle(clusterPeaks[0].MZ),
                //                                                                 Convert.ToSingle(clusterPeaks[0].Intensity),
                //                                                                 clusterPeaks[0].Charge,
                //                                                                 Convert.ToSingle(clusterPeaks[0].MZ),
                //                                                                 Convert.ToSingle(clusterPeaks[0].SN),
                //                                                                 MostIntenseMZ,
                //                                                                 MostIntenseIntneisty,
                //                                                                 ClusterIntensity));

                //    }
                //} while (TPeaks.Count != 0);
            }
            #endregion
            #region MS/MS Scan
            else
            {
                float[] mz        = new float[peaks.Length];
                float[] intensity = new float[peaks.Length];
                for (int i = 0; i < peaks.Length; i++)
                {
                    mz[i]        = Convert.ToSingle(peaks[i].MZ);
                    intensity[i] = Convert.ToSingle(peaks[i].Intensity);
                    //MSPsks.Add(new MSPeak(mz[i], intensity[i]));
                }
                scan.MZs         = mz;
                scan.Intensities = intensity;
                //scan.MSPeaks = MSPsks;
                // Get parent information

                scan.ParentScanNo = _raw.GetParentSpectrumNumber(argScanNo);
                scan.ParentMZ     = Convert.ToSingle(_raw.GetPrecusorMz(argScanNo));
                scan.ParentCharge = _raw.GetPrecusorCharge(argScanNo);

                //Parent Mono
                if (scan.ParentScanNo != 0)
                {
                    MSScan     ParentScan = GetScanFromFile(scan.ParentScanNo);
                    int        ClosedIdx  = MassUtility.GetClosestMassIdx(ParentScan.MZs, scan.ParentMZ);
                    List <int> Peaks      = FindPeakIdx(ParentScan.MZs, ClosedIdx, scan.ParentCharge, 10);
                    scan.ParentMonoMz = ParentScan.MZs[Peaks[0]];
                }
            }
            #endregion
            scan.IsCIDScan = IsCIDScan(argScanNo);
            scan.IsHCDScan = IsHCDScan(argScanNo);
            scan.IsFTScan  = IsFTScan(argScanNo);
            return(scan);
        }
Example #4
0
        public enumGlycanType DetermineGlycanType(List <MSPeak> argPeaks)
        {
            enumGlycanType GType = enumGlycanType.NA;
            // Function that attempts to categorize the glycan type by calculating cross correlation

            //First find peaks and get p value
            int    num_hcd_present = 0;
            double hcd_score       = 0;
            double del_mz_bin      = 0.015;
            double del_mz_range    = mdbl_max_mz - mdbl_min_mz;
            double p       = (2 * del_mz_bin) / del_mz_range;
            double p_value = 0;

            double[]   mzs               = new double[argPeaks.Count];
            double[]   intensities       = new double[argPeaks.Count];
            List <int> mint_peak_indices = new List <int>();

            for (int i = 0; i < argPeaks.Count; i++)
            {
                mzs[i]         = argPeaks[i].MonoisotopicMZ;
                intensities[i] = argPeaks[i].MonoIntensity;
            }
            float[] obs_intensities = new float[7];
            double  maxintensity    = 0;

            for (int j = 0; j < 7; j++)
            {
                obs_intensities[j] = 0;
            }
            mint_peak_indices.Clear();



            for (int j = 0; j < 7; j++)
            {
                double this_mz   = marr_theoretical_peaks[j];
                int    ClosedIdx = MassUtility.GetClosestMassIdx(argPeaks, Convert.ToSingle(mzs[j]));

                if (Math.Abs(mzs[ClosedIdx] - this_mz) < del_mz_bin)
                {
                    if (intensities[ClosedIdx] > obs_intensities[j])     //Anoop jan 2011, make sure you get teh highest intensity
                    {
                        num_hcd_present++;
                        mint_peak_indices.Add(ClosedIdx);
                        obs_intensities[j] = (float)intensities[ClosedIdx];
                        if (intensities[ClosedIdx] > maxintensity)
                        {
                            maxintensity = intensities[ClosedIdx];
                        }
                    }
                }
            }
            // Normalizing
            for (int j = 0; j < 7; j++)
            {
                obs_intensities[j] = (float)(obs_intensities[j] / maxintensity);
            }

            if (num_hcd_present >= mint_min_number_peaks)
            {
                for (int i = 0; i < mint_peak_indices.Count; i++)
                {
                    identified_peak_indices.Add(mint_peak_indices[i]);
                }

                // Start calculating p value
                long N_factorial = Factorial(7);

                if (num_hcd_present > 7)
                {
                    num_hcd_present = 7;
                }

                for (int x = num_hcd_present; x <= 7; x++)
                {
                    long   x_factorial   = Factorial(x);
                    long   N_x_factorial = Factorial(7 - x);
                    double N_choose_x    = (double)(N_factorial / (x_factorial * N_x_factorial));
                    double pX            = N_choose_x * Math.Pow(p, x) * Math.Pow(1 - p, 7 - x);
                    p_value += pX;
                }

                //Now do a correlation with each class
                float corr_HM     = 0;
                float corr_CA     = 0;
                float corr_CS     = 0;
                float corr_Hybrid = 0;
                float max_corr    = 0;

                //Anoop Jan 2011, performing the glycan type detection in two stages,
                //if NeuAc peak  (or its water equivalent) is present, a distinction between hybrid and sialylated structures is made
                // else only look for high mannose and complex_asialylated
                if ((obs_intensities[4] > 0) || (obs_intensities[3] > 0))
                {
                    corr_CS     = Correlation(obs_intensities, marr_theoretical_cs, 0);
                    corr_Hybrid = Correlation(obs_intensities, marr_theoretical_hybrid, 0);
                    corr_HM     = 0;
                    corr_CA     = 0;
                }
                else
                {
                    corr_CS     = 0;
                    corr_Hybrid = 0;
                    corr_HM     = Correlation(obs_intensities, marr_theoretical_hm, 0);
                    corr_CA     = Correlation(obs_intensities, marr_theoretical_ca, 0);
                }


                max_corr = Math.Max(Math.Max(Math.Max(corr_HM, corr_CA), corr_CS), corr_Hybrid);

                if (max_corr == corr_HM)
                {
                    GType = enumGlycanType.HM;
                }
                if (max_corr == corr_CA)
                {
                    GType = enumGlycanType.CA;
                }
                if (max_corr == corr_CS)
                {
                    GType = enumGlycanType.CS;
                }
                if (max_corr == corr_Hybrid)
                {
                    GType = enumGlycanType.HY;
                }
            }
            else
            {
                p_value = 1;
                GType   = enumGlycanType.NA;
            }

            return(GType);
        }
Example #5
0
        private MSScan GetScanFromFile(int argScanNo)
        {
            MSScan scan = new MSScan(argScanNo);

            float[] _cidMzs         = null;
            float[] _cidIntensities = null;

            Raw.GetSpectrum(argScanNo, ref _cidMzs, ref _cidIntensities);
            scan.MsLevel = Raw.GetMSLevel(argScanNo);

            double min_peptide_intensity = 0;

            scan.Time       = Raw.GetScanTime(scan.ScanNo);
            scan.ScanHeader = Raw.GetScanDescription(scan.ScanNo);
            if (scan.MsLevel != 1)
            {
                float[] _parentRawMzs        = null;
                float[] _parentRawIntensitys = null;

                string Header = Raw.GetScanDescription(argScanNo);
                cidPeakProcessor.ProfileType = GlypID.enmProfileType.CENTROIDED;
                if (Header.Substring(Header.IndexOf("+") + 1).Trim().StartsWith("p"))
                {
                    cidPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
                }

                // cidPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                //         Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), false);

                for (int chNum = 0; chNum < _cidMzs.Length; chNum++)
                {
                    scan.MSPeaks.Add(new MSPeak(
                                         Convert.ToSingle(_cidMzs[chNum]),
                                         Convert.ToSingle(_cidIntensities[chNum])));
                }

                //for (int chNum = 0; chNum < _cidMzs.Length; chNum++)
                //{
                //    scan.MSPeaks.Add(new MSPeak(
                //        Convert.ToSingle(_cidMzs[chNum]),
                //        Convert.ToSingle(_cidIntensities[chNum])));
                //}

                // Get parent information
                scan.ParentScanNo = Raw.GetParentScan(scan.ScanNo);

                Raw.GetSpectrum(scan.ParentScanNo, ref _parentRawMzs, ref _parentRawIntensitys);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;
                parentPeakProcessor.DiscoverPeaks(ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                float _parentBackgroundIntensity = (float)parentPeakProcessor.GetBackgroundIntensity(ref _parentRawIntensitys);
                _transformResult = new GlypID.HornTransform.clsHornTransformResults[1];
                bool found = false;
                if (Raw.IsFTScan(scan.ParentScanNo))
                {
                    // High resolution data
                    found = mobjTransform.FindPrecursorTransform(Convert.ToSingle(_parentBackgroundIntensity), Convert.ToSingle(min_peptide_intensity), ref _parentRawMzs, ref _parentRawIntensitys, ref _parentPeaks, Convert.ToSingle(scan.ParentMZ), ref _transformResult);
                }
                if (!found)//de-isotope fail
                {
                    // Low resolution data or bad high res spectra
                    short        cs        = Raw.GetMonoChargeFromHeader(scan.ScanNo);
                    double       monoMZ    = Raw.GetMonoMzFromHeader(scan.ScanNo);
                    List <float> ParentMzs = new List <float>(_parentRawMzs);
                    int          CloseIdx  = MassUtility.GetClosestMassIdx(ParentMzs, Convert.ToSingle(monoMZ));

                    if (cs > 0)
                    {
                        short[] charges = new short[1];
                        charges[0] = cs;
                        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult);
                    }
                    else
                    {
                        // instrument has no charge just store 2 and 3.
                        short[] charges = new short[2];
                        charges[0] = 2;
                        charges[1] = 3;
                        mobjTransform.AllocateValuesToTransform(Convert.ToSingle(scan.ParentMZ), Convert.ToInt32(_parentRawIntensitys[CloseIdx]), ref charges, ref _transformResult);
                    }
                }

                if (_transformResult[0].mint_peak_index == -1) //De-isotope parent scan
                {
                    //Get parent info
                    MSScan  _parentScan    = GetScanFromFile(scan.ParentScanNo);
                    float[] _MSMzs         = null;
                    float[] _MSIntensities = null;

                    Raw.GetSpectrum(scan.ParentScanNo, ref _MSMzs, ref _MSIntensities);
                    // Now find peaks
                    parentPeakParameters.SignalToNoiseThreshold = 0;
                    parentPeakParameters.PeakBackgroundRatio    = 0.01;
                    parentPeakProcessor.SetOptions(parentPeakParameters);
                    parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;

                    parentPeakProcessor.DiscoverPeaks(ref _MSMzs, ref _MSIntensities, ref _cidPeaks,
                                                      Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);



                    //Look for charge and mono.


                    float[] monoandcharge = FindChargeAndMono(_cidPeaks, Convert.ToSingle(Raw.GetParentMz(scan.ScanNo)), scan.ScanNo);
                    //scan.ParentMonoMW = _parentScan.MSPeaks[ClosedIdx].MonoMass;
                    //scan.ParentAVGMonoMW = _parentScan.MSPeaks[ClosedIdx].;
                    scan.ParentMZ = monoandcharge[0];
                    if (monoandcharge[1] == 0.0f)
                    {
                        scan.ParentCharge = Convert.ToInt32(Raw.GetMonoChargeFromHeader(scan.ParentScanNo));
                    }
                    else
                    {
                        scan.ParentCharge = Convert.ToInt32(monoandcharge[1]);
                    }

                    scan.ParentMonoMW = (monoandcharge[0] - Atoms.ProtonMass) * monoandcharge[1];
                }
                else
                {
                    scan.ParentMonoMW    = (float)_transformResult[0].mdbl_mono_mw;
                    scan.ParentAVGMonoMW = (float)_transformResult[0].mdbl_average_mw;
                    scan.ParentMZ        = (float)_transformResult[0].mdbl_mz;
                    scan.ParentCharge    = (int)_transformResult[0].mshort_cs;
                }
                scan.IsCIDScan = Raw.IsCIDScan(argScanNo);
                scan.IsFTScan  = Raw.IsFTScan(argScanNo);

                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
                Array.Clear(_parentRawMzs, 0, _parentRawMzs.Length);
                Array.Clear(_parentRawIntensitys, 0, _parentRawIntensitys.Length);
            }
            else //MS Scan
            {
                scan.ParentMZ = 0.0f;
                double mdbl_current_background_intensity = 0;

                // Now find peaks
                parentPeakParameters.SignalToNoiseThreshold = _singleToNoiseRatio;
                parentPeakParameters.PeakBackgroundRatio    = _peakBackgroundRatio;
                parentPeakProcessor.SetOptions(parentPeakParameters);
                parentPeakProcessor.ProfileType = GlypID.enmProfileType.PROFILE;

                parentPeakProcessor.DiscoverPeaks(ref _cidMzs, ref _cidIntensities, ref _cidPeaks,
                                                  Convert.ToSingle(mobjTransformParameters.MinMZ), Convert.ToSingle(mobjTransformParameters.MaxMZ), true);
                mdbl_current_background_intensity = parentPeakProcessor.GetBackgroundIntensity(ref _cidIntensities);

                // Settings
                min_peptide_intensity = mdbl_current_background_intensity * mobjTransformParameters.PeptideMinBackgroundRatio;
                if (mobjTransformParameters.UseAbsolutePeptideIntensity)
                {
                    if (min_peptide_intensity < mobjTransformParameters.AbsolutePeptideIntensity)
                    {
                        min_peptide_intensity = mobjTransformParameters.AbsolutePeptideIntensity;
                    }
                }
                mobjTransformParameters.PeptideMinBackgroundRatio = _peptideMinBackgroundRatio;
                mobjTransformParameters.MaxCharge = _maxCharge;
                mobjTransform.TransformParameters = mobjTransformParameters;


                //  Now perform deisotoping
                _transformResult = new GlypID.HornTransform.clsHornTransformResults[1];
                mobjTransform.PerformTransform(Convert.ToSingle(mdbl_current_background_intensity), Convert.ToSingle(min_peptide_intensity), ref _cidMzs, ref _cidIntensities, ref _cidPeaks, ref _transformResult);
                // for getting results

                for (int chNum = 0; chNum < _transformResult.Length; chNum++)
                {
                    double sumintensity         = 0.0;
                    double mostIntenseIntensity = 0.0;
                    for (int i = 0; i < _transformResult[chNum].marr_isotope_peak_indices.Length; i++)
                    {
                        sumintensity = sumintensity + _cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_intensity;
                        if (Math.Abs(_transformResult[chNum].mdbl_most_intense_mw -
                                     (_cidPeaks[_transformResult[chNum].marr_isotope_peak_indices[i]].mdbl_mz * _transformResult[chNum].mshort_cs - Atoms.ProtonMass * _transformResult[chNum].mshort_cs))
                            < 1.0 / _transformResult[chNum].mshort_cs)
                        {
                            mostIntenseIntensity = _cidPeaks[_transformResult[chNum].mint_peak_index].mdbl_intensity;
                        }
                    }
                    scan.MSPeaks.Add(new MSPeak(
                                         Convert.ToSingle(_transformResult[chNum].mdbl_mono_mw),
                                         _transformResult[chNum].mint_mono_intensity,
                                         _transformResult[chNum].mshort_cs,
                                         Convert.ToSingle(_transformResult[chNum].mdbl_mz),
                                         Convert.ToSingle(_transformResult[chNum].mdbl_fit),
                                         Convert.ToSingle(_transformResult[chNum].mdbl_most_intense_mw),
                                         mostIntenseIntensity,
                                         sumintensity
                                         ));
                }
                Array.Clear(_transformResult, 0, _transformResult.Length);
                Array.Clear(_cidPeaks, 0, _cidPeaks.Length);
                Array.Clear(_cidMzs, 0, _cidMzs.Length);
                Array.Clear(_cidIntensities, 0, _cidIntensities.Length);
            }
            return(scan);
        }