/// <summary> /// Computes a list of potential mixed precursors. /// Based on mass and elution time, spectrum are assembled and elution curves are computed for every precursor /// that has a coverage satisfying the minimum necessary to undergo the deconvolution process. /// </summary> /// <param name="mixedSample"></param> /// <param name="mixedResult"></param> /// <param name="dbOptions"></param> /// <param name="charPeptides"></param> /// <returns></returns> 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); }
/// <summary> /// Computes a list of precursor from a sample, based on Propheus identification results /// </summary> /// <param name="result"></param> /// <param name="sample"></param> /// <param name="dbOptions"></param> /// <param name="keys"></param> /// <returns></returns> public static Dictionary <double, PrecursorIon> GetPrecursors(Result result, Sample sample, DBOptions dbOptions, IEnumerable <double> keys) { Dictionary <double, PrecursorIon> DicOfSpectrumMasses = new Dictionary <double, PrecursorIon>(); foreach (Query query in result.queries) { if (query.sample == sample) { double foundKey = query.spectrum.PrecursorMZ; bool foundInKeys = false; foreach (double key in keys) { double distance = Math.Abs(Utilities.Numerics.CalculateMassError(query.spectrum.PrecursorMZ, key, dbOptions.precursorMassTolerance.Units)); if (distance <= dbOptions.precursorMassTolerance.Value) { if (!foundInKeys || distance < Math.Abs(Utilities.Numerics.CalculateMassError(query.spectrum.PrecursorMZ, foundKey, dbOptions.precursorMassTolerance.Units))) { foundKey = key; } foundInKeys = true; } } if (!foundInKeys) { foreach (double key in DicOfSpectrumMasses.Keys) { if (Math.Abs(Utilities.Numerics.CalculateMassError(query.spectrum.PrecursorMZ, key, dbOptions.precursorMassTolerance.Units)) <= dbOptions.precursorMassTolerance.Value) { foundKey = key; } } } if (!DicOfSpectrumMasses.ContainsKey(foundKey)) { PrecursorIon precIon = new PrecursorIon(sample, new Queries(dbOptions), foundKey, -1); precIon.AddQuery(query); DicOfSpectrumMasses.Add(foundKey, precIon); } else { DicOfSpectrumMasses[foundKey].AddQuery(query); } } } //Split similar precursor mass not eluting at the same time //aussi://retirer le processus de clustering de pAce return(DicOfSpectrumMasses); }
/// <summary> /// Creates a dictionnary of characterized precursors based on ProPheus assignement results /// </summary> /// <param name="spikedSamples"></param> /// <param name="spikedResult"></param> /// <param name="dbOptions"></param> /// <param name="nbMinFragments"></param> /// <param name="nbMaxFragments"></param> /// <returns></returns> 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 = 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(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); }
public MixedPrecursor(Sample sample, PrecursorIon precursorIon, double mz) : base(sample, precursorIon.Queries, mz, -1) { }