Пример #1
0
 public PeakSet(DbPeptideFileAnalysis dbPeptideFileAnalysis, IEnumerable <Peak> peaks) : this()
 {
     TracerPercent       = dbPeptideFileAnalysis.TracerPercent;
     DeconvolutionScore  = dbPeptideFileAnalysis.DeconvolutionScore;
     PrecursorEnrichment = dbPeptideFileAnalysis.PrecursorEnrichment;
     if (dbPeptideFileAnalysis.PrecursorEnrichmentFormula != null)
     {
         PrecursorEnrichmentFormula = TracerPercentFormula.Parse(dbPeptideFileAnalysis.PrecursorEnrichmentFormula);
     }
     Turnover        = dbPeptideFileAnalysis.Turnover;
     TurnoverScore   = dbPeptideFileAnalysis.TurnoverScore;
     IntegrationNote = IntegrationNote.Parse(dbPeptideFileAnalysis.IntegrationNote);
     if (peaks != null)
     {
         _peaks = ImmutableList.ValueOf(peaks);
     }
 }
Пример #2
0
        private void BtnGoOnClick(object sender, EventArgs e)
        {
            graphDetails.GraphPane.CurveList.Clear();
            int    pointCount    = PointCount;
            double precursorPool = PrecursorPool;
            double turnover      = Turnover;
            int    labelCount    = LabelCount;
            double noise         = Noise;
            var    points        = new PointPairList();
            var    tracerDef     = Workspace.GetTracerDefs().FirstOrDefault(td => td.AminoAcidSymbol.HasValue);

            if (tracerDef == null)
            {
                MessageBox.Show(
                    "The simulation cannot be run because there is no amino acid tracer defined in this workspace");
                return;
            }

            Debug.Assert(tracerDef.AminoAcidSymbol.HasValue);
            string peptide               = new string(tracerDef.AminoAcidSymbol.Value, labelCount);
            var    turnoverCalculator    = new TurnoverCalculator(Workspace, peptide);
            var    initialTracerPercents = TracerPercentFormula.Parse("").SetElementCount(tracerDef.Name, tracerDef.InitialApe);
            var    newTracerPercents     = TracerPercentFormula.Parse("").SetElementCount(tracerDef.Name, precursorPool);
            var    initialDistribution   = turnoverCalculator.GetDistribution(initialTracerPercents);
            var    newDistribution       = turnoverCalculator.GetDistribution(newTracerPercents);
            var    currentMixture        = Mix(initialDistribution, (100.0 - turnover) / 100, newDistribution, turnover / 100);
            var    keys = new List <TracerFormula>();

            for (int i = 0; i <= labelCount; i++)
            {
                keys.Add(TracerFormula.Parse("").SetElementCount(tracerDef.Name, i));
            }
            var bestMatches          = new List <IDictionary <TracerFormula, double> >();
            var precursorEnrichments = new List <TracerPercentFormula>();
            var observedResults      = new List <IDictionary <TracerFormula, double> >();

            while (points.Count < pointCount)
            {
                var    noisyMixture = Perturb(keys, currentMixture, noise / 100);
                double calcTurnover;
                double calcTurnoverScore;
                double calcPrecursorPool;
                IDictionary <TracerFormula, double> bestMatch;
                var calcMixture = turnoverCalculator.ComputePrecursorEnrichmentAndTurnover(noisyMixture, out calcTurnover, out calcTurnoverScore, out bestMatch);
                if (calcMixture == null)
                {
                    continue;
                }
                calcMixture.TryGetValue(tracerDef.Name, out calcPrecursorPool);
                points.Add(new PointPair(calcTurnover * 100, calcPrecursorPool));
                bestMatches.Add(bestMatch);
                precursorEnrichments.Add(calcMixture);
                observedResults.Add(noisyMixture);
            }
            graphResults.GraphPane.CurveList.Clear();
            graphResults.GraphPane.GraphObjList.Clear();
            var lineItem = graphResults.GraphPane.AddCurve(null, points, Color.Black);

            lineItem.Line.IsVisible = false;
            graphResults.GraphPane.XAxis.Title.Text = "% newly synthesized";
            graphResults.GraphPane.YAxis.Title.Text = "Precursor pool";
            graphResults.GraphPane.AxisChange();
            graphResults.Invalidate();
            dataGridView.Rows.Clear();
            var row = dataGridView.Rows[dataGridView.Rows.Add()];

            row.Cells[colQuantity.Index].Value = "% newly synthesized";
            var statsTurnover = new Statistics(points.Select(p => p.X).ToArray());

            row.Cells[colMean.Index].Value   = statsTurnover.Mean();
            row.Cells[colMedian.Index].Value = statsTurnover.Median();
            row.Cells[colStdDev.Index].Value = statsTurnover.StdDev();

            row = dataGridView.Rows[dataGridView.Rows.Add()];
            var statsPrecursorPool = new Statistics(points.Select(p => p.Y).ToArray());

            row.Cells[colQuantity.Index].Value = "Precursor Pool";
            row.Cells[colMean.Index].Value     = statsPrecursorPool.Mean();
            row.Cells[colMedian.Index].Value   = statsPrecursorPool.Median();
            row.Cells[colStdDev.Index].Value   = statsPrecursorPool.StdDev();
            _precursorEnrichmentsByPoint       = points.Select(p => p.Y).ToArray();
            _bestMatches      = bestMatches;
            _observedResults  = observedResults;
            _scatterPlotCurve = lineItem;
            _expected         = currentMixture;
            _turnovers        = points.Select(p => p.X).ToArray();
            _tracerFormulas   = keys;
            ShowResult(-1);
        }
Пример #3
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;
            }
        }