Beispiel #1
0
        public frmProcessing(MultiGlycanESI argMultiNGlycan, bool argLog)
        {
            InitializeComponent();
            DoLog = argLog;

            _MultiNGlycan = argMultiNGlycan;
            _MultiNGlycan.MaxGlycanCharge = 5;
            int StartScan = argMultiNGlycan.StartScan;
            int EndScan   = argMultiNGlycan.EndScan;

            LstScanNumber = new List <int>();

            for (int i = StartScan; i <= EndScan; i++)
            {
                if (_MultiNGlycan.RawReader.GetMsLevel(i) == 1)
                {
                    LstScanNumber.Add(i);
                }
            }
            Start = DateTime.Now;
            if (DoLog)
            {
                Logger.WriteLog("Start process each scan");
            }
            try
            {
                bgWorker_Process.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        public frmProcessing(MultiGlycanESI argMultiNGlycan, bool argLog )
        {
            InitializeComponent();
            DoLog = argLog;

            _MultiNGlycan = argMultiNGlycan;
            _MultiNGlycan.MaxGlycanCharge = 5;
            int StartScan = argMultiNGlycan.StartScan;
            int EndScan = argMultiNGlycan.EndScan;
            LstScanNumber = new List<int>();

            for (int i = StartScan; i <= EndScan; i++)
            {
                if (_MultiNGlycan.RawReader.GetMsLevel(i) == 1)
                {
                    LstScanNumber.Add(i);
                }
            }
            Start = DateTime.Now;
            if (DoLog)
            {
                Logger.WriteLog("Start process each scan");
            }
            try
            {
                bgWorker_Process.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        public frmBatchProcessing(MultiGlycanESI argMultiNGlycan, List <string> argRawFiles, int argConCurrent, bool argLog)
        {
            NumberOfParallel = argConCurrent;
            InitializeComponent();
            DoLog = argLog;

            _MultiNGlycan = argMultiNGlycan;
            _MultiNGlycan.MaxGlycanCharge = 5;
            _RawFilesList = argRawFiles;
            //ProcessMultiGlycan();
            ProgressUpdate = new Dictionary <string, int>();
            TotalScanNum   = new Dictionary <string, int>();
            _MultiNGlycan.ReadGlycanList();
            _MultiNGlycan.CandidateMzList = _MultiNGlycan.GenerateCandidateGlycanMZList(_MultiNGlycan.GlycanList);
            ProcessingFile   = new string[] { "0", "0", "0" };
            ProcessingStatus = new string[] { "ProcessingStatus", "ProcessingStatus", "ProcessingStatus" };

            progressBar1.Maximum = 100;
            progressBar2.Maximum = 100;
            progressBar3.Maximum = 100;
            lblCurrentFile.Text  = "0 / " + _RawFilesList.Count.ToString();
            bgWorker_Process.RunWorkerAsync();
        }
        public frmBatchProcessing(MultiGlycanESI argMultiNGlycan, List<string> argRawFiles, int argConCurrent, bool argLog)
        {
            NumberOfParallel = argConCurrent;
            InitializeComponent();
            DoLog = argLog;

            _MultiNGlycan = argMultiNGlycan;
            _MultiNGlycan.MaxGlycanCharge = 5;
            _RawFilesList = argRawFiles;
            //ProcessMultiGlycan();
            ProgressUpdate = new Dictionary<string, int>();
            TotalScanNum = new Dictionary<string, int>();
            _MultiNGlycan.ReadGlycanList();
            _MultiNGlycan.CandidateMzList = _MultiNGlycan.GenerateCandidateGlycanMZList(_MultiNGlycan.GlycanList);
            ProcessingFile = new string[] { "0", "0", "0" };
            ProcessingStatus = new string[] { "ProcessingStatus", "ProcessingStatus", "ProcessingStatus" };

            progressBar1.Maximum = 100;
            progressBar2.Maximum = 100;
            progressBar3.Maximum = 100;
            lblCurrentFile.Text = "0 / " + _RawFilesList.Count.ToString();
            bgWorker_Process.RunWorkerAsync();
        }
Beispiel #5
0
        private void PreparingMultiGlycan(Dictionary<COL.GlycoLib.enumLabelingTag,float> argLabeling, List<string> argRawFiles )
        {
            //saveFileDialog1.Filter = "Excel Files (*.xslx)|*.xslx";
            //saveFileDialog1.Filter = "CSV Files (*.csv)|*.csv";

            DateTime time = DateTime.Now;             // Use current time
            string TimeFormat = "yyMMdd HHmm";            // Use this format
            if (DoLog)
            {
                Logger.WriteLog(System.Environment.NewLine + System.Environment.NewLine + "-----------------------------------------------------------");
                Logger.WriteLog("Start Process");
            }

            //saveFileDialog1.FileName = Path.GetDirectoryName(txtRawFile.Text) + "\\" + Path.GetFileNameWithoutExtension(txtRawFile.Text) + "-" + time.ToString(TimeFormat);

            if (txtRawFile.Text == "" || (rdoUserList.Checked && txtGlycanList.Text == "") || txtMaxLCTime.Text == "")
            {
                MessageBox.Show("Please check input values.");
                if (DoLog)
                {
                    Logger.WriteLog("End Process- because input value not complete");
                }
                return;
            }
            //folderBrowserDialog1.SelectedPath = txtRawFile.Text;
            string defaultOutputFolder = txtRawFile.Text + "\\" +DateTime.Now.ToString("yyMMdd-HHmm");
            if (!Directory.Exists(defaultOutputFolder))
            {
                Directory.CreateDirectory(defaultOutputFolder);
            }
            folderBrowserDialog1.SelectedPath = defaultOutputFolder;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string glycanlist = System.Windows.Forms.Application.StartupPath + "\\Default_Combination.csv";
                if (!rdoDefaultList.Checked)
                {
                    glycanlist = txtGlycanList.Text;
                }

                if (DoLog)
                {

                    Logger.WriteLog("Start initial program");

                }
                List<float> AdductMasses = new List<float>();
                Dictionary<float, string> AdductLabel = new Dictionary<float, string>();
                if (chkAdductK.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.Potassium);
                    AdductLabel.Add(MassLib.Atoms.Potassium, "K");
                }
                if (chkAdductNH4.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass);
                    AdductLabel.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass, "NH4");
                }
                if (chkAdductNa.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.SodiumMass);
                    AdductLabel.Add(MassLib.Atoms.SodiumMass, "Na");
                }
                if (chkAdductProton.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.ProtonMass);
                    AdductLabel.Add(MassLib.Atoms.ProtonMass, "H");
                }
                float outMass = 0.0f;
                if (chkAdductUser.Checked && float.TryParse(txtAdductMass.Text, out outMass))
                {
                    AdductMasses.Add(outMass);
                    AdductLabel.Add(outMass, "User");
                }

                // MultiNGlycanESIMultiThreads MultiESIs = new MultiNGlycanESIMultiThreads(glycanlist, txtRawFile.Text, Convert.ToInt32(cboCPU.SelectedItem), _peakParameter, _transformParameters);
                MultiGlycanESI ESI = null;
                if (argLabeling.Count!=0)
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text, 0,99999, glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked,cboSia.SelectedIndex, argLabeling, AdductLabel,AdductMasses, DoLog);
                }
                else
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text,0, 99999, glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked, cboSia.SelectedIndex, DoLog);
                }
                ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.None;
                if (rdoDRAG.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.DRAG;
                }
                else if (rdoMultiplePemrthylated.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.MultiplexPermethylated;
                }

                ESI.MergeDifferentChargeIntoOne = chkMergeDffCharge.Checked;
                ESI.ExportFilePath = folderBrowserDialog1.SelectedPath;
                ESI.MaxLCBackMin = Convert.ToSingle(txtMaxLCTime.Text);
                ESI.MaxLCFrontMin = Convert.ToSingle(txtMinLCTime.Text);
                ESI.IsotopePPM = Convert.ToSingle(txtIsotopeEnvTolerence.Text);
                ESI.MininumIsotopePeakCount = Convert.ToInt32(txtIsotopeEnvMinPeakCount.Text);
                ESI.PeakSNRatio = Convert.ToSingle(txtSN.Text);
                ESI.IsMatchMonoisotopicOnly = chkMonoOnly.Checked;
                ESI.ApplyLinearRegLC = chkApplyLinearRegLC.Checked;
                ESI.ForceProtonatedGlycan = chkForceProtonated.Checked;
                ESI.MinPeakHeightPrecentage = Convert.ToSingle(txtMinPeakHeight.Text);
                if (chkAbundance.Checked)
                {
                    ESI.MinAbundance = Convert.ToDouble(txtAbundanceMin.Text);
                }
                else
                {
                    ESI.MinAbundance = 0;
                }
                if (chkMinLengthOfLC.Checked)
                {
                    ESI.MinLengthOfLC = Convert.ToSingle(txtScanCount.Text);
                }
                else
                {
                    ESI.MinLengthOfLC = 0;
                }

               // ESI.AdductMass = AdductMasses;
                //ESI.AdductMassToLabel = AdductLabel;
                ESI.IndividualImgs = chkIndividualImg.Checked;
                ESI.QuantificationImgs = chkQuantImgs.Checked;
                ESI.TotalLCTime = Convert.ToSingle(txtLCTime.Text);
                ESI.LCTimeTolerance = Convert.ToSingle(txtLCTolerance.Text) / 100.0f;
                if (DoLog)
                {
                    Logger.WriteLog("Initial program complete");
                }
                this.Visible = false;
                int concurrent = Convert.ToInt32(cboConcurrent.Text);
                frmBatchProcessing frmProcess = new frmBatchProcessing(ESI, argRawFiles,  concurrent,DoLog);
                frmProcess.ProtonatedResult = chkProtonatedResult.Checked;
                if (concurrent == 1)
                {
                    frmProcess.Size = new Size(370, 120);
                }
                else if (concurrent ==2)
                {
                    frmProcess.Size = new Size(370, 180);
                }
                else
                {
                    frmProcess.Size = new Size(370, 240);
                }
                frmProcess.ShowDialog();
                this.Visible = true;
                if (DoLog)
                {
                    Logger.WriteLog("Finish process");
                }
            }
        }
