public void ChromatogramTest()
        {
            Chromatogram a = new Chromatogram(new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 6, 4, 2 }, false);
            var          b = a.CreateSmoothChromatogram(SmoothingType.BoxCar, 4);

            Assert.IsTrue(b.GetTimes().SequenceEqual(new double[] { 2, 3, 4 }));
            Assert.IsTrue(b.GetIntensities().SequenceEqual(new double[] { 3, 4, 4 }));

            Chromatogram d = new Chromatogram(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new double[] { 10, 0, 2, 6, 2, 0, 1, 10, 1 }, false);

            // Finds the APEX! Not nearest peak!
            Assert.AreEqual(6, d.FindNearestApex(5.9, 1).Intensity);
            Assert.AreEqual(10, d.FindNearestApex(6.1, 1).Intensity);

            var elutionProfile = d.GetElutionProfile(new DoubleRange(3, 7));

            Assert.AreEqual(5, elutionProfile.Count);
            Assert.AreEqual(9.5, elutionProfile.TrapezoidalArea());

            Assert.AreEqual(2, elutionProfile.StartPeak.Intensity);
            Assert.AreEqual(3, elutionProfile.StartPeak.Time);
            Assert.AreEqual(7, elutionProfile.EndPeak.Time);

            var thePeak = new ChromatographicPeak(1, 10);

            Assert.AreEqual(1, thePeak.Time);
            Assert.AreEqual(10, thePeak.Intensity);
            Assert.AreEqual("(1, 10)", thePeak.ToString());

            var elutionProfileEmpty = d.GetElutionProfile(new DoubleRange(6.5, 6.5));

            Assert.AreEqual(0, elutionProfileEmpty.TrapezoidalArea());
            Assert.AreEqual(0, elutionProfileEmpty.SummedArea);

            Assert.AreEqual("Count = 9 TIC = 32", d.ToString());
            Assert.AreEqual(10, d.GetApex().Intensity);
            Assert.AreEqual(1, d.GetApex().Time);
        }
 public int CompareTo(ChromatographicPeak other)
 {
     return(Time.CompareTo(other.Time));
 }
Beispiel #3
0
        //This function changes the LFQ (apex) intensities of the peaks to be SILAC intensities that only use intensities from MS1 scans where both heavy and light were quantified (only requires 2 for missed cleavages)
        //TODO: unclear how this affects data quality when deuterium shift is in play. A retention time calibration may be necessary.
        private static void CalculateSilacIntensities(Dictionary <SpectraFileInfo, List <ChromatographicPeak> > peakDictionary, Dictionary <string, List <FlashLFQ.Peptide> > unlabeledToPeptidesDictionary)
        {
            foreach (KeyValuePair <SpectraFileInfo, List <ChromatographicPeak> > kvp in peakDictionary)
            {
                //make a dictionary for easy peak lookup from peptide sequences
                Dictionary <string, ChromatographicPeak> sequenceToPeakDictionary = new Dictionary <string, ChromatographicPeak>();
                foreach (ChromatographicPeak peak in kvp.Value)
                {
                    //sometimes chromatographic peaks are separated (elute on both sides of the gradient, random blips, etc)
                    //in these situations, we want to use both chromatographic peaks for quantification, not just a single one.
                    string fullSequence = peak.Identifications.First().ModifiedSequence;
                    if (sequenceToPeakDictionary.ContainsKey(fullSequence))
                    {
                        ChromatographicPeak previousPeak = sequenceToPeakDictionary[fullSequence];
                        previousPeak.IsotopicEnvelopes.AddRange(peak.IsotopicEnvelopes);
                    }
                    else
                    {
                        sequenceToPeakDictionary.Add(fullSequence, peak);
                    }
                }

                foreach (List <FlashLFQ.Peptide> peptideGroup in unlabeledToPeptidesDictionary.Select(x => x.Value))
                {
                    List <string> sequences = peptideGroup.Select(x => x.Sequence).ToList();

                    //get peaks of interest for this peptide group
                    List <ChromatographicPeak> peaksOfInterest = new List <ChromatographicPeak>();
                    foreach (string sequence in sequences)
                    {
                        if (sequenceToPeakDictionary.TryGetValue(sequence, out ChromatographicPeak peakOfInterest))
                        {
                            peaksOfInterest.Add(peakOfInterest);
                        }
                    }

                    //If there are fewer than 2 peaks, we can't do any comparisons
                    if (peaksOfInterest.Count > 1)
                    {
                        //get isotopic envelopes that are shared by all
                        List <int> scanIndex = peaksOfInterest.First().IsotopicEnvelopes.Select(x => x.IndexedPeak).Select(x => x.ZeroBasedMs1ScanIndex).ToList();
                        for (int i = 1; i < peaksOfInterest.Count; i++)
                        {
                            List <int> currentScanIndexes = peaksOfInterest[i].IsotopicEnvelopes.Select(x => x.IndexedPeak).Select(x => x.ZeroBasedMs1ScanIndex).ToList();
                            scanIndex = scanIndex.Intersect(currentScanIndexes).ToList();
                            if (scanIndex.Count == 0) //if there's no overlap, then we're done!
                            {
                                break;
                            }
                        }
                        //if we aren't sticking with the default values
                        if (scanIndex.Count != 0)
                        {
                            //update peptides
                            foreach (FlashLFQ.Peptide peptide in peptideGroup)
                            {
                                ChromatographicPeak peakForThisPeptide = peaksOfInterest.Where(x => peptide.Sequence.Equals(x.Identifications.First().ModifiedSequence)).FirstOrDefault();
                                if (peakForThisPeptide != null)
                                {
                                    double summedIntensity = peakForThisPeptide.IsotopicEnvelopes.Where(x => scanIndex.Contains(x.IndexedPeak.ZeroBasedMs1ScanIndex)).Select(x => x.Intensity).Sum();
                                    peptide.SetIntensity(kvp.Key, summedIntensity);
                                }
                                else //rare instance, cause unknown. Crash identified using 180524_LMuscle_30d_bio3.raw, Mus_Canonical_180122.xml, 1 missed cleavage
                                {
                                    peptide.SetIntensity(kvp.Key, 0);
                                }
                            }
                        }
                    }
                }
            }
        }
 public int CompareTo(ChromatographicPeak other)
 {
     return Time.CompareTo(other.Time);
 }