/// <summary> /// Constructor used for Unit tests /// </summary> /// <param name="masses"></param> public Queries(DBOptions options, double[] masses) { Precursors = new Precursors(); foreach (double mass in masses) { Precursor precursor = new Precursor(); precursor.Mass = mass; Add(new Query(options, null, null, precursor)); Precursors.Add(precursor); } }
public void CumulPsm(List <Precursor> matches) { foreach (Precursor precursor in matches) { Sample entry = precursor.sample; precursors.Add(precursor);//Remove blank psm (unmatched spectrum/query duos) /* if (!samples.ContainsKey(entry.PROJECT.CONDITION)) * samples.Add(entry.PROJECT.CONDITION, new List<int>()); * if (!samples[entry.PROJECT.CONDITION].Contains(entry.PROJECT.REPLICATE)) * samples[entry.PROJECT.CONDITION].Add(entry.PROJECT.REPLICATE);//*/ } }
public long SetPrecursors(Precursors precursors) { this.precursors = precursors; this.matchedPrecursors = new Precursors(); long nbTargets = 0; foreach (Precursor precursor in precursors) { if (precursor.psms != null && precursor.psms.Count > 0) { if (precursor.Target) { nbTargets++; } matchedPrecursors.Add(precursor); } } return(nbTargets); }
public void Export(double fdr, string keyword = "", bool onlyPrecursors = false) { dbOptions.ConSole.WriteLine("Exporting at " + (fdr * 100) + "% FDR (Decoy/Target)..."); List <Precursor> prec = null; if (precursors != null) { if (matchedPrecursors == null) { this.matchedPrecursors = new Precursors(); foreach (Precursor precursor in precursors) { if (precursor.psms.Count > 0) { matchedPrecursors.Add(precursor); } } }/* * List<Precursor> prec = FDR.PrecursorsV2(precursors, fdr, 1); * Sol.CONSOLE.OutputLine("> " + prec.Count + " Precursors"); * MSSearcher.Export(dbOptions.outputFolder + keyword + "precursors.csv", prec);//*/ /* * prec = Optimizer.PrecursorOptimizer(matchedPrecursors, fdr); * Sol.CONSOLE.OutputLine("> " + prec.Count + " Optimized Precursors"); * MSSearcher.Export(dbOptions.outputFolder + keyword + "Optimized_precursors.csv", prec);//*/ prec = matchedPrecursors.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + prec.Count + " Uptimized V5 Precursors"); MSSearcher.Export(dbOptions.OutputFolder + keyword + "UptimizedV5_precursors.csv", prec); } if (!onlyPrecursors) { if (queries != null) { List <Query> qs = queries.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + qs.Count + " PSMs (Top 10)"); MSSearcher.Export(dbOptions.OutputFolder + keyword + "queries.csv", qs); } if (clusters != null) { //List<PeptideSpectrumMatch> psms = FDR.PSMs(clusters, fdr, 1, 10); //dbOptions.ConSole.WriteLine("> " + psms.Count + " PSMs (Top 10)"); //MSSearcher.Export(dbOptions.outputFolder + keyword + "psms_Top10.csv", psms); //psms = FDR.PSMs(clusters, fdr, 1, 1); //dbOptions.ConSole.WriteLine("> " + psms.Count + " PSMs"); //MSSearcher.Export(dbOptions.outputFolder + keyword + "psms_Best.csv", psms); } if (peptides != null) { List <PeptideMatch> pep = peptideSequences.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + pep.Count + " Peptides Sequences (Version 5)"); PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptideSequencesV5_.csv", pep); PeptideSearcher sr = new PeptideSearcher(dbOptions); PeptideMatches seqs = sr.Search(clusters, prec, false); pep = seqs.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + pep.Count + " Peptides Sequences (Version 5b)"); PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptideSequencesV5b_PrecursorFDRed.csv", pep); pep = peptides.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + pep.Count + " Peptides (Version 5)"); PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptidesV5_.csv", pep); } if (proteins != null) { List <ProteinGroupMatch> prots = proteins.ComputeAtFDR(fdr); dbOptions.ConSole.WriteLine("> " + prots.Count + " Proteins"); ProteinSearcher.Export(dbOptions.OutputFolder + keyword + "proteins_.csv", prots); } } }
public void GenerateQueries(Sample entry, Spectra spectra, Tracks tracks)//, double mz, double rt, double intensity) { Dictionary <Track, Precursor> Tracks = new Dictionary <Track, Precursor>(); Dictionary <Track, Precursor> Isotopes = new Dictionary <Track, Precursor>(); //Create one query per Spectrum-Precursor duo, including Isotopes in the process to ease search //For further analysis, maintain a list of precursors (excluding isotopes) int nbMissedTrack = 0; //vsSDF sdf = entry.GetSDF();// Samples.LoadSDF(entry); //tracks.PrepareRtSort(); //sdf.TRACKS_LIST.PrepareRtSort(); spectra.Sort(ProductSpectrum.AscendingPrecursorMassComparison); foreach (ProductSpectrum spectrum in spectra) { NbSpectrum++; double intensityCumul = 0.0; bool foundCharge = false; Track closestTrack = null; List <Query> newQueries = new List <Query>(); //TODO No threshold on sdf files, and preferably a C# routine that does what MassSense do foreach (Track track in tracks.GetTracksInMzRange(spectrum.PrecursorMZ, spectrum.IsolationWindow * dbOptions.EffectiveIsolationWindowRatio))//TODO Optimize this value { Precursor prec = null; if (track.RT_Min <= spectrum.RetentionTimeInMin && track.RT_Max >= spectrum.RetentionTimeInMin) { if (closestTrack == null || Math.Abs(track.MZ - spectrum.PrecursorMZ) < Math.Abs(closestTrack.MZ - spectrum.PrecursorMZ)) { closestTrack = track; } if (Isotopes.ContainsKey(track)) { break; } if (Tracks.ContainsKey(track)) { prec = Tracks[track]; } else { GraphML_List <Precursor> isotopes = GetIsotopes(track, dbOptions, tracks, entry); if (isotopes.Count > 0) { prec = new Precursor(track, isotopes[0].Charge, entry, 0.0, isotopes); Tracks.Add(track, prec); prec.OtherCharges = GetOtherCharges(prec, dbOptions, tracks, entry); foreach (Precursor isotope in prec.Isotopes) { if (!Isotopes.ContainsKey(isotope.Track)) { Isotopes.Add(isotope.Track, isotope); } } } } if (prec != null) { intensityCumul += track.INTENSITY; newQueries.Add(new Query(dbOptions, entry, spectrum, prec, NbSpectrum)); if (prec.Charge == spectrum.PrecursorCharge) { foundCharge = true; } } } } if (!foundCharge) { /*if (closestTrack != null && Tracks.ContainsKey(closestTrack) && Math.Abs(Numerics.CalculateMassError(closestTrack.MZ, spectrum.PrecursorMZ, dbOptions.precursorMassTolerance.Units)) < dbOptions.precursorMassTolerance.Value) * { * if(closestTrack.RT_Min > (float)(spectrum.RetentionTimeInMin - dbOptions.ComputedRetentionTimeDiff)) * closestTrack.RT_Min = (float)(spectrum.RetentionTimeInMin - dbOptions.ComputedRetentionTimeDiff); * if (closestTrack.RT_Max < (float)(spectrum.RetentionTimeInMin + dbOptions.ComputedRetentionTimeDiff)) * closestTrack.RT_Max = (float)(spectrum.RetentionTimeInMin + dbOptions.ComputedRetentionTimeDiff); * if (closestTrack.INTENSITY < spectrum.PrecursorIntensity) * closestTrack.INTENSITY = spectrum.PrecursorIntensity; * * Precursor prec = Tracks[closestTrack]; * if (prec.Charge == spectrum.PrecursorCharge) * { * Add(new Query(dbOptions, entry, spectrum, prec, NbSpectrum)); * } * else * { * Precursor newPrec = new Precursor(closestTrack, spectrum.PrecursorCharge, entry); * Add(new Query(dbOptions, entry, spectrum, newPrec, NbSpectrum)); * } * } * else//*/ { nbMissedTrack++; closestTrack = new Track((float)spectrum.PrecursorMZ, (float)spectrum.RetentionTimeInMin, spectrum.PrecursorIntensity, (float)(spectrum.RetentionTimeInMin - dbOptions.ComputedRetentionTimeDiff), (float)(spectrum.RetentionTimeInMin + dbOptions.ComputedRetentionTimeDiff), true); Precursor prec = new Precursor(closestTrack, spectrum.PrecursorCharge, entry); Tracks.Add(closestTrack, prec); Add(new Query(dbOptions, entry, spectrum, prec, NbSpectrum)); } }//*/ if (newQueries.Count > 0) { //Remove precursors if estimated fragment intensities are too low (based on precursor intensity ratios and isolation window placement) foreach (Query q in newQueries) { //if (q.precursor.Track.INTENSITY > intensityCumul * dbOptions.MinimumPrecursorIntensityRatioInIsolationWindow)//Need to be 5% of all intensity //{ this.Add(q); //} } } Console.Write("\r{0}% ", ((100 * NbSpectrum) / spectra.Count)); } Console.Write("\r{0}% ", 100); //Sort queries to ease search this.Sort(AscendingPrecursorMassComparison); foreach (Track track in Tracks.Keys) { if (!Isotopes.ContainsKey(track)) { Precursors.Add(Tracks[track]); } } //TODO Validate this approach //REMOVE QUERIES RELATED TO AN ISOTOPE and Compute the average CoElution Dictionary <ProductSpectrum, double> DicOfSpectrumIntensities = new Dictionary <ProductSpectrum, double>(); for (int i = 0; i < this.Count;) { Query query = this[i]; if (!Isotopes.ContainsKey(query.precursor.Track)) { if (!DicOfSpectrumIntensities.ContainsKey(query.spectrum)) { DicOfSpectrumIntensities.Add(query.spectrum, query.precursor.Track.INTENSITY); } else { DicOfSpectrumIntensities[query.spectrum] += query.precursor.Track.INTENSITY; } i++; } else { this.RemoveAt(i); } } //REMOVE Queries with Precursor intensities too low for (int i = 0; i < this.Count;) { Query query = this[i]; if (query.precursor.Track.INTENSITY < DicOfSpectrumIntensities[query.spectrum] * dbOptions.MinimumPrecursorIntensityRatioInIsolationWindow) { this.RemoveAt(i); } else { i++; } }//*/ Dictionary <ProductSpectrum, int> DicOfSpectrumTracks = new Dictionary <ProductSpectrum, int>(); for (int i = 0; i < this.Count;) { Query query = this[i]; if (!Isotopes.ContainsKey(query.precursor.Track)) { if (!DicOfSpectrumTracks.ContainsKey(query.spectrum)) { DicOfSpectrumTracks.Add(query.spectrum, 1); } else { DicOfSpectrumTracks[query.spectrum]++; } i++; } else { this.RemoveAt(i); } } double averageNbPrecursorPerSpectrum = 0; int nbSpectrumMatchedToTrack = 0; foreach (ProductSpectrum spectrum in DicOfSpectrumTracks.Keys) { nbSpectrumMatchedToTrack++; averageNbPrecursorPerSpectrum += DicOfSpectrumTracks[spectrum]; } dbOptions.ConSole.WriteLine(entry.sSDF + " :" + Precursors.Count + " precursors [" + Isotopes.Count + " isotopes] spreaded in " + Count + " queries [" + nbMissedTrack + " trackless precursors]"); dbOptions.ConSole.WriteLine("Average Precursors per Spectrum : " + averageNbPrecursorPerSpectrum / (double)nbSpectrumMatchedToTrack); }