示例#1
0
        /// <summary>
        /// Get data in Xvalues and Yvalues where the y value is positive
        /// </summary>
        /// <returns></returns>
        public XYData GetNonZeroXYData()
        {
            var yDataCount = Yvalues.Length;

            var data      = new XYData();
            var tempXVals = new List <double>();
            var tempYVals = new List <double>();

            for (var i = 0; i < Xvalues.Length; i++)
            {
                if (i == yDataCount)
                {
                    break;
                }

                if (Yvalues[i] > 0)
                {
                    tempXVals.Add(Xvalues[i]);
                    tempYVals.Add(Yvalues[i]);
                }
            }

            data.Xvalues = tempXVals.ToArray();
            data.Yvalues = tempYVals.ToArray();

            return(data);
        }
        public void GetSpectrumTest1()
        {
            Run run = new DeconTools.Backend.Runs.AgilentDRun(agilentDataset1);

            var scanset = new ScanSet(25);
            var xydata  = new XYData();

            xydata = run.GetMassSpectrum(scanset, 0, 6000);
            //TestUtilities.DisplayXYValues(xydata);
            Console.WriteLine("numPoints = " + xydata.Xvalues.Length);
            Assert.AreEqual(156723, xydata.Xvalues.Length);
        }
        ///  Writes three spectra files to disk so that the data can be compared before and after summing
        public void GetSummedSpectrumTestWriteToDisk()
        {
            var testfile =
                @"\\proto-5\BionetXfer\People\ScottK\2012_01_12 SPIN QTOF3\GLY06_11JAN12_LYNX_SN7980_TOP4wList_75000_SPIN_2.d";

            Run run = new DeconTools.Backend.Runs.AgilentDRun(testfile);

            var primaryScan = 10000;
            //Scan A
            var scansetA = new ScanSet(primaryScan - 1);
            var xydata   = new XYData();

            xydata = run.GetMassSpectrum(scansetA, 0, 6000);

            TestUtilities.WriteToFile(xydata, @"P:\ScanA.txt");

            TestUtilities.DisplayXYValues(xydata);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);

            //Scan B
            var scansetB = new ScanSet(primaryScan);

            xydata = run.GetMassSpectrum(scansetB, 0, 6000);

            TestUtilities.WriteToFile(run.XYData, @"P:\ScanB.txt");

            TestUtilities.DisplayXYValues(run.XYData);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);

            //Scan C
            var scansetC = new ScanSet(primaryScan + 1);

            xydata = run.GetMassSpectrum(scansetC, 0, 6000);

            TestUtilities.WriteToFile(run.XYData, @"P:\ScanC.txt");

            TestUtilities.DisplayXYValues(run.XYData);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);

            //Scan ABC summed
            var scansetSum = new ScanSet(primaryScan, primaryScan - 1, primaryScan + 1);//primary, min, max

            xydata = run.GetMassSpectrum(scansetSum, 0, 6000);

            TestUtilities.WriteToFile(run.XYData, @"P:\ScanABC.txt");

            TestUtilities.DisplayXYValues(run.XYData);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);
        }
示例#4
0
        /// <summary>
        /// Filter the data to only keep data with x values between minX and maxX, optionally specifying a startingIndex
        /// If startingIndex is greater than or equal to data.Xvalues.Length, returns null
        /// </summary>
        /// <param name="data"></param>
        /// <param name="minX"></param>
        /// <param name="maxX"></param>
        /// <param name="startingIndex"></param>
        /// <returns></returns>
        /// <remarks>Assumes the data in Xvalues is sorted</remarks>
        public static XYData GetFilteredXYValues(XYData data, double minX, double maxX, int startingIndex = 0)
        {
            if (data == null || startingIndex >= data.Xvalues.Length)
            {
                return(null);
            }

            if (startingIndex < 0)
            {
                startingIndex = 0;
            }

            var yDataCount = data.Yvalues.Length;

            var xVals = new List <double>();
            var yVals = new List <double>();

            for (var i = startingIndex; i < data.Xvalues.Length; i++)
            {
                if (i == yDataCount)
                {
                    break;
                }

                if (data.Xvalues[i] < minX)
                {
                    continue;
                }

                if (data.Xvalues[i] > maxX)
                {
                    break;
                }

                xVals.Add(data.Xvalues[i]);
                yVals.Add(data.Yvalues[i]);
            }

            if (xVals.Count == 0)
            {
                return(null);
            }

            var returnedData = new XYData
            {
                Xvalues = xVals.ToArray(),
                Yvalues = yVals.ToArray()
            };

            return(returnedData);
        }
示例#5
0
        public static XYData ConvertDrawingPoints(System.Drawing.PointF[] points)
        {
            var xydata = new XYData();

            xydata.Xvalues = new double[points.Length];
            xydata.Yvalues = new double[points.Length];

            for (var i = 0; i < points.Length; i++)
            {
                xydata.Xvalues[i] = (double)points[i].X;
                xydata.Yvalues[i] = (double)points[i].Y;
            }

            return(xydata);
        }
