Exemple #1
0
 private IEnumerable <ChromGraphItem> GetChromGraphItems(MSGraphPane msGraphPane)
 {
     return(msGraphPane.CurveList
            .Where(curve => !string.IsNullOrEmpty(curve.Label.Text))
            .Select(curve => curve.Tag)
            .OfType <ChromGraphItem>());
 }
 /// <summary>
 /// Resets the all of the properties of a graph pane that might have changed
 /// (or initialize the properties of a newly  created pane) so that it's ready
 /// to be used by a different set of graphs.
 /// </summary>
 public virtual void ApplySettingsToGraphPane(MSGraphPane graphPane)
 {
     graphPane.Legend.IsVisible  = ShowLegend;
     graphPane.Title.IsVisible   = true;
     graphPane.Title.Text        = null;
     graphPane.AllowLabelOverlap = AllowLabelOverlap;
 }
Exemple #3
0
 /// <summary>
 /// Resets the all of the properties of a graph pane that might have changed
 /// (or initialize the properties of a newly  created pane) so that it's ready
 /// to be used by a different set of graphs.
 /// </summary>
 public virtual void ApplySettingsToGraphPane(MSGraphPane graphPane)
 {
     graphPane.Legend.IsVisible  = ShowLegend;
     graphPane.Title.IsVisible   = true;
     graphPane.Title.Text        = null;
     graphPane.AllowLabelOverlap = true; // Always allow labels to overlap - they're transparent so it's OK to do so
 }
Exemple #4
0
        private int GetChromatogramCount(MSGraphPane msGraphPane)
        {
            int count = 0;

            RunUI(() => count = GetChromGraphItems(msGraphPane).Count());
            return(count);
        }
Exemple #5
0
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            foreach (var rmi in SpectrumInfo.PeaksMatched)
            {
                if (!IsVisibleIon(rmi))
                {
                    continue;
                }

                var matchedIon = rmi.MatchedIons.First(IsVisibleIon);

                Color color;
                switch (matchedIon.IonType)
                {
                default: color = COLOR_NONE; break;

                case IonType.a: color = COLOR_A; break;

                case IonType.x: color = COLOR_X; break;

                case IonType.b: color = COLOR_B; break;

                case IonType.y: color = COLOR_Y; break;

                case IonType.c: color = COLOR_C; break;

                case IonType.z: color = COLOR_Z; break;

                case IonType.custom: color = (rmi.Rank > 0) ? COLOR_OTHER_IONS : COLOR_NONE; break;     // Small molecule fragments - only color if ranked

                case IonType.precursor: color = COLOR_PRECURSOR; break;
                }

                if (rmi.MatchedIons.Any(mfi => IsMatch(mfi.PredictedMz)))
                {
                    color = COLOR_SELECTED;
                }

                double mz    = rmi.ObservedMz;
                var    stick = new LineObj(color, mz, rmi.Intensity, mz, 0);
                stick.IsClippedToChartRect     = true;
                stick.Location.CoordinateFrame = CoordType.AxisXYScale;
                stick.Line.Width = LineWidth + 1;
                annotations.Add(stick);
            }
            //ReSharper restore UseObjectOrCollectionInitializer
        }
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            foreach (var rmi in SpectrumInfo.PeaksMatched)
            {
                if (!IsVisibleIon(rmi))
                {
                    continue;
                }

                IonType type = IsVisibleIon(rmi.IonType, rmi.Ordinal, rmi.Charge) ?
                               rmi.IonType : rmi.IonType2;

                Color color;
                switch (type)
                {
                default: color = COLOR_NONE; break;

                case IonType.a: color = COLOR_A; break;

                case IonType.x: color = COLOR_X; break;

                case IonType.b: color = COLOR_B; break;

                case IonType.y: color = COLOR_Y; break;

                case IonType.c: color = COLOR_C; break;

                case IonType.z: color = COLOR_Z; break;

                // FUTURE: Add custom ions when LibraryRankedSpectrumInfo can support them
                case IonType.precursor: color = COLOR_PRECURSOR; break;
                }

                if (IsMatch(rmi.PredictedMz))
                {
                    color = COLOR_SELECTED;
                }

                double mz    = rmi.ObservedMz;
                var    stick = new LineObj(color, mz, rmi.Intensity, mz, 0);
                stick.IsClippedToChartRect     = true;
                stick.Location.CoordinateFrame = CoordType.AxisXYScale;
                stick.Line.Width = LineWidth + 1;
                annotations.Add(stick);
            }
            //ReSharper restore UseObjectOrCollectionInitializer
        }
            private MSGraphPane InsertMsGraphPane(MSGraphControl graphControl, int iInsert)
            {
                var pane = new MSGraphPane
                {
                    Border            = { IsVisible = false },
                    AllowCurveOverlap = true,
                };

                ApplySettingsToGraphPane(pane);
                var primaryPane = graphControl.GraphPane;

                pane.CurrentItemType = primaryPane.CurrentItemType;
                pane.ZoomStack.AddRange(primaryPane.ZoomStack);
                var zoomState = new ZoomState(primaryPane, ZoomState.StateType.Zoom);

                zoomState.ApplyState(pane);
                pane.YAxis.Title.Text = primaryPane.YAxis.Title.Text;
                pane.XAxis.Title.Text = primaryPane.XAxis.Title.Text;
                graphControl.MasterPane.PaneList.Insert(iInsert, pane);
                return(pane);
            }