Beispiel #6
0
        private void PreparingMultiGlycan(Dictionary <COL.GlycoLib.enumLabelingTag, float> argLabeling)
        {
            DoLog = chkLog.Checked;
            //saveFileDialog1.Filter = "Excel Files (*.xslx)|*.xslx";
            //saveFileDialog1.Filter = "CSV Files (*.csv)|*.csv";

            DateTime time       = DateTime.Now;       // Use current time
            string   TimeFormat = "yyMMdd HHmm";      // Use this format

            if (DoLog)
            {
                Logger.WriteLog(System.Environment.NewLine + System.Environment.NewLine + "-----------------------------------------------------------");
                Logger.WriteLog("Start Process");
            }

            saveFileDialog1.FileName = Path.GetDirectoryName(txtRawFile.Text) + "\\" + Path.GetFileNameWithoutExtension(txtRawFile.Text) + "-" + time.ToString(TimeFormat);


            if (txtRawFile.Text == "" || (rdoUserList.Checked && txtGlycanList.Text == "") || txtMaxLCTime.Text == "")
            {
                MessageBox.Show("Please check input values.");
                if (DoLog)
                {
                    Logger.WriteLog("End Process- because input value not complete");
                }
                return;
            }

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string glycanlist = System.Windows.Forms.Application.StartupPath + "\\Default_Combination.csv";
                if (!rdoDefaultList.Checked)
                {
                    glycanlist = txtGlycanList.Text;
                }

                if (DoLog)
                {
                    Logger.WriteLog("Start initial program");
                }
                List <float> AdductMasses = new List <float>();
                Dictionary <float, string> AdductLabel = new Dictionary <float, string>();
                if (chkAdductK.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.Potassium);
                    AdductLabel.Add(MassLib.Atoms.Potassium, "K");
                }
                if (chkAdductNH4.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass);
                    AdductLabel.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass, "NH4");
                }
                if (chkAdductNa.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.SodiumMass);
                    AdductLabel.Add(MassLib.Atoms.SodiumMass, "Na");
                }
                if (chkAdductProton.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.ProtonMass);
                    AdductLabel.Add(MassLib.Atoms.ProtonMass, "H");
                }
                float outMass = 0.0f;
                if (chkAdductUser.Checked && float.TryParse(txtAdductMass.Text, out outMass))
                {
                    AdductMasses.Add(outMass);
                    AdductLabel.Add(outMass, "User");
                }

                // MultiNGlycanESIMultiThreads MultiESIs = new MultiNGlycanESIMultiThreads(glycanlist, txtRawFile.Text, Convert.ToInt32(cboCPU.SelectedItem), _peakParameter, _transformParameters);
                MultiGlycanESI ESI = null;
                if (argLabeling.Count != 0)
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text, Convert.ToInt32(txtStartScan.Text), Convert.ToInt32(txtEndScan.Text), glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked, cboSia.SelectedIndex, argLabeling, AdductLabel, AdductMasses, DoLog, rdoPositive.Checked);
                }
                else
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text, Convert.ToInt32(txtStartScan.Text), Convert.ToInt32(txtEndScan.Text), glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked, cboSia.SelectedIndex, DoLog, rdoPositive.Checked);
                }
                ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.None;
                if (rdoDRAG.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.DRAG;
                }
                else if (rdoMultiplePemrthylated.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.MultiplexPermethylated;
                }
                ESI.PositiveChargeMode          = rdoPositive.Checked;
                ESI.MergeDifferentChargeIntoOne = chkMergeDffCharge.Checked;
                ESI.ExportFilePath          = saveFileDialog1.FileName;
                ESI.MaxLCBackMin            = Convert.ToSingle(txtMaxLCTime.Text);
                ESI.MaxLCFrontMin           = Convert.ToSingle(txtMinLCTime.Text);
                ESI.IsotopePPM              = Convert.ToSingle(txtIsotopeEnvTolerence.Text);
                ESI.MininumIsotopePeakCount = Convert.ToInt32(txtIsotopeEnvMinPeakCount.Text);
                ESI.PeakSNRatio             = Convert.ToSingle(txtSN.Text);
                ESI.IsMatchMonoisotopicOnly = chkMonoOnly.Checked;
                ESI.ApplyLinearRegLC        = chkApplyLinearRegLC.Checked;
                ESI.MinPeakHeightPrecentage = Convert.ToSingle(txtMinPeakHeight.Text);
                if (chkAbundance.Checked)
                {
                    ESI.MinAbundance = Convert.ToDouble(txtAbundanceMin.Text);
                }
                else
                {
                    ESI.MinAbundance = 0;
                }
                if (chkMinLengthOfLC.Checked)
                {
                    ESI.MinLengthOfLC = Convert.ToSingle(txtScanCount.Text);
                }
                else
                {
                    ESI.MinLengthOfLC = 0;
                }
                if (chkMZMatch.Checked)
                {
                    ESI.IncludeMZMatch = true;
                }
                ESI.ForceProtonatedGlycan = chkForceProtonated.Checked;
                // ESI.AdductMass = AdductMasses;
                //ESI.AdductMassToLabel = AdductLabel;
                ESI.IndividualImgs     = chkIndividualImg.Checked;
                ESI.QuantificationImgs = chkQuantImgs.Checked;
                ESI.TotalLCTime        = Convert.ToSingle(txtLCTime.Text);
                ESI.LCTimeTolerance    = Convert.ToSingle(txtLCTolerance.Text) / 100.0f;

                if (lstGU != null && lstGU.Count > 0)
                {
                    ESI.GlycanUnits = lstGU;
                    double[] x = lstGU.Select(ti => Convert.ToDouble(ti.EluctionTime)).ToArray();
                    double[] y = lstGU.Select(gu => Convert.ToDouble(gu.GU)).ToArray();
                    ESI.GUFitFunction = new ViliPetek.LinearAlgebra.PolyFit(x, y, 5);
                }
                if (DoLog)
                {
                    Logger.WriteLog("Initial program complete");
                }
                frmProcessing frmProcess = new frmProcessing(ESI, DoLog);
                frmProcess.ShowDialog();
                if (DoLog)
                {
                    Logger.WriteLog("Finish process");
                }
            }
        }
        public static void Processing(ref MultiGlycanESI argMultiGlycan)
        {
            GlycanCompound processed;
            try
            {

                List<string> identifiedGlycan =argMultiGlycan.IdentifiedGlycanCompounds.Select(x => x.GlycanKey).Distinct().ToList();
                Dictionary<string,List<int>> dictGlycanKeySearchRange = new Dictionary<string, List<int>>();

                int LastScan = argMultiGlycan.RawReader.NumberOfScans;
                foreach (string glycanKey in identifiedGlycan)
                {
                    List<int> identifedScans =
                        argMultiGlycan.MatchedPeakInScan.Where(x => x.GlycanComposition.GlycanKey == glycanKey)
                            .Select(y => y.ScanNum)
                            .ToList();
                    identifedScans.Sort();

                    int frontEdge = identifedScans[0];
                    double FirstIdentifiedTime = argMultiGlycan.RawReader.ReadScan(frontEdge).Time;
                    while (frontEdge>1)
                    {
                        frontEdge -= 1;
                        if (argMultiGlycan.RawReader.GetMsLevel(frontEdge) != 1)
                        {
                            continue;
                        }
                        MSScan s = argMultiGlycan.RawReader.ReadScan(frontEdge);
                        if (FirstIdentifiedTime - s.Time > 5)
                        {
                            break;
                        }
                    }
                    int backEdge = identifedScans[identifedScans.Count - 1];
                    double LastIdentifedTime = argMultiGlycan.RawReader.ReadScan(backEdge).Time;

                    while (backEdge < LastScan)
                    {
                        backEdge += 1;
                        if (argMultiGlycan.RawReader.GetMsLevel(backEdge) != 1)
                        {
                            continue;
                        }
                        MSScan s = argMultiGlycan.RawReader.ReadScan(backEdge);
                        if (s.Time - LastIdentifedTime > 5)
                        {
                            break;
                        }
                    }
                    dictGlycanKeySearchRange.Add(glycanKey, new List<int>(){frontEdge,backEdge});
                }

                List<MSScan> msScans = new List<MSScan>();
                string previousGlycanKey = "";
                foreach (GlycanCompound g in argMultiGlycan.GlycanList.OrderBy(x=> x.GlycanKey))
                {
                    if (!identifiedGlycan.Contains(g.GlycanKey))
                    {
                        continue;
                    }
                    if (previousGlycanKey != g.GlycanKey)
                    {
                        msScans.Clear();
                        //Read Scans
                        int startScan = dictGlycanKeySearchRange[g.GlycanKey][0] >= 1 ? dictGlycanKeySearchRange[g.GlycanKey][0] : 1;
                        int endScan = dictGlycanKeySearchRange[g.GlycanKey][1] <= LastScan ? dictGlycanKeySearchRange[g.GlycanKey][1] : LastScan;
                        msScans.AddRange(argMultiGlycan.RawReader.ReadScanWMSLevel(startScan, endScan,1));
                        previousGlycanKey = g.GlycanKey;
                    }

                    //FindPeaks
                    int charge = g.Charge;
                    List<List<MSScan>> scanSectionsContainPeaks = new List<List<MSScan>>();
                    for (int i = 0; i < msScans.Count; i++)
                    {
                        MSScan scan = msScans[i];
                        int closedIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float) g.MZ);
                        if (MassUtility.GetMassPPM(scan.MZs[closedIdx], g.MZ) <=argMultiGlycan.MassPPM)
                        {
                            List<int> peaks = FindPeakIdx(scan.MZs, closedIdx, charge, argMultiGlycan.IsotopePPM);
                            if (peaks.Count - peaks.IndexOf(closedIdx) < argMultiGlycan.MininumIsotopePeakCount)
                            {
                                continue;
                            }
                            //Found peaks
                            if (scanSectionsContainPeaks.Count > 0)
                            {
                                MSScan lastSectionLastScan = scanSectionsContainPeaks.Last().Last();
                                if (scan.Time - lastSectionLastScan.Time > 2.5)
                                {
                                    scanSectionsContainPeaks.Add(new List<MSScan>(){scan});
                                }
                                else
                                {
                                    scanSectionsContainPeaks.Last().Add(scan);
                                }
                            }
                            else
                            {
                                scanSectionsContainPeaks.Add(new List<MSScan>(){scan});
                            }
                        }
                    }

                    //If scans can form an elution profile add to identifed result;

                    foreach (List<MSScan> sectionScans in scanSectionsContainPeaks)
                    {
                        if (sectionScans.Count < 3)
                        {
                            continue;
                        }
                        else
                        {
                            //Add matched peak
                            foreach (MSScan s in sectionScans)
                            {
                                int PeakIdx = MassUtility.GetClosestMassIdx(s.MZs, (float)g.MZ);
                                MatchedGlycanPeak mPeak = new MatchedGlycanPeak(s.ScanNo, s.Time, s.MSPeaks[PeakIdx], g);

                                List<int> peaks = FindPeakIdx(s.MZs, PeakIdx, charge, argMultiGlycan.IsotopePPM);
                                int startIdx = peaks.IndexOf(PeakIdx);
                                List<MSPoint> lstIsotopes= new List<MSPoint>();
                                for (int i = startIdx; i < peaks.Count; i++)
                                {
                                    lstIsotopes.Add(new MSPoint(s.MZs[peaks[i]],s.Intensities[peaks[i]]));
                                }
                                mPeak.MSPoints = lstIsotopes;
                                if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                                {
                                    argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                                }
                            }
                        }
                    }
                }

                //foreach (GlycanCompound g in argMultiGlycan.IdentifiedGlycanCompounds)
                //{
                //    processed = g;
                //    //Search Peak in front of the peak
                //    ThermoRawReader raw = (ThermoRawReader)argMultiGlycan.RawReader;
                //    List<int> identifedScans = argMultiGlycan.MatchedPeakInScan.Where(x => x.GlycanComposition == g).Select(y => y.ScanNum).ToList();
                //    for (int i = 0; i < identifedScans.Count; i++)
                //    {
                //        int identifiedScanNum = identifedScans[i];
                //        while (true)
                //        {
                //            identifiedScanNum -= 1;
                //            if (identifiedScanNum < 1 || raw.GetRetentionTime(identifedScans[i]) - raw.GetRetentionTime(identifiedScanNum) > argMultiGlycan.MaxLCFrontMin)
                //            {
                //                break;
                //            }
                //            if (raw.GetMsLevel((identifiedScanNum)) != 1)
                //            {
                //                continue;
                //            }
                //            MSScan scan = raw.ReadScan(identifiedScanNum);
                //            int PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float)g.MZ);
                //            if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], g.MZ) > argMultiGlycan.MassPPM)
                //            {
                //                continue;
                //            }
                //            //Find isotope cluster
                //            List<MSPoint> lstIsotopes = new List<MSPoint>();
                //            lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx],scan.Intensities[PeakIdx]));
                //            float targetMZ = (float)g.MZ;
                //            do
                //            {
                //                targetMZ += 1.0f/g.Charge;
                //                PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, targetMZ);
                //                if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], targetMZ) <= argMultiGlycan.MassPPM)
                //                {
                //                    lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx],scan.Intensities[PeakIdx]));
                //                }
                //                else
                //                {
                //                    break;
                //                }
                //            } while (true);
                //            if (lstIsotopes.Count < argMultiGlycan.MininumIsotopePeakCount)
                //            {
                //                continue;
                //            }
                //            MatchedGlycanPeak mPeak = new MatchedGlycanPeak(scan.ScanNo, scan.Time, scan.MSPeaks[PeakIdx], g);
                //            mPeak.MSPoints = lstIsotopes;
                //            if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                //            {
                //                argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                //            }
                //        }
                //        identifiedScanNum = identifedScans[i];
                //        while (true)
                //        {
                //            identifiedScanNum += 1;
                //            if (identifiedScanNum > raw.NumberOfScans || raw.GetRetentionTime(identifiedScanNum) - raw.GetRetentionTime(identifedScans[i]) > argMultiGlycan.MaxLCBackMin)
                //            {
                //                break;
                //            }
                //            if (raw.GetMsLevel((identifiedScanNum)) != 1)
                //            {
                //                continue;
                //            }
                //            MSScan scan = raw.ReadScan(identifiedScanNum);
                //            int PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float)g.MZ);
                //            if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], g.MZ) > argMultiGlycan.MassPPM)
                //            {
                //                continue;
                //            }
                //            //Find isotope cluster
                //            List<MSPoint> lstIsotopes = new List<MSPoint>();
                //            lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx], scan.Intensities[PeakIdx]));
                //            float targetMZ = (float)g.MZ;
                //            do
                //            {
                //                targetMZ += 1.0f / g.Charge;
                //                PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, targetMZ);
                //                if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], targetMZ) <= argMultiGlycan.MassPPM)
                //                {
                //                    lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx], scan.Intensities[PeakIdx]));
                //                }
                //                else
                //                {
                //                    break;
                //                }
                //            } while (true);
                //            if (lstIsotopes.Count < argMultiGlycan.MininumIsotopePeakCount)
                //            {
                //                continue;
                //            }
                //            MatchedGlycanPeak mPeak = new MatchedGlycanPeak(scan.ScanNo, scan.Time, scan.MSPeaks[PeakIdx], g);
                //            mPeak.MSPoints = lstIsotopes;
                //            if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                //            {
                //                argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Beispiel #8
