コード例 #1
0
        protected virtual void InitializeProcessingTasks()
        {
            MSGenerator  = MSGeneratorFactory.CreateMSGenerator(Run.MSFileType);
            PeakDetector = PeakDetectorFactory.CreatePeakDetector(NewDeconToolsParameters);
            Deconvolutor = DeconvolutorFactory.CreateDeconvolutor(NewDeconToolsParameters);

            //the new iThrash imports the _peaks.txt file
            if (Deconvolutor is DeconTools.Backend.ProcessingTasks.Deconvoluters.InformedThrashDeconvolutor)
            {
                _deconvolutorRequiresPeaksFile = true;
            }

            //Will initialize these but whether or not they are used are determined elsewhere
            ZeroFiller = new DeconToolsZeroFiller(NewDeconToolsParameters.MiscMSProcessingParameters.ZeroFillingNumZerosToFill);
            Smoother   = new SavitzkyGolaySmoother(NewDeconToolsParameters.MiscMSProcessingParameters.SavitzkyGolayNumPointsInSmooth,
                                                   NewDeconToolsParameters.MiscMSProcessingParameters.SavitzkyGolayOrder);

            FitScoreCalculator = new DeconToolsFitScoreCalculator();
            ScanResultUpdater  = new ScanResultUpdater(NewDeconToolsParameters.ScanBasedWorkflowParameters.ProcessMS2);
            ResultValidator    = new ResultValidatorTask();

            IsosResultExporter = IsosExporterFactory.CreateIsosExporter(Run.ResultCollection.ResultType, ExporterType,
                                                                        IsosOutputFileName);

            ScanResultExporter = ScansExporterFactory.CreateScansExporter(Run.MSFileType, ExporterType,
                                                                          ScansOutputFileName);

            if (!_deconvolutorRequiresPeaksFile)
            {
                PeakListExporter = PeakListExporterFactory.Create(ExporterType, Run.MSFileType, PeakListExporterTriggerValue,
                                                                  PeakListOutputFileName);
            }

            PeakToMSFeatureAssociator = new PeakToMSFeatureAssociator();
        }
コード例 #2
0
 public Decoder(int sampleRate)
 {
     peakDetector  = new PeakDetector(this);
     bitDecoder    = new BitDecoder(this, sampleRate);
     symbolDecoder = new SymbolDecoder(this);
     Clear();
 }
