private List <double> PonderatedRatio(PeptideResult pep)
        {
            List <double> ratios = new List <double>();

            foreach (SQTScan s in pep.MyScans)
            {
                double weightSum = 0;
                double numerator = 0;
                foreach (List <double> quants in s.Quantitation)
                {
                    double w = quants[0] + quants[1];
                    numerator += ((quants[0] / quants[1]) * w);
                    weightSum += w;

                    ReportItem ri = new ReportItem(s.FileName, s.ScanNumber, s.ChargeState, quants[0], quants[1], Math.Log(quants[0] / quants[1], 2), s.PeptideSequence);
                    reportItems.Add(ri);
                }

                ratios.Add(numerator / weightSum);
            }



            return(ratios);
        }
        private static List <double> ExtractValues(PeptideResult pep, int dim)
        {
            List <double> q1 = (from sqts in pep.MyScans
                                from quants in sqts.Quantitation
                                select quants[dim]).ToList();

            q1.RemoveAll(a => double.IsInfinity(a) || double.IsNaN(a));

            return(q1);
        }
Exemple #3
0
 private void dataGridPeptideSelector_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     try
     {
         PeptideResult pepR = (PeptideResult)dataGridPeptideSelector.SelectedItem;
         dataGridPeptides.ItemsSource = pepR.MyScans;
     }
     catch (Exception e4)
     {
         Console.WriteLine("Couldn't plot protein : " + e4.Message);
     }
 }
        private void CorrectIsotopic(PeptideResult pep)
        {
            int           result = (int)Math.Round((pep.MyScans[0].MeasuredMH - pep.MyScans[0].TheoreticalMH), 0);
            List <double> signal = isotopicSignalGenerator.GetSignal(15, pep.MyScans[0].MeasuredMH, 0);

            foreach (SQTScan s in pep.MyScans)
            {
                int noMods = Regex.Matches(s.PeptideSequenceCleaned, Regex.Escape("(")).Count;
                foreach (List <double> q in s.Quantitation)
                {
                }
            }



            Console.Write(".");

            //Count how many deltas are there in the peptide
        }
        private static List <double> ExtractRatios(PeptideResult pep)
        {
            List <double> q1 = (from sqts in pep.MyScans
                                from quants in sqts.Quantitation
                                select Math.Log(quants[0] / quants[1], 2)).ToList();

            q1.RemoveAll(a => double.IsInfinity(a) || double.IsNaN(a));

            for (int i = 0; i < q1.Count; i++)
            {
                if (q1[i] > 15)
                {
                    q1[i] = 15;
                }
                else if (q1[i] < -15)
                {
                    q1[i] = -15;
                }
            }

            return(q1);
        }
