private void SetSpectraUI(MsDataSpectrum[] spectra)
        {
            _msDataFileScanHelper.MsDataSpectra = spectra;
            _heatMapData = null;
            if (_msDataFileScanHelper.MsDataSpectra == null)
            {
                return;
            }

            // Find max values.
            _maxMz        = 0;
            _maxIntensity = 0;
            GetMaxMzIntensity(out _maxMz, out _maxIntensity);
            _maxDriftTime = 0;
            foreach (var spectrum in spectra)
            {
                _maxDriftTime = Math.Max(_maxDriftTime, spectrum.DriftTimeMsec ?? 0);
            }

            if (_zoomXAxis)
            {
                _zoomXAxis = false;
                ZoomXAxis();
            }
            if (_zoomYAxis)
            {
                _zoomYAxis = false;
                ZoomYAxis();
            }
            CreateGraph();
            UpdateUI();
        }
Beispiel #2
0
        private void SetSpectraUI(MsDataSpectrum[] spectra)
        {
            _msDataFileScanHelper.MsDataSpectra = spectra;
            _heatMapData = null;
            if (_msDataFileScanHelper.MsDataSpectra == null)
            {
                return;
            }

            // Find max values.
            _maxMz        = 0;
            _maxIntensity = 0;
            GetMaxMzIntensity(out _maxMz, out _maxIntensity);
            GetMaxMobility(out _maxIonMobility);

            if (_zoomXAxis)
            {
                _zoomXAxis = false;
                ZoomXAxis();
            }
            if (_zoomYAxis)
            {
                _zoomYAxis = false;
                ZoomYAxis();
            }
            CreateGraph();
            UpdateUI();
        }
Beispiel #3
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 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 mobilityData       = ionMobilityBinsByScanTime[scanTime];
            var heatmapPointsTuple = heatmapPointsCache.GetOrAdd(mobilityData, o => o.Get3dSpectrum(), mobilityData);
            var bounds             = heatmapPointsTuple.Item2;

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

            heatmapGraphPane.GraphObjList.Clear(); // remove "Loading..."
            heatmapGraphPane.SetPoints(heatmapData, bounds.MinY, bounds.MaxY);

            string isolationMzTitle = String.Empty;

            if (msLevel + 1 == 2)
            {
                isolationMzTitle = " for isolation m/z " + String.Join(", ", isolationMzByScanTime[scanTime].Distinct());
            }

            heatmapGraphPane.Title.Text = String.Format("Ion Mobility Heatmap (ms{0} @ {1:F4} {3}{2})", msLevel + 1, scanTime, isolationMzTitle,
                                                        Properties.Settings.Default.TimeInMinutes ? "min." : "sec.");

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

            heatmapGraphPane.AxisChange(g);
            heatmapGraphPane.SetScale(g);
            msGraphControl.Refresh();
        }
Beispiel #4
0
        //function for printing out HeatMap structure data
        public static void printInfo(HeatMapData data)
        {
            double total_time = 0;

            Console.WriteLine("\nts: " + data.ts);

            Console.WriteLine("player_name: " + data.player_name);

            Console.WriteLine("gridType: " + data.gridType);
            foreach (var item in data.heatmap)
            {
                total_time += item.Value;
            }
            foreach (var item in data.heatmap)
            {
                Console.WriteLine("index: " + item.Key + "  time % : " + (item.Value / total_time) * 100);
            }
        }
Beispiel #5
0
        public float GetGrayColorRatio(int indexInitialDesired, int indexFinalDesired, int axisDivisionFactr, string requirementName)
        {
            float        grayColorRatio;
            HeatMapPoint correspondingHeatMapPoint = HeatMapData.Find(
                delegate(HeatMapPoint heatMapPoint){
                return((heatMapPoint.indexX == indexInitialDesired) && (heatMapPoint.indexY == indexFinalDesired));
            });

            grayColorRatio  = correspondingHeatMapPoint.objectiveFunctionValues[requirementName];
            grayColorRatio -= minimumValueOfObjectiveFunctions[requirementName];
            if ((maximumValueOfObjectiveFunctions[requirementName] - minimumValueOfObjectiveFunctions[requirementName]) != 0)
            {
                grayColorRatio /= (maximumValueOfObjectiveFunctions[requirementName] - minimumValueOfObjectiveFunctions[requirementName]);
            }
            else
            {
                grayColorRatio = 0;
            }
            return(grayColorRatio);
        }
