Beispiel #1
0
        /// <summary>
        /// Return Remove contaminant peak is Enabled.
        /// </summary>
        /// <param name="clrParams"></param>
        /// <returns></returns>
        public ClrVariant RemoveContaminantPeakIsEnabled(ClrParameters clrParams)
        {
            ClrVariant ret = new ClrVariant();

            ret.type = ClrVariant.DataType.BOOL;
            ret.obj  = false;

            try
            {
                ClrMsDataVariant msObj = new ClrMsDataVariant(ClrPluginCallTool.getActiveObject(clrParams));
                SampleWrapper    sw    = msObj.getSample();
                if (sw != null)
                {
                    DataGroupNodeWrapper dgnw = sw.getRootDataGroupNode();
                    if (1 < dgnw.getNumberOfSpectra())
                    {
                        ret.obj = true;
                    }
                }
            }
            catch
            {
                ret.obj = false;
            }
            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Define of Specified option.
        /// (This function is not called normally. Please reference design document Page 37.)
        /// </summary>
        /// <param name="clrParams"></param>
        /// <returns></returns>
        public ClrVariant BatPitchSpecified(ClrParameters clrParams)
        {
            // Return value (Success: true, Failure: false)
            ClrVariant ret = new ClrVariant();

            // 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.
            ret.type = ClrVariant.DataType.BOOL;
            ret.obj  = false;

            return(ret);
        }
Beispiel #3
0
        /**
         * @fn kome.clr.ClrVariant SimcaDisplayPluginFunction(kome.clr.ClrParameters* clrParams)
         * @brief write this function's brief.
         * @param[in] clrParams ClrParameters object
         * @return If true, it succeeded (boolean)
         */

        /// <summary>
        /// Mass++ menu(SimcaDisplay...) execute function
        /// </summary>
        /// <param name="clrParams">parameters object</param>
        /// <returns>This value has no meanings.</returns>
        public ClrVariant SimcaDisplayPluginFunction(ClrParameters clrParams)
        {
            // Return value (Success: true, Failure: false)
            ClrVariant ret = new ClrVariant();

            // 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.
            ret.type = ClrVariant.DataType.BOOL;
            ret.obj  = false;

            // Method write Here
            SimcaDisplayManager.DisplayMainForm();

            ret.obj = true;
            return(ret);
        }
Beispiel #4
0
        /// <summary>
        /// Remove contaminant peak is Enabled.
        /// </summary>
        /// <param name="clrParams">parameters for C# plug-in from Mass++</param>
        /// <returns></returns>
        public ClrVariant RemoveContaminantPeak(ClrParameters clrParams)
        {
            // Return value (Success: true, Failure: false)
            ClrVariant ret = new ClrVariant();

            // 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.
            ret.type = ClrVariant.DataType.BOOL;
            ret.obj  = false;

            // Convert clrParams to ActiveObject
            ClrVariant clrVar = ClrPluginCallTool.getActiveObject(clrParams);

            // Display main window.
            RemoveContaminantPeakManager.DisplayDlgRemovContamiPeak(clrVar);

            ret.obj = true;
            return(ret);
        }
Beispiel #5
0
        /// <summary>
        /// Batch Resampling Entry Function.
        /// </summary>
        /// <param name="clrParams"></param>
        /// <returns></returns>
        public ClrVariant BatResample(ClrParameters clrParams)
        {
            // Return value (Success: true, Failure: false)
            ClrVariant ret = new ClrVariant();

            // 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.
            ret.type = ClrVariant.DataType.BOOL;
            ret.obj  = false;

            // Call Manager
            int retValue = SpectrumCalculationManager.CommandlineSpecCalc(clrParams);

            if (retValue == 0)
            {
                ret.obj = true;     // Success.
            }
            else
            {
                ret.obj = false;    // Failure.
            }

            return(ret);
        }
Beispiel #6
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);
        }
        /// <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.
        }