Beispiel #1
0
        private void FinishCalculation()
        {
            double totalArea           = _peaks.Values.Sum(p => p.Area);
            double tracerPercent       = 0;
            double totalScore          = 0;
            var    tracerChromatograms = GetTracerChromatograms();

            foreach (var entry in _peaks.ToArray())
            {
                var peak = entry.Value;
                peak.RelativeAmount = totalArea == 0 ? 0 : peak.Area / totalArea;
                tracerPercent      += peak.RelativeAmount * peak.TracerPercent;
                totalScore         += peak.Area *
                                      tracerChromatograms.GetScore(
                    tracerChromatograms.ChromatogramSet.IndexFromTime(peak.StartTime),
                    tracerChromatograms.ChromatogramSet.IndexFromTime(peak.EndTime));
                _peaks[entry.Key] = peak;
            }
            TracerPercent      = tracerPercent;
            DeconvolutionScore = totalArea == 0 ? 0 : totalScore / totalArea;
            IDictionary <TracerFormula, double> bestMatch;
            var    peaksDict = ToDictionary();
            double turnover;
            double turnoverScore;

            PrecursorEnrichmentFormula = PeptideAnalysis.GetTurnoverCalculator().ComputePrecursorEnrichmentAndTurnover(peaksDict, out turnover, out turnoverScore, out bestMatch);
            if (PrecursorEnrichmentFormula != null)
            {
                PrecursorEnrichment = PrecursorEnrichmentFormula.Values.Sum() / 100.0;
                Turnover            = turnover;
                TurnoverScore       = turnoverScore;
            }
        }
Beispiel #2
0
 public void Dispose()
 {
     if (_peptideAnalysis != null)
     {
         _peptideAnalysis.DecChromatogramRefCount();
         _peptideAnalysis = null;
     }
 }
Beispiel #3
0
        public static PeptideFileAnalysis GetPeptideFileAnalysis(
            PeptideAnalysis peptideAnalysis, DbPeptideFileAnalysis dbPeptideFileAnalysis)
        {
            PeptideFileAnalysis peptideFileAnalysis;

            peptideAnalysis.FileAnalyses.TryGetValue(dbPeptideFileAnalysis.GetId(), out peptideFileAnalysis);
            return(peptideFileAnalysis);
        }
Beispiel #4
0
        public override WorkspaceData SetData(WorkspaceData workspaceData, PeptideFileAnalysisData value)
        {
            var peptideAnalysisData = PeptideAnalysis.GetData(workspaceData);

            peptideAnalysisData =
                peptideAnalysisData.SetFileAnalyses(peptideAnalysisData.FileAnalyses.Replace(Id, value));
            return(PeptideAnalysis.SetData(workspaceData, peptideAnalysisData));
        }
Beispiel #5
0
 public void SetCalculatedPeaks(CalculatedPeaks calculatedPeaks)
 {
     if (calculatedPeaks.AutoFindPeak)
     {
         throw new InvalidOperationException();
     }
     Data = Data.SetPeaks(false, calculatedPeaks.ToPeakSetData());
     PeptideAnalysis.InvalidatePeaks();
 }
Beispiel #6
0
        public override PeptideFileAnalysisData GetData(WorkspaceData workspaceData)
        {
            var peptideAnalysisData = PeptideAnalysis.GetData(workspaceData);
            PeptideFileAnalysisData peptideFileAnalysisData = null;

            if (null != peptideAnalysisData)
            {
                peptideAnalysisData.FileAnalyses.TryGetValue(Id, out peptideFileAnalysisData);
            }
            return(peptideFileAnalysisData);
        }
