コード例 #1
0
ファイル: ChromatogramForm.cs プロジェクト: zrolfs/pwiz
        protected override void Recalc()
        {
            cbxAutoFindPeak.Checked = PeptideFileAnalysis.AutoFindPeak;
            cbxSmooth.Checked       = Smooth;
            if (MsGraphControl.GraphPane == null)
            {
                // TODO(nicksh): listeners should have been detached.
                return;
            }
            ShowChromatograms();
            if (Times.Count > 0)
            {
//                var backgroundLine = new LineObj(Color.DarkGray, times[0], PeptideFileAnalysis.Background, times[times.Count - 1], PeptideFileAnalysis.Background);
//                msGraphControl.GraphPane.GraphObjList.Add(backgroundLine);
            }
            double detectedLineHeight = MsGraphControl.GraphPane.YAxis.Scale.Max * .9;

            if (null != PeptideFileAnalysis.PsmTimes)
            {
                foreach (var time in PeptideFileAnalysis.PsmTimes.SelectMany(entry => entry.Value))
                {
                    MsGraphControl.GraphPane.GraphObjList.Add(new LineObj(Color.LightBlue, time, detectedLineHeight, time, 0)
                    {
                        IsClippedToChartRect = true,
                        ZOrder = ZOrder.E_BehindCurves,
                    });
                }
            }
            MsGraphControl.Invalidate();
        }
コード例 #2
0
ファイル: TracerChromatogramForm.cs プロジェクト: zrolfs/pwiz
        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;
        }
コード例 #3
0
ファイル: TracerChromatogramForm.cs プロジェクト: zrolfs/pwiz
        protected override bool MsGraphControlOnMouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
        {
            if (_peakResize != null)
            {
                var         peakDisplay = _peakResize.PeakDisplay;
                PointPair[] points      = new[]
                {
                    new PointPair(peakDisplay.Start, peakDisplay.Height),
                    new PointPair(peakDisplay.End, peakDisplay.Height),
                };
                var    screenPt = new PointF(e.Location.X - _peakResize.MousePt.X + _peakResize.CoordPt.X, _peakResize.CoordPt.Y);
                double x, y;
                MsGraphControl.GraphPane.ReverseTransform(screenPt, out x, out y);
                switch (_peakResize.LineSegment)
                {
                case LineSegment.Start:
                    points[0] = new PointPair(x, points[0].Y);
                    break;

                case LineSegment.End:
                    points[1] = new PointPair(x, points[0].Y);
                    break;

                case LineSegment.Middle:
                    points = new[]
                    {
                        new PointPair(x, points[0].Y),
                        new PointPair(x - points[0].X + points[1].X, points[1].Y)
                    };
                    break;
                }

                if (peakDisplay.HorizontalLine != null)
                {
                    peakDisplay.HorizontalLine.RemovePoint(1);
                    peakDisplay.HorizontalLine.RemovePoint(0);
                    peakDisplay.HorizontalLine.AddPoint(points[0]);
                    peakDisplay.HorizontalLine.AddPoint(points[1]);
                }
                foreach (var lineItemPt in new[] {
                    new KeyValuePair <LineItem, PointPair>(peakDisplay.StartVerticalLine, points[0]),
                    new KeyValuePair <LineItem, PointPair>(peakDisplay.EndVerticalLine, points[1])
                })
                {
                    if (lineItemPt.Key == null)
                    {
                        continue;
                    }
                    lineItemPt.Key.RemovePoint(1);
                    lineItemPt.Key.RemovePoint(0);
                    lineItemPt.Key.AddPoint(new PointPair(lineItemPt.Value.X, peakDisplay.Height));
                    lineItemPt.Key.AddPoint(new PointPair(lineItemPt.Value.X, 0));
                }
                MsGraphControl.Invalidate();
                sender.Cursor = _peakResize.GetCursor();
                return(true);
            }
            if (base.MsGraphControlOnMouseMoveEvent(sender, e))
            {
                return(true);
            }
            PeakResize peakResize = PeakResizeFromPoint(e.Location);

            if (peakResize != null)
            {
                sender.Cursor = peakResize.GetCursor();
                return(true);
            }
            return(false);
        }
コード例 #4
0
ファイル: ChromatogramForm.cs プロジェクト: zrolfs/pwiz
        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;
                }
            }
        }