Ejemplo n.º 1
0
 public abstract void Execute(BackgroundWorker worker, ExperimentBase experimentBase);
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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");
        }