Beispiel #7
0
 public bool IsMzKeySetComplete(ICollection <MzKey> mzKeys)
 {
     for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge++)
     {
         for (int massIndex = 0; massIndex < PeptideAnalysis.GetMassCount(); massIndex++)
         {
             if (!mzKeys.Contains(new MzKey(charge, massIndex)))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #8
0
        public static PeptideFileAnalysis EnsurePeptideFileAnalysis(PeptideAnalysis peptideAnalysis, MsDataFile msDataFile)
        {
            var workspace = peptideAnalysis.Workspace;

            using (var session = workspace.OpenSession())
            {
                var criteria = session.CreateCriteria(typeof(DbPeptideFileAnalysis))
                               .Add(Restrictions.Eq("PeptideAnalysis", session.Load <DbPeptideAnalysis>(peptideAnalysis.Id)))
                               .Add(Restrictions.Eq("MsDataFile", session.Load <DbMsDataFile>(msDataFile.Id)));
                var dbPeptideAnalysis = (DbPeptideFileAnalysis)criteria.UniqueResult();
                if (dbPeptideAnalysis != null)
                {
                    return(GetPeptideFileAnalysis(peptideAnalysis, dbPeptideAnalysis));
                }
            }
            if (!msDataFile.HasTimes())
            {
                return(null);
            }
            using (var session = workspace.OpenWriteSession())
            {
                var dbPeptideAnalysis     = session.Load <DbPeptideAnalysis>(peptideAnalysis.Id);
                var psmTimesByDataFileId  = dbPeptideAnalysis.Peptide.PsmTimesByDataFileId(session);
                var dbPeptideFileAnalysis = CreatePeptideFileAnalysis(session, msDataFile, dbPeptideAnalysis, psmTimesByDataFileId);
                if (dbPeptideFileAnalysis == null)
                {
                    return(null);
                }

                session.BeginTransaction();
                session.Save(dbPeptideFileAnalysis);
                dbPeptideAnalysis.FileAnalysisCount++;
                session.Update(dbPeptideAnalysis);
                session.Save(new DbChangeLog(peptideAnalysis));
                session.Transaction.Commit();
                workspace.ChromatogramGenerator.SetRequeryPending();
                workspace.DatabasePoller.LoadAndMergeChanges(null);
                return(workspace.PeptideAnalyses.FindByKey(dbPeptideAnalysis.GetId())
                       .FileAnalyses.FindByKey(dbPeptideFileAnalysis.GetId()));
            }
        }
 public PeptideFileAnalyses(PeptideAnalysis peptideAnalysis) : base(peptideAnalysis.Workspace)
 {
     PeptideAnalysis = peptideAnalysis;
 }
        public TracerChromatograms(PeptideFileAnalysis peptideFileAnalysis, ChromatogramSetData chromatogramSet, bool smoothed)
        {
            Smoothed            = smoothed;
            ChromatogramSet     = chromatogramSet;
            PeptideFileAnalysis = peptideFileAnalysis;
            var    pointDict          = new Dictionary <TracerFormula, IList <double> >();
            var    chromatogramsDict  = new Dictionary <MzKey, IList <double> >();
            var    turnoverCalculator = PeptideAnalysis.GetTurnoverCalculator();
            double massAccuracy       = PeptideAnalysis.GetMassAccuracy();

            foreach (var chromatogramEntry in ChromatogramSet.Chromatograms)
            {
                if (PeptideAnalysis.ExcludedMasses.Contains(chromatogramEntry.Key.MassIndex))
                {
                    continue;
                }
                var chromatogram = chromatogramEntry.Value;
                var mzRange      = turnoverCalculator.GetMzs(chromatogramEntry.Key.Charge)[chromatogramEntry.Key.MassIndex];
                var intensities  = chromatogram.ChromatogramPoints.Select(point => point.GetIntensity(mzRange, massAccuracy)).ToArray();
                if (smoothed)
                {
                    intensities = SavitzkyGolaySmooth(intensities);
                }
                chromatogramsDict.Add(chromatogramEntry.Key, intensities);
            }
            int massCount              = PeptideFileAnalysis.PeptideAnalysis.GetMassCount();
            var times                  = chromatogramSet.Times.ToArray();
            var scores                 = new List <double>();
            var tracerFormulas         = turnoverCalculator.ListTracerFormulas();
            var theoreticalIntensities = turnoverCalculator.GetTheoreticalIntensities(tracerFormulas);

            for (int i = 0; i < times.Length; i++)
            {
                var intensities = new List <double>();
                for (int iMass = 0; iMass < massCount; iMass++)
                {
                    double intensity = 0;
                    for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge++)
                    {
                        IList <double> chromatogram;
                        if (chromatogramsDict.TryGetValue(new MzKey(charge, iMass), out chromatogram))
                        {
                            intensity += chromatogram[i];
                        }
                        else
                        {
                            intensity = double.NaN;
                        }
                    }
                    intensities.Add(intensity);
                }
                double score;
                IDictionary <TracerFormula, IList <double> > predictedIntensities;
                PeptideAnalysis.GetTurnoverCalculator().GetTracerAmounts(intensities, out score, out predictedIntensities, tracerFormulas, theoreticalIntensities);
                foreach (var entry in predictedIntensities)
                {
                    IList <double> list;
                    if (!pointDict.TryGetValue(entry.Key, out list))
                    {
                        list = new List <double>();
                        pointDict.Add(entry.Key, list);
                    }
                    list.Add(entry.Value.Sum());
                }
                scores.Add(score);
            }
            var points = new SortedDictionary <TracerFormula, IList <double> >();
            var peaks  = new Dictionary <TracerFormula, IList <CrawdadPeak> >();

            foreach (var entry in pointDict)
            {
                points.Add(entry.Key, entry.Value);
                CrawPeakFinderWrapper peakFinder = new CrawPeakFinderWrapper();
                peakFinder.SetChromatogram(times, entry.Value);
                peaks.Add(entry.Key, peakFinder.CalcPeaks(MaxPeaks));
            }
            Points   = points;
            Scores   = scores;
            Times    = chromatogramSet.Times;
            RawPeaks = peaks;
        }
Beispiel #11
0
 public PeptideAnalysis(Workspace workspace, PeptideAnalysis peptideAnalysis) : base(workspace, peptideAnalysis.Id)
 {
     _chromatogramRefCount = 0;
 }
Beispiel #12
0
 public RefCountHolder(PeptideAnalysis peptideAnalysis)
 {
     _peptideAnalysis = peptideAnalysis;
 }
Beispiel #13
0
 public PeptideFileAnalysis(PeptideAnalysis peptideAnalysis, long id, PeptideFileAnalysisData peptideFileAnalysisData)
     : base(peptideAnalysis.Workspace, id, peptideFileAnalysisData)
 {
     PeptideAnalysis = peptideAnalysis;
 }
Beispiel #14
0
 public String GetLabel()
 {
     return(PeptideAnalysis.GetLabel() + " " + MsDataFile.Label);
 }