コード例 #3
0
        void optionsChanged(object sender, EventArgs e)
        {
            if (panel.Tag != this)
            {
                return;
            }

            preferVendorPeakPicking = processingPanels.peakPickerPreferVendorCentroidingCheckbox.Checked;
            switch (processingPanels.peakPickerAlgorithmComboBox.SelectedIndex)
            {
            case 0:
                localMaximumWindowSize = (uint)processingPanels.peakPickerLocalMaximumWindowSizeTrackBar.Value;
                algorithm = new LocalMaximumPeakDetector(localMaximumWindowSize);
                break;

            case 1:
                minSNR       = Convert.ToDouble(processingPanels.peakPickerCantWaitMinSNRTextBox.Text);
                minPeakSpace = Convert.ToDouble(processingPanels.peakPickerCantWaitMinPeakSpaceTextBox.Text);
                algorithm    = new CwtPeakDetector(minSNR, minPeakSpace);
                break;
            }

            processingPanels.peakPickerLocalMaximumParameters.Visible = algorithm is LocalMaximumPeakDetector;
            processingPanels.peakPickerCantWaitParameters.Visible     = algorithm is CwtPeakDetector;

            OnOptionsChanged(sender, e);
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: PeterOzbot/ValTech
        public JsonResult GetData(string WindowSize, string Stringency, string PeakDensityPercentage)
        {
            DetectionSettings detectionSettings = new DetectionSettings();

            try {
                int    windowSizeValue       = Convert.ToInt32(WindowSize);
                double stringency            = Convert.ToDouble(Stringency);
                double peakDensityPercentage = Convert.ToDouble(PeakDensityPercentage);

                detectionSettings = new DetectionSettings(windowSizeValue, stringency, peakDensityPercentage);
            }
            catch { }



            List <IPoint> points = GeneratePoints();

            PeakDetector peakDetector = new PeakDetector(detectionSettings);

            peakDetector.Detect(points);



            return(Json(points, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
ファイル: PeakFinder.cs プロジェクト: picowatt/Atreyu
        /// <summary>
        /// Find the peaks in the data set passed and returns a list of peak information.
        /// </summary>
        /// <param name="dataList">
        /// The data List.
        /// </param>
        /// <param name="numberOfTopPeaks">
        /// The number of peaks to return, starting with the highest intensity, if less than one it will return all peaks.
        /// </param>
        /// <returns>
        /// The <see cref="System.Collections.Generic.List{T}"/> of peaks.
        /// </returns>
        public static PeakSet FindPeaks(IEnumerable <KeyValuePair <double, double> > data, int numberOfTopPeaks = 0)
        {
            var       dataList  = data.ToList();
            const int Precision = 100000;

            var peakDetector = new PeakDetector();

            var finderOptions = PeakDetector.GetDefaultSICPeakFinderOptions();

            List <double> smoothedY;

            // Create a new dictionary so we don't modify the original one
            var tempFrameList = new List <KeyValuePair <int, double> >(dataList.Count);

            // We have to give it integers for the double, but we need this to handle doubles, so we will multiply the key by the precision
            // and later get the correct value back by dividing it out again
            // resultant linq quesry is less readable than this.
            // ReSharper disable once LoopCanBeConvertedToQuery
            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < dataList.Count; i++)
            {
                tempFrameList.Add(new KeyValuePair <int, double>((int)(dataList[i].Key * Precision), dataList[i].Value));
            }

            // I am not sure what the library does with this but in the example exe file that came with the library
            // they used half of the length of the list in their previous examples and this seems to work.
            // To be extra clear to future programmers, changing this number causes memory out of bounds from the peak detector
            var originalpeakLocation = tempFrameList.Count / 2;

            var allPeaks = peakDetector.FindPeaks(
                finderOptions,
                tempFrameList.OrderBy(x => x.Key).ToList(),
                originalpeakLocation,
                out smoothedY);

            IEnumerable <clsPeak> peakSet;

            // if a few peaks are wanted, it is better that we trim them up front, before we calculate the extra information
            if (numberOfTopPeaks > 0)
            {
                var topPeaks = allPeaks.OrderByDescending(peak => smoothedY[peak.LocationIndex]).Take(numberOfTopPeaks);
                peakSet = topPeaks;
            }
            else
            {
                peakSet = allPeaks;
            }

            var calculatedPeakSet =
                peakSet.Select(peak => CalculatePeakInformation(peak, tempFrameList, smoothedY, Precision))
                .Where(p => p.ResolvingPower > 0 && !double.IsInfinity(p.ResolvingPower));

            return(new PeakSet(calculatedPeakSet));

            ////var tempList =
            ////    datapointList.Where(x => !double.IsInfinity(x.ResolvingPower)).OrderByDescending(x => x.Intensity).Take(10);
        }
コード例 #6
0
ファイル: Processing.cs プロジェクト: tomas-pluskal/pwiz
        public PeakPickingProcessor()
        {
            preferVendorPeakPicking = true;
            localMaximumWindowSize  = 3;
            algorithm = new LocalMaximumPeakDetector(localMaximumWindowSize);

            processingPanels.peakPickerPreferVendorCentroidingCheckbox.CheckedChanged += new EventHandler(optionsChanged);
            processingPanels.peakPickerAlgorithmComboBox.SelectedIndexChanged         += new EventHandler(optionsChanged);
            processingPanels.peakPickerLocalMaximumWindowSizeTrackBar.ValueChanged    += new EventHandler(optionsChanged);
        }
コード例 #7
0
        public void EmptyListTest()
        {
            List <TestPoint> points = new List <TestPoint>();

            PeakDetector peakDetector = new PeakDetector();

            List <IPoint> result = peakDetector.Detect(points);

            Assert.AreNotEqual(null, result);
            Assert.AreEqual(0, result.Count);
        }
コード例 #8
0
        public void SinglePointTest()
        {
            List <TestPoint> points = new List <TestPoint>();

            points.Add(new TestPoint(DateTime.Now, 1));

            PeakDetector peakDetector = new PeakDetector();

            List <IPoint> result = peakDetector.Detect(points);

            Assert.AreNotEqual(null, result);
            Assert.AreEqual(0, result.Count);
        }
コード例 #9
0
        public PeakPickingProcessor()
        {
            preferVendorPeakPicking = true;
            localMaximumWindowSize  = 3;
            minSNR       = 1;
            minPeakSpace = 0.1;
            algorithm    = new CwtPeakDetector(minSNR, minPeakSpace);

            processingPanels.peakPickerPreferVendorCentroidingCheckbox.CheckedChanged += optionsChanged;
            processingPanels.peakPickerAlgorithmComboBox.SelectedIndexChanged         += optionsChanged;
            processingPanels.peakPickerLocalMaximumWindowSizeTrackBar.ValueChanged    += optionsChanged;
            processingPanels.peakPickerCantWaitMinSNRTextBox.TextChanged       += optionsChanged;
            processingPanels.peakPickerCantWaitMinPeakSpaceTextBox.TextChanged += optionsChanged;
        }
コード例 #10
0
        public void AdvancedDetection_ResultCollectionTest()
        {
            List <TestPoint> points       = GeneratePoints();
            PeakDetector     peakDetector = new PeakDetector();
            List <IPoint>    result       = peakDetector.Detect(points);

            Assert.AreNotEqual(null, result);
            Assert.AreNotEqual(0, result.Count);

            foreach (IPoint point in result)
            {
                Assert.IsTrue(point.IsPeak);
                Assert.IsTrue(point.Y > 1);
            }
        }
コード例 #11
0
        /// <summary>
        /// The find peak using MASIC.
        /// </summary>
        /// <param name="intensityPoints">
        /// The intensity points.
        /// </param>
        public static IList<clsPeak> FindPeakUsingMasic(List<IntensityPoint> intensityPoints, int totalScans)
        {
            PeakDetector.udtSICPeakFinderOptionsType option = TuneMasicOption();

            var paddedIntensityPoints = IMSUtil.PadZeroesToPointList(intensityPoints, totalScans);

            // Convert intensity points to key value pair
            List<KeyValuePair<int, double>> cartesianData = paddedIntensityPoints.Select(point => new KeyValuePair<int, double>(point.ScanIms, point.Intensity)).ToList();

            PeakDetector detector = new PeakDetector();
            List<double> smoothedYData;

            // Find the peaks
            List<clsPeak> detectedPeaks = detector.FindPeaks(option, cartesianData, 1, out smoothedYData);
            return detectedPeaks;
        }
コード例 #12
0
        public void SimpleDetectionTest()
        {
            List <TestPoint> points = new List <TestPoint>();

            points.Add(new TestPoint(DateTime.Now, 1));
            points.Add(new TestPoint(DateTime.Now.AddDays(1), 1));
            points.Add(new TestPoint(DateTime.Now.AddDays(2), 5));
            points.Add(new TestPoint(DateTime.Now.AddDays(3), 1));
            points.Add(new TestPoint(DateTime.Now.AddDays(4), 1));

            PeakDetector peakDetector = new PeakDetector(new DetectionSettings(1));

            List <IPoint> result = peakDetector.Detect(points);

            Assert.AreNotEqual(null, result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(5, result[0].Y);
        }
コード例 #13
0
ファイル: Processing.cs プロジェクト: tomas-pluskal/pwiz
        void optionsChanged(object sender, EventArgs e)
        {
            if (panel.Tag != this)
            {
                return;
            }

            preferVendorPeakPicking = processingPanels.peakPickerPreferVendorCentroidingCheckbox.Checked;
            switch (processingPanels.peakPickerAlgorithmComboBox.SelectedIndex)
            {
            case 0:
                localMaximumWindowSize = (uint)processingPanels.peakPickerLocalMaximumWindowSizeTrackBar.Value;
                algorithm = new LocalMaximumPeakDetector(localMaximumWindowSize);
                break;
            }

            OnOptionsChanged(sender, e);
        }
コード例 #14
0
        public void AdvancedDetectionTest()
        {
            List <TestPoint> points       = GeneratePoints();
            PeakDetector     peakDetector = new PeakDetector();
            List <IPoint>    result       = peakDetector.Detect(points);

            Assert.AreNotEqual(null, result);
            Assert.AreNotEqual(0, result.Count);

            foreach (IPoint point in points)
            {
                if (point.IsPeak)
                {
                    Assert.IsTrue(point.Y > 1, point.Y.ToString());
                }
                else
                {
                    Assert.IsTrue(point.Y == 1, point.Y.ToString());
                }
            }
        }
コード例 #15
0
        protected override void IterateOverScans()
        {
            DeconMSnResults.Clear();
            _scanCounter = 0;

            var resultCounter = 0;

            foreach (var scanSet in Run.ScanSetCollection.ScanSetList)
            {
                _scanCounter++;

                if (BackgroundWorker != null)
                {
                    if (BackgroundWorker.CancellationPending)
                    {
                        return;
                    }
                }

                //check ms level
                var currentMSLevel = Run.GetMSLevel(scanSet.PrimaryScanNumber);

                if (currentMSLevel == 1)
                {
                    Run.ResultCollection.IsosResultBin.Clear();

                    Run.CurrentScanSet = scanSet;

                    MSGenerator.Execute(Run.ResultCollection);

                    _currentMS1XYValues = new XYData
                    {
                        Xvalues = Run.XYData.Xvalues,
                        Yvalues = Run.XYData.Yvalues
                    };

                    _currentMS1TICIntensity = Run.GetTICFromInstrumentInfo(scanSet.PrimaryScanNumber);

                    PeakDetector.Execute(Run.ResultCollection);
                    _currentMS1Peaks = new List <Peak>(Run.PeakList);
                }
                else if (currentMSLevel == 2)
                {
                    if (_currentMS1Peaks == null || _currentMS1Peaks.Count == 0)
                    {
                        continue;
                    }

                    var precursorInfo = Run.GetPrecursorInfo(scanSet.PrimaryScanNumber);
                    Run.CurrentScanSet = scanSet;
                    var inaccurateParentMZ = precursorInfo.PrecursorMZ;

                    resultCounter++;
                    var deconMSnResult = new DeconMSnResult {
                        ParentScan = Run.GetParentScan(scanSet.PrimaryScanNumber)
                    };
                    deconMSnResult.IonInjectionTime       = Run.GetIonInjectionTimeInMilliseconds(deconMSnResult.ParentScan);
                    deconMSnResult.ScanNum                = scanSet.PrimaryScanNumber;
                    deconMSnResult.OriginalMZTarget       = inaccurateParentMZ;
                    deconMSnResult.ParentScanTICIntensity = _currentMS1TICIntensity;

                    MSGenerator.Execute(Run.ResultCollection);

                    var lowerMZ = inaccurateParentMZ - 1.1;
                    var upperMZ = inaccurateParentMZ + 1.1;

                    var dataIsCentroided = Run.IsDataCentroided(scanSet.PrimaryScanNumber);
                    if (dataIsCentroided)
                    {
                        _ms2PeakDetectorForCentroidData.Execute(Run.ResultCollection);
                    }
                    else
                    {
                        _ms2PeakDetectorForProfileData.Execute(Run.ResultCollection);
                    }
                    var ms2Peaks = new List <Peak>(Run.PeakList);

                    var filteredMS1Peaks = _currentMS1Peaks.Where(p => p.XValue > lowerMZ && p.XValue < upperMZ).ToList();

                    IsotopicProfile selectedMS1Feature = null;
                    for (var attemptNum = 0; attemptNum < NumMaxAttemptsAtLowIntensitySpecies; attemptNum++)
                    {
                        var candidateMS1Features = GetCandidateMS1Features(inaccurateParentMZ, filteredMS1Peaks);

                        //if none were found, will regenerate MS1 spectrum and find peaks again
                        if (candidateMS1Features.Count == 0)
                        {
                            var numSummed = attemptNum * 2 + 3;
                            var ms1Scan   = precursorInfo.PrecursorScan;

                            var ms1ScanSet = new ScanSetFactory().CreateScanSet(Run, ms1Scan, numSummed);

                            //get MS1 mass spectrum again. This time sum spectra
                            Run.CurrentScanSet = ms1ScanSet;
                            MSGenerator.Execute(Run.ResultCollection);

                            //run MS1 peak detector, with greater sensitivity
                            var isLastAttempt = attemptNum >= NumMaxAttemptsAtLowIntensitySpecies - 2;    //need to do -2 because of the way the loop advances the counter.

                            if (isLastAttempt)
                            {
                                _superSensitiveMS1PeakDetector.MinX = lowerMZ;
                                _superSensitiveMS1PeakDetector.MaxX = upperMZ;
                                _superSensitiveMS1PeakDetector.Execute(Run.ResultCollection);
                                filteredMS1Peaks = new List <Peak>(Run.PeakList);
                            }
                            else
                            {
                                _moreSensitiveMS1PeakDetector.Execute(Run.ResultCollection);
                                var moreSensitiveMS1Peaks = new List <Peak>(Run.PeakList);
                                filteredMS1Peaks = moreSensitiveMS1Peaks.Where(p => p.XValue > lowerMZ && p.XValue < upperMZ).ToList();
                            }
                        }
                        else if (candidateMS1Features.Count == 1)
                        {
                            selectedMS1Feature = candidateMS1Features.First();
                            break;   //we found something, so no need for any further attempts
                        }
                        else
                        {
                            var highQualityCandidates = candidateMS1Features.Where(p => p.Score < 0.15).ToList();
                            if (highQualityCandidates.Count == 0)
                            {
                                selectedMS1Feature = candidateMS1Features.OrderByDescending(p => p.IntensityMostAbundantTheor).First();
                            }
                            else if (highQualityCandidates.Count == 1)
                            {
                                selectedMS1Feature = highQualityCandidates.First();
                            }
                            else
                            {
                                selectedMS1Feature = highQualityCandidates.OrderByDescending(p => p.IntensityMostAbundantTheor).First();
                            }

                            deconMSnResult.ExtraInfo = "Warning - multiple MSFeatures found for target parent MZ";
                            break;   //we found something, so no need for any further attempts
                        }
                    }

                    if (selectedMS1Feature != null)
                    {
                        deconMSnResult.ParentMZ           = selectedMS1Feature.MonoPeakMZ;
                        deconMSnResult.ParentChargeState  = selectedMS1Feature.ChargeState;
                        deconMSnResult.ParentIntensity    = selectedMS1Feature.IntensityMostAbundantTheor;
                        deconMSnResult.IntensityAggregate = selectedMS1Feature.IntensityMostAbundantTheor;
                        deconMSnResult.IsotopicProfile    = selectedMS1Feature;
                    }
                    else
                    {
                        var candidatePeaks = new List <Peak>();

                        foreach (var peak in filteredMS1Peaks)
                        {
                            var currentDiff = Math.Abs(peak.XValue - inaccurateParentMZ);

                            var toleranceInMZ = ToleranceInPPM * peak.XValue / 1e6;

                            if (currentDiff < toleranceInMZ)
                            {
                                candidatePeaks.Add(peak);
                            }
                        }

                        Peak selectedPeak = null;

                        if (candidatePeaks.Count == 0)
                        {
                            //cannot even find a suitable MS1 peak. So can't do anything
                        }
                        else if (candidatePeaks.Count == 1)
                        {
                            selectedPeak = candidatePeaks.First();
                        }
                        else
                        {
                            selectedPeak = candidatePeaks.OrderByDescending(p => p.Height).First();
                        }

                        if (selectedPeak != null)
                        {
                            deconMSnResult.ParentMZ          = selectedPeak.XValue;
                            deconMSnResult.ParentChargeState = 1;   //not sure what charge I should assign... Ask SangTae
                            deconMSnResult.ParentIntensity   = selectedPeak.Height;
                            deconMSnResult.IsotopicProfile   = null;
                            deconMSnResult.ExtraInfo         = "Failure code 1: No MSFeature, but peak found";
                        }
                        else
                        {
                            deconMSnResult.ParentMZ          = precursorInfo.PrecursorMZ; //could not find the accurate parentMZ, so just report what the instrument found.
                            deconMSnResult.ParentChargeState = 1;                         //not sure what charge I should assign... Ask SangTae
                            deconMSnResult.ParentIntensity   = 0;
                            deconMSnResult.IsotopicProfile   = null;
                            deconMSnResult.ExtraInfo         = "Failure code 2: No MSFeature or peak found";
                        }
                    }

                    //Build export data.
                    var outputString = GetMGFOutputString(Run, scanSet.PrimaryScanNumber, deconMSnResult, ms2Peaks);

                    var includeHeader = resultCounter == 1;
                    var summaryString = GetSummaryString(deconMSnResult, includeHeader);

                    var parentProfileString = GetParentProfileString(deconMSnResult, includeHeader);

                    if (ExportData)
                    {
                        WriteOutMainData(outputString);

                        WriteOutDeconMSnSummary(summaryString);

                        if (IsParentProfileDataExported)
                        {
                            WriteOutParentProfileInfoString(parentProfileString);
                        }
                    }

                    if (deconMSnResult.ParentIntensity > 0)
                    {
                        DeconMSnResults.Add(deconMSnResult);
                    }
                }
                else
                {
                    throw new ApplicationException(
                              "DeconMSn only works on MS1 and MS2 data; You are attempting MS3");
                }

                ReportProgress();
            }
        }