0
        private void PreparingMultiGlycan(Dictionary <COL.GlycoLib.enumLabelingTag, float> argLabeling, List <string> argRawFiles)
        {
            //saveFileDialog1.Filter = "Excel Files (*.xslx)|*.xslx";
            //saveFileDialog1.Filter = "CSV Files (*.csv)|*.csv";

            DateTime time = DateTime.Now;             // Use current time

            //string TimeFormat = "yyMMdd HHmm";            // Use this format
            if (DoLog)
            {
                Logger.WriteLog(System.Environment.NewLine + System.Environment.NewLine + "-----------------------------------------------------------");
                Logger.WriteLog("Start Process");
            }

            //saveFileDialog1.FileName = Path.GetDirectoryName(txtRawFile.Text) + "\\" + Path.GetFileNameWithoutExtension(txtRawFile.Text) + "-" + time.ToString(TimeFormat);


            if (txtRawFile.Text == "" || (rdoUserList.Checked && txtGlycanList.Text == "") || txtMaxLCTime.Text == "")
            {
                MessageBox.Show("Please check input values.");
                if (DoLog)
                {
                    Logger.WriteLog("End Process- because input value not complete");
                }
                return;
            }
            //folderBrowserDialog1.SelectedPath = txtRawFile.Text;
            string defaultOutputFolder = txtRawFile.Text + "\\" + DateTime.Now.ToString("yyMMdd-HHmm");

            if (!Directory.Exists(defaultOutputFolder))
            {
                Directory.CreateDirectory(defaultOutputFolder);
            }
            folderBrowserDialog1.SelectedPath = defaultOutputFolder;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string glycanlist = System.Windows.Forms.Application.StartupPath + "\\Default_Combination.csv";
                if (!rdoDefaultList.Checked)
                {
                    glycanlist = txtGlycanList.Text;
                }

                if (DoLog)
                {
                    Logger.WriteLog("Start initial program");
                }
                List <float> AdductMasses = new List <float>();
                Dictionary <float, string> AdductLabel = new Dictionary <float, string>();
                if (chkAdductK.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.Potassium);
                    AdductLabel.Add(MassLib.Atoms.Potassium, "K");
                }
                if (chkAdductNH4.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass);
                    AdductLabel.Add(MassLib.Atoms.NitrogenMass + 4 * MassLib.Atoms.HydrogenMass, "NH4");
                }
                if (chkAdductNa.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.SodiumMass);
                    AdductLabel.Add(MassLib.Atoms.SodiumMass, "Na");
                }
                if (chkAdductProton.Checked)
                {
                    AdductMasses.Add(MassLib.Atoms.ProtonMass);
                    AdductLabel.Add(MassLib.Atoms.ProtonMass, "H");
                }
                float outMass = 0.0f;
                if (chkAdductUser.Checked && float.TryParse(txtAdductMass.Text, out outMass))
                {
                    AdductMasses.Add(outMass);
                    AdductLabel.Add(outMass, "User");
                }

                // MultiNGlycanESIMultiThreads MultiESIs = new MultiNGlycanESIMultiThreads(glycanlist, txtRawFile.Text, Convert.ToInt32(cboCPU.SelectedItem), _peakParameter, _transformParameters);
                MultiGlycanESI ESI = null;
                if (argLabeling.Count != 0)
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text, 0, 99999, glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked, cboSia.SelectedIndex, argLabeling, AdductLabel, AdductMasses, DoLog);
                }
                else
                {
                    ESI = new MultiGlycanESI(txtRawFile.Text, 0, 99999, glycanlist, Convert.ToDouble(txtPPM.Text), Convert.ToDouble(txtGlycanPPM.Text), chkPermethylated.Checked, chkReducedReducingEnd.Checked, cboSia.SelectedIndex, DoLog);
                }
                ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.None;
                if (rdoDRAG.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.DRAG;
                }
                else if (rdoMultiplePemrthylated.Checked)
                {
                    ESI.LabelingMethod = GlycoLib.enumGlycanLabelingMethod.MultiplexPermethylated;
                }

                ESI.MergeDifferentChargeIntoOne = chkMergeDffCharge.Checked;
                ESI.ExportFilePath          = folderBrowserDialog1.SelectedPath;
                ESI.MaxLCBackMin            = Convert.ToSingle(txtMaxLCTime.Text);
                ESI.MaxLCFrontMin           = Convert.ToSingle(txtMinLCTime.Text);
                ESI.IsotopePPM              = Convert.ToSingle(txtIsotopeEnvTolerence.Text);
                ESI.MininumIsotopePeakCount = Convert.ToInt32(txtIsotopeEnvMinPeakCount.Text);
                ESI.PeakSNRatio             = Convert.ToSingle(txtSN.Text);
                ESI.IsMatchMonoisotopicOnly = chkMonoOnly.Checked;
                ESI.ApplyLinearRegLC        = chkApplyLinearRegLC.Checked;
                ESI.ForceProtonatedGlycan   = chkForceProtonated.Checked;
                ESI.MinPeakHeightPrecentage = Convert.ToSingle(txtMinPeakHeight.Text);
                if (chkAbundance.Checked)
                {
                    ESI.MinAbundance = Convert.ToDouble(txtAbundanceMin.Text);
                }
                else
                {
                    ESI.MinAbundance = 0;
                }
                if (chkMinLengthOfLC.Checked)
                {
                    ESI.MinLengthOfLC = Convert.ToSingle(txtScanCount.Text);
                }
                else
                {
                    ESI.MinLengthOfLC = 0;
                }


                // ESI.AdductMass = AdductMasses;
                //ESI.AdductMassToLabel = AdductLabel;
                ESI.IndividualImgs     = chkIndividualImg.Checked;
                ESI.QuantificationImgs = chkQuantImgs.Checked;
                ESI.TotalLCTime        = Convert.ToSingle(txtLCTime.Text);
                ESI.LCTimeTolerance    = Convert.ToSingle(txtLCTolerance.Text) / 100.0f;
                if (DoLog)
                {
                    Logger.WriteLog("Initial program complete");
                }
                this.Visible = false;
                int concurrent = Convert.ToInt32(cboConcurrent.Text);
                frmBatchProcessing frmProcess = new frmBatchProcessing(ESI, argRawFiles, concurrent, DoLog);
                frmProcess.ProtonatedResult = chkProtonatedResult.Checked;
                if (concurrent == 1)
                {
                    frmProcess.Size = new Size(370, 120);
                }
                else if (concurrent == 2)
                {
                    frmProcess.Size = new Size(370, 180);
                }
                else
                {
                    frmProcess.Size = new Size(370, 240);
                }
                frmProcess.ShowDialog();
                this.Visible = true;
                if (DoLog)
                {
                    Logger.WriteLog("Finish process");
                }
            }
        }
        private void ProcessMultiGlycanAsync(string argFile)
        {
            int runningSlot = -1;
            for (int i = 0; i < 3; i++)
            {
                if (ProcessingFile[i] == "0")
                {
                    ProcessingFile[i] = argFile;
                    runningSlot = i;
                    break;
                }
            }
            MultiGlycanESI multiGlycan = null;
            //ZedGraphControl zedGraphControl = new ZedGraphControl();
            try
            {
                //debugWriter.WriteLine("---------------------Process file:" + argFile + "------------------------");
                ProcessingStatus[runningSlot] = "Status: Reading Raw file";
                bgWorker_Process.ReportProgress(0);
                ProgressUpdate.Add(argFile, 0);
                TotalScanNum.Add(argFile, 99999);
                if (_MultiNGlycan.LabelingRatio.Count != 0)
                {
                    multiGlycan = new MultiGlycanESI(argFile, 1, 99999, _MultiNGlycan.GlycanFile, _MultiNGlycan.MassPPM, _MultiNGlycan.GlycanPPM, _MultiNGlycan.IsPermethylated, _MultiNGlycan.IsReducedReducingEnd, _MultiNGlycan.SiaType, _MultiNGlycan.LabelingRatio, _MultiNGlycan.AdductMassToLabel, _MultiNGlycan.AdductMass, _MultiNGlycan.DoLOG);
                }
                else
                {
                    multiGlycan = new MultiGlycanESI(argFile, 1, 99999, _MultiNGlycan.GlycanFile, _MultiNGlycan.MassPPM, _MultiNGlycan.GlycanPPM, _MultiNGlycan.IsPermethylated, _MultiNGlycan.IsReducedReducingEnd, _MultiNGlycan.SiaType, _MultiNGlycan.DoLOG);
                }
                //debugWriter.WriteLine("init finish");
                multiGlycan.LabelingMethod = _MultiNGlycan.LabelingMethod;
                multiGlycan.MergeDifferentChargeIntoOne = _MultiNGlycan.MergeDifferentChargeIntoOne;
                multiGlycan.ExportFilePath = _MultiNGlycan.ExportFilePath + "\\" + Path.GetFileNameWithoutExtension(argFile);
                multiGlycan.MaxLCBackMin = _MultiNGlycan.MaxLCBackMin;
                multiGlycan.MaxLCFrontMin = _MultiNGlycan.MaxLCFrontMin;
                multiGlycan.IsotopePPM = _MultiNGlycan.IsotopePPM;
                multiGlycan.MininumIsotopePeakCount = _MultiNGlycan.MininumIsotopePeakCount;
                multiGlycan.PeakSNRatio = _MultiNGlycan.PeakSNRatio;
                multiGlycan.IsMatchMonoisotopicOnly = _MultiNGlycan.IsMatchMonoisotopicOnly;
                multiGlycan.MinAbundance = _MultiNGlycan.MinAbundance;
                multiGlycan.MinLengthOfLC = _MultiNGlycan.MinLengthOfLC;
                multiGlycan.IncludeMZMatch = _MultiNGlycan.IncludeMZMatch;
                multiGlycan.IndividualImgs = _MultiNGlycan.IndividualImgs;
                multiGlycan.QuantificationImgs = _MultiNGlycan.QuantificationImgs;
                multiGlycan.GlycanList = _MultiNGlycan.GlycanList;
                multiGlycan.CandidateMzList = _MultiNGlycan.CandidateMzList;
                multiGlycan.MinPeakHeightPrecentage = _MultiNGlycan.MinPeakHeightPrecentage;
                if (_MultiNGlycan.ApplyLinearRegLC)
                {
                    multiGlycan.ApplyLinearRegLC = _MultiNGlycan.ApplyLinearRegLC;
                    multiGlycan.TotalLCTime = _MultiNGlycan.TotalLCTime;
                    multiGlycan.LCTimeTolerance = _MultiNGlycan.LCTimeTolerance;
                }
                TotalScanNum[argFile] = multiGlycan.RawReader.NumberOfScans;

                //ProcessingStatus[runningSlot] = "Status:  Processing";
                //Parallel.ForEach(Enumerable.Range(1, multiGlycan.RawReader.NumberOfScans),
                //    new ParallelOptions() { MaxDegreeOfParallelism = 4 }, (i) =>
                //    {
                //        //Console.WriteLine(argFile + "-" + i.ToString());
                //        ProgressUpdate[argFile] = ProgressUpdate[argFile] + 1;
                //        bgWorker_Process.ReportProgress(Convert.ToInt32(ProgressUpdate[argFile] / TotalScanNum[argFile]));
                //        if (multiGlycan.RawReader.GetMsLevel(i) == 1)
                //        {
                //            multiGlycan.ProcessSingleScan(i);
                //        }
                //    });
               // debugWriter.WriteLine("Start processing");
                for (int i = 1; i <= multiGlycan.RawReader.NumberOfScans; i++)
                {
                    ProgressUpdate[argFile] = ProgressUpdate[argFile] + 1;
                    bgWorker_Process.ReportProgress(Convert.ToInt32(ProgressUpdate[argFile] / TotalScanNum[argFile]));
                    if (multiGlycan.RawReader.GetMsLevel(i) == 1)
                    {
                        multiGlycan.ProcessSingleScan(i);
               //         debugWriter.WriteLine("Processed scen:" + i.ToString());
                    }
                }
                //debugWriter.WriteLine("Merge");
                ProcessingStatus[runningSlot] = "Status:  Mergeing Result";
                multiGlycan.MergeSingleScanResultToPeak();
                multiGlycan.SolveDuplicateAssignment();
                multiGlycan.MergeSingleScanResultToPeak();
                //debugWriter.WriteLine("Merge completed");
                if (multiGlycan.GlycanLCorderExist)
                {
                    multiGlycan.ApplyLCordrer();
                }
                if (!Directory.Exists(multiGlycan.ExportFilePath + "\\Pic") && (multiGlycan.IndividualImgs || multiGlycan.QuantificationImgs))
                {
                    Directory.CreateDirectory(multiGlycan.ExportFilePath + "\\Pic");
                }
                if (multiGlycan.LabelingMethod == GlycoLib.enumGlycanLabelingMethod.MultiplexPermethylated)
                {
                    multiGlycan.EstimatePurity();

                    foreach (GlycoLib.enumLabelingTag tag in multiGlycan.LabelingRatio.Keys)
                    {
                        if (tag == enumLabelingTag.MP_CH3 || !multiGlycan.HasEstimatePurity((tag)))
                            continue;
                        multiGlycan.GetPurityEstimateImage(tag,multiGlycan.ExportFilePath + "\\Pic\\EstimatePurity_" + tag.ToString() + ".png");
                    }
                }
                ProcessingStatus[runningSlot] = "Status:  Waiting for Export";
                bgWorker_Process.ReportProgress(0);

                ProcessingStatus[runningSlot] = "Status:  Exporting";
                bgWorker_Process.ReportProgress(0);
                //debugWriter.WriteLine("Export to CSV");
                multiGlycan.ExportToCSV();
                ProcessingStatus[runningSlot] = "Export completed";
                //debugWriter.WriteLine("Export completed");
                ProcessingStatus[runningSlot] = "Generate Pics";
                if (multiGlycan.IndividualImgs &&
                   File.Exists(multiGlycan.ExportFilePath+"\\" +Path.GetFileNameWithoutExtension(argFile)+ "_FullList.csv"))
                {
                    //GenerateImages.GenGlycanLcImg(
                    //    _MultiNGlycan.ExportFilePath + "\\" + Path.GetFileName(_MultiNGlycan.ExportFilePath) +"_FullList.csv",
                    //    _MultiNGlycan.ExportFilePath);
                    GenerateImages.GenGlycanLcImg(multiGlycan);
                }

                bgWorker_Process.ReportProgress(0);
                SucceedFileCount = SucceedFileCount + 1;
                //debugWriter.WriteLine("Finish");
                //debugWriter.Flush();
            }
            catch (Exception e)
            {
                ErrMsg = ErrMsg + (argFile + "  error.  ErrMSG:" + e.ToString() + "\n");
            }
            finally
            {
                ProcessingStatus[runningSlot] = "Status:  Ready";
                ProcessingFile[runningSlot] = "0";
                ProcessedFileCount = ProcessedFileCount + 1;
            }
        }