Exemple #6
0
 private static PeptideLabelRatio FindPeptideLabelRatio(PeptideResult peptideResult, IsotopeLabelType labelType, IsotopeLabelType standardType)
 {
     return(peptideResult.ChromInfo.LabelRatios.FirstOrDefault(
                labelRatio => ReferenceEquals(labelType, labelRatio.LabelType) &&
                ReferenceEquals(standardType, labelRatio.StandardType)));
 }
        private void Old()
        {
            //Load the SEPro files;



            PatternTools.LstSquQuadRegr lstsqr = new PatternTools.LstSquQuadRegr();

            Console.WriteLine("Loading SEPro1");
            ResultPackage sepro1 = ResultPackage.Load(textBoxSEProL1.Text);

            Console.WriteLine("Loading SEPro2");
            ResultPackage sepro2 = ResultPackage.Load(textBoxSEProL2.Text);

            //Generate a list of all clean peptide sequences
            List <string> cleanPeptideSequences = sepro1.AllPeptideSequences;

            cleanPeptideSequences.AddRange(sepro2.AllPeptideSequences);
            cleanPeptideSequences = cleanPeptideSequences.Distinct().ToList();
            Console.WriteLine(" Peptides loaded: " + cleanPeptideSequences.Count);


            //First lets normalize
            List <GraphData> theData  = new List <GraphData>(cleanPeptideSequences.Count);
            double           totalXP1 = 0;
            double           totalXP2 = 0;
            double           totalYP1 = 0;
            double           totalYP2 = 0;

            foreach (string peptide in cleanPeptideSequences)
            {
                PeptideResult pep1 = sepro1.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));
                PeptideResult pep2 = sepro2.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));

                CorrectIsotopic(pep1);
                CorrectIsotopic(pep2);


                if (pep1 == null || pep2 == null)
                {
                    continue;
                }

                totalXP1 += ExtractValues(pep1, 0).Sum();
                totalYP1 += ExtractValues(pep1, 1).Sum();
                totalXP2 += ExtractValues(pep2, 0).Sum();
                totalYP2 += ExtractValues(pep2, 1).Sum();
            }

            foreach (string peptide in cleanPeptideSequences)
            {
                PeptideResult pep1 = sepro1.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));
                PeptideResult pep2 = sepro2.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));

                if (pep1 == null || pep2 == null)
                {
                    continue;
                }

                List <double> beforeNorm = ExtractRatios(pep1);
                if (pep1 == null || pep2 == null)
                {
                    continue;
                }

                foreach (SQTScan scan in pep1.MyScans)
                {
                    for (int i = 0; i < scan.Quantitation.Count; i++)
                    {
                        scan.Quantitation[i][0] /= totalXP1;
                        scan.Quantitation[i][1] /= totalYP1;
                    }
                }

                foreach (SQTScan scan in pep2.MyScans)
                {
                    for (int i = 0; i < scan.Quantitation.Count; i++)
                    {
                        scan.Quantitation[i][0] /= totalXP2;
                        scan.Quantitation[i][1] /= totalYP2;
                    }
                }
                List <double> afterNorm = ExtractRatios(pep1);
            }

            //finished Normalizing


            foreach (string peptide in cleanPeptideSequences)
            {
                PeptideResult pep1 = sepro1.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));
                PeptideResult pep2 = sepro2.MyProteins.MyPeptideList.Find(a => a.CleanedPeptideSequence.Equals(peptide));


                if (pep1 == null || pep2 == null)
                {
                    continue;
                }

                List <double> q1 = ExtractRatios(pep1);
                List <double> q2 = ExtractRatios(pep2);

                if (q1.Count == 0 || q2.Count == 0)
                {
                    //Most likely we are here because this peptide is a false positive as it has two different labels in it.
                    Console.Write("x");
                    continue;
                }

                double x = 0;
                if (q1.Count > 0)
                {
                    x = q1.Average();
                }
                //x = q1[0];

                double y = 0;
                if (q2.Count > 0)
                {
                    y = q2.Average();
                }
                //y = q2[0];

                theData.Add(new GraphData(x, y));

                Console.Write(".");
            }

            //And now, print the data to the graph

            chart1.Series[0].Points.Clear();

            chart1.ChartAreas[0].AxisX.Crossing          = 0;
            chart1.ChartAreas[0].AxisY.Crossing          = 0;
            chart1.ChartAreas[0].AxisY.IsStartedFromZero = true;
            chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;

            foreach (GraphData g in theData)
            {
                lstsqr.AddPoints(g.X, g.Y);
                chart1.Series[0].Points.AddXY(g.X, g.Y);
            }

            //Finally, update the labels
            labelL1.Text = Math.Round(theData.Average(a => a.X), 3).ToString() + " +- " + Math.Round(PatternTools.pTools.Stdev(theData.Select(a => a.X).ToList(), true), 3);
            labelL2.Text = Math.Round(theData.Average(a => a.Y), 3).ToString() + " +- " + Math.Round(PatternTools.pTools.Stdev(theData.Select(a => a.Y).ToList(), true), 3);


            //labelRSquared.Text = Math.Round(lstsqr.rSquare(),3).ToString();
            //labelRegressorEquation.Text = "y = " + Math.Round(lstsqr.aTerm(),2) + " x^2 + " + Math.Round(lstsqr.bTerm(),2) + " x + " + Math.Round(lstsqr.cTerm(),2);


            dataGridViewPoints.DataSource = theData;
        }