Beispiel #6
0
        /// <summary>
        /// Registers Properties for Heat Map
        /// </summary>
        /// <param name="shape">Map Shape</param>
        private void SetAdditionalData(MapShape shape)
        {
            ExtendedData data = shape.ExtendedData;

            if (data != null)
            {
                if (!data.PropertySet.ContainsKey(COUNTRY_PERFORMANCE_FIELD))
                {
                    data.PropertySet.RegisterProperty(COUNTRY_PERFORMANCE_FIELD, "CountryPerformance", typeof(int), 0);
                }
                if (!data.PropertySet.ContainsKey(COUNTRY_YTD_FIELD))
                {
                    data.PropertySet.RegisterProperty(COUNTRY_YTD_FIELD, "CountryYTD", typeof(Decimal), Convert.ToDecimal(0));
                }
                if (!data.PropertySet.ContainsKey(BENCHMARK_YTD_FIELD))
                {
                    data.PropertySet.RegisterProperty(BENCHMARK_YTD_FIELD, "BenchmarkYTD", typeof(Decimal), Convert.ToDecimal(0));
                }

                if (heatMapInfo != null)
                {
                    string      countryID     = (string)shape.ExtendedData.GetValue("ISO_2DIGIT");
                    HeatMapData countryRecord = heatMapInfo.Where(r => r.CountryID == countryID).FirstOrDefault();

                    if (countryRecord != null)
                    {
                        shape.ExtendedData.SetValue(COUNTRY_PERFORMANCE_FIELD, (int)(countryRecord.CountryPerformance));
                        shape.ExtendedData.SetValue(COUNTRY_YTD_FIELD, countryRecord.CountryYTD);
                        shape.ExtendedData.SetValue(BENCHMARK_YTD_FIELD, countryRecord.BenchmarkYTD);
                        AddColorizerToInformationLayer(shape, countryRecord);
                    }
                    else
                    {
                        shape.ExtendedData.SetValue(COUNTRY_PERFORMANCE_FIELD, null);
                        shape.ExtendedData.SetValue(COUNTRY_YTD_FIELD, null);
                        shape.ExtendedData.SetValue(BENCHMARK_YTD_FIELD, null);
                        AddTransparentColorizerToInformationLayer(shape);
                    }
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Adding Colour to Each Shape
 /// </summary>
 /// <param name="shape">Shape</param>
 /// <param name="countryRecord">Country record of type heat map data</param>
 private void AddColorizerToInformationLayer(MapShape shape, HeatMapData countryRecord)
 {
     if ((int)(countryRecord.CountryPerformance) == 3)
     {
         shape.Fill = new SolidColorBrush(Colors.Green);
     }
     else
     if ((int)(countryRecord.CountryPerformance) == 1)
     {
         shape.Fill = new SolidColorBrush(Colors.Red);
     }
     else
     if ((int)(countryRecord.CountryPerformance) == 2)
     {
         shape.Fill = new SolidColorBrush(Colors.Gray);
     }
     else
     if ((int)(countryRecord.CountryPerformance) == 0)
     {
         shape.Fill = new SolidColorBrush(Colors.White);
     }
 }
Beispiel #8
0
        //aggregatorFunction used in TimeWindow based aggregation
        private static HeatMapData aggregatorFunction(HeatMapData seed, TimeInCell curr,
                                                      IList <TimeInCell> expList, long count)
        {
            HeatMapData new_seed = new HeatMapData {
                ts       = curr.ts, player_name = curr.player_name,
                gridType = curr.gridType, heatmap = seed.heatmap
            };

            foreach (var item in expList)
            {
                if (item.time_in_cell != -999)
                {
                    if (new_seed.heatmap.ContainsKey(item.prev_index))
                    {
                        new_seed.heatmap[item.prev_index] -= item.time_in_cell;
                        if (new_seed.heatmap[item.prev_index] <= 0)
                        {
                            new_seed.heatmap.Remove(item.prev_index);
                        }
                    }
                    else
                    {
                        Console.WriteLine("HeatMapProcessor: Attempt to access non-existent key");
                    }
                }
            }
            if (curr.time_in_cell != -999)
            {
                if (new_seed.heatmap.ContainsKey(curr.prev_index))
                {
                    new_seed.heatmap[curr.prev_index] += curr.time_in_cell;
                }
                else
                {
                    new_seed.heatmap.Add(curr.prev_index, curr.time_in_cell);
                }
            }
            return(new_seed);
        }
Beispiel #9
0
        private void SetSpectraUI(MsDataSpectrum[] spectra)
        {
            _msDataFileScanHelper.MsDataSpectra = spectra;
            _heatMapData = null;
            if (_msDataFileScanHelper.MsDataSpectra == null)
            {
                return;
            }

            foreach (var spectrum in spectra)
            {
                if (spectrum.IonMobilities != null)
                {
                    ArrayUtil.Sort(spectrum.Mzs, spectrum.Intensities, spectrum.IonMobilities);
                }
            }

            // Find max values.
            _maxMz        = 0;
            _maxIntensity = 0;
            GetMaxMzIntensity(out _maxMz, out _maxIntensity);
            GetMaxMobility(out _maxIonMobility);

            if (_zoomXAxis)
            {
                _zoomXAxis = false;
                ZoomXAxis();
            }
            if (_zoomYAxis)
            {
                _zoomYAxis = false;
                ZoomYAxis();
            }
            CreateGraph();
            UpdateUI();
        }
Beispiel #10
0
            public GraphData(SrmDocument document, GraphData dataPrevious, int resultIndex,
                             bool bestResult, PointsTypeMassError pointsType)
            {
                _document         = document;
                _resultIndex      = resultIndex;
                _replicateDisplay = ShowReplicate;

                int[,] counts2D = EMPTY_COUNTS;
                _displayType    = MassErrorGraphController.HistogramDisplayType;
                _binSizePpm     = Settings.Default.MassErorrHistogramBinSize;
                _transition     = MassErrorGraphController.HistogramTransiton;
                _xAxis          = MassErrorGraphController.Histogram2DXAxis;
                _pointsType     = pointsType;
                if (_pointsType == PointsTypeMassError.targets_1FDR && !document.Settings.PeptideSettings.Integration.PeakScoringModel.IsTrained)
                {
                    _pointsType = PointsTypeMassError.targets;
                }

                bool decoys     = pointsType == PointsTypeMassError.decoys;
                bool precursors = _displayType == DisplayTypeMassError.precursors;

                while (ReferenceEquals(counts2D, EMPTY_COUNTS))
                {
                    if (_maxMass != double.MinValue)
                    {
                        counts2D = new int[xAxisBins, (int)((_maxMass - _minMass) / _binSizePpm + 1)];
                    }

                    foreach (var nodePep in document.Molecules)
                    {
                        if (decoys != nodePep.IsDecoy)
                        {
                            continue;
                        }

                        var replicateIndex = bestResult && nodePep.BestResult != -1 ? nodePep.BestResult : resultIndex;
                        foreach (var nodeGroup in nodePep.TransitionGroups)
                        {
                            foreach (var nodeTran in nodeGroup.Transitions)
                            {
                                if (precursors != nodeTran.IsMs1)
                                {
                                    continue;
                                }
                                var mz = nodeTran.Mz.Value;
                                if (replicateIndex >= 0)
                                {
                                    AddChromInfo(nodeGroup, nodeTran, replicateIndex, mz, counts2D);
                                }
                                else
                                {
                                    for (int i = 0; i < nodeTran.Results.Count; i++)
                                    {
                                        AddChromInfo(nodeGroup, nodeTran, i, mz, counts2D);
                                    }
                                }
                            }
                        }
                    }

                    // No values. Leave _maxCount == 0
                    if (_maxMass == double.MinValue)
                    {
                        return;
                    }
                }

                var points = new List <Point3D>();

                for (int x = 0; x < counts2D.GetLength(0); x++)
                {
                    for (int y = 0; y < counts2D.GetLength(1); y++)
                    {
                        int count = counts2D[x, y];
                        if (count > 0)
                        {
                            double binSizeX = (_maxX - _minX) / xAxisBins;
                            double xPoint   = x * binSizeX + _minX + binSizeX / 2;
                            double yPoint   = y * _binSizePpm + _minMass + _binSizePpm / 2;
                            points.Add(new Point3D(xPoint, yPoint, count));
                        }
                        _maxCount = Math.Max(_maxCount, count);
                    }
                }
                _heatMapData = new HeatMapData(points);
            }
Beispiel #11
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();
        }
Beispiel #12
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();
            }
        }