示例#6
0
        public static XYData GetFilteredXYValues(XYData data, double minX, double maxX, int startingIndex)
        {
            //this assumes XY pairs with ordered x-values.

            if (data == null || startingIndex > data.Xvalues.Length - 1)
            {
                return(null);
            }

            var xvals = new List <double>();
            var yvals = new List <double>();


            for (var i = startingIndex; i < data.Xvalues.Length; i++)
            {
                if (data.Xvalues[i] >= minX)
                {
                    if (data.Xvalues[i] <= maxX)
                    {
                        xvals.Add(data.Xvalues[i]);
                        yvals.Add(data.Yvalues[i]);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                }
            }

            if (xvals.Count == 0)
            {
                return(null);
            }

            var returnedData = new XYData();

            returnedData.Xvalues = xvals.ToArray();
            returnedData.Yvalues = yvals.ToArray();

            return(returnedData);
        }
        ///checks the length of a non-summed and summed spectra
        public void GetSummedSpectrumTest1()
        {
            var testfile =
                @"\\proto-5\BionetXfer\People\ScottK\2012_01_12 SPIN QTOF3\GLY06_11JAN12_LYNX_SN7980_TOP4wList_75000_SPIN_2.d";

            var stopWatch = new Stopwatch();


            Run run = new DeconTools.Backend.Runs.AgilentDRun(testfile);

            var scanset = new ScanSet(25);

            stopWatch.Start();

            var xydata = new XYData();

            xydata = run.GetMassSpectrum(scanset);

            stopWatch.Stop();
            var singleSpectraLoadTime = stopWatch.Elapsed;

            TestUtilities.DisplayXYValues(run.XYData);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);


            var scansetSum = new ScanSet(25, 24, 26);

            stopWatch.Start();

            xydata = run.GetMassSpectrum(scansetSum);

            stopWatch.Stop();
            var threeScanSumSpectraLoadTime = stopWatch.Elapsed;


            TestUtilities.DisplayXYValues(run.XYData);
            Console.WriteLine("numPoints = " + run.XYData.Xvalues.Length);
            Console.WriteLine("This took " + singleSpectraLoadTime + " seconds to load one scan");
            Console.WriteLine("This took " + threeScanSumSpectraLoadTime + " seconds to load and sum three scans");
            Assert.AreEqual(258899, run.XYData.Xvalues.Length);
        }
示例#8
0
        public XYData GetNonZeroXYData()
        {
            var data      = new XYData();
            var tempxvals = new List <double>();
            var tempyvals = new List <double>();

            for (var i = 0; i < xvalues.Length; i++)
            {
                if (yvalues[i] > 0)
                {
                    tempxvals.Add(xvalues[i]);
                    tempyvals.Add(yvalues[i]);
                }
            }

            data.Xvalues = tempxvals.ToArray();
            data.Yvalues = tempyvals.ToArray();

            return(data);
        }
示例#9
0
        public XYData TrimData(double xmin, double xmax, double tolerance = 0.1)
        {
            if (xvalues == null || yvalues == null || xvalues.Length == 0 || yvalues.Length == 0)
            {
                return(this);
            }

            var currentMinXValue = xvalues[0];
            var currentMaxXValue = xvalues[xvalues.Length - 1];

            //if it doesn't need trimming, return it.
            if (xmin < currentMinXValue && xmax > currentMaxXValue)
            {
                return(this);
            }


            var data = new XYData();
            var indexClosestXValMin = MathUtils.GetClosest(xvalues, xmin, tolerance);

            var indexClosestXValMax = MathUtils.GetClosest(xvalues, xmax, tolerance);

            var numPoints = indexClosestXValMax - indexClosestXValMin + 1;

            if (numPoints <= 0)
            {
                throw new InvalidOperationException("indexClosestXValMin > indexClosestXValMax in XYData.TrimData; xvalues are likely not sorted");
            }

            data.Xvalues = new double[numPoints];
            data.Yvalues = new double[numPoints];

            for (var i = indexClosestXValMin; i <= indexClosestXValMax; i++)
            {
                data.Xvalues[i - indexClosestXValMin] = xvalues[i];
                data.Yvalues[i - indexClosestXValMin] = yvalues[i];
            }

            return(data);
        }
示例#10
0
        /// <summary>
        /// Trim the Xvalues and Yvalues properties to only keep the data between xMin and xMax
        /// </summary>
        /// <param name="xMin"></param>
        /// <param name="xMax"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        /// <remarks>Assumes the data in Xvalues is sorted</remarks>
        public XYData TrimData(double xMin, double xMax, double tolerance = 0.1)
        {
            if (Xvalues == null || Yvalues == null || Xvalues.Length == 0 || Yvalues.Length == 0)
            {
                return(this);
            }

            var currentMinXValue = Xvalues[0];
            var currentMaxXValue = Xvalues[Xvalues.Length - 1];

            if (xMin < currentMinXValue && xMax > currentMaxXValue)
            {
                // Nothing to trim
                return(this);
            }

            var data = new XYData();
            var indexClosestXValMin = MathUtils.GetClosest(Xvalues, xMin, tolerance);

            var indexClosestXValMax = MathUtils.GetClosest(Xvalues, xMax, tolerance);

            var numPoints = indexClosestXValMax - indexClosestXValMin + 1;

            if (numPoints <= 0)
            {
                throw new InvalidOperationException("indexClosestXValMin > indexClosestXValMax in XYData.TrimData; Xvalues is likely not sorted");
            }

            data.Xvalues = new double[numPoints];
            data.Yvalues = new double[numPoints];

            for (var i = indexClosestXValMin; i <= indexClosestXValMax; i++)
            {
                data.Xvalues[i - indexClosestXValMin] = Xvalues[i];
                data.Yvalues[i - indexClosestXValMin] = Yvalues[i];
            }

            return(data);
        }
示例#11
0
 public static XYData GetFilteredXYValues(XYData data, double minX, double maxX)
 {
     return(GetFilteredXYValues(data, minX, maxX, 0));
 }