public void GetRatioBasedOnTopPeaks(IsotopicProfile iso1, IsotopicProfile iso2, IsotopicProfile theorIso1, IsotopicProfile theorIso2, double backgroundIntensity, int numPeaks, out double ratio, out double ratioContribForIso1, out double ratioContribForIso2) { //Find top n peaks of the theor profile. Reference them by their peak index so that they can be looked up in the experimental. //List<int> sortedTheorIso1Indexes = getIndexValsOfTopPeaks(theorIso1); //List<int> sortedTheorIso2Indexes = getIndexValsOfTopPeaks(theorIso2); IList <Peak> topTheorIso1Peaks = GetTopPeaks(theorIso1, numPeaks); IList <Peak> topTheorIso2Peaks = GetTopPeaks(theorIso2, numPeaks); //get the top n peaks of the experimental profile, based on peaks of the theor profile //adjust intensity (subtract background intensity) var topIso1Peaks = GetTopPeaksBasedOnTheor(iso1, topTheorIso1Peaks, MSToleranceInPPM); var topIso2Peaks = GetTopPeaksBasedOnTheor(iso2, topTheorIso2Peaks, MSToleranceInPPM); //Since the number of top experimental iso peaks may be less than the number of top theor iso peaks, //we have to filter and ensure that they have the same peak numbers, so that the correction factor // (applied below) is properly applied. HOWEVER, this may induce some differences between runs var filteredTopTheorIso1Peaks = GetTopPeaksBasedOnTheor(theorIso1, topIso1Peaks, MSToleranceInPPM); var filteredTopTheorIso2Peaks = GetTopPeaksBasedOnTheor(theorIso2, topIso2Peaks, MSToleranceInPPM); var summedTopIso1PeakIntensities = PeakUtilities.GetSumOfIntensities(topIso1Peaks, backgroundIntensity); var summedTopIso2PeakIntensities = PeakUtilities.GetSumOfIntensities(topIso2Peaks, backgroundIntensity); //Console.WriteLine(backgroundIntensity); //need to find out the contribution of the top n peaks to the overall isotopic envelope. Base this on the theor profile double summedTheorIso1Intensities = filteredTopTheorIso1Peaks.Sum(p => (p.Height)); double summedTheorIso2Intensities = filteredTopTheorIso2Peaks.Sum(p => (p.Height)); var fractionTheor1 = summedTheorIso1Intensities / theorIso1.Peaklist.Sum(p => p.Height); var fractionTheor2 = summedTheorIso2Intensities / theorIso2.Peaklist.Sum(p => p.Height); //use the above ratio to correct the intensities based on how much the top n peaks contribute to the profile. var correctedIso1SummedIntensity = summedTopIso1PeakIntensities / fractionTheor1; var correctedIso2SummedIntensity = summedTopIso2PeakIntensities / fractionTheor2; var summedAllIsos1PeakIntensities = iso1.Peaklist.Sum(p => (p.Height - backgroundIntensity)); var summedAllIsos2PeakIntensities = iso2.Peaklist.Sum(p => (p.Height - backgroundIntensity)); switch (RatioType) { case RatioType.ISO1_OVER_ISO2: ratio = correctedIso1SummedIntensity / correctedIso2SummedIntensity; break; case RatioType.ISO2_OVER_ISO1: ratio = correctedIso2SummedIntensity / correctedIso1SummedIntensity; break; default: ratio = correctedIso1SummedIntensity / correctedIso2SummedIntensity; break; } ratioContribForIso1 = summedTopIso1PeakIntensities / summedAllIsos1PeakIntensities * 1 / fractionTheor1; //we expect a value of '1' ratioContribForIso2 = summedTopIso2PeakIntensities / summedAllIsos2PeakIntensities * 1 / fractionTheor2; }