Exemple #8
0
        private void AddRetentionTimeAnnotation(MSGraphPane graphPane, Graphics g, GraphObjList annotations,
                                                PointF ptTop, string title, GraphObjType graphObjType, Color color, ScaledRetentionTime retentionTime)
        {
            // ReSharper disable LocalizableElement
            string label = string.Format("{0}\n{1:F01}", title, retentionTime.DisplayTime);
            // ReSharper restore LocalizableElement
            FontSpec fontLabel    = CreateFontSpec(color, _fontSpec.Size);
            SizeF    sizeLabel    = fontLabel.MeasureString(g, label, graphPane.CalcScaleFactor());
            PointF   realTopPoint = ptTop;

            ptTop = new PointF(0, ptTop.Y + sizeLabel.Height + 15);
            float  chartHeightWithLabel   = graphPane.Chart.Rect.Height + sizeLabel.Height + 15;
            double intensityChartFraction = (ptTop.Y - realTopPoint.Y) / chartHeightWithLabel;

            LineObj stick = new LineObj(color, retentionTime.DisplayTime, intensityChartFraction, retentionTime.DisplayTime, 1)
            {
                IsClippedToChartRect = true,
                Location             = { CoordinateFrame = CoordType.XScaleYChartFraction },
                ZOrder = ZOrder.E_BehindCurves,
                Line   = { Width = 1 },
                Tag    = new GraphObjTag(this, graphObjType, retentionTime),
            };

            annotations.Add(stick);

            ptTop = new PointF(0, ptTop.Y - 5);
            intensityChartFraction = (ptTop.Y - realTopPoint.Y) / chartHeightWithLabel;
            TextObj text = new TextObj(label, retentionTime.DisplayTime, intensityChartFraction,
                                       CoordType.XScaleYChartFraction, AlignH.Center, AlignV.Bottom)
            {
                IsClippedToChartRect = true,
                ZOrder   = ZOrder.E_BehindCurves,
                FontSpec = CreateFontSpec(color, _fontSpec.Size),
                Tag      = new GraphObjTag(this, graphObjType, retentionTime),
            };

            annotations.Add(text);
        }
Exemple #9
0
        bool msGraphControl_MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e)
        {
            MSGraphPane hoverPane = sender.MasterPane.FindPane(e.Location) as MSGraphPane;

            if (hoverPane == null)
            {
                return(false);
            }

            CurveItem nearestCurve;
            int       nearestIndex;

            //change the cursor if the mouse is sufficiently close to a point
            if (hoverPane.FindNearestPoint(e.Location, out nearestCurve, out nearestIndex))
            {
                msGraphControl.Cursor = Cursors.Cross;
            }
            else
            {
                msGraphControl.Cursor = Cursors.Default;
            }
            return(false);
        }
Exemple #10
0
        bool msGraphControl_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e)
        {
            // keep track of MSGraphItem nearest the last left click
            Point pos = MousePosition;

            focusedPane = sender.MasterPane.FindPane(e.Location) as MSGraphPane;
            if (focusedPane == null)
            {
                return(false);
            }

            CurveItem nearestCurve; int nearestIndex;

            focusedPane.FindNearestPoint(e.Location, out nearestCurve, out nearestIndex);
            if (nearestCurve == null)
            {
                setFocusedItem(sender.MasterPane[0].CurveList[0]);
            }
            else
            {
                setFocusedItem(nearestCurve);
            }
            return(false);
        }
Exemple #11
0
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g,
                                            MSPointList pointList, GraphObjList annotations)
        {
            if (Chromatogram == null)
            {
                return;
            }


            // Calculate maximum y for potential retention time indicators
            PointF ptTop = new PointF(0, graphPane.Chart.Rect.Top);

            if (GraphChromatogram.ShowRT != ShowRTChrom.none)
            {
                if (RetentionMsMs != null)
                {
                    foreach (double retentionTime in RetentionMsMs)
                    {
                        Color color = COLOR_MSMSID_TIME;
                        if (SelectedRetentionMsMs.HasValue && Equals((float)retentionTime, (float)SelectedRetentionMsMs))
                        {
                            color = ColorSelected;
                        }
                        AddRetentionTimeAnnotation(graphPane, g, annotations, ptTop,
                                                   Resources.ChromGraphItem_AddAnnotations_ID, GraphObjType.ms_ms_id, color,
                                                   ScaleRetentionTime(retentionTime));
                    }
                }
                if (MidasRetentionMsMs != null)
                {
                    foreach (var retentionTime in MidasRetentionMsMs)
                    {
                        var color = SelectedRetentionMsMs.HasValue && Equals((float)retentionTime, (float)SelectedRetentionMsMs)
                            ? ColorSelected
                            : COLOR_MSMSID_TIME;
                        AddRetentionTimeAnnotation(graphPane, g, annotations, ptTop, string.Empty, GraphObjType.midas_spectrum, color, ScaleRetentionTime(retentionTime));
                    }
                }
                if (AlignedRetentionMsMs != null)
                {
                    foreach (var time in AlignedRetentionMsMs)
                    {
                        var scaledTime = ScaleRetentionTime(time);
                        var line       = new LineObj(COLOR_ALIGNED_MSMSID_TIME, scaledTime.DisplayTime, 0,
                                                     scaledTime.DisplayTime, 1)
                        {
                            ZOrder               = ZOrder.F_BehindGrid,
                            Location             = { CoordinateFrame = CoordType.XScaleYChartFraction },
                            IsClippedToChartRect = true,
                            Tag = new GraphObjTag(this, GraphObjType.aligned_ms_id, scaledTime),
                        };
                        annotations.Add(line);
                    }
                }
                if (UnalignedRetentionMsMs != null)
                {
                    foreach (var time in UnalignedRetentionMsMs)
                    {
                        var scaledTime = ScaleRetentionTime(time);
                        var line       = new LineObj(COLOR_UNALIGNED_MSMSID_TIME, scaledTime.DisplayTime, 0,
                                                     scaledTime.DisplayTime, 1)
                        {
                            ZOrder               = ZOrder.F_BehindGrid,
                            Location             = { CoordinateFrame = CoordType.XScaleYChartFraction },
                            IsClippedToChartRect = true,
                            Tag = new GraphObjTag(this, GraphObjType.unaligned_ms_id, scaledTime),
                        };
                        annotations.Add(line);
                    }
                }
            }

            // Draw retention time indicator, if set
            if (RetentionPrediction.HasValue)
            {
                double time = RetentionPrediction.Value;

                // Create temporary label to calculate positions
                if (GraphChromatogram.ShowRT != ShowRTChrom.none)
                {
                    AddRetentionTimeAnnotation(graphPane,
                                               g,
                                               annotations,
                                               ptTop,
                                               Resources.ChromGraphItem_AddAnnotations_Predicted,
                                               GraphObjType.predicted_rt_window,
                                               COLOR_RETENTION_TIME,
                                               ScaleRetentionTime(time));
                }

                // Draw background for retention time window
                if (RetentionWindow > 0)
                {
                    double x1  = ScaleRetentionTime(time - RetentionWindow / 2).DisplayTime;
                    double x2  = ScaleRetentionTime(time + RetentionWindow / 2).DisplayTime;
                    BoxObj box = new BoxObj(x1, 0, x2 - x1, 1,
                                            COLOR_RETENTION_WINDOW, COLOR_RETENTION_WINDOW)
                    {
                        Location             = { CoordinateFrame = CoordType.XScaleYChartFraction },
                        IsClippedToChartRect = true,
                        ZOrder = ZOrder.F_BehindGrid
                    };
                    annotations.Add(box);
                }
            }

            if (RetentionExplicit != null && GraphChromatogram.ShowRT != ShowRTChrom.none)
            {
                // Create temporary label to calculate positions
                AddRetentionTimeAnnotation(graphPane,
                                           g,
                                           annotations,
                                           ptTop,
                                           Resources.ChromGraphItem_AddAnnotations_Explicit,
                                           GraphObjType.predicted_rt_window,
                                           COLOR_RETENTION_TIME,
                                           ScaleRetentionTime(RetentionExplicit.RetentionTime));
            }

            for (int i = 0, len = Chromatogram.NumPeaks; i < len; i++)
            {
                if (_arrayLabelIndexes[i] == -1)
                {
                    continue;
                }

                double maxIntensity = _intensities[_arrayLabelIndexes[i]];

                // Show peak extent indicators, if they are far enough apart
                ChromPeak peak = Chromatogram.GetPeak(i);
                AddPeakBoundaries(graphPane, annotations, false,
                                  ScaleRetentionTime(peak.StartTime), ScaleRetentionTime(peak.EndTime), maxIntensity);
            }
        }
