Example #1
0
        public void Redisplay()
        {
            if (!IsHandleCreated)
            {
                return;
            }
            if (_inRedisplay)
            {
                return;
            }
            try
            {
                _inRedisplay = true;
                tbxMinCharge.Text = MinCharge.ToString();
                tbxMaxCharge.Text = MaxCharge.ToString();
                tbxPeptideSequence.Text = PeptideSequence;
                cbxShowPeptideMzs.Enabled = !string.IsNullOrEmpty(PeptideSequence);
                tbxMassAccuracy.Text = MassAccuracy.ToString();
                TurnoverCalculator turnoverCalculator = null;
                if (!string.IsNullOrEmpty(PeptideSequence))
                {
                    turnoverCalculator = new TurnoverCalculator(Workspace, PeptideSequence);
                }

                msGraphControlEx1.GraphPane.GraphObjList.Clear();
                msGraphControlEx1.GraphPane.CurveList.Clear();
                if (_spectrumData == null || comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex])
                {
                    using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name)))
                    {
                        if (comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex])
                        {
                            string chromatogramName;
                            float[] timeArray;
                            float[] intensityArray;
                            msDataFileImpl.GetChromatogram(comboChromatogram.SelectedIndex, out chromatogramName, out timeArray, out intensityArray);
                            _chromatogramDatas[comboChromatogram.SelectedIndex] = new ChromatogramData(chromatogramName, timeArray, intensityArray);
                        }
                        _spectrumData = _spectrumData ?? new SpectrumData(msDataFileImpl, ScanIndex);
                    }
                }
                ChromatogramData chromatogram = null;
                if (comboChromatogram.SelectedIndex >= 0)
                {
                    chromatogram = _chromatogramDatas[comboChromatogram.SelectedIndex];
                }
                tbxMsLevel.Text = _spectrumData.MsLevel.ToString();
                tbxTime.Text = _spectrumData.Time.ToString();
                if (chromatogram != null && ScanIndex < chromatogram.TimeArray.Length)
                {
                    tbxChromatogramRetentionTime.Text = chromatogram.TimeArray[ScanIndex].ToString();
                    tbxChromatogramIonCurrent.Text = chromatogram.IntensityArray[ScanIndex].ToString(NumberFormat);
                }
                else
                {
                    tbxChromatogramRetentionTime.Text = tbxChromatogramIonCurrent.Text = @"N/A";
                }

                if (cbxShowProfile.Checked && _spectrumData.ProfileMzs != null)
                {
                    msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, new SpectrumGraphItem()
                    {
                        Points =
                            new PointPairList(_spectrumData.ProfileMzs,
                                              _spectrumData.ProfileIntensities),
                        GraphItemDrawMethod = MSGraphItemDrawMethod.line,

                        Color = Color.Blue,
                    });
                }

                if (_spectrumData.ProfileIntensities != null)
                {
                    tbxSumOfProfileIntensities.Text = _spectrumData.ProfileIntensities.Sum().ToString(NumberFormat);
                }
                else
                {
                    tbxSumOfProfileIntensities.Text = "";
                }
                tbxCentroidIntensitySum.Text = _spectrumData.CentroidIntensities.Sum().ToString(NumberFormat);

                var spectrum = new SpectrumGraphItem
                                   {
                                       Points = new PointPairList(_spectrumData.CentroidMzs, _spectrumData.CentroidIntensities),
                                       GraphItemDrawMethod = MSGraphItemDrawMethod.stick,
                                       Color = Color.Black
                                   };

                if (turnoverCalculator != null)
                {
                    var mzRanges = new Dictionary<MzRange, String>();
                    double monoisotopicMass = Workspace.GetAminoAcidFormulas().GetMonoisotopicMass(PeptideSequence);
                    double peptideIntensity = 0.0;
                    for (int charge = MinCharge; charge <= MaxCharge; charge ++)
                    {
                        foreach (var mzRange in turnoverCalculator.GetMzs(charge))
                        {
                            double mass = (mzRange.Center - AminoAcidFormulas.ProtonMass)* charge;
                            double massDifference = mass - monoisotopicMass;
                            var label = massDifference.ToString("0.#");
                            if (label[0] != '-')
                            {
                                label = "+" + label;
                            }
                            label = "M" + label;
                            label += new string('+', charge);
                            mzRanges.Add(mzRange, label);
                            var chromatogramPoint = MsDataFileUtil.GetPoint(mzRange, _spectrumData.CentroidMzs, _spectrumData.CentroidIntensities);
                            peptideIntensity += chromatogramPoint.GetIntensity(mzRange, MassAccuracy);
                        }
                    }
                    spectrum.MassAccuracy = MassAccuracy;
                    spectrum.MzRanges = mzRanges;
                    tbxPeptideIntensity.Text = peptideIntensity.ToString(NumberFormat);
                }
                if (cbxShowCentroids.Checked)
                {
                    msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, spectrum);
                }

                if (turnoverCalculator != null && cbxShowPeptideMzs.Checked)
                {
                    double massAccuracy = MassAccuracy;
                    for (int charge = MinCharge; charge <= MaxCharge; charge++)
                    {
                        var mzs = turnoverCalculator.GetMzs(charge);
                        var height = int.MaxValue;
                        foreach (var mzRange in mzs)
                        {
                            double min = mzRange.MinWithMassAccuracy(massAccuracy);
                            double max = mzRange.MaxWithMassAccuracy(massAccuracy);

                            msGraphControlEx1.GraphPane.GraphObjList.Add(new BoxObj(min, height, max - min, height, Color.Goldenrod, Color.Goldenrod)
                                                                        {
                                                                            IsClippedToChartRect = true,
                                                                            ZOrder = ZOrder.F_BehindGrid
                                                                        });
                        }
                    }
                }
                msGraphControlEx1.Invalidate();
            }
            finally
            {
                _inRedisplay = false;
            }
        }