示例#1
0
        private void TestPeptide(Workspace workspace, PeakFinderPeptide peakFinderPeptide)
        {
            DbPeptideFileAnalysis dbPeptideFileAnalysis;

            using (var session = workspace.OpenSession())
            {
                dbPeptideFileAnalysis = (DbPeptideFileAnalysis)session.CreateQuery(
                    "FROM DbPeptideFileAnalysis T WHERE T.MsDataFile.Name = :dataFile AND T.PeptideAnalysis.Peptide.Sequence = :sequence")
                                        .SetParameter("dataFile", peakFinderPeptide.DataFile)
                                        .SetParameter("sequence",
                                                      peakFinderPeptide.PeptideSequence)
                                        .UniqueResult();
            }
            PeptideAnalysis peptideAnalysis = workspace.PeptideAnalyses.FindByKey(dbPeptideFileAnalysis.PeptideAnalysis.Id.GetValueOrDefault());

            using (peptideAnalysis.IncChromatogramRefCount())
            {
                workspace.DatabasePoller.LoadAndMergeChanges(new Dictionary <long, bool> {
                    { peptideAnalysis.Id, true }
                });
                PeptideFileAnalysis peptideFileAnalysis = peptideAnalysis.GetFileAnalysis(dbPeptideFileAnalysis.Id.GetValueOrDefault());
                var          peaks  = CalculatedPeaks.Calculate(peptideFileAnalysis, new CalculatedPeaks[0]);
                const string format = "0.000";
                Assert.AreEqual(
                    peakFinderPeptide.ExpectedPeakStart.ToString(format) + "-" + peakFinderPeptide.ExpectedPeakEnd.ToString(format),
                    (peaks.StartTime.GetValueOrDefault() / 60).ToString(format) + "-" + (peaks.EndTime.GetValueOrDefault() / 60).ToString(format), peakFinderPeptide.PeptideSequence);
            }
        }
示例#2
0
        void CalculateAnalysisResults(ResultCalculatorTask task)
        {
            StatusMessage = "Processing " + task.PeptideAnalysis.Peptide.FullSequence;
            var peaksList           = new List <CalculatedPeaks>();
            var peptideFileAnalyses = task.PeptideAnalysis.FileAnalyses.ToArray();

            Array.Sort(peptideFileAnalyses,
                       (f1, f2) => (null == f1.PsmTimes).CompareTo(null == f2.PsmTimes)
                       );
            foreach (var peptideFileAnalysis in peptideFileAnalyses)
            {
                if (peptideFileAnalysis.ChromatogramSet == null ||
                    !peptideFileAnalysis.IsMzKeySetComplete(peptideFileAnalysis.ChromatogramSet.Chromatograms.Keys))
                {
                    continue;
                }
                var peaks = CalculatedPeaks.Calculate(peptideFileAnalysis, peaksList);
                if (peaks.Peaks.Count != 0)
                {
                    peaksList.Add(peaks);
                }
            }
            task.PeptideAnalysis.SetCalculatedPeaks(peaksList);
            _workspace.RunOnEventQueue(() => _workspace.RetentionTimeAlignments.MergeFrom(task.Workspace.RetentionTimeAlignments));
            if (task.CanSave())
            {
                using (_session = _workspace.OpenWriteSession())
                {
                    _session.BeginTransaction();
                    foreach (var peptideFileAnalysis in task.PeptideAnalysis.GetFileAnalyses(false))
                    {
                        if (peptideFileAnalysis.ChromatogramSet != null &&
                            !peptideFileAnalysis.IsMzKeySetComplete(peptideFileAnalysis.ChromatogramSet.Chromatograms.Keys))
                        {
                            var dbPeptideFileAnalysis = _session.Get <DbPeptideFileAnalysis>(peptideFileAnalysis.Id);
                            var dbChromatogramSet     = dbPeptideFileAnalysis.ChromatogramSet;
                            if (null != dbChromatogramSet)
                            {
                                foreach (var dbChromatogram in dbPeptideFileAnalysis.ChromatogramSet.Chromatograms)
                                {
                                    _session.Delete(dbChromatogram);
                                }
                                dbPeptideFileAnalysis.ChromatogramSet = null;
                                _session.Update(dbPeptideFileAnalysis);
                                _session.Delete(dbChromatogramSet);
                            }
                        }
                        if (null == peptideFileAnalysis.CalculatedPeaks)
                        {
                            var dbPeptideFileAnalysis = _session.Get <DbPeptideFileAnalysis>(peptideFileAnalysis.Id);
                            CalculatedPeaks.DeleteResults(_session, dbPeptideFileAnalysis);
                            _session.Update(dbPeptideFileAnalysis);
                        }
                        else
                        {
                            peptideFileAnalysis.CalculatedPeaks.Save(_session);
                        }
                    }
                    _session.Save(new DbChangeLog(task.PeptideAnalysis));
                    task.FinishLock(_session);
                    try
                    {
                        _session.Transaction.Commit();
                    }
// ReSharper disable RedundantCatchClause
// ReSharper disable UnusedVariable
                    catch (Exception e)
// ReSharper restore UnusedVariable
                    {
                        throw;
                    }
// ReSharper restore RedundantCatchClause
                }
            }
        }