Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the ResamplingCalculation class.
 /// </summary>
 /// <param name="param"></param>
 public ResamplingCalculation(ResamplingParameter param)
 {
     if (param == null)
     {
         throw new ArgumentNullException("param");
     }
     _param = param;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the ResamplingPanel class
        /// </summary>
        /// <param name="parent">Form parent</param>
        public ResamplingPanel(Form parent, ResamplingParameter parameter)
        {
            InitializeComponent();

            this.TopLevel = false;
            this.Parent   = parent;

            _parameter          = parameter;
            _helpMessageControl = new HelpMessageControl();
        }
        /// <summary>
        /// Initializes a new instance of the SpectrumCalculationDialog class
        /// </summary>
        /// <param name="clrVar">Parameter</param>
        public RemoveContaminantPeakDialog(ClrVariant clrVar)
            : this()
        {
            // Set parent window
            var    current = Process.GetCurrentProcess();
            IntPtr hwnd    = current.MainWindowHandle;

            SetWindowLong(this.Handle, GWL_HWNDPARENT, (UInt32)hwnd);

            _clrVar          = clrVar;
            _baselineParam   = new BaselineSubtractionParameter();
            _resamplingParam = new ResamplingParameter();
            _calculate       = new RemoveContaminantPeakCalculation(_clrVar, _baselineParam, _resamplingParam);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the SpectrumCalculationManager class
 /// </summary>
 /// <param name="clrVariant">Target of operation</param>
 /// <exception cref="ArgumentNullException"></exception>
 public RemoveContaminantPeakCalculation(ClrVariant clrVariant,
                                         BaselineSubtractionParameter baselineParam,
                                         ResamplingParameter resamplingParam)
 {
     //Each arguments validation.
     if (clrVariant == null)
     {
         throw new ArgumentNullException("clrVariant");
     }
     if (baselineParam == null)
     {
         throw new ArgumentNullException("baselineParam");
     }
     if (resamplingParam == null)
     {
         throw new ArgumentNullException("resamplingParam");
     }
     _clrVariant      = clrVariant;
     _resamplingParam = resamplingParam;
     _resampling      = new ResamplingCalculation(_resamplingParam);
     _baselineParam   = baselineParam;
 }
Exemplo n.º 5
0
        private bool CreateBaselineSubtractedXIC(
            PluginFunctionItemWrapper pfiw,
            List <ClrDataPoints> resamplingList,
            List <SpectrumWrapper> ms1List,
            SettingParameterValuesWrapper spvw,
            ref ClrDataPoints[] subtractLowerXICList,
            ref ClrDataPoints[] subtractHigherXICList,
            ref ClrDataPoints subtractHighestXICList
            )
        {
            uint resamplingLength = resamplingList[0].getLength();

            int lowerIndex  = (resamplingLength < int.MaxValue) ? (int)resamplingLength : int.MaxValue;
            int higherIndex = (0 < (int)(resamplingLength - lowerIndex))? (int)(resamplingLength - lowerIndex) : 0;

            subtractLowerXICList  = new ClrDataPoints[lowerIndex];
            subtractHigherXICList = new ClrDataPoints[higherIndex];

            for (uint i = 0; i < resamplingLength; i++)
            {
                //Update message.
                if (UpdateProgress != null)
                {
                    UpdateProgress(
                        PROGRESS_REMOVECONTAMINANT_PHASE.REMOVE_CONTAMINANT_PEAK,
                        (int)i, (int)resamplingLength);
                }

                //Cancel.
                if (StopFlag)
                {
                    break;
                }

                //Create XIC.
                ClrDataPoints pts = new ClrDataPoints();
                for (int j = 0; j < resamplingList.Count; j++)
                {
                    //Cancel.
                    if (StopFlag)
                    {
                        break;
                    }
                    pts.addPoint(ms1List[j].getRt(), resamplingList[j].getY(i));
                }
                //Cancel.
                if (StopFlag)
                {
                    pts.clearPoints();
                    pts.Dispose();
                    break;
                }

                //Baseline Subtraction
                ClrParameters param    = new ClrParameters();
                ClrDataPoints baseline = new ClrDataPoints();
                ClrPluginCallTool.setXYData(param, pts);
                ClrPluginCallTool.setBaseline(param, baseline);
                ClrPluginCallTool.setSettingValues(param, spvw);
                pfiw.getCall().invoke(param);

                //Cancel.
                if (StopFlag)
                {
                    param.Dispose();
                    baseline.clearPoints();
                    baseline.Dispose();
                }

                //Resampling baseline.
                ClrDataPoints         subtracted      = new ClrDataPoints();
                ResamplingParameter   resamplingParam = new ResamplingParameter();
                ResamplingCalculation resamplingCalc  = new ResamplingCalculation(resamplingParam);
                resamplingParam.ResamplingMode = ResamplingParameter.SamplingMode.FIRST;
                resamplingParam.Interpolation  = _resamplingParam.Interpolation;
                resamplingParam.AddXYData(pts);
                resamplingParam.AddXYData(baseline);
                resamplingCalc.Execute();
                ClrDataPoints resampledBaseline = resamplingCalc.Result.getResultData(1);

                for (uint j = 0; j < resampledBaseline.getLength(); j++)
                {
                    double intensity = Math.Max(pts.getY(j) - resampledBaseline.getY(j), 0);
                    subtracted.addPoint(pts.getX(j), intensity);
                }

                // Countermeasure to OutOfBoundsException.
                if (i < int.MaxValue)
                {
                    subtractLowerXICList[i] = subtracted;
                }
                else if (int.MaxValue < i && i < (uint)int.MaxValue * 2)
                {
                    subtractHigherXICList[i - int.MaxValue] = subtracted;
                }
                else
                {
                    subtractHighestXICList = subtracted;
                }
                resamplingParam.ClearXYDataList();
                resamplingCalc.Result.ClearXYDataList();
            }
            return(!StopFlag);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Commandline Spec Calc.
        /// </summary>
        /// <param name="clrParams"></param>
        /// <returns>0:success, 1:fail</returns>
        public static int CommandlineSpecCalc(ClrParameters clrParams)
        {
            kome.clr.ClrLogger log = kome.clr.ClrLogger.getInstance();

            // Return value (Success: true, Failure: false)
            int ret = 0;

            // We initially set ret.prim.boolVal to false so that we can return a false
            // result easily using "return ret" if a failure condition occurs.

            // progress bar
            kome.clr.ProgressWrapper        progress         = null;
            kome.clr.DisplayProgressWrapper display_progress = new DisplayProgressWrapper(PROGRESS_TITLE);
            progress = display_progress;
            progress.createSubProgresses(2);          // Divide Progress bar into 2 sections.
            subProgress = progress.getSubProgress(0); // Get first Sub progress.
            subProgress.setRange(0, 5);               // Set value between 0 to 5.

            // start
            string[] strArrayParam = new string[NUMBER_OF_MAX_PARAM]; // Store 5 parameters without conversion.

            bool   flgTryParseSpecifiedInterval = true;               // If failed to convert to dSpecifiedInterval, set true.
            double dSpecifiedInterval           = -1;                 // Store the parameter of specified[999.99] option.

            kome.clr.SettingParameterValuesWrapper settings
                = kome.clr.ClrPluginCallTool.getSettingValues(clrParams);

            kome.clr.PluginManagerWrapper plgMgr = kome.clr.PluginManagerWrapper.getInstance();

            if (settings == null)
            {
                //Unexpected Error
                log.errorCode(ERROR_UNEXPECTED, ERROR_CODE_UNEXPECTED);
                return(1);    // Failed.
            }

            // Get the number of parameters.
            uint uNumberOfParameters = settings.getNumberOfParameters();

            //Get parameters.
            for (uint i = 0; i < uNumberOfParameters; i++)
            {
                string strParamName  = settings.getParameterName(i);
                string strParamValue = settings.getParameterValue(strParamName);

                if (i < NUMBER_OF_MAX_PARAM)
                {
                    strArrayParam[i] = strParamValue;   // Store parameter.
                }

                // If strParamName is not "sampling pitch", it has not potential that has parameter.
                if (strParamName != PARAMETER_NAME_SAMPLING_PITCH)
                {
                    continue;
                }

                // The case that strParamName equals sampling pitch.
                uint uNumberOfFunctionItems = plgMgr.getNumberOfFunctionItems(FUNCTION_TYPE_SAMPLING_PITCH);

                for (uint j = 0; j < uNumberOfFunctionItems; j++)
                {
                    kome.clr.PluginFunctionItemWrapper item = plgMgr.getFunctionItem(FUNCTION_TYPE_SAMPLING_PITCH, j);
                    string strLongName = item.getLongName();

                    if ((item.getShortName() != strParamValue) ||
                        (item.getSettingsPage() == null))
                    {
                        continue;
                    }

                    kome.clr.SettingParameterValuesWrapper settingsSub2
                        = settings.getSubParameterValues(strParamName, strParamValue);
                    uint   uNumberOfSubParameters = settingsSub2.getNumberOfParameters();
                    string strSubParamName        = settingsSub2.getParameterName(0);
                    string strSubParamValue       = settingsSub2.getParameterValue(strSubParamName);

                    if (!double.TryParse(strSubParamValue, out dSpecifiedInterval))
                    {
                        // Convert failed.
                        dSpecifiedInterval           = -1;
                        flgTryParseSpecifiedInterval = false;
                    }
                }
            }

            // Commandline parameter getting...
            ResamplingParameter param = new ResamplingParameter();

            // (1)File Spectrum Name
            string strSpectrumName = strArrayParam[(int)BatchParamType.FILE_SPECTRUM_NAME];

            // (2)Operation Type
            string strOperationType = strArrayParam[(int)BatchParamType.OPERATION_TYPE];

            // (3)Sampling Pitch
            string strSamplingPitch = strArrayParam[(int)BatchParamType.SAMPLING_PITCH];

            // (4)Output Range
            string strOutputRange = strArrayParam[(int)BatchParamType.OUTPUT_RANGE];

            // (5)Interpolate Algorithm
            string strInterpolateAlgorithm = strArrayParam[(int)BatchParamType.INTERPOLATE_ALGORITHM];

            // Commandline parameter TryParse... ////////
            bool bRet;  // return of TryParse.

            // Postpone Processing for (1)File Spectrum Name.

            // (2)Operation Type
            BatchParamOperationType resultOperationType;

            bRet = Enum.TryParse <BatchParamOperationType>(strOperationType.ToUpper(), out resultOperationType);
            if (bRet == false)
            {
                // error
                log.errorCode(string.Format(ERROR_FORMAT_OPERATION_TYPE, strOperationType), ERROR_CODE_OPERATION_TYPE);
                return(1);   // Failed to convert.
            }
            SpectrumCalculation.Cal.SpectrumCalculation.OperationSettings resultOperationSetting;
            resultOperationSetting = (SpectrumCalculation.Cal.SpectrumCalculation.OperationSettings)resultOperationType;   // AVERAGE, SUBTRACT, SUM, DIVIDE are the operation type option.
            log.debug(string.Format(DEBUG_LOG_OPERATION_TYPE, resultOperationSetting));
            subProgress.setPosition(1);

            // (3)Sampling Pitch
            BatchParamSamplingPitchType resultSamplingPitch;

            bRet = Enum.TryParse <BatchParamSamplingPitchType>(strSamplingPitch.ToUpper(), out resultSamplingPitch);
            if (bRet == false)
            {
                // error
                log.errorCode(string.Format(ERROR_FORMAT_SAMPLING_PITCH, strSamplingPitch), ERROR_CODE_SAMPLING_PITCH);
                return(1);   // Failed to convert.
            }
            ResamplingParameter.SamplingMode resultResamplingMode;
            resultResamplingMode = (ResamplingParameter.SamplingMode)resultSamplingPitch;   // Convert FIRST,MINIMUIM,AVERAGE,SPECIFIED into internal value.
            log.debug(string.Format(DEBUG_LOG_SAMPLING_PITCH, resultResamplingMode));

            param.ResamplingMode = resultResamplingMode;
            if (resultSamplingPitch == BatchParamSamplingPitchType.SPECIFIED)
            {
                if (!flgTryParseSpecifiedInterval)
                {
                    //error
                    return(1);
                }
                param.SpecifiedInterval = dSpecifiedInterval;
                log.debug(string.Format(DEBUG_LOG_SPECIFIED_INTERVAL, dSpecifiedInterval));
            }
            else
            {
                param.SpecifiedInterval = null;
                log.debug(string.Format(DEBUG_LOG_SPECIFIED_INTERVAL, NULL_STRING));
            }
            subProgress.setPosition(2);

            // (4)Output Range
            string strOutputRangeLow;
            string strOutputRangeHi;
            double dOutputRangeLow = 0;
            double dOutputRangeHi  = 0;

            string[] arrystrSeparatedOutputRange = kome.clr.SettingsValueWrapper.separateListValue(strOutputRange);
            if (2 == arrystrSeparatedOutputRange.Length)
            {
                strOutputRangeLow = arrystrSeparatedOutputRange[0];
                strOutputRangeHi  = arrystrSeparatedOutputRange[1];
            }
            else
            {
                //error
                log.errorCode(string.Format(ERROR_FORMAT_RANGE, strOutputRange), ERROR_CODE_OUTPUT_RANGE);
                return(1);
            }

            if (double.TryParse(strOutputRangeLow, out dOutputRangeLow))
            {
                param.OutputLowerRange = dOutputRangeLow;
                log.debug(string.Format(DEBUG_LOG_RANGE_LOW, param.OutputLowerRange));
            }
            else
            {
                param.OutputLowerRange = null;
                log.debug(string.Format(DEBUG_LOG_RANGE_LOW, NULL_STRING));
            }

            if (double.TryParse(strOutputRangeHi, out dOutputRangeHi))
            {
                param.OutputHigherRange = dOutputRangeHi;
                log.debug(string.Format(DEBUG_LOG_RANGE_HIGH, param.OutputHigherRange));
            }
            else
            {
                param.OutputHigherRange = null;
                log.debug(string.Format(DEBUG_LOG_RANGE_HIGH, NULL_STRING));
            }
            subProgress.setPosition(3);

            // (5)Interpolate Algorithm
            BatchParamInterpolateAlgorithmType resultInterpolateAlgorithm;

            bRet = Enum.TryParse <BatchParamInterpolateAlgorithmType>(strInterpolateAlgorithm.ToUpper(), out resultInterpolateAlgorithm);
            if (bRet == false)
            {
                // error
                log.errorCode(string.Format(ERROR_FORMAT_INTERPOLATE, strInterpolateAlgorithm), ERROR_CODE_INTERPOLATE);
                return(1);
            }
            log.debug(string.Format(DEBUG_LOG_INTERPOLATE, resultInterpolateAlgorithm));

            ResamplingParameter.InterpolationAlgorithm resultInterpolation;
            resultInterpolation = (ResamplingParameter.InterpolationAlgorithm)resultInterpolateAlgorithm;
            param.Interpolation = resultInterpolation;
            subProgress.setPosition(4);

            //param.ErrorMessage = ERROR_GENERAL_PURPOSE;

            // Create ResamplingParameter is Complete.
            // Assign to SpectrumCalculation().
            SpectrumCalculation.Cal.SpectrumCalculation calc = new Cal.SpectrumCalculation(param);

            calc.OperationSetting = resultOperationSetting; // (2)Operation Type

            // (1)File Spectrum Name
            AddSpectrumFromParameter(calc, strSpectrumName);
            subProgress.setPosition(5);
            subProgress.fill();

            subProgress = progress.getSubProgress(1);  // Get first sub progress.

            calc.GetResamplingCalculation.UpdateResamplingProgress += UpdateSpecCalcResamplingProgressCmd;

            try
            {
                calc.Execute();
            }
            catch (ArgumentException ex)
            {
                log.errorCode(string.Format(ERROR_FORMAT_PARAMETER, ex.Message), ERROR_CODE_PARAMETER);
                return(1);
            }

            subProgress.fill();

            // Set Spectrum calculation result to active object.
            SetResultToActiveObject(calc.GetResultSpecCalculation);

            return(ret);   // success.
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the ResamplingDialog class
 /// </summary>
 /// <param name="param">ResamplingParameter</param>
 public ResamplingDialog(ResamplingParameter param)
 {
     InitializeComponent();
     this._resamplingParameter = param;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the SpectrumCalculation class
 /// </summary>
 /// <param name="pram">ResamplingPrameter</param>
 public SpectrumCalculation(ResamplingParameter param)
 {
     _param     = param;
     _resampCal = new ResamplingCalculation(param);
 }