Beispiel #13
0
        public override void UpdateGraph(bool selectionChanged)
        {
            if (!GraphSummary.DocumentUIContainer.DocumentUI.Settings.HasResults)
            {
                _areaCVGraphData = null;
                return;
            }

            var settings = new AreaCVGraphData.AreaCVGraphSettings(GraphSummary.Type);

            _document   = GraphSummary.DocumentUIContainer.DocumentUI;
            _percentage = !Settings.Default.AreaCVShowDecimals;
            _decimals   = _percentage ? 1 : 3;

            CurveList.Clear();

            var gotData = _cache.TryGet(_document, settings, DataCallback, out _areaCVGraphData);

            if (!gotData)
            {
                Title.Text = Resources.AreaCVHistogram2DGraphPane_UpdateGraph_Calculating____;
                return;
            }

            if (!_areaCVGraphData.IsValid)
            {
                Title.Text = Resources.AreaCVHistogram2DGraphPane_Draw_Not_enough_data;
                return;
            }

            var factor = AreaGraphController.GetAreaCVFactorToDecimal();

            Title.Text = string.Empty;

            YAxis.Title.Text = Resources.AreaCVHistogram2DGraphPane_UpdateGraph_CV + (_percentage ? @" (%)" : string.Empty);
            XAxis.Title.Text = Resources.AreaCvHistogram2DGraphPane_UpdateGraph_Log10_Mean_Area;

            XAxis.Scale.MinAuto = XAxis.Scale.MinAuto = XAxis.Scale.MaxAuto = YAxis.Scale.MaxAuto = false;
            XAxis.Scale.Min     = Math.Max(0, double.IsNaN(Settings.Default.AreaCVMinLog10Area) ? _areaCVGraphData.MinMeanArea : Settings.Default.AreaCVMinLog10Area);
            XAxis.Scale.Max     = double.IsNaN(Settings.Default.AreaCVMaxLog10Area) ? _areaCVGraphData.MaxMeanArea : Settings.Default.AreaCVMaxLog10Area;
            YAxis.Scale.Min     = 0.0;
            YAxis.Scale.Max     = double.IsNaN(Settings.Default.AreaCVMaxCV) ? _areaCVGraphData.MaxCV * factor : Settings.Default.AreaCVMaxCV;

            AxisChange();

            var points = _areaCVGraphData.Data
                         .Select(d => new HeatMapData.TaggedPoint3D(new Point3D(d.MeanArea, d.CV * factor, d.Frequency), d))
                         .ToList();

            Items = points.Count; // Because heatmaps can't be trusted to have a consistent number of points on all monitors
            var heatMapData = new HeatMapData(points);

            HeatMapGraphPane.GraphHeatMap(this, heatMapData, 17, 2, (float)(_areaCVGraphData.MinCV * factor), (float)(_areaCVGraphData.MaxCV * factor), Settings.Default.AreaCVLogScale, 0);

            var unit = _percentage ? @"%" : string.Empty;

            if (Settings.Default.AreaCVShowMedianCV)
            {
                string text = string.Format(Resources.AreaCVHistogram2DGraphPane_UpdateGraph_Median___0_, HistogramHelper.FormatDouble(_areaCVGraphData.MedianCV * factor, _decimals) + unit);
                _lineItems[0] = AddLineItem(text, XAxis.Scale.Min, XAxis.Scale.Max, _areaCVGraphData.MedianCV * factor, _areaCVGraphData.MedianCV * factor, Color.Blue);
                CurveList.Insert(0, _lineItems[0]);
            }

            if (Settings.Default.AreaCVShowCVCutoff)
            {
                string text = string.Format(Resources.AreaCVHistogramGraphPane_UpdateGraph_Below__0____1_, Settings.Default.AreaCVCVCutoff + unit,
                                            HistogramHelper.FormatDouble(_areaCVGraphData.BelowCVCutoff * factor, _decimals) +
                                            unit);
                _lineItems[1] = AddLineItem(text, XAxis.Scale.Min, XAxis.Scale.Max, Settings.Default.AreaCVCVCutoff, Settings.Default.AreaCVCVCutoff, Color.Red);
                CurveList.Insert(0, _lineItems[1]);
            }
        }
