protected PeptideFileAnalysis UpdateDataFileCombo(ComboBox comboBox) { var selectedItem = comboBox.SelectedItem as OverlayFileAnalysisItem; PeptideFileAnalysis selectedFileAnalysis = null; if (selectedItem != null) { selectedFileAnalysis = selectedItem.PeptideFileAnalysis; } comboBox.Items.Clear(); comboBox.Items.Add(""); PeptideFileAnalysis selectedPeptideFileAnalysis = null; foreach (var peptideFileAnalysis in PeptideAnalysis.FileAnalyses) { if (peptideFileAnalysis.Equals(PeptideFileAnalysis)) { continue; } comboBox.Items.Add(new OverlayFileAnalysisItem(peptideFileAnalysis)); if (peptideFileAnalysis.Equals(selectedFileAnalysis)) { selectedPeptideFileAnalysis = peptideFileAnalysis; comboBox.SelectedIndex = comboBox.Items.Count - 1; } } return(selectedPeptideFileAnalysis); }
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); } }
public PrecursorPoolForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); zedGraphControl.GraphPane.Title.IsVisible = false; zedGraphControl.GraphPane.YAxis.Title.Text = "Chromatogram Area"; zedGraphControl.GraphPane.XAxis.Title.Text = "Labeled form"; }
public PeptideInfoForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); TabText = "General Info"; PeptideFileAnalysisChanged(); }
private bool IsIncluded(HalfLifeSettings halfLifeSettings, PeptideFileAnalysis peptideFileAnalysis) { if (!string.IsNullOrEmpty(Cohort)) { if (Cohort != HalfLifeCalculator.GetCohort(peptideFileAnalysis.MsDataFile, GetHalfLifeSettings().BySample)) { return(false); } } if (peptideFileAnalysis.MsDataFile.TimePoint == null) { return(false); } if (IsTimePointExcluded(peptideFileAnalysis.MsDataFile.TimePoint.Value)) { return(false); } if (halfLifeSettings.PrecursorPoolCalculation == PrecursorPoolCalculation.Individual) { if (null == peptideFileAnalysis.CalculatedPeaks || !peptideFileAnalysis.CalculatedPeaks.Turnover.HasValue) { return(false); } } return(true); }
protected override bool MsGraphControlOnMouseUpEvent(ZedGraphControl sender, MouseEventArgs e) { if (_peakResize != null) { var point = new PointF(e.X - _peakResize.MousePt.X + _peakResize.CoordPt.X, e.Y); double x, y; MsGraphControl.GraphPane.ReverseTransform(point, out x, out y); var peaks = PeptideFileAnalysis.CalculatedPeaks; double newStart, newEnd; switch (_peakResize.LineSegment) { case LineSegment.Start: newStart = x; newEnd = _peakResize.Peak.EndTime; break; case LineSegment.End: newStart = _peakResize.Peak.StartTime; newEnd = x; break; default: newStart = x; newEnd = x - _peakResize.Peak.StartTime + _peakResize.Peak.EndTime; break; } var newPeaks = peaks.ChangeTime(_peakResize.TracerFormula, Math.Min(newStart, newEnd), Math.Max(newStart, newEnd)); _peakResize = null; PeptideFileAnalysis.SetCalculatedPeaks(newPeaks); PeptideAnalysis.EnsurePeaksCalculated(); } return(base.MsGraphControlOnMouseUpEvent(sender, e)); }
private DataGridViewRow AddRow(PeptideFileAnalysis peptideFileAnalysis) { var row = dataGridView.Rows[dataGridView.Rows.Add()]; row.Tag = peptideFileAnalysis; _peptideFileAnalysisRows.Add(peptideFileAnalysis, row); return(row); }
public AnalysisChromatograms(PeptideFileAnalysis peptideFileAnalysis) { PeptideFileAnalysisId = peptideFileAnalysis.Id; PeptideAnalysisId = peptideFileAnalysis.PeptideAnalysis.Id; FirstTime = peptideFileAnalysis.ChromatogramStartTime; LastTime = peptideFileAnalysis.ChromatogramEndTime; MinCharge = peptideFileAnalysis.PeptideAnalysis.MinCharge; MaxCharge = peptideFileAnalysis.PeptideAnalysis.MaxCharge; Sequence = peptideFileAnalysis.PeptideAnalysis.Peptide.Sequence; }
public ChromatogramForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); gridIntensities.PeptideFileAnalysis = PeptideFileAnalysis; gridIntensities.SelectionChanged += (o, e) => UpdateUi(); gridIntensities.CurrentCellChanged += (o, e) => UpdateUi(); splitContainer1.Panel2.Controls.Add(MsGraphControl); }
public ProcessedRowData ToRowData(PeptideFileAnalysis peptideFileAnalysis) { var rawRowData = ToRawRowData(peptideFileAnalysis); if (null == rawRowData) { return(null); } return(ComputeAvgTurnover(rawRowData)); }
public static PeptideFileAnalysisFrame ShowFileAnalysisForm <T>(PeptideFileAnalysis peptideFileAnalysis) where T : PeptideFileAnalysisForm { var analysisForm = PeptideAnalysisFrame.ShowPeptideAnalysis(peptideFileAnalysis.PeptideAnalysis); if (null == analysisForm) { return(null); } return(ActivatePeptideDataForm <T>(analysisForm.PeptideAnalysisSummary, peptideFileAnalysis)); }
private void Remove(PeptideFileAnalysis peptideFileAnalysis) { DataGridViewRow row; if (!_peptideFileAnalysisRows.TryGetValue(peptideFileAnalysis, out row)) { return; } dataGridView.Rows.Remove(row); _peptideFileAnalysisRows.Remove(peptideFileAnalysis); }
private void UpdateTitle() { if (DockState == DockState.Floating) { TabText = Text + ": " + PeptideFileAnalysis.GetLabel(); } else { TabText = Text; } }
private void AddRows(ICollection <RowData> rowDatas) { var newRows = new List <DataGridViewRow>(); foreach (var rowData in rowDatas) { if (_rows.ContainsKey(rowData.PeptideFileAnalysisId)) { continue; } var row = new DataGridViewRow { Tag = rowData, }; _rows.Add(rowData.PeptideFileAnalysisId, row); newRows.Add(row); } if (newRows.Count > 0) { dataGridView.Rows.AddRange(newRows.ToArray()); } foreach (var rowData in rowDatas) { DataGridViewRow row; if (!_rows.TryGetValue(rowData.PeptideFileAnalysisId, out row)) { continue; } PeptideFileAnalysis peptideFileAnalysis = null; var peptideAnalysis = Workspace.PeptideAnalyses.FindByKey(rowData.PeptideAnalysisId); if (peptideAnalysis != null) { peptideFileAnalysis = peptideAnalysis.GetFileAnalysis(rowData.PeptideFileAnalysisId); } if (peptideFileAnalysis != null) { row.Cells[colApe.Index].Value = peptideFileAnalysis.CalculatedPeaks.TracerPercent; row.Cells[colPeakStart.Index].Value = peptideFileAnalysis.PeakStartTime; row.Cells[colPeakEnd.Index].Value = peptideFileAnalysis.PeakEndTime; row.Cells[colSequence.Index].Value = peptideFileAnalysis.Peptide.FullSequence; row.Cells[colStatus.Index].Value = peptideFileAnalysis.ValidationStatus; row.Cells[colTurnover.Index].Value = peptideFileAnalysis.CalculatedPeaks.Turnover; } else { row.Cells[colApe.Index].Value = rowData.TracerPercent; row.Cells[colPeakStart.Index].Value = rowData.PeakStart; row.Cells[colPeakEnd.Index].Value = rowData.PeakEnd; row.Cells[colSequence.Index].Value = rowData.Sequence; row.Cells[colStatus.Index].Value = rowData.Status; //row.Cells[colScore.Index].Value = rowData.DeconvolutionScore; } } }
private DataGridViewRow AddRow(PeptideFileAnalysis peptideFileAnalysis) { var row = dataGridView.Rows[dataGridView.Rows.Add()]; row.Tag = peptideFileAnalysis; peptideAnalysisRows.Add(peptideFileAnalysis, row); if (!peptideFileAnalysis.EnsureCalculated()) { Workspace.EnsureChromatograms(peptideFileAnalysis); } return(row); }
private PeptideFileAnalysisFrame(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); // TODO(nicksh): Move this into .designer file. _dockPanel = new DockPanel { Dock = DockStyle.Fill }; panel1.Controls.Add(_dockPanel); tbxDataFile.Text = peptideFileAnalysis.MsDataFile.Name; tbxSequence.Text = peptideFileAnalysis.PeptideAnalysis.Peptide.Sequence; }
public TracerChromatogramForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); splitContainer1.Panel2.Controls.Add(MsGraphControl); colAreaPct.DefaultCellStyle.Format = "0.##%"; colSlopePct.DefaultCellStyle.Format = "0.##%"; colTracerPercent.DefaultCellStyle.Format = "0.##%"; comboAdjustPeaks.SelectedIndex = 0; cbxPeaksAsVerticalLines.Checked = Settings.Default.PeaksAsVerticalLines; cbxPeaksAsHorizontalLines.Checked = Settings.Default.PeaksAsHorizontalLines; cbxShowScore.Checked = Settings.Default.ShowChromatogramScore; }
RawRowData ToRawRowData(PeptideFileAnalysis peptideFileAnalysis) { if (!peptideFileAnalysis.PeakData.IsCalculated) { return(null); } return(new RawRowData(peptideFileAnalysis.Data) { MsDataFile = peptideFileAnalysis.MsDataFile, Peptide = peptideFileAnalysis.Peptide, PeptideFileAnalysisId = peptideFileAnalysis.Id, PsmCount = peptideFileAnalysis.PsmCount, }); }
protected AbstractChromatogramForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); MsGraphControl = new MSGraphControlEx { Dock = DockStyle.Fill }; MsGraphControl.DoubleClickEvent += MsGraphControlOnDoubleClickEvent; MsGraphControl.MouseMoveEvent += MsGraphControlOnMouseMoveEvent; MsGraphControl.MouseDownEvent += MsGraphControlOnMouseDownEvent; MsGraphControl.MouseUpEvent += MsGraphControlOnMouseUpEvent; MsGraphControl.ContextMenuBuilder += MsGraphControlOnContextMenuBuilder; Smooth = Settings.Default.SmoothChromatograms; }
private void ShowPeptideAnalysis(Peptide peptide) { using (var session = Workspace.OpenSession()) { var dbPeptide = session.Load <DbPeptide>(peptide.Id); var dbPeptideAnalysis = (DbPeptideAnalysis)session .CreateCriteria(typeof(DbPeptideAnalysis)) .Add(Restrictions.Eq("Peptide", dbPeptide)) .UniqueResult(); if (dbPeptideAnalysis == null) { var psmTimesByDataFileId = dbPeptide.PsmTimesByDataFileId(session); if (psmTimesByDataFileId.Count == 0) { MessageBox.Show( "This peptide cannot be analyzed because it has no search results.", Program.AppName); return; } if (MessageBox.Show("This peptide has not yet been analyzed. Do you want to analyze it now?", Program.AppName, MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } session.BeginTransaction(); session.Save(dbPeptideAnalysis = Peptide.CreateDbPeptideAnalysis(session, dbPeptide)); foreach (var grouping in psmTimesByDataFileId) { MsDataFile msDataFile; if (!Workspace.MsDataFiles.TryGetValue(grouping.Key, out msDataFile)) { continue; } session.Save(PeptideFileAnalysis.CreatePeptideFileAnalysis( session, msDataFile, dbPeptideAnalysis, psmTimesByDataFileId)); dbPeptideAnalysis.FileAnalysisCount++; } session.Update(dbPeptideAnalysis); session.Transaction.Commit(); } var peptideAnalysis = TopographForm.Instance.LoadPeptideAnalysis(dbPeptideAnalysis.GetId()); if (peptideAnalysis == null) { return; } PeptideAnalysisFrame.ShowPeptideAnalysis(peptideAnalysis); } }
public AnalysisChromatograms(PeptideFileAnalysis peptideFileAnalysis) { PeptideFileAnalysis = peptideFileAnalysis; FirstTime = peptideFileAnalysis.FirstTime; LastTime = peptideFileAnalysis.LastTime; Chromatograms = new List <ChromatogramGenerator.Chromatogram>(); for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge++) { var mzs = PeptideAnalysis.TurnoverCalculator.GetMzs(charge); for (int massIndex = 0; massIndex < mzs.Count; massIndex++) { Chromatograms.Add(new ChromatogramGenerator.Chromatogram(new MzKey(charge, massIndex), mzs[massIndex])); } } ScanIndexes = new List <int>(); Times = new List <double>(); }
public AnalysisChromatograms(PeptideFileAnalysis peptideFileAnalysis) { PeptideFileAnalysis = peptideFileAnalysis; FirstTime = peptideFileAnalysis.FirstTime; LastTime = peptideFileAnalysis.LastTime; Chromatograms = new List<ChromatogramGenerator.Chromatogram>(); for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge ++) { var mzs = PeptideAnalysis.TurnoverCalculator.GetMzs(charge); for (int massIndex = 0; massIndex < mzs.Count; massIndex ++) { Chromatograms.Add(new ChromatogramGenerator.Chromatogram(new MzKey(charge, massIndex), mzs[massIndex])); } } ScanIndexes = new List<int>(); Times = new List<double>(); }
protected override bool MsGraphControlOnDoubleClickEvent(ZedGraphControl sender, MouseEventArgs e) { var peakResize = PeakResizeFromPoint(e.Location); if (peakResize != null) { var peaks = PeptideFileAnalysis.CalculatedPeaks; var newPeaks = peaks.AutoSizePeak(peakResize.TracerFormula, (AdjustPeaksMode)comboAdjustPeaks.SelectedIndex); if (newPeaks != null) { PeptideFileAnalysis.SetCalculatedPeaks(newPeaks); } return(true); } return(base.MsGraphControlOnDoubleClickEvent(sender, e)); }
protected void SetAutoFindPeak(bool autoFindPeak) { if (autoFindPeak == PeptideFileAnalysis.AutoFindPeak) { return; } if (autoFindPeak) { PeptideFileAnalysis.SetAutoFindPeak(); } else { PeptideAnalysis.EnsurePeaksCalculated(); var newPeaks = PeptideFileAnalysis.CalculatedPeaks.ChangeBasePeak(PeptideFileAnalysis.CalculatedPeaks.BasePeakKey); Debug.Assert(!newPeaks.AutoFindPeak); PeptideFileAnalysis.SetCalculatedPeaks(newPeaks); } }
public void Run(LongOperationBroker longOperationBroker) { using (var session = PeptideAnalysis.Workspace.OpenSession()) { var peptideAnalysis = session.Get <DbPeptideAnalysis>(PeptideAnalysis.Id); var peptide = peptideAnalysis.Peptide; var psmTimesByDataFileId = peptide.PsmTimesByDataFileId(session); session.BeginTransaction(); foreach (var msDataFile in MsDataFiles) { var dbPeptideFileAnalysis = PeptideFileAnalysis.CreatePeptideFileAnalysis( session, msDataFile, peptideAnalysis, psmTimesByDataFileId); session.Save(dbPeptideFileAnalysis); peptideAnalysis.FileAnalysisCount++; } session.Update(peptideAnalysis); session.Save(new DbChangeLog(PeptideAnalysis)); session.Transaction.Commit(); } PeptideAnalysis.Workspace.DatabasePoller.MergeChangesNow(); }
private void UpdateUiNow() { try { if (PeptideFileAnalysis == null) { return; } if (PeptideFileAnalysis.GetChromatograms() == null) { return; } PeptideFileAnalysis.PeptideAnalysis.EnsurePeaksCalculated(); Times = PeptideFileAnalysis.ChromatogramSet.Times ?? new double[0]; Recalc(); } finally { _updatePending = false; } }
private void btnAdjustPeaks_Click(object sender, EventArgs e) { var adjustPeaksMode = (AdjustPeaksMode)comboAdjustPeaks.SelectedIndex; var peaks = PeptideFileAnalysis.CalculatedPeaks; foreach (var tracerFormula in peaks.Peaks.Keys) { if (!IsDisplayed(tracerFormula)) { continue; } var newPeaks = peaks.AutoSizePeak(tracerFormula, adjustPeaksMode); if (newPeaks.Peaks.Count == peaks.Peaks.Count) { peaks = newPeaks; } else { newPeaks = newPeaks; } } PeptideFileAnalysis.SetCalculatedPeaks(peaks); }
private void btnCreateAnalyses_Click(object sender, EventArgs e) { dataGridView.Rows.Clear(); peptideAnalysisRows.Clear(); foreach (var msDataFile in Workspace.GetMsDataFiles()) { if (!msDataFile.HasTimes()) { if (!msDataFile.HasSearchResults(Peptide)) { continue; } if (!TurnoverForm.Instance.EnsureMsDataFile(msDataFile)) { continue; } } PeptideFileAnalysis peptideFileAnalysis = PeptideFileAnalysis.EnsurePeptideFileAnalysis(PeptideAnalysis, msDataFile); if (peptideFileAnalysis != null) { UpdateRow(AddRow(peptideFileAnalysis)); } } }
public ProcessedRowData ToRowData(PeptideFileAnalysis peptideFileAnalysis) { var rawRowData = ToRawRowData(peptideFileAnalysis); if (null == rawRowData) { return null; } return ComputeAvgTurnover(rawRowData); }
private void DoCreateAnalyses(char[] excludeAas, int minTracerCount) { var peptides = new List <DbPeptide>(); bool includeMissingMs2 = cbxIncludeMissingMS2.Checked; _statusMessage = "Listing peptides"; using (var session = Workspace.OpenWriteSession()) { session.CreateCriteria(typeof(DbPeptide)).List(peptides); for (int i = 0; i < peptides.Count(); i++) { _statusMessage = "Peptide " + (i + 1) + "/" + peptides.Count; _progress = 100 * i / peptides.Count; if (_cancelled) { break; } var peptide = peptides[i]; if (peptide.Sequence.IndexOfAny(excludeAas) >= 0) { continue; } if (Workspace.GetMaxTracerCount(peptide.Sequence) < minTracerCount) { continue; } var dbPeptideAnalysis = (DbPeptideAnalysis)session.CreateCriteria(typeof(DbPeptideAnalysis)) .Add(Restrictions.Eq("Peptide", peptide)).UniqueResult(); if (dbPeptideAnalysis == null) { dbPeptideAnalysis = Peptide.CreateDbPeptideAnalysis(session, peptide); } var idList = new List <long>(); if (dbPeptideAnalysis.Id.HasValue) { var dataFileIdQuery = session.CreateQuery("SELECT A.MsDataFile.Id FROM " + typeof(DbPeptideFileAnalysis) + " A WHERE A.PeptideAnalysis.Id = :peptideAnalysisId") .SetParameter("peptideAnalysisId", dbPeptideAnalysis.Id); dataFileIdQuery.List(idList); } var existingDataFileIds = new HashSet <long>(idList); var psmTimesByDataFileId = peptide.PsmTimesByDataFileId(session); if (psmTimesByDataFileId.Count == 0) { continue; } session.BeginTransaction(); bool newAnalysis; if (dbPeptideAnalysis.Id.HasValue) { newAnalysis = false; } else { session.Save(dbPeptideAnalysis); newAnalysis = true; } var sqlStatementBuilder = new SqlStatementBuilder(session.GetSessionImplementation().Factory.Dialect); var insertStatements = new List <string>(); IList <MsDataFile> dataFiles; if (includeMissingMs2) { dataFiles = Workspace.MsDataFiles .Where(msDataFile => !existingDataFileIds.Contains(msDataFile.Id)) .ToArray(); } else { dataFiles = new List <MsDataFile>(); foreach (var grouping in psmTimesByDataFileId) { MsDataFile dataFile; if (existingDataFileIds.Contains(grouping.Key) || !Workspace.MsDataFiles.TryGetValue(grouping.Key, out dataFile)) { continue; } dataFiles.Add(dataFile); } } foreach (var msDataFile in dataFiles) { var dbPeptideFileAnalysis = PeptideFileAnalysis.CreatePeptideFileAnalysis(session, msDataFile, dbPeptideAnalysis, psmTimesByDataFileId); insertStatements.Add(sqlStatementBuilder.GetInsertStatement("DbPeptideFileAnalysis", new Dictionary <string, object> { { "ChromatogramEndTime", dbPeptideFileAnalysis.ChromatogramEndTime }, { "ChromatogramStartTime", dbPeptideFileAnalysis.ChromatogramStartTime }, { "MsDataFile", msDataFile.Id }, { "PeptideAnalysis", dbPeptideAnalysis.Id }, { "AutoFindPeak", 1 }, { "Version", 1 }, { "PeakCount", 0 }, { "PsmCount", dbPeptideFileAnalysis.PsmCount }, { "ValidationStatus", 0 }, } )); dbPeptideAnalysis.FileAnalysisCount++; existingDataFileIds.Add(msDataFile.Id); } sqlStatementBuilder.ExecuteStatements(session, insertStatements); session.Update(dbPeptideAnalysis); if (!newAnalysis) { session.Save(new DbChangeLog(Workspace, dbPeptideAnalysis)); } else { var dbWorkspace = Workspace.LoadDbWorkspace(session); session.Update(dbWorkspace); } session.Transaction.Commit(); } } }
RawRowData ToRawRowData(PeptideFileAnalysis peptideFileAnalysis) { if (!peptideFileAnalysis.PeakData.IsCalculated) { return null; } return new RawRowData(peptideFileAnalysis.Data) { MsDataFile = peptideFileAnalysis.MsDataFile, Peptide = peptideFileAnalysis.Peptide, PeptideFileAnalysisId = peptideFileAnalysis.Id, PsmCount = peptideFileAnalysis.PsmCount, }; }
public void AddPeptideAnalysis(PeptideFileAnalysis peptideFileAnalysis) { AddPeptideFileAnalyses(new[] {peptideFileAnalysis}); }
protected PeptideFileAnalysisForm(PeptideFileAnalysis peptideFileAnalysis) : base(peptideFileAnalysis) { InitializeComponent(); }
private TracerChromatograms GetPoints() { return(PeptideFileAnalysis.GetTracerChromatograms(Smooth)); }
protected override void Recalc() { cbxAutoFindPeak.Checked = PeptideFileAnalysis.AutoFindPeak; cbxSmooth.Checked = Smooth; MsGraphControl.GraphPane.GraphObjList.Clear(); MsGraphControl.GraphPane.CurveList.Clear(); _peakLines = null; if (!PeptideFileAnalysis.IsMzKeySetComplete(PeptideFileAnalysis.ChromatogramSet.Chromatograms.Keys)) { return; } var overlayFileAnalysis = UpdateDataFileCombo(comboOverlay); var peakLines = new Dictionary <TracerFormula, PeakDisplay>(); var tracerChromatograms = GetPoints(); TracerChromatograms overlayTracerChromatograms = null; double[] mappedTimes = null; if (overlayFileAnalysis != null) { overlayTracerChromatograms = overlayFileAnalysis.GetTracerChromatograms(Smooth); var retentionTimeAlignment = overlayFileAnalysis.MsDataFile.GetRetentionTimeAlignment(PeptideFileAnalysis.MsDataFile); mappedTimes = overlayTracerChromatograms.Times.Select(retentionTimeAlignment.GetTargetTime).ToArray(); } var peaks = PeptideFileAnalysis.CalculatedPeaks; var entries = tracerChromatograms.Points.ToArray(); if (dataGridView1.Rows.Count != entries.Length) { dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(entries.Length); } if (cbxShowScore.Checked) { var scoreLine = MsGraphControl.GraphPane.AddCurve("Score", tracerChromatograms.Times.ToArray(), tracerChromatograms.Scores.ToArray(), Color.Black, SymbolType.None); scoreLine.IsY2Axis = true; scoreLine.Line.Width = Settings.Default.ChromatogramLineWidth; } double totalAmount = peaks.Peaks.Values.Sum(p => p.Area); double totalSlope = peaks.Peaks.Values.Sum(p => p.RatioToBase); for (int iCandidate = 0; iCandidate < entries.Count(); iCandidate++) { var entry = entries[iCandidate]; var label = entry.Key.ToDisplayString(); var row = dataGridView1.Rows[iCandidate]; row.Cells[colFormula.Index].Value = label; var peak = peaks.GetPeak(entry.Key); if (peak != null) { row.Cells[colAreaPct.Index].Value = peak.Value.Area / totalAmount; row.Cells[colSlopePct.Index].Value = peak.Value.RatioToBase / totalSlope; row.Cells[colStartTime.Index].Value = peak.Value.StartTime; row.Cells[colEndTime.Index].Value = peak.Value.EndTime; row.Cells[colArea.Index].Value = peak.Value.Area; row.Cells[colCorr.Index].Value = peak.Value.Correlation; } else { row.Cells[colAreaPct.Index].Value = null; row.Cells[colStartTime.Index].Value = null; row.Cells[colEndTime.Index].Value = null; row.Cells[colArea.Index].Value = null; row.Cells[colCorr.Index].Value = null; } row.Cells[colFormula.Index].Style.BackColor = row.Cells[colAreaPct.Index].Style.BackColor = GetColor(iCandidate, entries.Length); row.Tag = entry.Key; if (IsDisplayed(entry.Key)) { var curve = new ChromatogramGraphItem { Title = label, Color = GetColor(iCandidate, entries.Length), Points = new PointPairList(tracerChromatograms.Times, entry.Value), }; var chromCurveItem = (LineItem)MsGraphControl.AddGraphItem(MsGraphControl.GraphPane, curve); chromCurveItem.Label.IsVisible = false; chromCurveItem.Line.Width = Settings.Default.ChromatogramLineWidth; if (overlayTracerChromatograms != null) { var overlayCurve = new ChromatogramGraphItem { Title = overlayFileAnalysis.MsDataFile.Label + " " + label, Color = GetColor(iCandidate, entries.Length), Points = new PointPairList(mappedTimes, overlayTracerChromatograms.Points[entry.Key]) }; var overlayCurveItem = (LineItem)MsGraphControl.AddGraphItem(MsGraphControl.GraphPane, overlayCurve); overlayCurveItem.Label.IsVisible = false; overlayCurveItem.Line.Style = DashStyle.Dash; overlayCurveItem.Line.Width = Settings.Default.ChromatogramLineWidth; } if (peak != null) { var peakDisplay = new PeakDisplay(); var color = GetColor(iCandidate, entries.Length); var max = MaxInRange(entry.Value, tracerChromatograms.ChromatogramSet.IndexFromTime(peak.Value.StartTime), tracerChromatograms.ChromatogramSet.IndexFromTime(peak.Value.EndTime)); peakDisplay.Start = peak.Value.StartTime; peakDisplay.End = peak.Value.EndTime; peakDisplay.Height = max; if (PeaksAsHorizontalLines) { peakDisplay.HorizontalLine = MsGraphControl.GraphPane.AddCurve(null, new[] { peakDisplay.Start, peakDisplay.End }, new[] { max, max }, color); peakDisplay.HorizontalLine.Line.Width = Settings.Default.ChromatogramLineWidth; } if (PeaksAsVerticalLines) { peakDisplay.StartVerticalLine = MsGraphControl.GraphPane.AddCurve( null, new[] { peakDisplay.Start, peakDisplay.Start }, new[] { max, 0 }, color, SymbolType.None ); peakDisplay.StartVerticalLine.Line.Width = Settings.Default.ChromatogramLineWidth; peakDisplay.EndVerticalLine = MsGraphControl.GraphPane.AddCurve( null, new[] { peakDisplay.End, peakDisplay.End }, new[] { max, 0 }, color, SymbolType.None ); peakDisplay.EndVerticalLine.Line.Width = Settings.Default.ChromatogramLineWidth; } peakLines.Add(entry.Key, peakDisplay); } } } // foreach (var peakSet in tracerChromatograms.GetNonOverlappingPeakSets()) // { // double start = PeptideFileAnalysis.TimeFromScanIndex(peakSet.StartIndex); // double end = PeptideFileAnalysis.TimeFromScanIndex(peakSet.EndIndex); // double rawScore = tracerChromatograms.GetScore(peakSet.StartIndex, peakSet.EndIndex); // double colorScore = Math.Pow(rawScore, 4); // var color = Color.FromArgb((int) (255 - (255*colorScore)), (int) (255*colorScore), 0); // var box = new BoxObj(start, int.MaxValue, end - start, int.MaxValue, Color.Black, color) // { // IsClippedToChartRect = true, // ZOrder = ZOrder.F_BehindGrid, // }; // msGraphControl.GraphPane.GraphObjList.Add(box); // double retentionTime = tracerChromatograms.Times[peakSet.BestRetentionTime]; // double intensity = tracerChromatograms.GetMaxIntensity(peakSet); // var textObj = new TextObj(retentionTime.ToString("0.##"), retentionTime, // intensity, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom) // { // FontSpec = {Fill = new Fill(color),}, // Tag = peakSet, // }; // msGraphControl.GraphPane.GraphObjList.Add(textObj); // } if (PeptideFileAnalysis.PsmTimes != null) { foreach (var time in PeptideFileAnalysis.PsmTimes.SelectMany(entry => entry.Value)) { MsGraphControl.GraphPane.GraphObjList.Add(new LineObj(Color.LightBlue, time, 0, time, 1) { Line = { Style = DashStyle.DashDot }, ZOrder = ZOrder.E_BehindCurves, IsClippedToChartRect = true, Location = { CoordinateFrame = CoordType.XScaleYChartFraction } }); } } else { var otherPeaks = PeptideAnalysis.FileAnalyses.Select(f => f.CalculatedPeaks); double firstDetectedTime, lastDetectedTime; PeptideFileAnalysis.CalculatedPeaks.GetFirstLastTimes(otherPeaks, out firstDetectedTime, out lastDetectedTime); MsGraphControl.GraphPane.GraphObjList.Add(new LineObj(Color.Black, firstDetectedTime, 0, firstDetectedTime, 1) { Line = { Style = DashStyle.DashDotDot }, ZOrder = ZOrder.E_BehindCurves, IsClippedToChartRect = true, Location = { CoordinateFrame = CoordType.XScaleYChartFraction } }); MsGraphControl.GraphPane.GraphObjList.Add(new LineObj(Color.Black, lastDetectedTime, 0, lastDetectedTime, 1) { Line = { Style = DashStyle.DashDotDot }, ZOrder = ZOrder.E_BehindCurves, IsClippedToChartRect = true, Location = { CoordinateFrame = CoordType.XScaleYChartFraction } }); } MsGraphControl.AxisChange(); MsGraphControl.Invalidate(); _peakLines = peakLines; tbxTracerPercentByAreas.Text = peaks.CalcTracerPercentByAreas().ToString(); tbxTracerPercentBySlopes.Text = peaks.CalcTracerPercentByRatios().ToString(); tbxScore.Text = peaks.DeconvolutionScore.ToString(); double rtShift, rtStdDev; peaks.RetentionTimeShift(out rtShift, out rtStdDev); var retentionTimeShift = rtShift.ToString("#.00"); if (!double.IsNaN(rtStdDev) && !double.IsInfinity(rtStdDev)) { retentionTimeShift += "+/-" + rtStdDev.ToString("#.00"); } tbxRetentionTimeShift.Text = retentionTimeShift; }
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; }
private bool IsIncluded(HalfLifeSettings halfLifeSettings, PeptideFileAnalysis peptideFileAnalysis) { if (!string.IsNullOrEmpty(Cohort)) { if (Cohort != HalfLifeCalculator.GetCohort(peptideFileAnalysis.MsDataFile, GetHalfLifeSettings().BySample)) { return false; } } if (peptideFileAnalysis.MsDataFile.TimePoint == null) { return false; } if (IsTimePointExcluded(peptideFileAnalysis.MsDataFile.TimePoint.Value)) { return false; } if (halfLifeSettings.PrecursorPoolCalculation == PrecursorPoolCalculation.Individual) { if (null == peptideFileAnalysis.CalculatedPeaks || !peptideFileAnalysis.CalculatedPeaks.Turnover.HasValue) { return false; } } return true; }
private CalculatedPeaks(PeptideFileAnalysis peptideFileAnalysis) { PeptideFileAnalysis = peptideFileAnalysis; AutoFindPeak = peptideFileAnalysis.AutoFindPeak; }
public static CalculatedPeaks Calculate(PeptideFileAnalysis peptideFileAnalysis, IEnumerable<CalculatedPeaks> otherPeaks) { var tracerFormulae = peptideFileAnalysis.TurnoverCalculator.ListTracerFormulas(); var result = new CalculatedPeaks(peptideFileAnalysis); if (!peptideFileAnalysis.AutoFindPeak) { var previous = peptideFileAnalysis.PeakData; if (previous.Peaks.Count == tracerFormulae.Count) { for (int i = 0; i < previous.Peaks.Count; i++) { var peak = previous.Peaks[i]; if (result._peaks.Count == 0) { result.MakeBasePeak(tracerFormulae[i], peak.StartTime, peak.EndTime); } else { result.MakeSecondaryPeak(tracerFormulae[i], peak.StartTime, peak.EndTime); } } var maxArea = result._peaks.Values.Max(peak => peak.Area); result = result.ChangeBasePeak(result._peaks.First(kvp => kvp.Value.Area.Equals(maxArea)).Key); result.IntegrationNote = IntegrationNote.Manual; } } if (result._peaks.Count == 0 ) { result.LookForBestPeak(otherPeaks); } result.FinishCalculation(); return result; }
private DataGridViewRow AddRow(PeptideFileAnalysis peptideFileAnalysis) { var row = dataGridView.Rows[dataGridView.Rows.Add()]; row.Tag = peptideFileAnalysis; _peptideFileAnalysisRows.Add(peptideFileAnalysis, row); return row; }
private DataGridViewRow AddRow(PeptideFileAnalysis peptideFileAnalysis) { var row = dataGridView.Rows[dataGridView.Rows.Add()]; row.Tag = peptideFileAnalysis; peptideAnalysisRows.Add(peptideFileAnalysis, row); if (!peptideFileAnalysis.EnsureCalculated()) { Workspace.EnsureChromatograms(peptideFileAnalysis); } return row; }
public OverlayFileAnalysisItem(PeptideFileAnalysis peptideFileAnalysis) { PeptideFileAnalysis = peptideFileAnalysis; }