public void ReducePsms(IEqualityComparer <Peptide> comparer) { Dictionary <Peptide, Peptide> peptides = new Dictionary <Peptide, Peptide>(comparer); foreach (PSM psm in PeptideSpectralMatches) { Peptide peptide = new Peptide(psm); Peptide realPeptide; if (peptides.TryGetValue(peptide, out realPeptide)) { realPeptide.AddPsm(psm); } else { peptides.Add(peptide, peptide); } } Peptides = peptides.Values.ToList(); }
public int CompareTo(Peptide other) { return(BestMatch.CompareTo(other.BestMatch)); }
private void ReducePsms(IList <InputFile> csvFiles, UniquePeptideType uniquePeptideType, bool isBatched = false) { string msg = "Converting PSMs into unique peptides based "; IEqualityComparer <Peptide> comparer; switch (uniquePeptideType) { default: msg += "on sequence only"; comparer = new SequenceComparer(); break; case UniquePeptideType.Mass: msg += "on mass"; comparer = new MassComparer(); break; case UniquePeptideType.SequenceAndModifications: msg += "on sequence and positional modifications"; comparer = new SequenceModComparer(); break; case UniquePeptideType.SequenceAndModLocations: msg += "on sequence and modification locations"; comparer = new SequenceAndModPositionComparer(); break; case UniquePeptideType.SequenceAndMass: msg += "on sequence and mass"; comparer = new SequenceMassComparer(); break; case UniquePeptideType.Nothing: msg += "on nothing (no reduction)"; comparer = new IdentityComparer <Peptide>(); break; } Log(msg); foreach (InputFile csvFile in csvFiles) { csvFile.ReducePsms(comparer); Log(string.Format("{0:N0} unique peptides remain from {1:N0} PSMs from {2}", csvFile.Peptides.Count, csvFile.PeptideSpectralMatches.Count, csvFile.Name)); } if (!isBatched) { return; } Dictionary <Peptide, Peptide> peptideDictionary = new Dictionary <Peptide, Peptide>(comparer); foreach (Peptide peptide in csvFiles.SelectMany(csvFile => csvFile.Peptides)) { Peptide realPeptide; if (peptideDictionary.TryGetValue(peptide, out realPeptide)) { foreach (PSM psm in peptide.PSMs) { realPeptide.AddPsm(psm); } } else { Peptide newPeptide = new Peptide(peptide); peptideDictionary.Add(newPeptide, newPeptide); } } _allPeptides = peptideDictionary.Values.ToList(); Log(string.Format("{0:N0} unique peptides from all files [Batched]", _allPeptides.Count)); }