Esempio n. 1
0
        /// <summary>
        /// Helper method for CombineScans
        /// Identifies which scan in the set has the most points in the boxcar range
        /// </summary>
        /// <param name="set"></param>
        /// <param name="boxcar"></param> BestScan object with first index, last index, total intensity, and scan
        public static BestScan FindBoxcarScan(SetOfScans set, BoxcarRange range, int count)
        {
            double     bestIntensity  = 0;
            MsDataScan bestScan       = set.BoxcarScans[0];
            int        bestFirstIndex = 0;
            int        bestLastIndex  = 0;
            int        bestLen        = 0;

            List <MsDataScan> boxcarScans = set.BoxcarScans;

            // Check each scan to find the one that corresponds best to the boxcar scan range
            foreach (var scan in boxcarScans)
            {
                BestScan bestrange = FindScanRange(scan, range);

                // the scan is better than the previous scan if:
                // it has more m/z values in the range, and if
                // the total intensity is higher

                int firstIndex = bestrange.FirstIndex;
                int lastIndex  = bestrange.LastIndex;
                int currentLen = lastIndex - firstIndex;

                if (currentLen > bestLen)
                {
                    if (bestrange.TotalIntensity < bestIntensity)
                    {
                        Console.WriteLine("ACK! scan#: " + count + " has a lot of very low intensity scans and may have been incorrectly counted in a boxcar range!");
                    }

                    // if the scan has more m/z points in the boxcar range than the previously best scan, update variables.
                    bestLen        = currentLen;
                    bestLastIndex  = lastIndex;
                    bestFirstIndex = firstIndex;
                    bestScan       = scan;
                }
            }
            return(new BestScan(bestFirstIndex, bestLastIndex, bestIntensity, bestScan));
        }
Esempio n. 2
0
        /// <summary>
        /// Helper method for MergeScans
        /// Combines the 3 scans in a set into one MsDataScan.
        /// </summary>
        /// <param name="set"></param>
        /// <param name="boxcarRanges"></param>
        /// <returns></returns> MsDataScan combined scans
        public static MsDataScan CombineScans(SetOfScans set, SetOfBoxcarRanges[] boxcarTypes)
        {
            List <double[]> bestPoints = new List <double[]>();
            var             count      = 1;

            foreach (var boxcarRanges in boxcarTypes)
            {
                foreach (var boxcarRange in boxcarRanges)
                {
                    BestScan bestScan = FindBoxcarScan(set, boxcarRange, count);

                    // find the m/z values and intensities in that scan's x and y arrays between the first and last index, add to the lists
                    for (int i = bestScan.FirstIndex; i <= bestScan.LastIndex; i++)
                    {
                        double x = bestScan.Scan.MassSpectrum.XArray[i];
                        double y = bestScan.Scan.MassSpectrum.YArray[i];
                        bestPoints.Add(new double[] { x, y });
                    }
                }
            }

            // recast bestPoints (List<Double[]>) into double[,]
            double[,] mzIntensities = new double[bestPoints[0].Length, bestPoints.Count];

            for (int i = 0; i < bestPoints[0].Length; i++)
            {
                for (int j = 0; j < bestPoints.Count; j++)
                {
                    mzIntensities[i, j] = bestPoints[j][i];
                }
            }

            // create and return the new MsDataScan
            MzSpectrum newMassSpectrum = new MzSpectrum(mzIntensities);
            MsDataScan newScan         = new MsDataScan(newMassSpectrum, count, 1, true, set.BoxcarScans[0].Polarity, set.BoxcarScans[0].RetentionTime, set.BoxcarScans[0].ScanWindowRange, set.BoxcarScans[0].ScanFilter, set.BoxcarScans[0].MzAnalyzer, set.BoxcarScans[0].TotalIonCurrent, set.BoxcarScans[0].InjectionTime, set.BoxcarScans[0].NoiseData, set.BoxcarScans[0].NativeId);

            count++;
            return(newScan);
        }