Exemple #12
0
        public override void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g,
                                                    MSPointList pointList, GraphObjList annotations)
        {
            if (Chromatogram == null)
            {
                return;
            }

            // Give priority to showing the best peak text object above all other annotations
            if (DragInfo != null || (!HideBest && TransitionChromInfo != null) || CurveAnnotation != null)
            {
                // Show text and arrow for the best peak
                double intensityBest = 0;
                if (_bestPeakTimeIndex != -1)
                {
                    ScaledRetentionTime timeBest = new ScaledRetentionTime(_measuredTimes[_bestPeakTimeIndex], _displayTimes[_bestPeakTimeIndex]);
                    float xBest = graphPane.XAxis.Scale.Transform(timeBest.DisplayTime);
                    intensityBest = _intensities[_bestPeakTimeIndex];
                    float yBest = graphPane.YAxis.Scale.Transform(intensityBest);

                    if (GraphChromatogram.ShowRT != ShowRTChrom.none || DragInfo != null)
                    {
                        // Best peak gets its own label to avoid curve overlap detection
                        double intensityLabel = graphPane.YAxis.Scale.ReverseTransform(yBest - 5);
                        float? massError      = Settings.Default.ShowMassError && TransitionChromInfo != null
                                               ? TransitionChromInfo.MassError
                                               : null;
                        double dotProduct = _dotProducts != null ? _bestProduct : 0;

                        TextObj text;
                        if (CurveAnnotation != null)
                        {
                            // Darken peptide name a little so light colors stand out against the white background.
                            var color = FontSpec.FontColor;
                            if (!GraphInfo.IsSelected)
                            {
                                color = Color.FromArgb(color.R * 7 / 10, color.G * 7 / 10, color.B * 7 / 10);
                            }
                            var fontSpec = new FontSpec(FontSpec)
                            {
                                FontColor = color, Angle = 90
                            };
                            if (GraphInfo.IsSelected)
                            {
                                fontSpec = new FontSpec(fontSpec)
                                {
                                    IsBold = true, Size = fontSpec.Size + 2, IsAntiAlias = true
                                }
                            }
                            ;

                            // Display peptide name label using vertical text.
                            text = new TextObj(CurveAnnotation, timeBest.DisplayTime, intensityLabel,
                                               CoordType.AxisXYScale, AlignH.Left, AlignV.Center)
                            {
                                ZOrder = ZOrder.A_InFront,
                                IsClippedToChartRect = true,
                                FontSpec             = fontSpec,
                                Tag = new GraphObjTag(this, GraphObjType.best_peak, timeBest),
                            };
                        }
                        else
                        {
                            string label = FormatTimeLabel(timeBest.DisplayTime, massError, dotProduct);

                            text = new TextObj(label, timeBest.DisplayTime, intensityLabel,
                                               CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom)
                            {
                                ZOrder = ZOrder.A_InFront,
                                IsClippedToChartRect = true,
                                FontSpec             = FontSpec,
                                Tag = new GraphObjTag(this, GraphObjType.best_peak, timeBest),
                            };
                        }

                        annotations.Add(text);
                    }

                    // If showing multiple peptides, skip the best peak arrow indicator.
                    if (CurveAnnotation == null)
                    {
                        // Show the best peak arrow indicator
                        double timeArrow      = graphPane.XAxis.Scale.ReverseTransform(xBest - 4);
                        double intensityArrow = graphPane.YAxis.Scale.ReverseTransform(yBest - 2);

                        ArrowObj arrow = new ArrowObj(COLOR_BEST_PEAK, 12f,
                                                      timeArrow, intensityArrow, timeArrow, intensityArrow)
                        {
                            Location             = { CoordinateFrame = CoordType.AxisXYScale },
                            IsArrowHead          = true,
                            IsClippedToChartRect = true,
                            ZOrder = ZOrder.A_InFront
                        };
                        annotations.Add(arrow);
                    }
                }

                // Show the best peak boundary lines
                if (CurveAnnotation == null)
                {
                    double startTime = 0, endTime = 0;
                    if (DragInfo != null)
                    {
                        startTime = DragInfo.StartTime.MeasuredTime;
                        endTime   = DragInfo.EndTime.MeasuredTime;
                    }
                    else if (TransitionChromInfo != null)
                    {
                        var tranPeakInfo = TransitionChromInfo;
                        startTime = tranPeakInfo.StartRetentionTime;
                        endTime   = tranPeakInfo.EndRetentionTime;
                    }
                    AddPeakBoundaries(graphPane, annotations, true,
                                      ScaleRetentionTime(startTime), ScaleRetentionTime(endTime), intensityBest);
                }
                if (Chromatogram.BestPeakIndex >= 0)
                {
                    // Only shade peak when user modified. Otherwise, shading can be added when an entire
                    // precursor was force integrated because of another precursor (e.g. heavy) since that
                    // leads to an empty peak, which will not match the best peak.
                    if (Settings.Default.ShowOriginalPeak && TransitionChromInfo != null && TransitionChromInfo.IsUserModified)
                    {
                        var bestPeak = Chromatogram.GetPeak(Chromatogram.BestPeakIndex);
                        if (bestPeak.StartTime != TransitionChromInfo.StartRetentionTime ||
                            bestPeak.EndTime != TransitionChromInfo.EndRetentionTime)
                        {
                            AddOriginalPeakAnnotation(bestPeak, annotations, graphPane);
                        }
                    }
                }
            }
            if (_displayRawTimes.HasValue)
            {
                AddPeakRawTimes(graphPane, annotations,
                                ScaleRetentionTime(_displayRawTimes.Value.StartBound),
                                ScaleRetentionTime(_displayRawTimes.Value.EndBound),
                                Chromatogram);
            }
        }