Beispiel #10
0
        private void ProcessMultiGlycanAsync(string argFile)
        {
            int runningSlot = -1;

            for (int i = 0; i < 3; i++)
            {
                if (ProcessingFile[i] == "0")
                {
                    ProcessingFile[i] = argFile;
                    runningSlot       = i;
                    break;
                }
            }
            MultiGlycanESI multiGlycan = null;

            //ZedGraphControl zedGraphControl = new ZedGraphControl();
            try
            {
                //debugWriter.WriteLine("---------------------Process file:" + argFile + "------------------------");
                ProcessingStatus[runningSlot] = "Status: Reading Raw file";
                bgWorker_Process.ReportProgress(0);
                ProgressUpdate.Add(argFile, 0);
                TotalScanNum.Add(argFile, 99999);
                if (_MultiNGlycan.LabelingRatio.Count != 0)
                {
                    multiGlycan = new MultiGlycanESI(argFile, 1, 99999, _MultiNGlycan.GlycanFile, _MultiNGlycan.MassPPM, _MultiNGlycan.GlycanPPM, _MultiNGlycan.IsPermethylated, _MultiNGlycan.IsReducedReducingEnd, _MultiNGlycan.SiaType, _MultiNGlycan.LabelingRatio, _MultiNGlycan.AdductMassToLabel, _MultiNGlycan.AdductMass, _MultiNGlycan.DoLOG);
                }
                else
                {
                    multiGlycan = new MultiGlycanESI(argFile, 1, 99999, _MultiNGlycan.GlycanFile, _MultiNGlycan.MassPPM, _MultiNGlycan.GlycanPPM, _MultiNGlycan.IsPermethylated, _MultiNGlycan.IsReducedReducingEnd, _MultiNGlycan.SiaType, _MultiNGlycan.DoLOG);
                }
                //debugWriter.WriteLine("init finish");
                multiGlycan.LabelingMethod = _MultiNGlycan.LabelingMethod;
                multiGlycan.MergeDifferentChargeIntoOne = _MultiNGlycan.MergeDifferentChargeIntoOne;
                multiGlycan.ExportFilePath          = _MultiNGlycan.ExportFilePath + "\\" + Path.GetFileNameWithoutExtension(argFile);
                multiGlycan.MaxLCBackMin            = _MultiNGlycan.MaxLCBackMin;
                multiGlycan.MaxLCFrontMin           = _MultiNGlycan.MaxLCFrontMin;
                multiGlycan.IsotopePPM              = _MultiNGlycan.IsotopePPM;
                multiGlycan.MininumIsotopePeakCount = _MultiNGlycan.MininumIsotopePeakCount;
                multiGlycan.PeakSNRatio             = _MultiNGlycan.PeakSNRatio;
                multiGlycan.IsMatchMonoisotopicOnly = _MultiNGlycan.IsMatchMonoisotopicOnly;
                multiGlycan.MinAbundance            = _MultiNGlycan.MinAbundance;
                multiGlycan.MinLengthOfLC           = _MultiNGlycan.MinLengthOfLC;
                multiGlycan.IncludeMZMatch          = _MultiNGlycan.IncludeMZMatch;
                multiGlycan.IndividualImgs          = _MultiNGlycan.IndividualImgs;
                multiGlycan.QuantificationImgs      = _MultiNGlycan.QuantificationImgs;
                multiGlycan.GlycanList              = _MultiNGlycan.GlycanList;
                multiGlycan.CandidateMzList         = _MultiNGlycan.CandidateMzList;
                multiGlycan.MinPeakHeightPrecentage = _MultiNGlycan.MinPeakHeightPrecentage;
                if (_MultiNGlycan.ApplyLinearRegLC)
                {
                    multiGlycan.ApplyLinearRegLC = _MultiNGlycan.ApplyLinearRegLC;
                    multiGlycan.TotalLCTime      = _MultiNGlycan.TotalLCTime;
                    multiGlycan.LCTimeTolerance  = _MultiNGlycan.LCTimeTolerance;
                }
                TotalScanNum[argFile] = multiGlycan.RawReader.NumberOfScans;


                //ProcessingStatus[runningSlot] = "Status:  Processing";
                //Parallel.ForEach(Enumerable.Range(1, multiGlycan.RawReader.NumberOfScans),
                //    new ParallelOptions() { MaxDegreeOfParallelism = 4 }, (i) =>
                //    {
                //        //Console.WriteLine(argFile + "-" + i.ToString());
                //        ProgressUpdate[argFile] = ProgressUpdate[argFile] + 1;
                //        bgWorker_Process.ReportProgress(Convert.ToInt32(ProgressUpdate[argFile] / TotalScanNum[argFile]));
                //        if (multiGlycan.RawReader.GetMsLevel(i) == 1)
                //        {
                //            multiGlycan.ProcessSingleScan(i);
                //        }
                //    });
                // debugWriter.WriteLine("Start processing");
                for (int i = 1; i <= multiGlycan.RawReader.NumberOfScans; i++)
                {
                    ProgressUpdate[argFile] = ProgressUpdate[argFile] + 1;
                    bgWorker_Process.ReportProgress(Convert.ToInt32(ProgressUpdate[argFile] / TotalScanNum[argFile]));
                    if (multiGlycan.RawReader.GetMsLevel(i) == 1)
                    {
                        multiGlycan.ProcessSingleScan(i);
                        //         debugWriter.WriteLine("Processed scen:" + i.ToString());
                    }
                }
                //debugWriter.WriteLine("Merge");
                ProcessingStatus[runningSlot] = "Status:  Mergeing Result";
                multiGlycan.MergeSingleScanResultToPeak();
                multiGlycan.SolveDuplicateAssignment();
                multiGlycan.MergeSingleScanResultToPeak();
                //debugWriter.WriteLine("Merge completed");
                if (multiGlycan.GlycanLCorderExist)
                {
                    multiGlycan.ApplyLCordrer();
                }
                if (!Directory.Exists(multiGlycan.ExportFilePath + "\\Pic") && (multiGlycan.IndividualImgs || multiGlycan.QuantificationImgs))
                {
                    Directory.CreateDirectory(multiGlycan.ExportFilePath + "\\Pic");
                }
                if (multiGlycan.LabelingMethod == GlycoLib.enumGlycanLabelingMethod.MultiplexPermethylated)
                {
                    multiGlycan.EstimatePurity();

                    foreach (GlycoLib.enumLabelingTag tag in multiGlycan.LabelingRatio.Keys)
                    {
                        if (tag == enumLabelingTag.MP_CH3 || !multiGlycan.HasEstimatePurity((tag)))
                        {
                            continue;
                        }
                        multiGlycan.GetPurityEstimateImage(tag, multiGlycan.ExportFilePath + "\\Pic\\EstimatePurity_" + tag.ToString() + ".png");
                    }
                }
                ProcessingStatus[runningSlot] = "Status:  Waiting for Export";
                bgWorker_Process.ReportProgress(0);


                ProcessingStatus[runningSlot] = "Status:  Exporting";
                bgWorker_Process.ReportProgress(0);
                //debugWriter.WriteLine("Export to CSV");
                multiGlycan.ExportToCSV();
                ProcessingStatus[runningSlot] = "Export completed";
                //debugWriter.WriteLine("Export completed");
                ProcessingStatus[runningSlot] = "Generate Pics";
                if (multiGlycan.IndividualImgs &&
                    File.Exists(multiGlycan.ExportFilePath + "\\" + Path.GetFileNameWithoutExtension(argFile) + "_FullList.csv"))
                {
                    //GenerateImages.GenGlycanLcImg(
                    //    _MultiNGlycan.ExportFilePath + "\\" + Path.GetFileName(_MultiNGlycan.ExportFilePath) +"_FullList.csv",
                    //    _MultiNGlycan.ExportFilePath);
                    GenerateImages.GenGlycanLcImg(multiGlycan);
                }


                bgWorker_Process.ReportProgress(0);
                SucceedFileCount = SucceedFileCount + 1;
                //debugWriter.WriteLine("Finish");
                //debugWriter.Flush();
            }
            catch (Exception e)
            {
                ErrMsg = ErrMsg + (argFile + "  error.  ErrMSG:" + e.ToString() + "\n");
            }
            finally
            {
                ProcessingStatus[runningSlot] = "Status:  Ready";
                ProcessingFile[runningSlot]   = "0";
                ProcessedFileCount            = ProcessedFileCount + 1;
            }
        }
