Ejemplo n.º 1
0
        public void PerformTransform(
            float backgroundIntensity, float minPeptideIntensity, int maxProcessingTimeMinutes,
            ref float[] mzs, ref float[] intensities,
            ref ThrashV1Peak[] peaks, ref HornTransformResults[] transformResults,
            out bool processingAborted)
        {
            PercentDone       = 0;
            processingAborted = false;

            var numPoints = mzs.Length;

            if (mzs.Length == 0)
            {
                return;
            }

            // mzs should be in sorted order
            double minMz         = mzs[0];
            double maxMz         = mzs[numPoints - 1];
            var    mzList        = new List <double>(mzs.Select(x => (double)x));
            var    intensityList = new List <double>(intensities.Select(x => (double)x));

            var peakData = new PeakData();

            peakData.SetPeaks(peaks);
            peakData.MzList        = mzList;
            peakData.IntensityList = intensityList;

            if (IsMZRangeUsed)
            {
                minMz = MinMZ;
                maxMz = MaxMZ;
            }

            //loads 'currentPeak' with the most intense peak within minMZ and maxMZ
            ThrashV1Peak currentPeak;
            var          found = peakData.GetNextPeak(minMz, maxMz, out currentPeak);
            //var fwhm_SN = currentPeak.FWHM;

            var transformRecords = new List <HornTransformResults>();
            var numTotalPeaks    = peakData.GetNumPeaks();

            StatusMessage = "Performing Horn Transform on peaks";
            var startTime = DateTime.UtcNow;

            while (found)
            {
                var numPeaksLeft = peakData.GetNumUnprocessedPeaks();
                PercentDone = 100 * (numTotalPeaks - numPeaksLeft) / numTotalPeaks;
                if (PercentDone % 5 == 0)
                {
                    StatusMessage = string.Concat("Done with ", Convert.ToString(numTotalPeaks - numPeaksLeft), " of ",
                                                  Convert.ToString(numTotalPeaks), " peaks.");
                }
                if (currentPeak.Intensity < minPeptideIntensity)
                {
                    break;
                }

                //--------------------- Transform performed ------------------------------
                HornTransformResults transformRecord;
                var foundTransform = FindTransform(peakData, ref currentPeak, out transformRecord, backgroundIntensity);
                if (foundTransform && transformRecord.ChargeState <= MaxChargeAllowed)
                {
                    if (IsActualMonoMZUsed)
                    {
                        //retrieve experimental monoisotopic peak
                        var          monoPeakIndex = transformRecord.IsotopePeakIndices[0];
                        ThrashV1Peak monoPeak;
                        peakData.GetPeak(monoPeakIndex, out monoPeak);

                        //set threshold at 20% less than the expected 'distance' to the next peak
                        var errorThreshold = 1.003 / transformRecord.ChargeState;
                        errorThreshold = errorThreshold - errorThreshold * 0.2;

                        var calcMonoMz = transformRecord.MonoMw / transformRecord.ChargeState + 1.00727638;

                        if (Math.Abs(calcMonoMz - monoPeak.Mz) < errorThreshold)
                        {
                            transformRecord.MonoMw = monoPeak.Mz * transformRecord.ChargeState -
                                                     1.00727638 * transformRecord.ChargeState;
                        }
                    }
                    transformRecords.Add(transformRecord);
                }

                if (DateTime.UtcNow.Subtract(startTime).TotalMinutes > maxProcessingTimeMinutes)
                {
                    processingAborted = true;
                    found             = false;
                }
                else
                {
                    found = peakData.GetNextPeak(minMz, maxMz, out currentPeak);
                }
            }
            PercentDone = 100;

            // Done with the transform. Lets copy them all to the given memory structure.
            //Console.WriteLine("Done with Mass Transform. Found " + transformRecords.Count + " features");

            transformResults = transformRecords.ToArray();
            PercentDone      = 100;
        }