Exemple #13
0
 public abstract void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g,
                                             MSPointList pointList, GraphObjList annotations);
Exemple #14
0
 public override void AddPreCurveAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
 {
     // Do nothing
 }
Exemple #15
0
 public void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
 {
 }
Exemple #16
0
        protected override void OnShown(EventArgs e)
        {
            var dgv = source.SpectrumListForm.GridView;

            var ionMobilityColumn = dgv.Columns["IonMobility"];

            if (ionMobilityColumn == null || !ionMobilityColumn.Visible)
            {
                throw new InvalidOperationException("cannot show heatmap if SpectrumListForm doesn't have an IonMobility column");
            }

            var scanTimeColumn   = dgv.Columns["ScanTime"];
            var ticColumn        = dgv.Columns["TotalIonCurrent"];
            var msLevelColumn    = dgv.Columns["MsLevel"];
            var dataPointsColumn = dgv.Columns["DataPoints"];
            var idColumn         = dgv.Columns["Id"];
            var mainSpectrumList = source.Source.MSDataFile.run.spectrumList;

            if (scanTimeColumn == null || ticColumn == null || msLevelColumn == null || dataPointsColumn == null)
            {
                throw new InvalidOperationException("scan time, TIC, ms level, and data points columns should never be null");
            }

            // build map of ms levels, to scan times, to scan indices

            for (int i = 0; i < dgv.RowCount; ++i)
            {
                int msLevel = (int)dgv[msLevelColumn.Index, i].Value - 1;
                while (heatmapGraphPaneByMsLevel.Count <= msLevel)
                {
                    heatmapBoundsByMsLevel.Add(new BoundingBox {
                        MinX = Double.MaxValue, MaxX = Double.MinValue, MinY = Double.MaxValue, MaxY = Double.MinValue
                    });
                    heatmapGraphPaneByMsLevel.Add(new HeatMapGraphPane()
                    {
                        ShowHeatMap  = true,
                        MinDotRadius = 4,
                        MaxDotRadius = 13,
                        //XAxis = {Title = {Text = "Scan Time"}},
                        XAxis           = { Title = { Text = "m/z" } },
                        YAxis           = { Title = { Text = "Ion Mobility" } },
                        Legend          = { IsVisible = false },
                        Title           = { Text = String.Format("Ion Mobility Heatmap (ms{0})", msLevel + 1), IsVisible = true },
                        LockYAxisAtZero = false
                    });
                    ionMobilityBinsByMsLevelAndScanTime.Add(new Map <double, List <MobilityBin> >());
                }

                int dataPoints = Convert.ToInt32(dgv[dataPointsColumn.Index, i].Value);
                if (dataPoints == 0)
                {
                    continue;
                }

                double scanTime    = (double)dgv[scanTimeColumn.Index, i].Value;
                double ionMobility = (double)dgv[ionMobilityColumn.Index, i].Value;
                if (ionMobility == 0)
                {
                    var s             = mainSpectrumList.spectrum(i, true);
                    var mobilityArray = s.getArrayByCVID(pwiz.CLI.cv.CVID.MS_mean_drift_time_array);
                    if (mobilityArray == null)
                    {
                        mobilityArray = s.getArrayByCVID(pwiz.CLI.cv.CVID.MS_mean_inverse_reduced_ion_mobility_array);
                        if (mobilityArray == null)
                        {
                            continue;
                        }
                    }
                    var mobilityBins = mobilityArray.data;
                    foreach (double bin in mobilityBins)
                    {
                        ionMobilityBinsByMsLevelAndScanTime[msLevel][scanTime].Add(new MobilityBin(bin, i));
                    }
                }
                else
                {
                    ionMobilityBinsByMsLevelAndScanTime[msLevel][scanTime].Add(new MobilityBin(ionMobility, i));
                }

                //double intensity = (double) dgv[ticColumn.Index, i].Value;
            }

            var g = msGraphControl.CreateGraphics();

            msGraphControl.MasterPane.PaneList.Clear();
            int numColumns = ionMobilityBinsByMsLevelAndScanTime.Count(o => !o.IsNullOrEmpty()); // skip empty MS levels (e.g. files with only MS2)
            var rowCounts  = new int[2] {
                numColumns, numColumns
            };

            msGraphControl.MasterPane.SetLayout(g, true, rowCounts, new float[2] {
                0.25f, 0.75f
            });

            // first row is control chromatograms
            for (int i = 0; i < heatmapGraphPaneByMsLevel.Count; ++i)
            {
                if (ionMobilityBinsByMsLevelAndScanTime[i].IsNullOrEmpty())
                {
                    ticChromatogramByMsLevel.Add(null);
                    continue; // skip empty MS levels (e.g. files with only MS2)
                }

                var chromatogramPane = new MSGraphPane()
                {
                    Legend = { IsVisible = false },
                    Title  = { Text = String.Format("TIC Chromatogram (ms{0})", i + 1), IsVisible = true },
                    Tag    = i
                };
                msGraphControl.MasterPane.Add(chromatogramPane);

                ticChromatogramByMsLevel.Add(new ChromatogramControl(source, i + 1, chromatogramPane));
                msGraphControl.AddGraphItem(chromatogramPane, ticChromatogramByMsLevel[i], true);
            }

            // second row is heatmaps
            for (int i = 0; i < heatmapGraphPaneByMsLevel.Count; ++i)
            {
                if (ionMobilityBinsByMsLevelAndScanTime[i].IsNullOrEmpty())
                {
                    continue; // skip empty MS levels (e.g. files with only MS2)
                }
                var heatmapGraphPane = heatmapGraphPaneByMsLevel[i];
                msGraphControl.MasterPane.Add(heatmapGraphPane);

                heatmapGraphPane.GraphObjList.Add(new TextObj("Click on a chromatogram point to generate an IMS heatmap...", 0.5, 0.5, CoordType.ChartFraction)
                {
                    FontSpec = new FontSpec {
                        Border = new Border {
                            IsVisible = false
                        }, IsBold = true, Size = 16
                    }
                });

                var bounds = heatmapBoundsByMsLevel[i];
                setScale(heatmapGraphPane.XAxis.Scale, 0, 2000);
                setScale(heatmapGraphPane.YAxis.Scale, 0, 100);
                heatmapGraphPane.AxisChange(g);
                heatmapGraphPane.SetScale(g);
            }
            //msGraphControl.PerformAutoScale();
            msGraphControl.MasterPane.DoLayout(g);
            msGraphControl.Refresh();

            base.OnShown(e);
        }