Beispiel #11
0
        public static void GenGlycanLcImg(MultiGlycanESI argMultiGlycanESI)
        {
            string dir = argMultiGlycanESI.ExportFilePath + "\\Pic";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            List <Color> LstColor = new List <Color>()
            {
                Color.DarkCyan, Color.DarkGoldenrod, Color.DarkGray, Color.DarkGreen, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrchid, Color.DarkRed, Color.DarkSalmon, Color.DarkSeaGreen, Color.DarkSlateBlue, Color.DarkSlateGray, Color.DarkTurquoise, Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue
            };
            Dictionary <string, List <ClusteredPeak> > dictCluster = new Dictionary <string, List <ClusteredPeak> >();

            foreach (ClusteredPeak clsPeak in argMultiGlycanESI.MergedResultList)
            {
                string Key = clsPeak.GlycanKey;
                if (argMultiGlycanESI.LabelingMethod != enumGlycanLabelingMethod.None)
                {
                    Key = clsPeak.GlycanKey + "-" + clsPeak.GlycanComposition.LabelingTag;
                }
                if (!dictCluster.ContainsKey(Key))
                {
                    dictCluster.Add(Key, new List <ClusteredPeak>());
                }
                dictCluster[Key].Add(clsPeak);
            }
            //Parallel.ForEach(dictCluster.Keys, new ParallelOptions() {MaxDegreeOfParallelism = MaxDegreeParallelism},Gkey =>
            foreach (string Gkey in dictCluster.Keys)
            {
                string ProcessingGlycanKey = "";
                try
                {
                    Dictionary <string, List <LCPointPair> > dictAdductPoints = new Dictionary <string, List <LCPointPair> >();
                    Dictionary <float, float> MergeIntensity = new Dictionary <float, float>();
                    List <float> Time         = new List <float>();
                    float        maxIntensity = 0;
                    List <Tuple <double, double> > lstPeakMargin = new List <Tuple <double, double> >();
                    foreach (ClusteredPeak clsPeak in dictCluster[Gkey])
                    {
                        lstPeakMargin.Add(new Tuple <double, double>(clsPeak.StartTime, clsPeak.EndTime));
                        foreach (MatchedGlycanPeak Peak in clsPeak.MatchedPeaksInScan)
                        {
                            if (!dictAdductPoints.ContainsKey(Peak.AdductString))
                            {
                                dictAdductPoints.Add(Peak.AdductString, new List <LCPointPair>());
                            }
                            float TimeKey = Convert.ToSingle(Peak.ScanTime.ToString("0.00"));

                            dictAdductPoints[Peak.AdductString].Add(new LCPointPair(Peak.ScanTime, Peak.MSPoints[0].Intensity));
                            if (!MergeIntensity.ContainsKey(TimeKey))
                            {
                                MergeIntensity.Add(TimeKey, 0);
                            }
                            MergeIntensity[TimeKey] = MergeIntensity[TimeKey] + Peak.MSPoints[0].Intensity;
                            if (maxIntensity <= MergeIntensity[TimeKey])
                            {
                                maxIntensity = MergeIntensity[TimeKey];
                            }
                            if (!Time.Contains(TimeKey))
                            {
                                Time.Add(TimeKey);
                            }
                        }
                    }

                    #region LC Images
                    using (Chart cht = new Chart())
                    {
                        //---------------Generate Graph-----------------
                        ProcessingGlycanKey = Gkey;

                        cht.Size = new Size(2400, 1200);

                        cht.ChartAreas.Add("Default");
                        cht.ChartAreas["Default"].AxisX.Title                   = "Scan time (min)";
                        cht.ChartAreas["Default"].AxisX.TitleFont               = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisX.LabelStyle.Format       = "{F2}";
                        cht.ChartAreas["Default"].AxisX.LabelStyle.Font         = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
                        cht.ChartAreas["Default"].AxisX.IsMarginVisible         = true;
                        cht.ChartAreas["Default"].AxisY.Title                   = "Abundance";
                        cht.ChartAreas["Default"].AxisY.TitleFont               = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisY.LabelStyle.Format       = "{0.#E+00}";
                        cht.ChartAreas["Default"].AxisY.LabelStyle.Font         = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
                        cht.ChartAreas["Default"].AxisY.IsMarginVisible         = true;

                        cht.Titles.Add("Default");
                        cht.Titles[0].Text = "Glycan: " + Gkey;
                        cht.Titles[0].Font = new Font("Arial", 24, FontStyle.Bold);

                        cht.Legends.Add("Default");
                        cht.Legends["Default"].Docking     = Docking.Bottom;
                        cht.Legends["Default"].Alignment   = StringAlignment.Center;
                        cht.Legends["Default"].LegendStyle = LegendStyle.Row;
                        cht.Legends["Default"].Font        = new Font("Arial", 24, FontStyle.Bold);
                        int ColorIdx = 0;
                        // int SymbolIdx = 0;

                        foreach (string Adduct in dictAdductPoints.Keys)
                        {
                            dictAdductPoints[Adduct].OrderBy(x => x.Time); //Sort by time
                            Series series = cht.Series.Add(Adduct);
                            series.ChartArea   = "Default";
                            series.ChartType   = SeriesChartType.Spline;
                            series.MarkerStyle = MarkerStyle.Circle;
                            series.MarkerSize  = 15;
                            series.BorderWidth = 2;
                            series.Color       = LstColor[ColorIdx];

                            foreach (LCPointPair pp in dictAdductPoints[Adduct])
                            {
                                float TimeKey = Convert.ToSingle(pp.Time.ToString("0.00"));
                                if (series.Points.Where(x => x.XValue == TimeKey).Count() != 0)
                                {
                                    series.Points.Where(x => x.XValue == TimeKey).ToList()[0].YValues[0] += pp.Intensity;
                                }
                                else
                                {
                                    series.Points.AddXY(TimeKey, pp.Intensity);
                                }
                            }
                            series.Points.OrderBy(x => x.XValue);
                            ColorIdx = (ColorIdx + 1) % LstColor.Count;
                        }
                        //Merge Intensity
                        Time.Sort();
                        List <LCPointPair> PPLMerge = new List <LCPointPair>();
                        foreach (float tim in Time)
                        {
                            PPLMerge.Add(new LCPointPair(Convert.ToSingle(tim.ToString("0.00")), MergeIntensity[tim]));
                        }

                        Series merge = cht.Series.Add("Merge");
                        merge.ChartArea       = "Default";
                        merge.ChartType       = SeriesChartType.Spline;
                        merge.BorderWidth     = 2;
                        merge.MarkerStyle     = MarkerStyle.Diamond;
                        merge.MarkerSize      = 15;
                        merge.Color           = Color.Black;
                        merge.BorderDashStyle = ChartDashStyle.Dot;
                        foreach (LCPointPair pp in PPLMerge)
                        {
                            merge.Points.AddXY(pp.Time, pp.Intensity);
                        }
                        merge.Points.OrderBy(x => x.XValue);
                        cht.SaveImage(dir + "\\" + Gkey + ".png", ChartImageFormat.Png);
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    throw new Exception("GetLC Pic failed " + ProcessingGlycanKey + "  Err Msg:" + ex.ToString());
                }
            }//);
        }
Beispiel #12
0
        public static void GenGlycanLcImg(MultiGlycanESI argMultiGlycanESI)
        {
            string dir = argMultiGlycanESI.ExportFilePath + "\\Pic";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            List<Color> LstColor = new List<Color>() { Color.DarkCyan, Color.DarkGoldenrod, Color.DarkGray, Color.DarkGreen, Color.DarkKhaki, Color.DarkMagenta, Color.DarkOliveGreen, Color.DarkOrchid, Color.DarkRed, Color.DarkSalmon, Color.DarkSeaGreen, Color.DarkSlateBlue, Color.DarkSlateGray, Color.DarkTurquoise, Color.DarkViolet, Color.DeepPink, Color.DeepSkyBlue };
            Dictionary<string, List<ClusteredPeak>> dictCluster = new Dictionary<string, List<ClusteredPeak>>();
            foreach (ClusteredPeak clsPeak in argMultiGlycanESI.MergedResultList)
            {
                string Key = clsPeak.GlycanKey;
                if (argMultiGlycanESI.LabelingMethod != enumGlycanLabelingMethod.None)
                {
                    Key = clsPeak.GlycanKey + "-" + clsPeak.GlycanComposition.LabelingTag;
                }
                if (!dictCluster.ContainsKey(Key))
                {
                    dictCluster.Add(Key, new List<ClusteredPeak>());
                }
                dictCluster[Key].Add(clsPeak);
            }
            //Parallel.ForEach(dictCluster.Keys, new ParallelOptions() {MaxDegreeOfParallelism = MaxDegreeParallelism},Gkey =>
            foreach (string Gkey in dictCluster.Keys)
            {
                string ProcessingGlycanKey = "";
                try
                {
                    Dictionary<string, List<LCPointPair>> dictAdductPoints = new Dictionary<string, List<LCPointPair>>();
                    Dictionary<float, float> MergeIntensity = new Dictionary<float, float>();
                    List<float> Time = new List<float>();
                    float maxIntensity = 0;
                    List<Tuple<double, double>> lstPeakMargin = new List<Tuple<double, double>>();
                    foreach (ClusteredPeak clsPeak in dictCluster[Gkey])
                    {
                        lstPeakMargin.Add(new Tuple<double, double>(clsPeak.StartTime,clsPeak.EndTime));
                        foreach (MatchedGlycanPeak Peak in clsPeak.MatchedPeaksInScan)
                        {
                            if (!dictAdductPoints.ContainsKey(Peak.AdductString))
                            {
                                dictAdductPoints.Add(Peak.AdductString, new List<LCPointPair>());
                            }
                                float TimeKey = Convert.ToSingle(Peak.ScanTime.ToString("0.00"));

                                dictAdductPoints[Peak.AdductString].Add(new LCPointPair(Peak.ScanTime, Peak.MSPoints[0].Intensity));
                                if (!MergeIntensity.ContainsKey(TimeKey))
                                {
                                    MergeIntensity.Add(TimeKey, 0);
                                }
                                MergeIntensity[TimeKey] = MergeIntensity[TimeKey] + Peak.MSPoints[0].Intensity;
                                if (maxIntensity <= MergeIntensity[TimeKey])
                                {
                                    maxIntensity = MergeIntensity[TimeKey];
                                }
                                if (!Time.Contains(TimeKey))
                                {
                                    Time.Add(TimeKey);
                                }
                        }
                    }

                    #region LC Images
                    using (Chart cht = new Chart())
                    {
                        //---------------Generate Graph-----------------
                        ProcessingGlycanKey = Gkey;

                        cht.Size = new Size(2400, 1200);

                        cht.ChartAreas.Add("Default");
                        cht.ChartAreas["Default"].AxisX.Title = "Scan time (min)";
                        cht.ChartAreas["Default"].AxisX.TitleFont = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisX.LabelStyle.Format = "{F2}";
                        cht.ChartAreas["Default"].AxisX.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
                        cht.ChartAreas["Default"].AxisX.IsMarginVisible = true;
                        cht.ChartAreas["Default"].AxisY.Title = "Abundance";
                        cht.ChartAreas["Default"].AxisY.TitleFont = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisY.LabelStyle.Format = "{0.#E+00}";
                        cht.ChartAreas["Default"].AxisY.LabelStyle.Font = new Font("Arial", 24, FontStyle.Bold);
                        cht.ChartAreas["Default"].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
                        cht.ChartAreas["Default"].AxisY.IsMarginVisible = true;

                        cht.Titles.Add("Default");
                        cht.Titles[0].Text = "Glycan: " + Gkey;
                        cht.Titles[0].Font = new Font("Arial",24,FontStyle.Bold);

                        cht.Legends.Add("Default");
                        cht.Legends["Default"].Docking = Docking.Bottom;
                        cht.Legends["Default"].Alignment = StringAlignment.Center;
                        cht.Legends["Default"].LegendStyle = LegendStyle.Row;
                        cht.Legends["Default"].Font = new Font("Arial", 24, FontStyle.Bold);
                        int ColorIdx = 0;
                       // int SymbolIdx = 0;

                        foreach (string Adduct in dictAdductPoints.Keys)
                        {
                            dictAdductPoints[Adduct].OrderBy(x=> x.Time); //Sort by time
                            Series series = cht.Series.Add(Adduct);
                            series.ChartArea = "Default";
                            series.ChartType = SeriesChartType.Spline;
                            series.MarkerStyle = MarkerStyle.Circle;
                            series.MarkerSize = 15;
                            series.BorderWidth = 2;
                            series.Color = LstColor[ColorIdx];

                            foreach (LCPointPair pp in dictAdductPoints[Adduct])
                            {
                                float TimeKey = Convert.ToSingle(pp.Time.ToString("0.00"));
                                if (series.Points.Where(x => x.XValue == TimeKey).Count()!=0)
                                {
                                    series.Points.Where(x => x.XValue == TimeKey).ToList()[0].YValues[0]+=pp.Intensity;
                                }
                                else
                                {
                                    series.Points.AddXY(TimeKey, pp.Intensity);
                                }
                            }
                            series.Points.OrderBy(x => x.XValue);
                            ColorIdx = (ColorIdx + 1) % LstColor.Count;
                        }
                        //Merge Intensity
                        Time.Sort();
                        List<LCPointPair> PPLMerge = new List<LCPointPair>();
                        foreach (float tim in Time)
                        {
                            PPLMerge.Add(new LCPointPair(Convert.ToSingle(tim.ToString("0.00")), MergeIntensity[tim]));
                        }

                        Series merge = cht.Series.Add("Merge");
                        merge.ChartArea = "Default";
                        merge.ChartType = SeriesChartType.Spline;
                        merge.BorderWidth = 2;
                        merge.MarkerStyle = MarkerStyle.Diamond;
                        merge.MarkerSize = 15;
                        merge.Color = Color.Black;
                        merge.BorderDashStyle = ChartDashStyle.Dot;
                        foreach (LCPointPair pp in PPLMerge)
                        {
                            merge.Points.AddXY(pp.Time, pp.Intensity);
                        }
                        merge.Points.OrderBy(x => x.XValue);
                        cht.SaveImage(dir + "\\" + Gkey + ".png", ChartImageFormat.Png);
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    throw new Exception("GetLC Pic failed " + ProcessingGlycanKey + "  Err Msg:" + ex.ToString());
                }
            }//);
        }
        public static void Processing(ref MultiGlycanESI argMultiGlycan)
        {
            try
            {
                List <string> identifiedGlycan = argMultiGlycan.IdentifiedGlycanCompounds.Select(x => x.GlycanKey).Distinct().ToList();
                Dictionary <string, List <int> > dictGlycanKeySearchRange = new Dictionary <string, List <int> >();


                int LastScan = argMultiGlycan.RawReader.NumberOfScans;
                foreach (string glycanKey in identifiedGlycan)
                {
                    List <int> identifedScans =
                        argMultiGlycan.MatchedPeakInScan.Where(x => x.GlycanComposition.GlycanKey == glycanKey)
                        .Select(y => y.ScanNum)
                        .ToList();
                    identifedScans.Sort();

                    int    frontEdge           = identifedScans[0];
                    double FirstIdentifiedTime = argMultiGlycan.RawReader.ReadScan(frontEdge).Time;
                    while (frontEdge > 1)
                    {
                        frontEdge -= 1;
                        if (argMultiGlycan.RawReader.GetMsLevel(frontEdge) != 1)
                        {
                            continue;
                        }
                        MSScan s = argMultiGlycan.RawReader.ReadScan(frontEdge);
                        if (FirstIdentifiedTime - s.Time > 5)
                        {
                            break;
                        }
                    }
                    int    backEdge          = identifedScans[identifedScans.Count - 1];
                    double LastIdentifedTime = argMultiGlycan.RawReader.ReadScan(backEdge).Time;

                    while (backEdge < LastScan)
                    {
                        backEdge += 1;
                        if (argMultiGlycan.RawReader.GetMsLevel(backEdge) != 1)
                        {
                            continue;
                        }
                        MSScan s = argMultiGlycan.RawReader.ReadScan(backEdge);
                        if (s.Time - LastIdentifedTime > 5)
                        {
                            break;
                        }
                    }
                    dictGlycanKeySearchRange.Add(glycanKey, new List <int>()
                    {
                        frontEdge, backEdge
                    });
                }

                List <MSScan> msScans           = new List <MSScan>();
                string        previousGlycanKey = "";
                foreach (GlycanCompound g in argMultiGlycan.GlycanList.OrderBy(x => x.GlycanKey))
                {
                    if (!identifiedGlycan.Contains(g.GlycanKey))
                    {
                        continue;
                    }
                    if (previousGlycanKey != g.GlycanKey)
                    {
                        msScans.Clear();
                        //Read Scans
                        int startScan = dictGlycanKeySearchRange[g.GlycanKey][0] >= 1 ? dictGlycanKeySearchRange[g.GlycanKey][0] : 1;
                        int endScan   = dictGlycanKeySearchRange[g.GlycanKey][1] <= LastScan ? dictGlycanKeySearchRange[g.GlycanKey][1] : LastScan;
                        msScans.AddRange(argMultiGlycan.RawReader.ReadScanWMSLevel(startScan, endScan, 1));
                        previousGlycanKey = g.GlycanKey;
                    }

                    //FindPeaks
                    int charge = g.Charge;
                    List <List <MSScan> > scanSectionsContainPeaks = new List <List <MSScan> >();
                    for (int i = 0; i < msScans.Count; i++)
                    {
                        MSScan scan      = msScans[i];
                        int    closedIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float)g.MZ);
                        if (MassUtility.GetMassPPM(scan.MZs[closedIdx], g.MZ) <= argMultiGlycan.MassPPM)
                        {
                            List <int> peaks = FindPeakIdx(scan.MZs, closedIdx, charge, argMultiGlycan.IsotopePPM);
                            if (peaks.Count - peaks.IndexOf(closedIdx) < argMultiGlycan.MininumIsotopePeakCount)
                            {
                                continue;
                            }
                            //Found peaks
                            if (scanSectionsContainPeaks.Count > 0)
                            {
                                MSScan lastSectionLastScan = scanSectionsContainPeaks.Last().Last();
                                if (scan.Time - lastSectionLastScan.Time > 2.5)
                                {
                                    scanSectionsContainPeaks.Add(new List <MSScan>()
                                    {
                                        scan
                                    });
                                }
                                else
                                {
                                    scanSectionsContainPeaks.Last().Add(scan);
                                }
                            }
                            else
                            {
                                scanSectionsContainPeaks.Add(new List <MSScan>()
                                {
                                    scan
                                });
                            }
                        }
                    }

                    //If scans can form an elution profile add to identifed result;

                    foreach (List <MSScan> sectionScans in scanSectionsContainPeaks)
                    {
                        if (sectionScans.Count < 3)
                        {
                            continue;
                        }
                        else
                        {
                            //Add matched peak
                            foreach (MSScan s in sectionScans)
                            {
                                int PeakIdx             = MassUtility.GetClosestMassIdx(s.MZs, (float)g.MZ);
                                MatchedGlycanPeak mPeak = new MatchedGlycanPeak(s.ScanNo, s.Time, s.MSPeaks[PeakIdx], g);

                                List <int>     peaks       = FindPeakIdx(s.MZs, PeakIdx, charge, argMultiGlycan.IsotopePPM);
                                int            startIdx    = peaks.IndexOf(PeakIdx);
                                List <MSPoint> lstIsotopes = new List <MSPoint>();
                                for (int i = startIdx; i < peaks.Count; i++)
                                {
                                    lstIsotopes.Add(new MSPoint(s.MZs[peaks[i]], s.Intensities[peaks[i]]));
                                }
                                mPeak.MSPoints = lstIsotopes;
                                if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                                {
                                    argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                                }
                            }
                        }
                    }
                }



                //foreach (GlycanCompound g in argMultiGlycan.IdentifiedGlycanCompounds)
                //{
                //    processed = g;
                //    //Search Peak in front of the peak
                //    ThermoRawReader raw = (ThermoRawReader)argMultiGlycan.RawReader;
                //    List<int> identifedScans = argMultiGlycan.MatchedPeakInScan.Where(x => x.GlycanComposition == g).Select(y => y.ScanNum).ToList();
                //    for (int i = 0; i < identifedScans.Count; i++)
                //    {
                //        int identifiedScanNum = identifedScans[i];
                //        while (true)
                //        {
                //            identifiedScanNum -= 1;
                //            if (identifiedScanNum < 1 || raw.GetRetentionTime(identifedScans[i]) - raw.GetRetentionTime(identifiedScanNum) > argMultiGlycan.MaxLCFrontMin)
                //            {
                //                break;
                //            }
                //            if (raw.GetMsLevel((identifiedScanNum)) != 1)
                //            {
                //                continue;
                //            }
                //            MSScan scan = raw.ReadScan(identifiedScanNum);
                //            int PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float)g.MZ);
                //            if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], g.MZ) > argMultiGlycan.MassPPM)
                //            {
                //                continue;
                //            }
                //            //Find isotope cluster
                //            List<MSPoint> lstIsotopes = new List<MSPoint>();
                //            lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx],scan.Intensities[PeakIdx]));
                //            float targetMZ = (float)g.MZ;
                //            do
                //            {
                //                targetMZ += 1.0f/g.Charge;
                //                PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, targetMZ);
                //                if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], targetMZ) <= argMultiGlycan.MassPPM)
                //                {
                //                    lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx],scan.Intensities[PeakIdx]));
                //                }
                //                else
                //                {
                //                    break;
                //                }
                //            } while (true);
                //            if (lstIsotopes.Count < argMultiGlycan.MininumIsotopePeakCount)
                //            {
                //                continue;
                //            }
                //            MatchedGlycanPeak mPeak = new MatchedGlycanPeak(scan.ScanNo, scan.Time, scan.MSPeaks[PeakIdx], g);
                //            mPeak.MSPoints = lstIsotopes;
                //            if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                //            {
                //                argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                //            }
                //        }
                //        identifiedScanNum = identifedScans[i];
                //        while (true)
                //        {
                //            identifiedScanNum += 1;
                //            if (identifiedScanNum > raw.NumberOfScans || raw.GetRetentionTime(identifiedScanNum) - raw.GetRetentionTime(identifedScans[i]) > argMultiGlycan.MaxLCBackMin)
                //            {
                //                break;
                //            }
                //            if (raw.GetMsLevel((identifiedScanNum)) != 1)
                //            {
                //                continue;
                //            }
                //            MSScan scan = raw.ReadScan(identifiedScanNum);
                //            int PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, (float)g.MZ);
                //            if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], g.MZ) > argMultiGlycan.MassPPM)
                //            {
                //                continue;
                //            }
                //            //Find isotope cluster
                //            List<MSPoint> lstIsotopes = new List<MSPoint>();
                //            lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx], scan.Intensities[PeakIdx]));
                //            float targetMZ = (float)g.MZ;
                //            do
                //            {
                //                targetMZ += 1.0f / g.Charge;
                //                PeakIdx = MassUtility.GetClosestMassIdx(scan.MZs, targetMZ);
                //                if (MassUtility.GetMassPPM(scan.MZs[PeakIdx], targetMZ) <= argMultiGlycan.MassPPM)
                //                {
                //                    lstIsotopes.Add(new MSPoint(scan.MZs[PeakIdx], scan.Intensities[PeakIdx]));
                //                }
                //                else
                //                {
                //                    break;
                //                }
                //            } while (true);
                //            if (lstIsotopes.Count < argMultiGlycan.MininumIsotopePeakCount)
                //            {
                //                continue;
                //            }
                //            MatchedGlycanPeak mPeak = new MatchedGlycanPeak(scan.ScanNo, scan.Time, scan.MSPeaks[PeakIdx], g);
                //            mPeak.MSPoints = lstIsotopes;
                //            if (!argMultiGlycan.MatchedPeakInScan.Contains(mPeak))
                //            {
                //                argMultiGlycan.MatchedPeakInScan.Add(mPeak);
                //            }
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }