Exemplo n.º 1
0
        public void GetProperties()
        {
            RunResult runResult = new RunResult();
            runResult.ActualDeutDistThreshold = 1;
            runResult.ActualPeaksInCalculation = 2;
            runResult.AverageMass = 3;
            runResult.TheoreticalAverageMass = 4;
            runResult.CentroidMR = 5;
            runResult.TheoreticalCentroidMR = 6;
            runResult.AmideHydrogenTotal = 7;
            runResult.AmountDeut = 8;
            runResult.IsUsedInCalculations = true;
            runResult.IsResultBasedOnFragment = true;
            runResult.FragmentIon = new FragmentIon();

            Assert.AreEqual(1, runResult.ActualDeutDistThreshold);
            Assert.AreEqual(2, runResult.ActualPeaksInCalculation);
            Assert.AreEqual(3, runResult.AverageMass);
            Assert.AreEqual(4, runResult.TheoreticalAverageMass);
            Assert.AreEqual(5, runResult.CentroidMR);
            Assert.AreEqual(6, runResult.TheoreticalCentroidMR);
            Assert.AreEqual(7, runResult.AmideHydrogenTotal);
            Assert.AreEqual(8, runResult.AmountDeut);
            Assert.AreEqual(true, runResult.IsResultBasedOnFragment);
            Assert.IsNotNull(runResult.FragmentIon);
            Assert.AreEqual(true, runResult.IsUsedInCalculations);
        }
Exemplo n.º 2
0
        public ValidationWrapper(RunResult runResult)
        {
            this.runResult = runResult;

            DeutDistMSUse = MSPeakListOptions.Threshold;
            deutDistTheoreticalUse = TheoreticalPeakListOptions.Threshold;
            DeutDistTheoreticalThreshold = 1;
            DeutDistTheoreticalPeaksInCalculation = 1;
        }
Exemplo n.º 3
0
 public void PeptideConstructor()
 {
     RunResult runResult = new RunResult(new Peptide("SAM") { PeaksInCalculation = 1, DeuteriumDistributionThreshold = 2 }, run);
     Assert.AreEqual("SAM", runResult.Peptide.Sequence);
     Assert.AreEqual(run, runResult.Run);
     Assert.AreEqual(1, runResult.ActualPeaksInCalculation);
     Assert.AreEqual(2, runResult.ActualDeutDistThreshold);
     Assert.AreEqual(false, runResult.IsResultBasedOnFragment);
 }
Exemplo n.º 4
0
 public void FragmentConstructor()
 {
     RunResult runResult = new RunResult(new FragmentIon("S", new Peptide("SAM")) { PeaksInCalculation = 1, DeutDistThreshold = 2 }, run);
     Assert.AreEqual("S", runResult.FragmentIon.Sequence);
     Assert.AreEqual("SAM", runResult.Peptide.Sequence);
     Assert.AreEqual(run, runResult.Run);
     Assert.AreEqual(1, runResult.ActualPeaksInCalculation);
     Assert.AreEqual(2, runResult.ActualDeutDistThreshold);
     Assert.AreEqual(true, runResult.IsResultBasedOnFragment);
 }
        public void ExecuteResultsBasedOnWholePeptide()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide, null);
            outputEvent.Subscribe(OnPublish);

            isotopicProfileFinder.PeakNumberMaximum = 5;
            isotopicProfileFinder.MassVariability = 1.5;
            isotopicProfileFinder.Execute(runResult, GenerateTestPeakList());

            Assert.AreEqual(5, runResult.IsotopicPeakList.Count);
            Assert.AreEqual(20, runResult.TheoreticalIsotopicPeakList.Count);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(31, messageCount);
        }
        public void ExecuteWhenMonoIsopticPeakNotFound()
        {
            Peptide peptide = CreatePeptide();
            peptide.MonoIsotopicMass = 200;
            RunResult runResult = new RunResult(peptide, null);
            outputEvent.Subscribe(OnPublishWithNoMonoisotopicPeak);

            isotopicProfileFinder.PeakNumberMaximum = 5;
            isotopicProfileFinder.MassVariability = 1.5;
            isotopicProfileFinder.Execute(runResult, GenerateTestPeakList());

            Assert.AreEqual(0, runResult.IsotopicPeakList.Count);
            Assert.AreEqual(20, runResult.TheoreticalIsotopicPeakList.Count);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(26, messageCount);
        }
        public void ExecuteResultsBasedOnFragment()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(new FragmentIon("SAMPLER", peptide), null);
            runResult.FragmentIon.FragmentIonType = Hydra.Core.FragmentIonType.BFragment;
            outputEvent.Subscribe(OnPublishWithFragments);

            isotopicProfileFinder.PeakNumberMaximum = 5;
            isotopicProfileFinder.MassVariability = 1.5;
            isotopicProfileFinder.Execute(runResult, GenerateTestPeakList());

            Assert.AreEqual(5, runResult.IsotopicPeakList.Count);
            Assert.AreEqual(20, runResult.TheoreticalIsotopicPeakList.Count);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(31, messageCount);
        }
        public void ExecuteWithFragment()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide.FragmentIonList[0], null);
            outputEvent.Subscribe(OnPublish);

            msmsFragmentAnalyzer.Execute(runResult, GenerateXYData());

            AssertPeptide(peptide);

            Assert.AreEqual(0, runResult.IsotopicPeakList.Count);
            Assert.AreEqual(152.09318, Math.Round(runResult.AverageMass, 5));
            Assert.AreEqual(152.1611, Math.Round(runResult.TheoreticalAverageMass, 5));
            Assert.AreEqual(-0.13584, Math.Round(runResult.AmountDeut, 5));
            Assert.AreEqual(true, runResult.IsUsedInCalculations);
            Assert.AreEqual(0, Math.Round(runResult.AmountDeutFromDeutDist, 5));
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(46, messageCount);
        }
        public void ExecuteWithAutomaticPeaksInLabelCalculationWithRelativeMz()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide, null);
            GenerateIsotopicPeakList(runResult);
            GenerateTheoreticalIsotopicPeakList(runResult);
            outputEvent.Subscribe(OnPublishWithAuto);

            labelAmountCalculator.PeaksInCalcMode = Hydra.Core.PeaksInLabelCalculationMode.Automatic;
            labelAmountCalculator.Mode = Mode.CalculatedMassAndExperimentalIntensity;
            labelAmountCalculator.Execute(runResult);

            Assert.AreEqual(500.4375, Math.Round(runResult.AverageMass, 5));
            Assert.AreEqual(500.38875, Math.Round(runResult.TheoreticalAverageMass, 5));
            Assert.AreEqual(499.42956, Math.Round(runResult.CentroidMR, 5));
            Assert.AreEqual(499.38081, Math.Round(runResult.TheoreticalCentroidMR, 5));
            Assert.AreEqual(5, runResult.AmideHydrogenTotal);
            Assert.AreEqual(0.04875, Math.Round(runResult.AmountDeut, 5));
            Assert.AreEqual(true, runResult.IsUsedInCalculations);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(8, messageCount);
        }
Exemplo n.º 10
0
        public void ExecuteWithManualPeaksInLabelCalculationWithoutRelativeMz()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide, null);
            GenerateIsotopicPeakList(runResult);
            GenerateTheoreticalIsotopicPeakList(runResult);
            runResult.ActualPeaksInCalculation = 5;
            outputEvent.Subscribe(OnPublishWithManualWithoutRelativeMZ);

            labelAmountCalculator.PeaksInCalcMode = Hydra.Core.PeaksInLabelCalculationMode.Manual;
            labelAmountCalculator.Mode = Mode.ExperimentalMassAndIntensity;
            labelAmountCalculator.Execute(runResult);

            Assert.AreEqual(500.45342, Math.Round(runResult.AverageMass, 5));
            Assert.AreEqual(500.42480, Math.Round(runResult.TheoreticalAverageMass, 5));
            Assert.AreEqual(499.44548, Math.Round(runResult.CentroidMR, 5));
            Assert.AreEqual(499.41686, Math.Round(runResult.TheoreticalCentroidMR, 5));
            Assert.AreEqual(5, runResult.AmideHydrogenTotal);
            Assert.AreEqual(0.02861, Math.Round(runResult.AmountDeut, 5));
            Assert.AreEqual(true, runResult.IsUsedInCalculations);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(8, messageCount);
        }
Exemplo n.º 11
0
        public void GetIsotopicProfileUsingRunResultWithInvalidSequence()
        {
            Peptide peptide = new Peptide("ZAMPLER");
            peptide.ChargeState = 2;
            RunResult runResult = new RunResult(peptide, null);
            peptideUtility.GetIsotopicProfile(runResult, true, 20, true, true);

            Assert.AreEqual(0, runResult.TheoreticalIsotopicPeakList.Count);
        }
Exemplo n.º 12
0
        public void GetIsotopicProfileUsingRunResult()
        {
            Peptide peptide = new Peptide("SAMPLER");
            peptide.ChargeState = 2;
            RunResult runResult = new RunResult(peptide, null);
            peptideUtility.GetIsotopicProfile(runResult, true, 20, true, true);

            Assert.AreEqual(402.711655, runResult.TheoreticalIsotopicPeakList[0].MZ);
            Assert.AreEqual(100, runResult.TheoreticalIsotopicPeakList[0].Intensity);
            Assert.AreEqual(403.211655, runResult.TheoreticalIsotopicPeakList[1].MZ);
            Assert.AreEqual(41.490242039325295, runResult.TheoreticalIsotopicPeakList[1].Intensity);
            Assert.AreEqual(20, runResult.TheoreticalIsotopicPeakList.Count);
        }
Exemplo n.º 13
0
        private static int CalculatePeaksInCalculation(RunResult result)
        {
            // determine max intensity
            MSPeak mostIntensePeak = new MSPeak();

            foreach (MSPeak peak in result.IsotopicPeakList)
            {
                if (peak.Intensity > mostIntensePeak.Intensity)
                {
                    mostIntensePeak = peak;
                }
            }

            bool foundPeakaboveThreshold = false;
            int returnedIndex = 0;

            for (int i = 0; i < result.IsotopicPeakList.Count; i++)
            {
                // start at Mono
                // add peaks if they are above the deutDistThreshold
                // Stop adding peaks if they are below the deutDistThreshold
                if (result.IsotopicPeakList[i].Intensity / mostIntensePeak.Intensity * 100 > result.ActualDeutDistThreshold)
                {
                    foundPeakaboveThreshold = true;
                }

                if (foundPeakaboveThreshold && result.IsotopicPeakList[i].Intensity / mostIntensePeak.Intensity * 100 < result.ActualDeutDistThreshold)
                {
                    returnedIndex = i;
                    break;
                }
                returnedIndex = i;
            }

            return returnedIndex;
        }
Exemplo n.º 14
0
        public RunResult ReExecute(BackgroundWorker worker, Result result, RunResult runResult)
        {
            _eventAggregator.GetEvent<ClearOutputEvent>().Publish(null);
            _eventAggregator.GetEvent<OutputEvent>().Publish("------ Reprocessing Started (" + DateTime.Now.ToString() + ") ------ " + DateTime.Now);
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            currentProgress = 1;
            progressFinish = 6;
            ReportProgress(worker, "Reprocessing");
            try
            {
                double rt1 = runResult.CachedXicPeak.Rt + runResult.ActualXicAdjustment - (runResult.ActualXicSelectionWidth / 2);
                double rt2 = runResult.CachedXicPeak.Rt + runResult.ActualXicAdjustment + (runResult.ActualXicSelectionWidth / 2);
                OutputText("     Calculated retention time window for spectrum selection is " + rt1 + "-" + rt2 + "(Peptide=" + runResult.Peptide.Sequence + ", XicAdjustment=" + runResult.ActualXicAdjustment + ", XicSelectionWidth=" + runResult.ActualXicSelectionWidth + ")");

                ReportStepProgress(worker, " 1: Spectrum Selection", "Spectrum Selection");
                IXYData spectralData = _spectrumSelection.Execute(runResult.Run, rt1, rt2, runResult.Peptide.MonoIsotopicMass);
                ReportStepProgress(worker, " 2: MS Smoothing", "MS Smoothing");
                spectralData = _spectrumSmoothing.Execute(spectralData);
                runResult.CachedSpectrum = spectralData;

                ReportStepProgress(worker, " 3: Spectral Peak Detection", "Spectral Peak Detection");
                IList<MSPeak> msPeakList = _spectralPeakDetection.Execute(spectralData);
                runResult.CachedMSPeakList = msPeakList;

                ReportStepProgress(worker, " 4: Isotopic Profile Finder", "Isotopic Profile Finder");
                _isotopicProfileFinder.Execute(runResult, msPeakList);
                _labelAmountCalculator.PeaksInCalcMode = Core.PeaksInLabelCalculationMode.Manual;
                ReportStepProgress(worker, " 5: Label Amount Calculation", "Label Amount Calculation");
                _labelAmountCalculator.Execute(runResult);

                ReportProgress(worker, "Generating Deuteration Results");
                _deuterationResultGenerator.Execute(runResult.Run.Experiment, result);

                _eventAggregator.GetEvent<StatusUpdateEvent>().Publish("Processing Succeeded");
            }
            catch (Exception ex)
            {
                ReportError(ex, stopWatch);
                return null;
            }

            return runResult;
        }
Exemplo n.º 15
0
        public void Execute(RunResult result, IXYData msmsSpectrum)
        {
            output.Publish("     MSMS Fragment Analyzer");

            PeptideUtility pu = new PeptideUtility();

            if (result.IsResultBasedOnFragment)
            {
                pu.GetIsotopicProfileForFragmentIon(result, 20);
            }
            else
            {
                result.TheoreticalIsotopicPeakList = pu.GetIsotopicProfile(result.Peptide.Sequence, result.Peptide.ChargeState, true, 20, true, true, string.Empty);
            }

            Peptide peptide = new Peptide(result.FragmentIon.Sequence);
            peptide.MonoIsotopicMass = result.FragmentIon.MZ;
            peptide.ChargeState = result.FragmentIon.ChargeState;
            peptide.PeaksInCalculation = result.FragmentIon.PeaksInCalculation;
            peptide.MsThreshold = result.FragmentIon.MsThreshold;
            peptide.DeuteriumDistributionRightPadding = result.FragmentIon.DeutDistRightPadding;
            peptide.DeuteriumDistributionThreshold = result.FragmentIon.DeutDistThreshold;

            RunResult rr = new RunResult(peptide, result.Run);
            rr.IsResultBasedOnFragment = true;
            rr.FragmentIon = result.FragmentIon;
            rr.TheoreticalIsotopicPeakList = result.TheoreticalIsotopicPeakList;

            try
            {
                output.Publish("     Executing Spectral Peak Detection");
                SpectralPeakDetection mspeakDetector = new SpectralPeakDetection(eventAggregator);
                mspeakDetector.PeakToBackgroundRatio = _peakToBackgroundRatio;
                mspeakDetector.SignalToNoiseThreshold = _signalToNoiseThreshold;
                IList<MSPeak> peakList = mspeakDetector.Execute(msmsSpectrum);

                output.Publish("     Executing Isotopic Profile Finder");
                IsotopicProfileFinder profileFinder = new IsotopicProfileFinder(eventAggregator);
                profileFinder.IntensityThreshold = intensityThreshold;
                profileFinder.MassVariability = massVariability;
                profileFinder.MSPeakSelectionOption = _msPeakSelectionOption;
                profileFinder.PeakNumberMaximum = peakNumberMaximum;
                profileFinder.PeakWidthMaximum = peakWidthMaximum;
                profileFinder.PeakWidthMinimum = peakWidthMinimum;
                profileFinder.Execute(rr, peakList);

                output.Publish("     Executing Label Amount Calculator");
                LabelAmountCalculator labelAmountCalc = new LabelAmountCalculator(eventAggregator);
                labelAmountCalc.PeaksInCalcMode = PeaksInLabelCalculationMode.Manual;
                labelAmountCalc.Mode = Mode.CalculatedMassAndExperimentalIntensity;
                labelAmountCalc.Execute(rr);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            result.IsotopicPeakList = rr.IsotopicPeakList;
            output.Publish("     IsotopicPeakList Count=" + result.IsotopicPeakList.Count);
            result.AverageMass = rr.AverageMass;
            output.Publish("     AverageMass=" + result.AverageMass);
            result.TheoreticalAverageMass = MSUtility.GetAverageMassFromPeakList(result.TheoreticalIsotopicPeakList, result.ActualPeaksInCalculation);  // TODO: this is a bandaid solution
            output.Publish("     TheoreticalAverageMass=" + result.TheoreticalAverageMass);
            result.AmountDeut = rr.AmountDeut;
            output.Publish("     AmountDeut=" + result.AmountDeut);
            result.IsUsedInCalculations = rr.IsUsedInCalculations;
            output.Publish("     IsUsedInCalculations=" + result.IsUsedInCalculations);
            result.AmountDeutFromDeutDist = rr.AmountDeutFromDeutDist;
            output.Publish("     AmountDeutFromDeutDist=" + result.AmountDeutFromDeutDist);
        }
Exemplo n.º 16
0
        private void GenerateTheoreticalIsotopicPeakList(RunResult runResult)
        {
            MSPeak mspeak1 = new MSPeak(500, 100, 0.5);
            MSPeak mspeak2 = new MSPeak(501, 44.25, 0.5);
            MSPeak mspeak3 = new MSPeak(502, 7.34, 0.5);
            MSPeak mspeak4 = new MSPeak(503, 1.22, 0.5);
            MSPeak mspeak5 = new MSPeak(504, 0.65, 0.5);

            runResult.TheoreticalIsotopicPeakList.Add(mspeak1);
            runResult.TheoreticalIsotopicPeakList.Add(mspeak2);
            runResult.TheoreticalIsotopicPeakList.Add(mspeak3);
            runResult.TheoreticalIsotopicPeakList.Add(mspeak4);
            runResult.TheoreticalIsotopicPeakList.Add(mspeak5);
        }
Exemplo n.º 17
0
        private void GenerateIsotopicPeakList(RunResult runResult)
        {
            MSPeak mspeak1 = new MSPeak(500, 100, 0.5);
            MSPeak mspeak2 = new MSPeak(501, 50, 0.5);
            MSPeak mspeak3 = new MSPeak(502, 10, 0.5);
            MSPeak mspeak4 = new MSPeak(503, 1, 0.5);

            runResult.IsotopicPeakList.Add(mspeak1);
            runResult.IsotopicPeakList.Add(mspeak2);
            runResult.IsotopicPeakList.Add(mspeak3);
            runResult.IsotopicPeakList.Add(mspeak4);
        }
Exemplo n.º 18
0
        public void ExecuteWithZeroAverageMass()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide, null);
            outputEvent.Subscribe(OnPublishWithNoPeaks);

            labelAmountCalculator.PeaksInCalcMode = Hydra.Core.PeaksInLabelCalculationMode.Automatic;
            labelAmountCalculator.Mode = Mode.CalculatedMassAndExperimentalIntensity;
            labelAmountCalculator.Execute(runResult);

            Assert.AreEqual(500, Math.Round(runResult.AverageMass, 5));
            Assert.AreEqual(0, Math.Round(runResult.TheoreticalAverageMass, 5));
            Assert.AreEqual(498.99206, Math.Round(runResult.CentroidMR, 5));
            Assert.AreEqual(-1.00794, Math.Round(runResult.TheoreticalCentroidMR, 5));
            Assert.AreEqual(5, runResult.AmideHydrogenTotal);
            Assert.AreEqual(500, Math.Round(runResult.AmountDeut, 5));
            Assert.AreEqual(true, runResult.IsUsedInCalculations);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(8, messageCount);
        }
Exemplo n.º 19
0
        private RunResult CreateRunResult(string sequence, FragmentIonType fragmentIonType)
        {
            Peptide peptide = new Peptide(sequence);
            RunResult runResult = new RunResult(new FragmentIon(sequence, peptide), null);
            runResult.FragmentIon.FragmentIonType = fragmentIonType;

            return runResult;
        }
Exemplo n.º 20
0
        public override void Execute(BackgroundWorker worker, ExperimentBase experimentBase)
        {
            currentProgress = 1;
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            Experiment experiment = experimentBase as Experiment;
            _eventAggregator.GetEvent<ClearOutputEvent>().Publish(null);
            _eventAggregator.GetEvent<OutputEvent>().Publish("------ Processing Started (" + DateTime.Now.ToString() + ") ------ " + DateTime.Now);

            progressFinish = experiment.Runs.Count * experiment.Peptides.PeptideCollection.Count * ProcessingSteps.Count;

            Result result = new Result("Result (" + DateTime.Now.ToString() + ")", (Experiment)experimentBase);
            try
            {
                for (int j = 0; j < experiment.ProteinStates.Count; ++j)
                {
                    ProteinState proteinState = experiment.ProteinStates[j];
                    OutputText("-PROTEIN STATE '" + proteinState.Name + "'");

                    IList<Run> runs = experiment.GetRunsByProteinState(proteinState);
                    for (int i = 0; i < runs.Count; i++)
                    {
                        Run run = runs[i];
                        OutputText("-RUN '" + run.FileName + "'");

                        // TODO: crashed here when I closed the progress bar; seems to be a threading issue
                        foreach (Peptide peptide in experiment.Peptides.PeptideCollection)
                        {
                            RunResult runResult = new RunResult(peptide, run);

                            try
                            {
                                OutputText("-PEPTIDE '" + peptide.Sequence + "'");
                                ReportProgress(worker, "Processing " + Path.GetFileName(run.FileName) + " (" + proteinState.Name + ")");

                                ReportStepProgress(worker, " 1: XIC Selection", "XIC Selection");
                                IXYData xicData = _xicSelection.Execute(run, peptide.XicMass1);

                                ReportStepProgress(worker, " 2: XIC Smoothing", "XIC Smoothing");
                                xicData = _xicSmoothing.Execute(xicData);

                                ReportStepProgress(worker, " 3: Chromatographic Peak Detection", "Chromatographic Peak Detection");
                                IList<ChromatographicPeak> xicPeakList = _chromatographicPeakDetection.Execute(xicData);

                                ReportStepProgress(worker, " 4: XIC Peak Picking", "XIC Peak Picking");
                                ChromatographicPeak xicPeak = _xicPeakPicker.Execute(xicPeakList, peptide);

                                runResult.CachedXicPeak = xicPeak;
                                runResult.CachedXicPeakList = xicPeakList;
                                runResult.CachedXic = xicData;

                                if (xicPeak != null)
                                {
                                    double rt1 = xicPeak.Rt + peptide.XicAdjustment - (peptide.XicSelectionWidth / 2);
                                    double rt2 = xicPeak.Rt + peptide.XicAdjustment + (peptide.XicSelectionWidth / 2);
                                    OutputText("     Calculated retention time window for spectrum selection is " + rt1 + "-" + rt2 + "(Peptide=" + peptide.Sequence + ", XicAdjustment=" + peptide.XicAdjustment + ", XicSelectionWidth=" + peptide.XicSelectionWidth + ")");

                                    ReportStepProgress(worker, " 5: Spectrum Selection", "Spectrum Selection");
                                    IXYData spectralData = _spectrumSelection.Execute(run, rt1, rt2, peptide.MonoIsotopicMass);

                                    ReportStepProgress(worker, " 6: MS Smoothing", "MS Smoothing");
                                    spectralData = _spectrumSmoothing.Execute(spectralData);

                                    ReportStepProgress(worker, " 7: Spectral Peak Detection", "Spectral Peak Detection");
                                    IList<MSPeak> msPeakList = _spectralPeakDetection.Execute(spectralData);

                                    runResult.CachedSpectrum = spectralData;
                                    runResult.CachedMSPeakList = msPeakList;

                                    ReportStepProgress(worker, " 8: Isotopic Profile Finder", "Isotopic Profile Finder");
                                    _isotopicProfileFinder.Execute(runResult, msPeakList);

                                    ReportStepProgress(worker, " 9: Label Amount Calculation", "Label Amount Calculation");
                                    _labelAmountCalculator.Execute(runResult);
                                }
                            }
                            catch (Exception ex)
                            {
                                runResult.Note = ex.Message;
                                OutputText("ERROR:");
                                OutputText(ex.Message);
                                OutputText(ex.StackTrace);
                            }

                            result.RunResults.Add(runResult);
                            currentProgress++;
                        }

                        run.SetDataProvider(_serviceLocator.GetAllInstances<IDataProvider>().Where(item => item.TypeId == experiment.DataProviderType).First());
                    }
                }

                ReportProgress(worker, "Generating Deuteration Results");
                _deuterationResultGenerator.Execute(experiment, result);

                experiment.IsProcessed = true;

                experiment.Results.Add(result);

                stopWatch.Stop();
                OutputText("------ Processing Completed (" + DateTime.Now.ToString() + ") - Duration=" + stopWatch.Elapsed.ToString() + " ------");
            }
            catch (Exception ex)
            {
                ReportError(ex, stopWatch);

                return;
            }

            result.AlgorithmUsed = new MassSpecStudio.Core.Domain.Algorithm(this);
            RecentAlgorithms.Write(result.AlgorithmUsed);

            // Publish event with new result so we can create a ResultViewModel for it and display the results.
            _eventAggregator.GetEvent<ResultAddedEvent>().Publish(result);
            _eventAggregator.GetEvent<ViewResultsEvent>().Publish(result);
            _eventAggregator.GetEvent<StatusUpdateEvent>().Publish("Processing Succeeded");
        }
Exemplo n.º 21
0
 public void BlankConstructor()
 {
     RunResult runResult = new RunResult();
     Assert.AreEqual(0, runResult.IsotopicPeakList.Count);
     Assert.AreEqual(0, runResult.TheoreticalIsotopicPeakList.Count);
 }
Exemplo n.º 22
0
        public void GetIsotopicProfileForFragmentIon(RunResult result, int numberOfIsotopesInProfile)
        {
            if (IsPeptideSequenceValid(result.Peptide.Sequence))
            {
                // the dimensions change once used by the MolecularWeightCalculator
                double[,] isotopeData = new double[100, 2];

                string threeLetterCodedPeptide;
                switch (result.FragmentIon.FragmentIonType)
                {
                    case Hydra.Core.FragmentIonType.Parent:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, true, true, string.Empty);
                        break;
                    case Hydra.Core.FragmentIonType.BFragment:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, false, false, string.Empty);
                        break;
                    case Hydra.Core.FragmentIonType.YFragment:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, true, true, string.Empty);
                        break;
                    case Hydra.Core.FragmentIonType.AFragment:
                        throw new System.ArgumentException("Code not yet written for a-ions");
                    case Hydra.Core.FragmentIonType.BMinusH2O:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, false, false, ">H2O");

                        break;
                    case Hydra.Core.FragmentIonType.YMinusH2O:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, true, true, ">H2O");

                        break;
                    case Hydra.Core.FragmentIonType.BMinusNH3:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, false, false, ">NH3");

                        break;
                    case Hydra.Core.FragmentIonType.YMinusNH3:
                        threeLetterCodedPeptide = GetPeptideThreeLetterCode(result.FragmentIon.Sequence, true, true, true, ">NH3");

                        break;
                    default:
                        throw new System.ArgumentException("Invalid fragment ion Type");
                }

                string resultsString = string.Empty;
                int numResults = 0;
                mw.ComputeIsotopicAbundances(ref threeLetterCodedPeptide, (short)result.FragmentIon.ChargeState, ref resultsString, ref isotopeData, ref numResults, string.Empty, string.Empty, string.Empty, string.Empty);

                for (int i = 1; i < isotopeData.GetLength(0); i++)
                {
                    MSPeak peak = new MSPeak();
                    peak.MZ = isotopeData[i, 0];
                    peak.Intensity = isotopeData[i, 1];
                    result.TheoreticalIsotopicPeakList.Add(peak);
                }

                if (result.TheoreticalIsotopicPeakList.Count < numberOfIsotopesInProfile)
                {
                    for (int i = result.TheoreticalIsotopicPeakList.Count; i < numberOfIsotopesInProfile; i++)
                    {
                        result.TheoreticalIsotopicPeakList.Add(new MSPeak(0, 0, 0));
                    }
                }
            }
        }
 private RunResult CreateRunResult(double theoreticalAverageMass, double amountDeut, double amountDeutFromDeutDist, double averageMass, bool isUsedInCalculations)
 {
     RunResult runResult = new RunResult(new Peptide(), run);
     runResult.TheoreticalAverageMass = theoreticalAverageMass;
     runResult.AmountDeut = amountDeut;
     runResult.AmountDeutFromDeutDist = amountDeutFromDeutDist;
     runResult.AverageMass = averageMass;
     runResult.IsUsedInCalculations = isUsedInCalculations;
     return runResult;
 }
Exemplo n.º 24
0
        public void Execute(RunResult result, IList<MSPeak> msPeakList)
        {
            _output.Publish("     Isotopic Profile Finder Started (MassRange=" + MassVariability + ", PeakWidthMinimum=" + PeakWidthMinimum + ", PeakWidthMaximum=" + PeakWidthMaximum + ", IntensityThreshold=" + IntensityThreshold + ", PeakNumberMaximum=" + PeakNumberMaximum + ", MSPeakSelectionOption=" + MSPeakSelectionOption + ")");
            double monoIsotopicMass = result.Peptide.MonoIsotopicMass;
            int chargeState = result.Peptide.ChargeState;

            double massStep = 1 / Convert.ToDouble(chargeState);
            List<double> targetMasses = new List<double>();
            int msPeakIndex = 0;

            // built list of target masses
            string targetedMasses = "     Targeted isotopic peak masses: ";
            for (int i = 0; i < peakNumberMaximum; i++)
            {
                targetMasses.Add(monoIsotopicMass + (massStep * i));
                targetedMasses += targetMasses.Last().ToString() + ", ";
            }
            _output.Publish(targetedMasses);

            result.InitializePeakLists();

            //----------- first will find the monoisotopic peak ----------------------------
            MSPeak monoIsotopicPeak;
            try
            {
                monoIsotopicPeak = MSUtility.GetBestMSPeak(targetMasses[0], msPeakList, msPeakIndex, this.MassVariability, this.PeakWidthMinimum, this.PeakWidthMaximum, this.IntensityThreshold, this.MSPeakSelectionOption, out msPeakIndex);
                if (monoIsotopicPeak != null)
                {
                    result.IsotopicPeakList.Add(monoIsotopicPeak);
                    _output.Publish("     Monoisotopic Peak Found (MZ=" + monoIsotopicPeak.MZ + ", Intensity=" + monoIsotopicPeak.Intensity + ", " + monoIsotopicPeak.PeakWidth + ")");
                }
            }
            catch (NullReferenceException ex)
            {
                _output.Publish("ERROR: " + ex.Message);
            }
            catch (Exception)
            {
                // Do Nothing
            }

            // means that only the monoisotopic peak was requested
            if (targetMasses.Count < 2)
            {
                ////return isotopicProfilePeaklist;
            }

            // start at the second peak of the target masses.  Loop through the target masses
            // and try to find a MS peak for each target mass. If no peak can be found, will break out of the
            // loop and return the MS peak list.
            _output.Publish("     Identifying Isotopic Peak List:");
            for (int i = 1; i < targetMasses.Count; i++)
            {
                MSPeak selectedMSPeak;
                try
                {
                    selectedMSPeak = MSUtility.GetBestMSPeak(targetMasses[i], msPeakList, msPeakIndex, this.MassVariability, this.PeakWidthMinimum, this.PeakWidthMaximum, this.IntensityThreshold, MSPeakSelectionOption, out msPeakIndex);
                }
                catch (Exception ex)
                {
                    _output.Publish("ERROR: " + ex.Message);
                    break;
                }

                if (selectedMSPeak != null)
                {
                    result.IsotopicPeakList.Add(selectedMSPeak);
                    _output.Publish("     Peak Found: (MZ=" + selectedMSPeak.MZ + ", Intensity=" + selectedMSPeak.Intensity + ", PeakWidth=" + selectedMSPeak.PeakWidth + ")");
                }
            }
            _output.Publish("     " + Math.Max(0, result.IsotopicPeakList.Count - 1) + " peaks found.");

            if (result.IsResultBasedOnFragment)
            {
                _output.Publish("     Calculating Theoretical Isotopic Peak List (based on fragment sequences)");
                peptideUtility.GetIsotopicProfileForFragmentIon(result, 20);
            }
            else
            {
                _output.Publish("     Calculating Theoretical Isotopic Peak List (based on peptide sequence)");

                // TODO: addProton set to false from true (from meeting with Dave).
                peptideUtility.GetIsotopicProfile(result, false, 20, true, true);
            }

            foreach (MSPeak peak in result.TheoreticalIsotopicPeakList)
            {
                _output.Publish("     Calculated Peak (MZ=" + peak.MZ + ", Intensity=" + peak.Intensity + ", PeakWidth=" + peak.PeakWidth + ")");
            }
            _output.Publish("     " + result.TheoreticalIsotopicPeakList.Count + " peaks found.");
        }