Exemple #17
0
        protected override void OnShown(EventArgs e)
        {
            var dgv = Source.SpectrumListForm.GridView;

            var ionMobilityColumn = dgv.Columns["IonMobility"];
            //if (ionMobilityColumn == null || !ionMobilityColumn.Visible)
            //    throw new InvalidOperationException("cannot show heatmap if SpectrumListForm doesn't have an IonMobility column");

            var scanTimeColumn    = dgv.Columns["ScanTime"];
            var ticColumn         = dgv.Columns["TotalIonCurrent"];
            var msLevelColumn     = dgv.Columns["MsLevel"];
            var isolationMzColumn = dgv.Columns["PrecursorInfo"];
            var dataPointsColumn  = dgv.Columns["DataPoints"];
            var indexColumn       = dgv.Columns["Index"];
            var idColumn          = dgv.Columns["Id"];
            var mainSpectrumList  = Source.Source.MSDataFile.run.spectrumList;

            if (scanTimeColumn == null || ticColumn == null || msLevelColumn == null || dataPointsColumn == null)
            {
                throw new InvalidOperationException("scan time, TIC, ms level, and data points columns should never be null");
            }

            // build map of ms levels, to scan times, to scan indices;
            // group keys are ms level and scan time, aggregated values are isolation m/z and spectrum index
            var ionMobilityRows = GetIonMobilityRows().GroupBy(r => new Tuple <int, double>((int)r.Cells[msLevelColumn.Index].Value, (double)r.Cells[scanTimeColumn.Index].Value),
                                                               r => new Tuple <double, int>(ToDoubleOrDefault(r.Cells[isolationMzColumn.Index].Value), r.Index));

            foreach (var group in ionMobilityRows)
            {
                int msLevel = group.Key.Item1 - 1;
                while (heatmapGraphPaneByMsLevel.Count <= msLevel)
                {
                    heatmapGraphPaneByMsLevel.Add(new HeatMapGraphPane()
                    {
                        ShowHeatMap  = true,
                        MinDotRadius = 4,
                        MaxDotRadius = 13,
                        //XAxis = {Title = {Text = "Scan Time"}},
                        XAxis           = { Title = { Text = "m/z" } },
                        YAxis           = { Title = { Text = "Ion Mobility" } },
                        Legend          = { IsVisible = false },
                        Title           = { Text = String.Format("Ion Mobility Heatmap (ms{0})", msLevel + 1), IsVisible = true },
                        LockYAxisAtZero = false
                    });
                    ionMobilityBinsByMsLevelAndScanTime.Add(new Map <double, MobilityData>());
                }

                double scanTime = group.Key.Item2;

                ionMobilityBinsByMsLevelAndScanTime[msLevel][scanTime] = new MobilityData(mainSpectrumList, scanTime,
                                                                                          (int)group.Min(o => o.Item2),
                                                                                          (int)group.Max(o => o.Item2));
                if (msLevel + 1 == 2)
                {
                    isolationMzByScanTime[scanTime] = group.Select(o => o.Item1.ToString()).ToList();
                }

                //double intensity = (double) dgv[ticColumn.Index, i].Value;
            }

            var g = msGraphControl.CreateGraphics();

            msGraphControl.MasterPane.PaneList.Clear();
            int numColumns = ionMobilityBinsByMsLevelAndScanTime.Count(o => !o.IsNullOrEmpty()); // skip empty MS levels (e.g. files with only MS2)
            var rowCounts  = new int[2] {
                numColumns, numColumns
            };

            msGraphControl.MasterPane.SetLayout(g, true, rowCounts, new float[2] {
                0.25f, 0.75f
            });

            heatmapPointsCache = new MemoryCache <MobilityData, Tuple <List <Point3D>, BoundingBox> >(ionMobilityBinsByMsLevelAndScanTime.Count);

            // first row is control chromatograms
            for (int i = 0; i < heatmapGraphPaneByMsLevel.Count; ++i)
            {
                if (ionMobilityBinsByMsLevelAndScanTime[i].IsNullOrEmpty())
                {
                    ticChromatogramByMsLevel.Add(null);
                    continue; // skip empty MS levels (e.g. files with only MS2)
                }

                var chromatogramPane = new MSGraphPane()
                {
                    Legend = { IsVisible = false },
                    Title  = { Text = String.Format("TIC Chromatogram (ms{0})", i + 1), IsVisible = true },
                    Tag    = i
                };
                msGraphControl.MasterPane.Add(chromatogramPane);

                ticChromatogramByMsLevel.Add(new ChromatogramControl(Source, i + 1, chromatogramPane));
                msGraphControl.AddGraphItem(chromatogramPane, ticChromatogramByMsLevel[i], true);
            }

            // second row is heatmaps
            for (int i = 0; i < heatmapGraphPaneByMsLevel.Count; ++i)
            {
                if (ionMobilityBinsByMsLevelAndScanTime[i].IsNullOrEmpty())
                {
                    continue; // skip empty MS levels (e.g. files with only MS2)
                }
                var heatmapGraphPane = heatmapGraphPaneByMsLevel[i];
                msGraphControl.MasterPane.Add(heatmapGraphPane);

                heatmapGraphPane.GraphObjList.Add(new TextObj("Click on a chromatogram point to generate an IMS heatmap...", 0.5, 0.5, CoordType.ChartFraction)
                {
                    FontSpec = new FontSpec {
                        Border = new Border {
                            IsVisible = false
                        }, IsBold = true, Size = 16
                    }
                });

                setScale(heatmapGraphPane.XAxis.Scale, 0, 2000);
                setScale(heatmapGraphPane.YAxis.Scale, 0, 100);
                heatmapGraphPane.AxisChange(g);
                heatmapGraphPane.SetScale(g);
            }
            //msGraphControl.PerformAutoScale();
            msGraphControl.MasterPane.DoLayout(g);
            msGraphControl.Refresh();

            base.OnShown(e);
        }
Exemple #18
0
        public override void Refresh()
        {
            MasterPane mp = msGraphControl.MasterPane;

            mp.Border.IsVisible = false;
            //pane.Chart.Border.IsVisible = false;

            if (mp.PaneList.Count != paneList.Count)
            {
                mp.PaneList.Clear();
                foreach (Pane logicalPane in paneList)
                {
                    MSGraphPane pane = new MSGraphPane();
                    pane.Border.IsVisible        = false;
                    pane.IsFontsScaled           = false;
                    pane.YAxis.ScaleFormatEvent += YAxis_ScaleFormatEvent;
                    mp.Add(pane);
                }
                //mp.SetLayout( msGraphControl.CreateGraphics(), paneLayout );
            }
            else
            {
                for (int i = 0; i < paneList.Count; ++i)
                {
                    MSGraphPane pane = mp.PaneList[i] as MSGraphPane;
                    pane.Border.IsVisible = false;
                    pane.CurveList.Clear();
                    pane.GraphObjList.Clear();
                }
            }

            for (int i = 0; i < paneList.Count; ++i)
            {
                Pane        logicalPane = paneList[i];
                MSGraphPane pane        = mp.PaneList[i] as MSGraphPane;
                pane.IsFontsScaled    = false;
                pane.Border.IsVisible = false;

                bool needSourceNamePrefix = logicalPane.Select(o => o.Source).Distinct().Count() > 1;
                int  maxAutoLegendItems   = needSourceNamePrefix ? 5 : 10;

                foreach (GraphItem item in logicalPane.Take(logicalPane.Count - 1))
                {
                    //item.AddSourceToId = needSourceNamePrefix;
                    msGraphControl.AddGraphItem(pane, item, false);
                }
                //logicalPane.Last().AddSourceToId = needSourceNamePrefix;
                msGraphControl.AddGraphItem(pane, logicalPane.Last(), true);

                if (mp.PaneList.Count > 1)
                {
                    if (msGraphControl.IsSynchronizeXAxes && i < paneList.Count - 1)
                    {
                        pane.XAxis.Title.IsVisible = false;
                        pane.XAxis.Scale.IsVisible = false;
                        pane.Margin.Bottom         = 0;
                        //pane.Margin.Top = 0;
                    }
                    else
                    {
                        //pane.Margin.Top = 0;
                        pane.XAxis.Title.IsVisible = true;
                        pane.XAxis.Scale.IsVisible = true;
                    }
                    pane.YAxis.Title.IsVisible = true;
                    pane.YAxis.Scale.IsVisible = true;
                    pane.YAxis.Title.Text      = String.Join(", ", logicalPane.Select(o => o.Title)) + "\n" + pane.YAxis.Title.Text.Split('\n').Last();
                    pane.YAxis.Scale.SetupScaleData(pane, pane.YAxis);
                }
                else
                {
                    pane.XAxis.IsVisible       = true;
                    pane.XAxis.Title.IsVisible = true;
                    pane.XAxis.Scale.IsVisible = true;
                    pane.YAxis.Title.IsVisible = true;
                    pane.YAxis.Scale.IsVisible = true;
                }

                if (logicalPane.Count == 1)
                {
                    pane.Legend.IsVisible = false;
                }
                else
                {
                    pane.Legend.IsVisible = ShowPaneLegends ?? (logicalPane.Count < maxAutoLegendItems);
                    pane.Legend.Position  = ZedGraph.LegendPos.TopCenter;

                    ZedGraph.ColorSymbolRotator rotator = new ColorSymbolRotator();
                    foreach (CurveItem item in pane.CurveList)
                    {
                        item.Color = rotator.NextColor;
                    }
                }

                if (paneList.Count > 0 && paneList[0].Count > 0)
                {
                    this.Text = paneList[0][0].Id;
                    if (paneList[0][0].IsMassSpectrum)
                    {
                        this.TabText = (paneList[0][0] as MassSpectrum).AbbreviatedId;
                    }
                    else
                    {
                        this.TabText = this.Text;
                    }
                }

                if (pane.XAxis.Scale.MaxAuto)
                {
                    using (Graphics g = msGraphControl.CreateGraphics())
                    {
                        if (msGraphControl.IsSynchronizeXAxes || msGraphControl.IsSynchronizeYAxes)
                        {
                            foreach (GraphPane p in msGraphControl.MasterPane.PaneList)
                            {
                                p.XAxis.ResetAutoScale(p, g);
                                p.X2Axis.ResetAutoScale(p, g);
                                foreach (YAxis axis in p.YAxisList)
                                {
                                    axis.ResetAutoScale(p, g);
                                }
                                foreach (Y2Axis axis in p.Y2AxisList)
                                {
                                    axis.ResetAutoScale(p, g);
                                }
                            }
                        }
                        else
                        {
                            pane.XAxis.ResetAutoScale(pane, g);
                            pane.X2Axis.ResetAutoScale(pane, g);
                            foreach (YAxis axis in pane.YAxisList)
                            {
                                axis.ResetAutoScale(pane, g);
                            }
                            foreach (Y2Axis axis in pane.Y2AxisList)
                            {
                                axis.ResetAutoScale(pane, g);
                            }
                        }
                    }
                    //msGraphControl.RestoreScale(pane);
                }
                else
                {
                    pane.AxisChange();
                }
            }

            mp.SetLayout(msGraphControl.CreateGraphics(), paneLayout);

            /*if( isOverlay )
             * {
             *  pane.Legend.IsVisible = true;
             *  pane.Legend.Position = ZedGraph.LegendPos.TopCenter;
             *  for( int i = 0; i < pane.CurveList.Count; ++i )
             *  {
             *      pane.CurveList[i].Color = overlayColors[i];
             *      ( pane.CurveList[i] as ZedGraph.LineItem ).Line.Width = 2;
             *  }
             * } else
             * {
             *  pane.Legend.IsVisible = false;
             *  currentGraphItem = chromatogram;
             * }*/

            //msGraphControl.RestoreScale( pane );
            //msGraphControl.ZoomOutAll( pane );

            /*bool isScaleAuto = !pane.IsZoomed;
             *
             * if( isScaleAuto )
             *  pointList.SetScale( bins, pointList[0].X, pointList[pointList.Count - 1].X );
             * else
             *  pointList.SetScale( bins, pane.XAxis.Scale.Min, pane.XAxis.Scale.Max );*/

            // String.Format( "{0} - {1}", currentDataSource.Name, chromatogram.Id )

            if (mp.PaneList.Count > 0 &&
                (focusedPane == null ||
                 !mp.PaneList.Contains(focusedPane)))
            {
                focusedPane = mp.PaneList[0] as MSGraphPane;
            }

            if (mp.PaneList.Count > 0 &&
                mp.PaneList[0].CurveList.Count > 0 &&
                (focusedItem == null ||
                 //!focusedPane.CurveList.Contains( focusedItem ) ) ) // somehow focusedItem.Tag can be the same as one of focusedPane.CurveList's Tags, but Contains returns false
                 !focusedPane.CurveList.Any(o => o.Tag == focusedItem.Tag)))
            {
                setFocusedItem(mp.PaneList[0].CurveList[0]);
            }

            msGraphControl.Refresh();
        }