Beispiel #14
0
 public void AddPoint(HeatMapPoint heatMapPoint)
 {
     HeatMapData.Add(heatMapPoint);
 }
Beispiel #15
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 mainSpectrumList = source.Source.MSDataFile.run.spectrumList;
            var bounds           = heatmapBoundsByMsLevel[msLevel];
            int lastBinIndex     = -1;

            foreach (var bin in ionMobilityBins)
            {
                // skip bins where the spectrum is the same as the last bin (that spectrum's points were added from its mobility array)
                if (bin.BinIndex == lastBinIndex)
                {
                    continue;
                }
                lastBinIndex = bin.BinIndex;

                var s              = mainSpectrumList.spectrum(bin.BinIndex, true);
                var mzArray        = s.getMZArray().data;
                var intensityArray = s.getIntensityArray().data;
                var mobilityBDA    = s.getArrayByCVID(pwiz.CLI.cv.CVID.MS_mean_drift_time_array);
                if (mobilityBDA == null)
                {
                    mobilityBDA = s.getArrayByCVID(pwiz.CLI.cv.CVID.MS_mean_inverse_reduced_ion_mobility_array);
                }

                if (mobilityBDA != null)
                {
                    var mobilityArray = mobilityBDA.data;
                    for (int j = 0, end = mzArray.Count; j < end; ++j)
                    {
                        double mz        = mzArray[j];
                        double intensity = intensityArray[j];
                        double mobility  = mobilityArray[j];
                        bounds.MinX = Math.Min(bounds.MinX, mz);
                        bounds.MinY = Math.Min(bounds.MinY, mobility);
                        bounds.MaxX = Math.Max(bounds.MaxX, mz);
                        bounds.MaxY = Math.Max(bounds.MaxY, mobility);

                        heatmapPoints.Add(new Point3D(mz, mobility, intensity));
                    }
                }
                else
                {
                    for (int j = 0, end = mzArray.Count; j < end; ++j)
                    {
                        double mz        = mzArray[j];
                        double intensity = intensityArray[j];
                        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();
        }
Beispiel #16
0
        /// <summary>
        /// Create an ion mobility heat map graph.
        /// </summary>
        private void CreateIonMobilityHeatmap()
        {
            GraphPane.YAxis.Title.Text = IonMobilityFilter.IonMobilityUnitsL10NString(_msDataFileScanHelper.IonMobilityUnits);
            graphControl.IsEnableVZoom = graphControl.IsEnableVPan = true;

            if (_heatMapData == null)
            {
                var points = new List <Point3D>(5000);
                foreach (var scan in _msDataFileScanHelper.MsDataSpectra)
                {
                    if (!scan.IonMobility.HasValue && scan.IonMobilities == null)
                    {
                        continue;
                    }
                    for (int j = 0; j < scan.Mzs.Length; j++)
                    {
                        double mobilityValue = scan.IonMobilities != null
                            ? scan.IonMobilities[j]
                            : scan.IonMobility.Mobility.Value;

                        points.Add(new Point3D(scan.Mzs[j], mobilityValue, scan.Intensities[j]));
                    }
                }
                _heatMapData = new HeatMapData(points);
            }

            double minDrift;
            double maxDrift;

            _msDataFileScanHelper.GetIonMobilityRange(out minDrift, out maxDrift, _msDataFileScanHelper.Source);  // There may be a different drift time filter for products in Waters

            if (minDrift > 0 && maxDrift < double.MaxValue)
            {
                // Add gray shaded box behind heat points.
                var driftTimeBox = new BoxObj(
                    0.0,
                    maxDrift,
                    1.0,
                    maxDrift - minDrift,
                    Color.Transparent,
                    Color.FromArgb(50, Color.Gray))
                {
                    Location             = { CoordinateFrame = CoordType.XChartFractionYScale },
                    ZOrder               = ZOrder.F_BehindGrid,
                    IsClippedToChartRect = true,
                };
                GraphPane.GraphObjList.Add(driftTimeBox);

                // Add outline in front of heat points, so you can tell where the limits are in a dense graph.
                var driftTimeOutline = new BoxObj(
                    0.0,
                    maxDrift,
                    1.0,
                    maxDrift - minDrift,
                    Color.FromArgb(50, Color.DarkViolet),
                    Color.Transparent)
                {
                    Location             = { CoordinateFrame = CoordType.XChartFractionYScale },
                    ZOrder               = ZOrder.C_BehindChartBorder,
                    IsClippedToChartRect = true,
                    Border               = new Border(Color.FromArgb(100, Color.DarkViolet), 2)
                };
                GraphPane.GraphObjList.Add(driftTimeOutline);
            }

            if (!Settings.Default.FilterIonMobilityFullScan)
            {
                minDrift = 0;
                maxDrift = double.MaxValue;
            }
            var heatMapGraphPane = (HeatMapGraphPane)GraphPane;

            heatMapGraphPane.SetPoints(_heatMapData, minDrift, maxDrift);
        }
        //function for printing out HeatMap structure data
        public static void printInfo(HeatMapData data)
        {
            double total_time = 0;
               Console.WriteLine("\nts: " + data.ts);

               Console.WriteLine("player_name: " + data.player_name);

            Console.WriteLine("gridType: " + data.gridType);
               foreach (var item in data.heatmap)
                total_time += item.Value;
               foreach (var item in data.heatmap)
                Console.WriteLine("index: " + item.Key + "  time % : " + (item.Value / total_time) * 100);
        }
        //aggregatorFunction used in TimeWindow based aggregation
        private static HeatMapData aggregatorFunction(HeatMapData seed, TimeInCell curr,
           IList<TimeInCell> expList, long count)
        {
            HeatMapData new_seed = new HeatMapData { ts = curr.ts, player_name = curr.player_name,
                gridType=curr.gridType, heatmap = seed.heatmap};

            foreach(var item in expList)
            {
                if (item.time_in_cell != -999)
                {

                    if (new_seed.heatmap.ContainsKey(item.prev_index))
                    {
                        new_seed.heatmap[item.prev_index] -= item.time_in_cell;
                        if (new_seed.heatmap[item.prev_index] <= 0)
                            new_seed.heatmap.Remove(item.prev_index);
                    }
                    else
                    {
                        Console.WriteLine("HeatMapProcessor: Attempt to access non-existent key");
                    }

                }

            }
            if (curr.time_in_cell != -999)
            {
                if (new_seed.heatmap.ContainsKey(curr.prev_index))
                    new_seed.heatmap[curr.prev_index] += curr.time_in_cell;
                else
                    new_seed.heatmap.Add(curr.prev_index, curr.time_in_cell);

            }
            return new_seed;
        }