protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (Workspace == null) { return; } if (_tracerChromatogramForm == null) { _tracerChromatogramForm = new TracerChromatogramForm(PeptideFileAnalysis) { CloseButton = false }; _tracerChromatogramForm.Show(_dockPanel, DockState.Document); } if (_chromatogramForm == null) { _chromatogramForm = new ChromatogramForm(PeptideFileAnalysis) { CloseButton = false }; _chromatogramForm.Show(_dockPanel, DockState.Document); } if (_precursorPoolForm == null) { _precursorPoolForm = new PrecursorPoolForm(PeptideFileAnalysis) { CloseButton = false, }; _precursorPoolForm.Show(_dockPanel, DockState.Document); } UpdateForm(); }
private void RefreshUi() { if (_inRefreshUi) { return; } try { _inRefreshUi = true; _zedGraphControl.GraphPane.CurveList.Clear(); _zedGraphControl.GraphPane.GraphObjList.Clear(); if (_queryRows == null) { return; } var values = new Dictionary <CohortKey, double[]>(); var xValues = new double[101]; for (int i = 0; i < xValues.Length; i++) { xValues[i] = i; } foreach (var row in _queryRows) { double[] vector; if (!values.TryGetValue(row.Key, out vector)) { vector = new double[xValues.Length]; values.Add(row.Key, vector); } foreach (var entry in row.Value) { if (entry.Key < 0 || entry.Key > 1) { continue; } vector[(int)Math.Round(entry.Key * 100)] += entry.Value; } } var cohortKeys = new List <CohortKey>(values.Keys); cohortKeys.Sort(); if (dataGridView1.Rows.Count != cohortKeys.Count) { dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(cohortKeys.Count); } for (int i = 0; i < cohortKeys.Count; i++) { var cohortKey = cohortKeys[i]; var yValues = values[cohortKey]; var row = dataGridView1.Rows[i]; if (dataGridView1.SelectedRows.Count == 0 || dataGridView1.SelectedRows.Contains(row)) { _zedGraphControl.GraphPane.AddBar(cohortKey.ToString(), xValues, yValues, TracerChromatogramForm.GetColor(i, cohortKeys.Count)); } row.Cells[colCohort.Index].Value = cohortKey; var statsX = new Statistics(xValues); var statsY = new Statistics(yValues); row.Cells[colMean.Index].Value = statsX.Mean(statsY); row.Cells[colStdDev.Index].Value = statsX.StdDev(statsY); row.Cells[colMedian.Index].Value = statsX.Median(statsY); } _zedGraphControl.GraphPane.AxisChange(); _zedGraphControl.Invalidate(); } finally { _inRefreshUi = false; } }
protected void ShowChromatograms() { if (MsGraphControl.GraphPane == null) { // TODO: How can this happen? return; } MsGraphControl.GraphPane.GraphObjList.Clear(); MsGraphControl.GraphPane.CurveList.Clear(); var selectedCharges = gridIntensities.GetSelectedCharges(); var selectedMasses = gridIntensities.GetSelectedMasses(); var chromatograms = PeptideFileAnalysis.ChromatogramSet; var mzRanges = PeptideFileAnalysis.TurnoverCalculator.GetMzs(0); var monoisotopicMass = Workspace.GetAminoAcidFormulas().GetMonoisotopicMass(PeptideAnalysis.Peptide.Sequence); for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge++) { if (selectedCharges.Count > 0 && !selectedCharges.Contains(charge)) { continue; } for (int iMass = 0; iMass < PeptideAnalysis.GetMassCount(); iMass++) { var mzKey = new MzKey(charge, iMass); double massDifference = mzRanges[iMass].Center - monoisotopicMass; var label = massDifference.ToString("0.#"); if (label[0] != '-') { label = "+" + label; } label = "M" + label; label += new string('+', charge); if (selectedMasses.Count > 0) { if (!selectedMasses.Contains(iMass)) { continue; } } else { if (ExcludedMasses.IsExcluded(mzKey.MassIndex)) { continue; } } ChromatogramSetData.Chromatogram chromatogram; if (!chromatograms.Chromatograms.TryGetValue(mzKey, out chromatogram)) { continue; } var graphItem = new ChromatogramGraphItem { Title = label, }; graphItem.Color = TracerChromatogramForm.GetColor(iMass, PeptideAnalysis.GetMassCount()); var mzRange = PeptideFileAnalysis.TurnoverCalculator.GetMzs(mzKey.Charge)[mzKey.MassIndex]; var massAccuracy = PeptideAnalysis.GetMassAccuracy(); var intensities = chromatogram.ChromatogramPoints.Select(point => point.GetIntensity(mzRange, massAccuracy)).ToArray(); if (Smooth) { intensities = TracerChromatograms.SavitzkyGolaySmooth(intensities); } PointPairList points = new PointPairList(chromatograms.Times, intensities); graphItem.Points = points; var lineItem = (LineItem)MsGraphControl.AddGraphItem(MsGraphControl.GraphPane, graphItem); lineItem.Line.Style = TracerChromatogramForm.GetDashStyle(charge - PeptideAnalysis.MinCharge); lineItem.Line.Width = Settings.Default.ChromatogramLineWidth; lineItem.Label.IsVisible = false; } } }
private void UpdateGraph() { zedGraphControl.GraphPane.CurveList.Clear(); zedGraphControl.GraphPane.GraphObjList.Clear(); zedGraphControl.GraphPane.Title.IsVisible = false; MsDataFile normalizeTo = null; var fileAnalyses = new List <PeptideFileAnalysis>(); for (int iRow = 0; iRow < dataGridView.Rows.Count; iRow++) { fileAnalyses.Add((PeptideFileAnalysis)dataGridView.Rows[iRow].Tag); } if (fileAnalyses.Count == 0) { return; } if (_normalizeRetentionTimes) { normalizeTo = fileAnalyses[0].MsDataFile; } var tracerFormulas = PeptideAnalysis.GetTurnoverCalculator().ListTracerFormulas(); var pointPairLists = tracerFormulas.Select(tf => new PointPairList()).ToArray(); for (int iFileAnalysis = 0; iFileAnalysis < fileAnalyses.Count; iFileAnalysis++) { var fileAnalysis = fileAnalyses[iFileAnalysis]; var peaks = fileAnalysis.CalculatedPeaks; if (peaks == null) { continue; } for (int iTracerFormula = 0; iTracerFormula < tracerFormulas.Count; iTracerFormula++) { var pointPairList = pointPairLists[iTracerFormula]; var peak = peaks.GetPeak(tracerFormulas[iTracerFormula]); if (peak == null) { pointPairList.Add(new PointPair(iFileAnalysis + 1, PointPairBase.Missing, PointPairBase.Missing)); } else { if (normalizeTo == null) { pointPairList.Add(new PointPair(iFileAnalysis + 1, peak.Value.EndTime, peak.Value.StartTime)); } else { var alignment = fileAnalysis.MsDataFile.GetRetentionTimeAlignment(normalizeTo); if (alignment.IsInvalid) { pointPairList.Add(new PointPair(iFileAnalysis + 1, PointPairBase.Missing, PointPairBase.Missing)); } else { pointPairList.Add(new PointPair(iFileAnalysis + 1, alignment.GetTargetTime(peak.Value.EndTime), alignment.GetTargetTime(peak.Value.StartTime), fileAnalysis)); } } } } } zedGraphControl.GraphPane.XAxis.Type = AxisType.Text; zedGraphControl.GraphPane.XAxis.Scale.TextLabels = fileAnalyses.Select(fileAnalysis => fileAnalysis.MsDataFile.ToString()).ToArray(); zedGraphControl.GraphPane.XAxis.Title.Text = "Data File"; zedGraphControl.GraphPane.YAxis.Title.Text = normalizeTo == null ? "Retention Time" : "Normalized Retention Time"; for (int iTracerFormula = 0; iTracerFormula < tracerFormulas.Count; iTracerFormula++) { zedGraphControl.GraphPane.AddHiLowBar(tracerFormulas[iTracerFormula].ToDisplayString(), pointPairLists[iTracerFormula], TracerChromatogramForm.GetColor(iTracerFormula, tracerFormulas.Count)); } zedGraphControl.GraphPane.AxisChange(); zedGraphControl.Invalidate(); }