Exemple #19
0
        public override void AddAnnotations(MSGraphPane graphPane, Graphics g, MSPointList pointList, GraphObjList annotations)
        {
            // ReSharper disable UseObjectOrCollectionInitializer
            foreach (var rmi in SpectrumInfo.PeaksMatched)
            {
                if (!IsVisibleIon(rmi))
                {
                    continue;
                }

                var matchedIon = rmi.MatchedIons.First(IsVisibleIon);

                Color color;
                switch (matchedIon.IonType)
                {
                default: color = COLOR_NONE; break;

                case IonType.a: color = COLOR_A; break;

                case IonType.x: color = COLOR_X; break;

                case IonType.b: color = COLOR_B; break;

                case IonType.y: color = COLOR_Y; break;

                case IonType.c: color = COLOR_C; break;

                case IonType.z: color = COLOR_Z; break;

                case IonType.custom: color = (rmi.Rank > 0) ? COLOR_OTHER_IONS : COLOR_NONE; break;     // Small molecule fragments - only color if ranked

                case IonType.precursor: color = COLOR_PRECURSOR; break;
                }

                if (Invert)
                {
                    color = InvertColor(color);
                }

                if (rmi.MatchedIons.Any(mfi => IsMatch(mfi.PredictedMz)))
                {
                    color = COLOR_SELECTED;
                }

                double mz        = rmi.ObservedMz;
                var    intensity = Invert ? -rmi.Intensity : rmi.Intensity;
                var    stick     = new LineObj(color, mz, intensity, mz, 0);
                stick.IsClippedToChartRect     = true;
                stick.Location.CoordinateFrame = CoordType.AxisXYScale;
                stick.Line.Width = LineWidth + 1;
                annotations.Add(stick);
            }
            //ReSharper restore UseObjectOrCollectionInitializer

            if (ShowScores && SpectrumInfo.Score.HasValue)
            {
                var text = new TextObj(
                    string.Format(LocalizationHelper.CurrentCulture, Resources.AbstractSpectrumGraphItem_AddAnnotations_, SpectrumInfo.Score),
                    0.01, 0, CoordType.ChartFraction, AlignH.Left, AlignV.Top)
                {
                    IsClippedToChartRect = true,
                    ZOrder   = ZOrder.E_BehindCurves,
                    FontSpec = GraphSummary.CreateFontSpec(Color.Black),
                };
                annotations.Add(text);
            }
        }
