Exemple #1
0
        /// <summary>
        /// Clear ClrDataPoints.
        /// </summary>
        /// <param name="subtractLowerXICList">Subtracted Lower XIC List</param>
        /// <param name="subtractHigherXICList">Subtracted Higher XIC List</param>
        /// <param name="subtractHighestXICList">Subtracted Highest XIC List</param>
        /// <param name="resamplingList">Resampling List</param>
        /// <param name="spvw">SettingParameterValuesWrapper</param>
        private void ClearClrDataPoints(
            ClrDataPoints[] subtractLowerXICList,
            ClrDataPoints[] subtractHigherXICList,
            ClrDataPoints subtractHighestXICList,
            List <ClrDataPoints> resamplingList,
            SettingParameterValuesWrapper spvw
            )
        {
            foreach (ClrDataPoints pts in subtractLowerXICList)
            {
                if (pts == null)
                {
                    break;
                }
                pts.clearPoints();
                pts.Dispose();
            }

            foreach (ClrDataPoints pts in subtractHigherXICList)
            {
                pts.clearPoints();
                pts.Dispose();
            }

            foreach (ClrDataPoints pts in resamplingList)
            {
                pts.clearPoints();
                pts.Dispose();
            }

            if (subtractHighestXICList != null)
            {
                subtractHighestXICList.clearPoints();
                subtractHighestXICList.Dispose();
            }

            spvw.clear();
            spvw.Dispose();
        }
