private void RemoveZeroesAtFrontAndBack(clsChromatogramInfo chromatogramInfo)
        {
            const int MAX_POINTS_TO_CHECK = 100;
            var       pointsChecked       = 0;

            // See if the last few values are zero, but the data before them is non-zero
            // If this is the case, remove the final entries

            var indexNonZeroValue = -1;
            var zeroPointCount    = 0;

            for (var index = chromatogramInfo.ScanCount - 1; index >= 0; index += -1)
            {
                if (Math.Abs(chromatogramInfo.GetDataPoint(index).Intensity) < float.Epsilon)
                {
                    zeroPointCount += 1;
                }
                else
                {
                    indexNonZeroValue = index;
                    break;
                }
                pointsChecked += 1;
                if (pointsChecked >= MAX_POINTS_TO_CHECK)
                {
                    break;
                }
            }

            if (zeroPointCount > 0 && indexNonZeroValue >= 0)
            {
                chromatogramInfo.RemoveRange(indexNonZeroValue + 1, zeroPointCount);
            }

            // Now check the first few values
            indexNonZeroValue = -1;
            zeroPointCount    = 0;
            for (var index = 0; index <= chromatogramInfo.ScanCount - 1; index++)
            {
                if (Math.Abs(chromatogramInfo.GetDataPoint(index).Intensity) < float.Epsilon)
                {
                    zeroPointCount += 1;
                }
                else
                {
                    indexNonZeroValue = index;
                    break;
                }
                pointsChecked += 1;
                if (pointsChecked >= MAX_POINTS_TO_CHECK)
                {
                    break;
                }
            }

            if (zeroPointCount > 0 && indexNonZeroValue >= 0)
            {
                chromatogramInfo.RemoveRange(0, indexNonZeroValue);
            }
        }
        /// <summary>
        /// Clear BPI and TIC data
        /// </summary>
        public void Reset()
        {
            if (mBPI == null)
            {
                mBPI = new clsChromatogramInfo();
                mTIC = new clsChromatogramInfo();
            }
            else
            {
                mBPI.Initialize();
                mTIC.Initialize();
            }

            mRecentFiles.Clear();
        }
 private clsPlotContainerBase InitializePlot(
     clsChromatogramInfo chromatogramData,
     string plotTitle,
     int msLevelFilter,
     string xAxisLabel,
     string yAxisLabel,
     bool autoMinMaxY,
     bool yAxisExponentialNotation)
 {
     if (PlotWithPython)
     {
         return(InitializePythonPlot(chromatogramData, plotTitle, msLevelFilter, xAxisLabel, yAxisLabel, autoMinMaxY, yAxisExponentialNotation));
     }
     else
     {
         return(InitializeOxyPlot(chromatogramData, plotTitle, msLevelFilter, xAxisLabel, yAxisLabel, autoMinMaxY, yAxisExponentialNotation));
     }
 }
        private void ValidateMSLevel(clsChromatogramInfo chromatogramInfo)
        {
            var msLevelDefined = false;

            for (var index = 0; index <= chromatogramInfo.ScanCount - 1; index++)
            {
                if (chromatogramInfo.GetDataPoint(index).MSLevel > 0)
                {
                    msLevelDefined = true;
                    break;
                }
            }

            if (!msLevelDefined)
            {
                // Set the MSLevel to 1 for all scans
                for (var index = 0; index <= chromatogramInfo.ScanCount - 1; index++)
                {
                    chromatogramInfo.GetDataPoint(index).MSLevel = 1;
                }
            }
        }