Exemplo n.º 25
0
        // TODO: This method is redudant with the one below.  Collapse it so it uses the method below.
        public void GetIsotopicProfile(RunResult result, bool addProton, int numberOfIsotopesInProfile, bool addNTerminalProteon, bool addCTerminalFreeAcid)
        {
            Peptide peptide = result.Peptide;
            if (IsPeptideSequenceValid(peptide.Sequence))
            {
                // the dimensions change once used by the MolecularWeightCalculator
                double[,] isotopeData = new double[100, 2];

                string threeLetterCodedPeptide = GetPeptideThreeLetterCode(peptide.Sequence, false, addNTerminalProteon, addCTerminalFreeAcid, string.Empty);

                if (addProton)
                {
                    threeLetterCodedPeptide += "H";
                }

                string resultsString = string.Empty;
                int numResults = 0;
                mw.ComputeIsotopicAbundances(ref threeLetterCodedPeptide, (short)peptide.ChargeState, ref resultsString, ref isotopeData, ref numResults, string.Empty, string.Empty, string.Empty, string.Empty);

                for (int i = 1; i < isotopeData.GetLength(0); i++)
                {
                    MSPeak peak = new MSPeak();
                    peak.MZ = isotopeData[i, 0];
                    peak.Intensity = isotopeData[i, 1];
                    result.TheoreticalIsotopicPeakList.Add(peak);
                }

                if (result.TheoreticalIsotopicPeakList.Count < numberOfIsotopesInProfile)
                {
                    for (int i = result.TheoreticalIsotopicPeakList.Count; i < numberOfIsotopesInProfile; i++)
                    {
                        result.TheoreticalIsotopicPeakList.Add(new MSPeak(0, 0, 0));
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void ExecuteWhenNoPeaks()
        {
            Peptide peptide = CreatePeptide();
            RunResult runResult = new RunResult(peptide, null);
            outputEvent.Subscribe(OnPublishWithNoPeaks);

            isotopicProfileFinder.PeakNumberMaximum = 5;
            isotopicProfileFinder.MassVariability = 1.5;
            isotopicProfileFinder.Execute(runResult, new List<MSPeak>());

            Assert.AreEqual(0, runResult.IsotopicPeakList.Count);
            Assert.AreEqual(20, runResult.TheoreticalIsotopicPeakList.Count);
            Assert.AreEqual(true, publishCalled);
            Assert.AreEqual(26, messageCount);
        }
Exemplo n.º 27
0
        public void Execute(RunResult result)
        {
            _output.Publish("     Label Amount Calculator Started (Mode=" + Mode + ", PeaksInCalcMode=" + PeaksInCalcMode + ")");

            if (this.PeaksInCalcMode == Core.PeaksInLabelCalculationMode.Automatic)
            {
                result.ActualPeaksInCalculation = CalculatePeaksInCalculation(result);
                _output.Publish("     Number of Peaks In Label Calculation: " + result.ActualPeaksInCalculation + " (Automatic)");
            }
            else
            {
                _output.Publish("     Number of Peaks In Label Calculation: " + result.ActualPeaksInCalculation + " (Manual)");
            }

            if (this.mode == Mode.CalculatedMassAndExperimentalIntensity)
            {
                IList<MSPeak> relIsotopicPeakList = MSUtility.ConvertToRelativeMassIsotopicPeakList(result.IsotopicPeakList, result.Peptide.ChargeState, 0);
                IList<MSPeak> relTheoreticalIsotopicPeakList = MSUtility.ConvertToRelativeMassIsotopicPeakList(result.TheoreticalIsotopicPeakList, result.Peptide.ChargeState, 0);

                double averageMass;
                if (result.TheoreticalIsotopicPeakList.Count > 0)
                {
                    averageMass = result.TheoreticalIsotopicPeakList[0].MZ;
                }
                else
                {
                    averageMass = result.Peptide.MonoIsotopicMass;
                }
                result.AverageMass = averageMass + MSUtility.GetAverageMassFromPeakList(relIsotopicPeakList, result.ActualPeaksInCalculation);
                result.TheoreticalAverageMass = MSUtility.GetAverageMassFromPeakList(result.TheoreticalIsotopicPeakList, result.ActualPeaksInCalculation);
            }
            else
            {
                result.AverageMass = MSUtility.GetAverageMassFromPeakList(result.IsotopicPeakList, result.ActualPeaksInCalculation);
                result.TheoreticalAverageMass = MSUtility.GetAverageMassFromPeakList(result.TheoreticalIsotopicPeakList, result.ActualPeaksInCalculation);
            }

            _output.Publish("     Calculated Average Mass=" + result.AverageMass);
            _output.Publish("     Calculated Theoretical Average Mass=" + result.TheoreticalAverageMass);

            // get mass of deuterated and theoretical peptides
            double centroidMr = PeptideUtility.CalculateMR(result.AverageMass, result.Peptide.ChargeState);
            double theoreticalCentroidMr = PeptideUtility.CalculateMR(result.TheoreticalAverageMass, result.Peptide.ChargeState);
            result.CentroidMR = centroidMr;
            result.TheoreticalCentroidMR = theoreticalCentroidMr;
            _output.Publish("     Calculated Centroid MR=" + result.CentroidMR);
            _output.Publish("     Calculated Theoretical Centroid MR=" + result.TheoreticalCentroidMR);

            result.AmideHydrogenTotal = PeptideUtility.GetNumberOfAmideHydrogens(result.Peptide.Sequence);
            _output.Publish("     Calculated Amide Hydrogen Total=" + result.AmideHydrogenTotal);

            // calculate amount of deuteration
            result.AmountDeut = (result.AverageMass - result.TheoreticalAverageMass) * result.Peptide.ChargeState;
            _output.Publish("     Calculated Amount Deuteration=" + result.AmountDeut + " [AvgMass(" + result.AverageMass + ") - TheoAvgMass(" + result.TheoreticalAverageMass + "] * ChargeState(" + result.Peptide.ChargeState + ")");
            result.IsUsedInCalculations = result.AverageMass > 0;
        }
Exemplo n.º 28
0
        public override void Execute(BackgroundWorker worker, ExperimentBase experimentBase)
        {
            currentProgress = 1;
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            Experiment experiment = experimentBase as Experiment;
            _eventAggregator.GetEvent<ClearOutputEvent>().Publish(null);
            _eventAggregator.GetEvent<OutputEvent>().Publish("------ Processing Started (" + DateTime.Now.ToString() + ") ------ " + DateTime.Now);
            OutputEvent output = _eventAggregator.GetEvent<OutputEvent>();

            progressFinish = experiment.Runs.Count * experiment.Peptides.PeptideCollection.Count * ProcessingSteps.Count;

            Result result = new Result("Result (" + DateTime.Now.ToString() + ")", (Experiment)experimentBase);
            try
            {
                for (int j = 0; j < experiment.ProteinStates.Count; ++j)
                {
                    ProteinState proteinState = experiment.ProteinStates[j];
                    OutputText("-PROTEIN STATE '" + proteinState.Name + "'");

                    IList<Run> runs = experiment.GetRunsByProteinState(proteinState);
                    for (int i = 0; i < runs.Count; i++)
                    {
                        Run run = runs[i];
                        OutputText("-RUN '" + run.FileName + "'");

                        // TODO: crashed here when I closed the progress bar; seems to be a threading issue
                        foreach (Peptide peptide in experiment.Peptides.PeptideCollection)
                        {
                            OutputText("-PEPTIDE '" + peptide.Sequence + "'");
                            ReportProgress(worker, "Processing " + Path.GetFileName(run.FileName) + " (" + proteinState.Name + ")");

                            ReportStepProgress(worker, " 1: MSMS Spectrum Selection", "MSMS Spectrum Selection");
                            IXYData msmsSpectrum = msmsSpectrumSelection.Execute(run, peptide.RT, peptide.MonoIsotopicMass);

                            ReportStepProgress(worker, " 2: MSMS Smoothing", "MSMS Smoothing");
                            msmsSpectrum = _smoothing.Execute(msmsSpectrum);

                            ReportStepProgress(worker, " 3: MSMS Fragment Analyzer", "MSMS Fragment Analyzer");
                            foreach (FragmentIon fragmentIon in peptide.FragmentIonList)
                            {
                                RunResult runResult = new RunResult(fragmentIon, run);
                                runResult.CachedSpectrum = msmsSpectrum;
                                try
                                {
                                    msmsFragmentAnalyzer.Execute(runResult, msmsSpectrum);
                                }
                                catch (Exception ex)
                                {
                                    OutputText(" ERROR: '" + ex.Message + "'");
                                    PeptideUtility pu = new PeptideUtility();
                                    pu.GetIsotopicProfileForFragmentIon(runResult, 20);
                                    runResult.TheoreticalAverageMass = MSUtility.GetAverageMassFromPeakList(runResult.TheoreticalIsotopicPeakList, runResult.ActualPeaksInCalculation);
                                }
                                result.RunResults.Add(runResult);
                            }

                            currentProgress++;
                        }

                        run.SetDataProvider(_serviceLocator.GetAllInstances<IDataProvider>().Where(item => item.GetType().Name.Contains("Proteo")).First());
                    }
                }

                ReportProgress(worker, "Generating Deuteration Results");
                deuterationResultGenerator.Execute(experiment, result);

                experiment.IsProcessed = true;

                experiment.Results.Add(result);

                stopWatch.Stop();
                OutputText("------ Processing Completed (" + DateTime.Now.ToString() + ") - Duration=" + stopWatch.Elapsed.ToString() + " ------");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                OutputText("------- ERROR: Processing Failed (" + DateTime.Now.ToString() + ") - Duration=" + stopWatch.Elapsed.ToString() + " ------");
                OutputText(ex.Message);
                OutputText(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    OutputText(ex.InnerException.Message);
                    OutputText(ex.StackTrace);
                }
                _eventAggregator.GetEvent<StatusUpdateEvent>().Publish("Processing Failed");
                return;
            }

            result.AlgorithmUsed = new MassSpecStudio.Core.Domain.Algorithm(this);
            RecentAlgorithms.Write(result.AlgorithmUsed);

            // Publish event with new result so we can create a ResultViewModel for it and display the results.
            _eventAggregator.GetEvent<ResultAddedEvent>().Publish(result);
            _eventAggregator.GetEvent<ViewResultsEvent>().Publish(result);
            _eventAggregator.GetEvent<StatusUpdateEvent>().Publish("Processing Succeeded");
        }
Exemplo n.º 29
0
 public RunResult Clone()
 {
     RunResult clonedRunResult = new RunResult();
     clonedRunResult.AmountDeutFromDeutDist = AmountDeutFromDeutDist;
     clonedRunResult.Run = Run;
     clonedRunResult.Peptide = Peptide;
     clonedRunResult.ActualXicAdjustment = ActualXicAdjustment;
     clonedRunResult.ActualXicSelectionWidth = ActualXicSelectionWidth;
     clonedRunResult.CachedXic = CachedXic;
     clonedRunResult.CachedMSPeakList = CachedMSPeakList;
     clonedRunResult.CachedXicPeakList = CachedXicPeakList;
     clonedRunResult.CachedSpectrum = CachedSpectrum;
     clonedRunResult.CachedXicPeak = CachedXicPeak;
     clonedRunResult.FragmentIon = FragmentIon;
     clonedRunResult.ActualDeutDistThreshold = ActualDeutDistThreshold;
     clonedRunResult.IsResultBasedOnFragment = IsResultBasedOnFragment;
     clonedRunResult.IsotopicPeakList = IsotopicPeakList;
     clonedRunResult.TheoreticalIsotopicPeakList = TheoreticalIsotopicPeakList;
     clonedRunResult.ActualPeaksInCalculation = ActualPeaksInCalculation;
     clonedRunResult.AverageMass = AverageMass;
     clonedRunResult.TheoreticalAverageMass = TheoreticalAverageMass;
     clonedRunResult.CentroidMR = CentroidMR;
     clonedRunResult.TheoreticalCentroidMR = TheoreticalCentroidMR;
     clonedRunResult.AmideHydrogenTotal = AmideHydrogenTotal;
     clonedRunResult.AmountDeut = AmountDeut;
     clonedRunResult.IsUsedInCalculations = IsUsedInCalculations;
     clonedRunResult.Note = Note;
     return clonedRunResult;
 }