Exemple #2
0
        /// <summary>
        /// Execute Remove Contaminant Peak.
        /// </summary>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public void Execute()
        {
            //Update Message
            if (UpdateProgress != null)
            {
                UpdateProgress(
                    PROGRESS_REMOVECONTAMINANT_PHASE.PREPARE,
                    (int)0, (int)1);
            }

            //Create Temporary Folder.
            string tempDir = CreateTempDir();

            if (tempDir == null)
            {
                return;
            }

            //Initialize.
            StopFlag = false;
            Result   = null;
            ResultRemove result = new ResultRemove();

            //Get root node
            ClrMsDataVariant     msObj = new ClrMsDataVariant(_clrVariant);
            DataGroupNodeWrapper dgnw  = msObj.getSample().getRootDataGroupNode();

            //Get all MS1 Spectrums.
            List <SpectrumWrapper> ms1List = new List <SpectrumWrapper>();

            ReadSpectrum(dgnw, ref ms1List);

            //If count of MS1 Spectrums is 0, quit remove contaminant peak.
            if (ms1List.Count <= 0)
            {
                //Update Message
                if (UpdateProgress != null)
                {
                    UpdateProgress(
                        PROGRESS_REMOVECONTAMINANT_PHASE.CANCELLED,
                        (int)1, (int)1);
                }
                msObj.Dispose();
                return;
            }
            else
            {
                foreach (SpectrumWrapper sw in ms1List)
                {
                    _resamplingParam.AddXYData(sw.getXYData());
                }
            }

            //Get wrappers
            SettingParameterValuesWrapper spvw = new SettingParameterValuesWrapper();
            PluginFunctionItemWrapper     pfiw = PluginManagerWrapper.getInstance().getFunctionItem(
                FUNCTIONTYPE_BASELINE, _baselineParam.Algorithm, null);

            //Convert parameters to string for SettingParameterValuesWrapper.
            string paramString = _baselineParam.ABCWindowWidth.ToString() + ","
                                 + _baselineParam.NoiseFactor.ToString() + ","
                                 + _baselineParam.SmoothingWidth.ToString();

            pfiw.getSettingsPage().setParameterString(spvw, paramString);

            if (StopFlag)
            {
                _resamplingParam.ClearXYDataList();
                return;
            }

            _resampling.UpdateResamplingProgress += UpdateSpecCalcResamplingProgress;
            //Resampling.
            _resampling.Execute();
            if (StopFlag)
            {
                _resamplingParam.ClearXYDataList();
                return;
            }

            List <ClrDataPoints> resamplingList = _resampling.Result.getAllResultData();

            _resampling.UpdateResamplingProgress -= UpdateSpecCalcResamplingProgress;

            //Dispose.
            _resamplingParam.ClearXYDataList();

            //if resampling result is empty, quit remove contaminant peak.
            if (resamplingList.Count == 0)
            {
                _resampling.Result.Dispose();
                return;
            }

            //Garbage collect.
            GC.Collect();

            // Countermeasure to OutOfBoundsException.
            // Max of List and Array Index is "int".
            // Max Index of XYDataPoints is bigger than maximum integer.
            // Maximum uint = (Maximum int) * 2 + 1.
            ClrDataPoints[] subtractLowerXICList   = null;
            ClrDataPoints[] subtractHigherXICList  = null;
            ClrDataPoints   subtractHighestXICList = null;

            bool complete = true;

            // Create Baseline subtracted XIC.
            if (CreateBaselineSubtractedXIC(
                    pfiw,
                    resamplingList,
                    ms1List,
                    spvw,
                    ref subtractLowerXICList,
                    ref subtractHigherXICList,
                    ref subtractHighestXICList))
            {
                //Create XIC Complete.
                uint count = (uint)(subtractHighestXICList == null ? 0 : 1);
                count += (uint)subtractLowerXICList.Length;
                count += (uint)subtractHigherXICList.Length;

                //Replace intensity of resampled spectrum
                for (int i = 0; i < resamplingList.Count; i++)
                {
                    if (UpdateProgress != null)
                    {
                        UpdateProgress(
                            PROGRESS_REMOVECONTAMINANT_PHASE.WRITE_TO_TEMPORARY,
                            i, resamplingList.Count);
                    }
                    if (StopFlag)
                    {
                        complete = false;
                        break;
                    }
                    try
                    {
                        using (StreamWriter sw = new StreamWriter(tempDir + @"\Scan" + i.ToString() + ".csv"))
                        {
                            for (uint j = 0; j < subtractLowerXICList.Length; j++)
                            {
                                if (j <= int.MaxValue)
                                {
                                    sw.WriteLine(resamplingList[i].getX(j).ToString() + ","
                                                 + subtractLowerXICList[(int)j].getY((uint)i).ToString());
                                }
                                else if (j == uint.MaxValue)
                                {
                                    sw.WriteLine(resamplingList[i].getX(j).ToString() + ","
                                                 + subtractHighestXICList.getY((uint)i).ToString());
                                }
                                else
                                {
                                    sw.WriteLine(resamplingList[i].getX(j).ToString() + ","
                                                 + subtractHigherXICList[(int)(j - int.MaxValue)].getY((uint)i).ToString());
                                }
                            }
                        }
                    }
                    catch
                    {
                        complete = false;
                        break;
                    }
                }
            }
            else
            {
                complete = false;
            }
            int scanNumbers = resamplingList.Count;


            foreach (ClrDataPoints pts in subtractLowerXICList)
            {
                if (pts == null)
                {
                    break;
                }
                pts.clearPoints();
                pts.Dispose();
            }
            foreach (ClrDataPoints pts in subtractHigherXICList)
            {
                pts.clearPoints();
                pts.Dispose();
            }
            if (complete == false)
            {
                return;
            }
            foreach (ClrDataPoints pts in resamplingList)
            {
                pts.Dispose();
            }

            if (subtractHighestXICList != null)
            {
                subtractHighestXICList.clearPoints();
                subtractHighestXICList.Dispose();
            }
            spvw.clear();
            spvw.Dispose();

            //Garbage collect.
            GC.Collect();

            if (StopFlag || !complete)
            {
                return;
            }

            for (int i = 0; i < scanNumbers; i++)
            {
                if (UpdateProgress != null)
                {
                    UpdateProgress(
                        PROGRESS_REMOVECONTAMINANT_PHASE.READ_FROM_TEMPORARY,
                        i, scanNumbers);
                }
                using (StreamReader sr = new StreamReader(tempDir + @"\Scan" + i.ToString() + ".csv"))
                {
                    ClrDataPoints pts = new ClrDataPoints();
                    while (!sr.EndOfStream)
                    {
                        string[] splitLine = sr.ReadLine().Split(',');
                        double   x         = double.Parse(splitLine[0]);
                        double   y         = double.Parse(splitLine[1]);
                        pts.addPoint(x, y);
                    }
                    result.AddResult(pts, ms1List[i]);
                }
            }

            if (UpdateProgress != null)
            {
                UpdateProgress(
                    PROGRESS_REMOVECONTAMINANT_PHASE.COMPLETE,
                    1, 1);
            }

            Result = result;
            GC.Collect();
            return;
        }