Exemple #5
0
        private void ValidateMSLevel(clsChromatogramInfo objChrom)
        {
            var blnMSLevelDefined = false;

            for (var intIndex = 0; intIndex <= objChrom.ScanCount - 1; intIndex++)
            {
                if (objChrom.GetDataPoint(intIndex).MSLevel > 0)
                {
                    blnMSLevelDefined = true;
                    break;
                }
            }

            if (!blnMSLevelDefined)
            {
                // Set the MSLevel to 1 for all scans
                for (var intIndex = 0; intIndex <= objChrom.ScanCount - 1; intIndex++)
                {
                    objChrom.GetDataPoint(intIndex).MSLevel = 1;
                }
            }
        }
        /// <summary>
        /// Plots a BPI or TIC chromatogram
        /// </summary>
        /// <param name="chromatogramData">Data to display</param>
        /// <param name="plotTitle">Title of the plot</param>
        /// <param name="msLevelFilter">0 to use all of the data, 1 to use data from MS scans, 2 to use data from MS2 scans, etc.</param>
        /// <param name="xAxisLabel"></param>
        /// <param name="yAxisLabel"></param>
        /// <param name="autoMinMaxY"></param>
        /// <param name="yAxisExponentialNotation"></param>
        /// <returns>Python PlotContainer</returns>
        private clsPythonPlotContainer InitializePythonPlot(
            clsChromatogramInfo chromatogramData,
            string plotTitle,
            int msLevelFilter,
            string xAxisLabel,
            string yAxisLabel,
            bool autoMinMaxY,
            bool yAxisExponentialNotation)
        {
            double scanTimeMax  = 0;
            double maxIntensity = 0;

            // Instantiate the list to track the data points
            var points = new List <DataPoint>();

            foreach (var dataPoint in chromatogramData.Scans)
            {
                if (msLevelFilter != 0 && dataPoint.MSLevel != msLevelFilter &&
                    !(msLevelFilter == 2 && dataPoint.MSLevel >= 2))
                {
                    continue;
                }

                points.Add(new DataPoint(dataPoint.ScanNum, dataPoint.Intensity));

                if (dataPoint.TimeMinutes > scanTimeMax)
                {
                    scanTimeMax = dataPoint.TimeMinutes;
                }

                if (dataPoint.Intensity > maxIntensity)
                {
                    maxIntensity = dataPoint.Intensity;
                }
            }

            if (points.Count == 0)
            {
                // Nothing to plot
                var emptyContainer = new clsPythonPlotContainer2D();
                return(emptyContainer);
            }

            var plotContainer = new clsPythonPlotContainer2D(plotTitle, xAxisLabel, yAxisLabel)
            {
                DeleteTempFiles = DeleteTempFiles
            };

            if (yAxisExponentialNotation)
            {
                plotContainer.YAxisInfo.StringFormat = clsAxisInfo.EXPONENTIAL_FORMAT;
            }

            plotContainer.SetData(points);

            // Update the axis format codes if the data values are small or the range of data is small

            // Assume the X axis is plotting integers
            var xVals = (from item in points select item.X).ToList();

            clsPlotUtilities.GetAxisFormatInfo(xVals, true, plotContainer.XAxisInfo);

            // Assume the Y axis is plotting doubles
            var yVals = (from item in points select item.Y).ToList();

            clsPlotUtilities.GetAxisFormatInfo(yVals, false, plotContainer.YAxisInfo);

            // Possibly add a label showing the maximum elution time
            if (scanTimeMax > 0)
            {
                string caption;
                if (scanTimeMax < 2)
                {
                    caption = Math.Round(scanTimeMax, 2).ToString("0.00") + " minutes";
                }
                else if (scanTimeMax < 10)
                {
                    caption = Math.Round(scanTimeMax, 1).ToString("0.0") + " minutes";
                }
                else
                {
                    caption = Math.Round(scanTimeMax, 0).ToString("0") + " minutes";
                }

                plotContainer.AnnotationBottomRight = caption;
            }

            // Override the auto-computed Y axis range
            if (autoMinMaxY)
            {
                // Auto scale
            }
            else
            {
                plotContainer.XAxisInfo.SetRange(0, maxIntensity);
            }

            return(plotContainer);
        }
        /// <summary>
        /// Plots a BPI or TIC chromatogram
        /// </summary>
        /// <param name="chromatogramData">Data to display</param>
        /// <param name="plotTitle">Title of the plot</param>
        /// <param name="msLevelFilter">0 to use all of the data, 1 to use data from MS scans, 2 to use data from MS2 scans, etc.</param>
        /// <param name="xAxisLabel"></param>
        /// <param name="yAxisLabel"></param>
        /// <param name="autoMinMaxY"></param>
        /// <param name="yAxisExponentialNotation"></param>
        /// <returns>OxyPlot PlotContainer</returns>
        private clsPlotContainer InitializeOxyPlot(
            clsChromatogramInfo chromatogramData,
            string plotTitle,
            int msLevelFilter,
            string xAxisLabel,
            string yAxisLabel,
            bool autoMinMaxY,
            bool yAxisExponentialNotation)
        {
            var    minScan      = int.MaxValue;
            var    maxScan      = 0;
            double scanTimeMax  = 0;
            double maxIntensity = 0;

            // Instantiate the list to track the data points
            var points = new List <DataPoint>();

            foreach (var dataPoint in chromatogramData.Scans)
            {
                if (msLevelFilter != 0 && dataPoint.MSLevel != msLevelFilter &&
                    !(msLevelFilter == 2 && dataPoint.MSLevel >= 2))
                {
                    continue;
                }

                points.Add(new DataPoint(dataPoint.ScanNum, dataPoint.Intensity));

                if (dataPoint.TimeMinutes > scanTimeMax)
                {
                    scanTimeMax = dataPoint.TimeMinutes;
                }

                if (dataPoint.ScanNum < minScan)
                {
                    minScan = dataPoint.ScanNum;
                }

                if (dataPoint.ScanNum > maxScan)
                {
                    maxScan = dataPoint.ScanNum;
                }

                if (dataPoint.Intensity > maxIntensity)
                {
                    maxIntensity = dataPoint.Intensity;
                }
            }

            if (points.Count == 0)
            {
                // Nothing to plot
                var emptyContainer = new clsPlotContainer(new PlotModel(), mWriteDebug, mDataSource);
                emptyContainer.WriteDebugLog("points.Count == 0 in InitializeOxyPlot for plot " + plotTitle);
                return(emptyContainer);
            }

            // Round maxScan down to the nearest multiple of 10
            maxScan = (int)Math.Ceiling(maxScan / 10.0) * 10;

            // Multiple maxIntensity by 2% and then round up to the nearest integer
            maxIntensity = Math.Ceiling(maxIntensity * 1.02);

            var myPlot = clsOxyPlotUtilities.GetBasicPlotModel(plotTitle, xAxisLabel, yAxisLabel);

            if (yAxisExponentialNotation)
            {
                myPlot.Axes[1].StringFormat = clsAxisInfo.EXPONENTIAL_FORMAT;
            }

            AddOxyPlotSeries(myPlot, points);

            // Update the axis format codes if the data values are small or the range of data is small
            var xVals = (from item in points select item.X).ToList();

            clsOxyPlotUtilities.UpdateAxisFormatCodeIfSmallValues(myPlot.Axes[0], xVals, true);

            var yVals = (from item in points select item.Y).ToList();

            clsOxyPlotUtilities.UpdateAxisFormatCodeIfSmallValues(myPlot.Axes[1], yVals, false);

            var plotContainer = new clsPlotContainer(myPlot, mWriteDebug, mDataSource)
            {
                FontSizeBase = clsPlotContainer.DEFAULT_BASE_FONT_SIZE
            };

            plotContainer.WriteDebugLog(string.Format("Instantiated plotContainer for plot {0}: {1} data points", plotTitle, points.Count));

            // Possibly add a label showing the maximum elution time
            if (scanTimeMax > 0)
            {
                string caption;
                if (scanTimeMax < 2)
                {
                    caption = Math.Round(scanTimeMax, 2).ToString("0.00") + " minutes";
                }
                else if (scanTimeMax < 10)
                {
                    caption = Math.Round(scanTimeMax, 1).ToString("0.0") + " minutes";
                }
                else
                {
                    caption = Math.Round(scanTimeMax, 0).ToString("0") + " minutes";
                }

                plotContainer.AnnotationBottomRight = caption;

                // Alternative method is to add a TextAnnotation, but these are inside the main plot area
                // and are tied to a data point
                //
                // var scanTimeMaxText = new OxyPlot.Annotations.TextAnnotation
                // {
                //     TextRotation = 0,
                //     Text = caption,
                //     Stroke = OxyColors.Black,
                //     StrokeThickness = 2,
                //     FontSize = clsPlotContainer.DEFAULT_BASE_FONT_SIZE
                // };
                //
                // scanTimeMaxText.TextPosition = new DataPoint(maxScan, 0);
                // myPlot.Annotations.Add(scanTimeMaxText);
            }

            // Override the auto-computed X axis range
            if (minScan == maxScan)
            {
                myPlot.Axes[0].Minimum = minScan - 1;
                myPlot.Axes[0].Maximum = minScan + 1;
            }
            else
            {
                myPlot.Axes[0].Minimum = 0;

                if (maxScan == 0)
                {
                    myPlot.Axes[0].Maximum = 1;
                }
                else
                {
                    myPlot.Axes[0].Maximum = maxScan;
                }
            }

            // Assure that we don't see ticks between scan numbers
            clsOxyPlotUtilities.ValidateMajorStep(myPlot.Axes[0]);

            // Override the auto-computed Y axis range
            if (autoMinMaxY)
            {
                // Auto scale
            }
            else
            {
                myPlot.Axes[1].Minimum = 0;
                myPlot.Axes[1].Maximum = maxIntensity;
            }

            // Hide the legend
            myPlot.IsLegendVisible = false;

            return(plotContainer);
        }