예제 #1
0
        public SpectrumViewer(string filename, object index, string interpretation)
        {
            // Prepare the annotation
            annotation = new PeptideFragmentationAnnotation(interpretation, 1, 2, false, true, false, false, true, false, false, true, false, true);
            annotation.OptionsPanel.Dock = DockStyle.None;
            annotation.OptionsPanel.Dock = DockStyle.Fill;

            // Get the mass spectrum
            spectrum = SpectrumCache.GetMassSpectrum(filename, index);
            if (spectrum == null)
            {
                return;
            }

            // Add annotation to the mass spectrum and get a new graph control
            spectrum.AnnotationList.Clear();
            spectrum.AnnotationList.Add((IAnnotation)annotation);
            graph = new MSGraphControl();
            graph.AddGraphItem(graph.GraphPane, spectrum);
            graph.Dock = DockStyle.Fill;


            // Create new panels and add the graph and annotations
            spectrumPanel = new Panel();
            spectrumPanel.Controls.Add(graph);
            spectrumPanel.Dock = DockStyle.None;
            spectrumPanel.Dock = DockStyle.Fill;
            annotationPanel    = new Panel();
            annotationPanel.Controls.Add(annotation.OptionsPanel);
            annotationPanel.Dock = DockStyle.None;
            annotationPanel.Dock = DockStyle.Fill;
            fragmentationPanel   = new Panel();
            annotation.FragmentInfoGridView.Location    = new Point(0, 0);
            annotation.FragmentInfoGridView.ScrollBars  = ScrollBars.Both;
            annotation.FragmentInfoGridView.Dock        = DockStyle.None;
            annotation.FragmentInfoGridView.Dock        = DockStyle.Fill;
            annotation.FragmentInfoGridView.BorderStyle = BorderStyle.FixedSingle;
            fragmentationPanel.Controls.Add(annotation.FragmentInfoGridView);
            fragmentationPanel.Dock = DockStyle.None;
            fragmentationPanel.Dock = DockStyle.Fill;

            // Add the call back for refreshing
            annotation.OptionsChanged += new EventHandler(OnOptionsChanged);
        }
예제 #2
0
        private void UpdateGraph()
        {
            if (_inUpdateGraph)
            {
                return;
            }
            try
            {
                _inUpdateGraph = true;
                _msGraphControl.GraphPane.GraphObjList.Clear();
                _msGraphControl.GraphPane.CurveList.Clear();
                dataGridView1.Rows.Clear();

                int charge;
                try
                {
                    charge = Convert.ToInt32(tbxCharge.Text);
                    tbxCharge.BackColor = Color.White;
                }
                catch
                {
                    charge = 0;
                    tbxCharge.BackColor = Color.Red;
                }
                double massResolution;
                try
                {
                    massResolution = double.Parse(tbxMassResolution.Text);
                    tbxMassResolution.BackColor = Color.White;
                }
                catch
                {
                    tbxMassResolution.BackColor = Color.Red;
                    massResolution = .01;
                }

                var sequence = tbxSequence.Text;
                MassDistribution spectrum;
                if (string.IsNullOrEmpty(sequence))
                {
                    var formula  = tbxFormula.Text;
                    var molecule = Molecule.Parse(formula);
                    if (molecule.Values.Sum() > 10000000)
                    {
                        tbxFormula.BackColor = Color.Red;
                        return;
                    }
                    try
                    {
                        spectrum             = Workspace.GetAminoAcidFormulas().GetMassDistribution(molecule, charge);
                        tbxFormula.BackColor = Color.White;
                    }
                    catch
                    {
                        tbxFormula.BackColor = Color.Red;
                        return;
                    }
                }
                else
                {
                    tbxFormula.Text = Workspace.GetAminoAcidFormulas().GetFormula(sequence).ToString();
                    var turnoverCalculator = new TurnoverCalculator(Workspace, sequence);
                    var aminoAcidFormulas  = Workspace.GetAminoAcidFormulasWithTracers();
                    aminoAcidFormulas = aminoAcidFormulas.SetMassResolution(massResolution);
                    try
                    {
                        if (cbxTracerPercents.Checked)
                        {
                            var tracerPercentFormula = TracerPercentFormula.Parse(tbxTracerFormula.Text);
                            spectrum = turnoverCalculator.GetAminoAcidFormulas(tracerPercentFormula)
                                       .GetMassDistribution(sequence, charge);
                        }
                        else
                        {
                            var tracerFormula = TracerFormula.Parse(tbxTracerFormula.Text);
                            spectrum = aminoAcidFormulas.GetMassDistribution(
                                turnoverCalculator.MoleculeFromTracerFormula(tracerFormula), charge);
                            double massShift = aminoAcidFormulas.GetMassShift(sequence);
                            if (charge > 0)
                            {
                                massShift /= charge;
                            }
                            spectrum = spectrum.OffsetAndDivide(massShift, 1);
                        }
                        tbxTracerFormula.BackColor = Color.White;
                    }
                    catch
                    {
                        tbxTracerFormula.BackColor = Color.Red;
                        spectrum = aminoAcidFormulas.GetMassDistribution(sequence, charge);
                    }
                }
                if (spectrum == null)
                {
                    return;
                }
                var curveItem = _msGraphControl.AddGraphItem(_msGraphControl.GraphPane, new GraphItem
                {
                    Title  = "Intensity",
                    Color  = Color.Black,
                    Points =
                        new PointPairList(
                            spectrum.Keys.
                            ToArray(),
                            spectrum.Values.
                            ToArray())
                });
                curveItem.Label.IsVisible = false;
                _msGraphControl.AxisChange();
                _msGraphControl.Invalidate();
                var entries = spectrum.ToArray();
                dataGridView1.Rows.Add(entries.Length);
                for (int i = 0; i < entries.Count(); i++)
                {
                    var row = dataGridView1.Rows[i];
                    row.Cells[colMass.Index].Value      = entries[i].Key;
                    row.Cells[colIntensity.Index].Value = entries[i].Value;
                }
            }
            finally
            {
                _inUpdateGraph = false;
            }
        }