Exemple #20
0
        public override void Refresh()
        {
            MasterPane mp = msGraphControl.MasterPane;

            mp.Border.IsVisible = false;
            //pane.Chart.Border.IsVisible = false;

            if (mp.PaneList.Count != paneList.Count)
            {
                mp.PaneList.Clear();
                foreach (Pane logicalPane in paneList)
                {
                    MSGraphPane pane = new MSGraphPane();
                    pane.Border.IsVisible = false;
                    pane.IsFontsScaled    = false;
                    mp.Add(pane);
                }
                //mp.SetLayout( msGraphControl.CreateGraphics(), paneLayout );
            }
            else
            {
                for (int i = 0; i < paneList.Count; ++i)
                {
                    MSGraphPane pane = mp.PaneList[i] as MSGraphPane;
                    pane.Border.IsVisible = false;
                    pane.CurveList.Clear();
                    pane.GraphObjList.Clear();
                }
            }

            for (int i = 0; i < paneList.Count; ++i)
            {
                Pane        logicalPane = paneList[i];
                MSGraphPane pane        = mp.PaneList[i] as MSGraphPane;
                pane.IsFontsScaled    = false;
                pane.Border.IsVisible = false;

                foreach (GraphItem item in logicalPane)
                {
                    msGraphControl.AddGraphItem(pane, item);
                }

                if (mp.PaneList.Count > 1)
                {
                    //if( i < paneList.Count - 1 )
                    {
                        pane.XAxis.Title.IsVisible = false;
                        pane.XAxis.Scale.IsVisible = false;
                        pane.Margin.Bottom         = 0;
                        pane.Margin.Top            = 2;
                    }/* else
                      * {
                      * pane.XAxis.Title.IsVisible = true;
                      * pane.XAxis.Scale.IsVisible = true;
                      * }*/
                    pane.YAxis.Title.IsVisible = false;
                    pane.YAxis.Scale.IsVisible = false;
                    pane.YAxis.Scale.SetupScaleData(pane, pane.YAxis);
                }
                else
                {
                    pane.XAxis.IsVisible       = true;
                    pane.XAxis.Title.IsVisible = true;
                    pane.XAxis.Scale.IsVisible = true;
                    pane.YAxis.Title.IsVisible = true;
                    pane.YAxis.Scale.IsVisible = true;
                }

                if (logicalPane.Count == 1)
                {
                    pane.Legend.IsVisible = false;
                }
                else
                {
                    pane.Legend.IsVisible = true;
                    pane.Legend.Position  = ZedGraph.LegendPos.TopCenter;

                    ZedGraph.ColorSymbolRotator rotator = new ColorSymbolRotator();
                    foreach (CurveItem item in pane.CurveList)
                    {
                        item.Color = rotator.NextColor;
                    }
                }

                if (paneList.Count > 0 && paneList[0].Count > 0)
                {
                    this.Text = paneList[0][0].Id;
                    if (paneList[0][0].IsMassSpectrum)
                    {
                        this.TabText = pwiz.CLI.msdata.id.abbreviate(paneList[0][0].Id);
                    }
                    else
                    {
                        this.TabText = this.Text;
                    }
                }

                if (pane.XAxis.Scale.MaxAuto)
                {
                    msGraphControl.RestoreScale(pane);
                }
                else
                {
                    pane.AxisChange();
                }
            }

            mp.SetLayout(msGraphControl.CreateGraphics(), paneLayout);

            /*if( isOverlay )
             * {
             *  pane.Legend.IsVisible = true;
             *  pane.Legend.Position = ZedGraph.LegendPos.TopCenter;
             *  for( int i = 0; i < pane.CurveList.Count; ++i )
             *  {
             *      pane.CurveList[i].Color = overlayColors[i];
             *      ( pane.CurveList[i] as ZedGraph.LineItem ).Line.Width = 2;
             *  }
             * } else
             * {
             *  pane.Legend.IsVisible = false;
             *  currentGraphItem = chromatogram;
             * }*/

            //msGraphControl.RestoreScale( pane );
            //msGraphControl.ZoomOutAll( pane );

            /*bool isScaleAuto = !pane.IsZoomed;
             *
             * if( isScaleAuto )
             *  pointList.SetScale( bins, pointList[0].X, pointList[pointList.Count - 1].X );
             * else
             *  pointList.SetScale( bins, pane.XAxis.Scale.Min, pane.XAxis.Scale.Max );*/

            // String.Format( "{0} - {1}", currentDataSource.Name, chromatogram.Id )

            if (mp.PaneList.Count > 0 &&
                (focusedPane == null ||
                 !mp.PaneList.Contains(focusedPane)))
            {
                focusedPane = mp.PaneList[0] as MSGraphPane;
            }

            if (mp.PaneList.Count > 0 &&
                mp.PaneList[0].CurveList.Count > 0 &&
                (focusedItem == null ||
                 !focusedPane.CurveList.Contains(focusedItem)))
            {
                setFocusedItem(mp.PaneList[0].CurveList[0]);
            }

            msGraphControl.Refresh();
        }