public static List <MixedPrecursor> GetMixedPrecursors(Sample mixedSample, Result mixedResult, DBOptions dbOptions, Dictionary <double, Dictionary <Sample, CharacterizedPrecursor> > charPeptides) { Dictionary <double, PrecursorIon> DicOfSpectrumMasses = PrecursorIon.GetPrecursors(mixedResult, mixedSample, dbOptions, charPeptides.Keys); //Dictionary<double, MixedPrecursor> DicOfMixedPrecursor = new Dictionary<double, MixedPrecursor>(); List <MixedPrecursor> listOfMixedPrec = new List <MixedPrecursor>(); foreach (double key in DicOfSpectrumMasses.Keys) { if (charPeptides.ContainsKey(key)) { foreach (PrecursorIon precIon in DicOfSpectrumMasses[key].SplitBasedOnTime(dbOptions)) { MixedPrecursor mixedPrecursor = new MixedPrecursor(mixedSample, precIon, key); //Don't try to characterize mixed precursors if there is less than five scans if (mixedPrecursor.Queries.Count > 4) { foreach (Query q in mixedPrecursor.Queries) { q.spectrum.PrecursorIntensityPerMilliSecond = mixedPrecursor.eCurveIntensityPerMS.InterpolateIntensity(q.spectrum.RetentionTimeInMin * 1000.0 * 60.0 + 0.5 * q.spectrum.InjectionTime); } listOfMixedPrec.Add(mixedPrecursor); } //DicOfMixedPrecursor.Add(key, mixedPrecursor); } } } return(listOfMixedPrec); }
public static Dictionary <double, Dictionary <Sample, CharacterizedPrecursor> > GetSpikedPrecursors(Samples spikedSamples, Result spikedResult, DBOptions dbOptions, int nbMinFragments, int nbMaxFragments, long precision) { Dictionary <double, Dictionary <Query, int> > mzKeys = new Dictionary <double, Dictionary <Query, int> >(); foreach (Query query in spikedResult.queries) { foreach (PeptideSpectrumMatch psm in query.psms) { double mz = Proteomics.Utilities.Numerics.MZFromMass(psm.Peptide.MonoisotopicMass, query.spectrum.PrecursorCharge); if (!mzKeys.ContainsKey(mz)) { bool found = false; foreach (double key in mzKeys.Keys) { if (Math.Abs(Proteomics.Utilities.Numerics.CalculateMassError(mz, key, dbOptions.precursorMassTolerance.Units)) <= dbOptions.precursorMassTolerance.Value) { mz = key; found = true; } } if (!found) { mzKeys.Add(mz, new Dictionary <Query, int>()); } } if (!mzKeys[mz].ContainsKey(query)) { mzKeys[mz].Add(query, 1); } } } Dictionary <double, Dictionary <Sample, CharacterizedPrecursor> > spikes = new Dictionary <double, Dictionary <Sample, CharacterizedPrecursor> >(); foreach (Sample spikedSample in spikedSamples) { Dictionary <double, PrecursorIon> DicOfSpectrumMasses = PrecursorIon.GetPrecursors(spikedResult, spikedSample, dbOptions, mzKeys.Keys); foreach (double mzKey in DicOfSpectrumMasses.Keys) { if (mzKeys.ContainsKey(mzKey)) { //Pick the best PSM for each sample/precursor pair Dictionary <Peptide, double> DicOfProbabilityScores = new Dictionary <Peptide, double>(); foreach (Query query in mzKeys[mzKey].Keys) { if (query.sample == spikedSample) { foreach (PeptideSpectrumMatch psm in query.psms) { if (!DicOfProbabilityScores.ContainsKey(psm.Peptide)) { DicOfProbabilityScores.Add(psm.Peptide, psm.ProbabilityScore()); } else { DicOfProbabilityScores[psm.Peptide] += psm.ProbabilityScore(); } } } } Peptide bestPeptide = null; double bestScore = double.MinValue; foreach (Peptide keyPep in DicOfProbabilityScores.Keys) { if (DicOfProbabilityScores[keyPep] > bestScore) { bestScore = DicOfProbabilityScores[keyPep]; bestPeptide = keyPep; } } if (bestPeptide != null) { CharacterizedPrecursor cPrec = new CharacterizedPrecursor(spikedSample, dbOptions, bestPeptide, mzKeys[mzKey].Keys, mzKey); //Don't keep precursors if they are not well characterized (unfragmented or missasigned) if (cPrec.AllFragments.Count >= cPrec.Peptide.Length - 2) { if (!spikes.ContainsKey(mzKey)) { spikes.Add(mzKey, new Dictionary <Sample, CharacterizedPrecursor>()); } if (!spikes[mzKey].ContainsKey(spikedSample)) { spikes[mzKey].Add(spikedSample, cPrec); } else { Console.WriteLine("Twice??"); } } } } } //End of foreach mzKey } //End of foreach spiked sample //Normalize intensities based on average area of each precursor List <double> tmpKeys = new List <double>(spikes.Keys); foreach (double mzKey in tmpKeys) { if (spikes[mzKey].Count > 0) { CharacterizedPrecursor.Update(spikes[mzKey].Values, nbMinFragments, nbMaxFragments, dbOptions, precision); } else { spikes.Remove(mzKey); } }//*/ return(spikes); }