Пример #1
0
        private void ShowHeatmaps()
        {
            var dgv                    = source.SpectrumListForm.GridView;
            var scanTimeColumn         = dgv.Columns["ScanTime"];
            var msLevelColumn          = dgv.Columns["MsLevel"];
            var heatmapPointsByMsLevel = new List <List <Point3D> >(dgv.RowCount);

            var msLevels = new Set <int>();

            for (int i = 0; i < dgv.RowCount; ++i)
            {
                msLevels.Add((int)dgv[msLevelColumn.Index, i].Value - 1);
            }

            while (heatmapPointsByMsLevel.Count <= msLevels.Max)
            {
                heatmapPointsByMsLevel.Add(new List <Point3D>());
            }

            var peakPicker = new pwiz.CLI.analysis.SpectrumList_PeakPicker(source.Source.MSDataFile.run.spectrumList, new pwiz.CLI.analysis.CwtPeakDetector(1, 0.5), true, new int[] { 1 });

            for (int i = 0; i < dgv.RowCount; ++i)
            {
                int msLevel          = (int)dgv[msLevelColumn.Index, i].Value - 1;
                var heatmapGraphPane = heatmapGraphPaneByMsLevel[msLevel];
                var heatmapPoints    = heatmapPointsByMsLevel[msLevel];

                if (i == 0 || i + 1 == dgv.RowCount || ((i + 1) % 1000) == 0)
                {
                    heatmapGraphPane.CurveList.Clear();
                    heatmapGraphPane.GraphObjList.Add(new TextObj(String.Format("Loading {0}/{1}", i + 1, dgv.RowCount), 0.5, 0.5, CoordType.ChartFraction)
                    {
                        FontSpec = new FontSpec {
                            Border = new Border {
                                IsVisible = false
                            }, IsBold = true, Size = 24
                        }
                    });
                    msGraphControl.Refresh();
                }
                Application.DoEvents();

                var    bounds   = heatmapBoundsByMsLevel[msLevel];
                var    spectrum = source.GetMassSpectrum(source.Source.Spectra[i].Index, peakPicker);
                double scanTime = (double)dgv[scanTimeColumn.Index, i].Value;
                var    points   = spectrum.Points;
                for (int j = 0; j < points.Count; ++j)
                {
                    double intensity = points[j].Y;
                    if (intensity == 0)
                    {
                        continue;
                    }

                    double mz = points[j].X;
                    bounds.MinX = Math.Min(bounds.MinX, mz);
                    bounds.MinY = Math.Min(bounds.MinY, scanTime);
                    bounds.MaxX = Math.Max(bounds.MaxX, mz);
                    bounds.MaxY = Math.Max(bounds.MaxY, scanTime);

                    heatmapPoints.Add(new Point3D(mz, scanTime, intensity));
                }
            }

            var g = msGraphControl.CreateGraphics();

            foreach (int msLevel in msLevels)
            {
                var bounds           = heatmapBoundsByMsLevel[msLevel];
                var heatmapData      = new HeatMapData(heatmapPointsByMsLevel[msLevel]);
                var heatmapGraphPane = heatmapGraphPaneByMsLevel[msLevel];
                heatmapGraphPane.GraphObjList.Clear(); // remove "Loading..."
                heatmapGraphPane.SetPoints(heatmapData, bounds.MinY, bounds.MaxY);
                heatmapGraphPane.Title.Text = String.Format("Time to m/z Heatmap (ms{0})", msLevel + 1);

                setScale(heatmapGraphPane.XAxis.Scale, bounds.MinX, bounds.MaxX);
                setScale(heatmapGraphPane.YAxis.Scale, bounds.MinY, bounds.MaxY);

                heatmapGraphPane.AxisChange(g);
                heatmapGraphPane.SetScale(g);
                msGraphControl.Refresh();
            }
        }
Пример #2
0
        private void ShowHeatmap(double scanTime, int msLevel)
        {
            if (ionMobilityBinsByMsLevelAndScanTime.Count <= msLevel)
            {
                throw new ArgumentOutOfRangeException("msLevel", "no ion mobility bins for ms level " + msLevel);
            }

            var ionMobilityBinsByScanTime = ionMobilityBinsByMsLevelAndScanTime[msLevel];

            if (!ionMobilityBinsByScanTime.Contains(scanTime))
            {
                throw new ArgumentOutOfRangeException("scanTime", "no ion mobility bins for scan time " + scanTime);
            }

            var ionMobilityBins = ionMobilityBinsByScanTime[scanTime];
            var heatmapPoints   = new List <Point3D>(ionMobilityBins.Count);

            var heatmapGraphPane = heatmapGraphPaneByMsLevel[msLevel];

            heatmapGraphPane.CurveList.Clear();
            heatmapGraphPane.GraphObjList.Add(new TextObj("Loading...", 0.5, 0.5, CoordType.ChartFraction)
            {
                FontSpec = new FontSpec {
                    Border = new Border {
                        IsVisible = false
                    }, IsBold = true, Size = 24
                }
            });
            msGraphControl.Refresh();

            var bounds = heatmapBoundsByMsLevel[msLevel];

            foreach (var bin in ionMobilityBins)
            {
                var spectrum = source.GetMassSpectrum(bin.BinIndex);
                var points   = spectrum.Points;
                for (int j = 0; j < points.Count; ++j)
                {
                    double mz        = points[j].X;
                    double intensity = points[j].Y;
                    bounds.MinX = Math.Min(bounds.MinX, mz);
                    bounds.MinY = Math.Min(bounds.MinY, bin.IonMobility);
                    bounds.MaxX = Math.Max(bounds.MaxX, mz);
                    bounds.MaxY = Math.Max(bounds.MaxY, bin.IonMobility);

                    heatmapPoints.Add(new Point3D(mz, bin.IonMobility, intensity));
                }
            }

            var g           = msGraphControl.CreateGraphics();
            var heatmapData = new HeatMapData(heatmapPoints);

            heatmapGraphPane.GraphObjList.Clear(); // remove "Loading..."
            heatmapGraphPane.SetPoints(heatmapData, bounds.MinY, bounds.MaxY);
            heatmapGraphPane.Title.Text = String.Format("Ion Mobility Heatmap (ms{0} @ {1:F4} min.)", msLevel + 1, scanTime);

            setScale(heatmapGraphPane.XAxis.Scale, bounds.MinX, bounds.MaxX);
            setScale(heatmapGraphPane.YAxis.Scale, bounds.MinY, bounds.MaxY);

            heatmapGraphPane.AxisChange(g);
            heatmapGraphPane.SetScale(g);
            msGraphControl.Refresh();
        }