//----------------------------- //----------------------------------------------------------------------------------------------------- public void RebuildProteinsFromScans() { //Find the proteins that have MyProteinList.AsParallel().ForAll(a => a.Scans = a.Scans.Intersect(AllSQTScans).ToList()); MyProteinList.RemoveAll(a => a.Scans.Count == 0); RebuildPeptideListFromUpdatedProteinList(); }
private void RebuildPeptideListFromUpdatedProteinList() { Console.WriteLine(" Building peptide list from protein list"); List <string> cleanedSequences = AllCleanedPeptideSequences; //Patch pointed out by tiago balbuena to deal with peptides of same sequence but different flanking aa. Dictionary <string, List <PeptideResult> > seqCounter = (from prot in MyProteinList.AsParallel() from pep in prot.PeptideResults where cleanedSequences.Contains(pep.CleanedPeptideSequence) group pep by pep.CleanedPeptideSequence into g select new { Sequence = g.Key, Peptides = g }).ToDictionary(a => a.Sequence, a => a.Peptides.ToList()); foreach (KeyValuePair <string, List <PeptideResult> > kvp in seqCounter) { if (kvp.Value.Count > 1) { List <string> dSequences = (from pr in kvp.Value select pr.PeptideSequence).Distinct().ToList(); if (dSequences.Count > 1) { //Lets create a new peptide result List <SQTScan> allScans = new List <SQTScan>(); foreach (PeptideResult pr in kvp.Value) { allScans.AddRange(pr.MyScans); } allScans = allScans.Distinct().ToList(); PeptideResult surrogate = new PeptideResult(kvp.Key, allScans); kvp.Value.Clear(); kvp.Value.Add(surrogate); } } } MyPeptideList = new List <PeptideResult>(seqCounter.Keys.Count); foreach (KeyValuePair <string, List <PeptideResult> > kvp in seqCounter) { MyPeptideList.Add(kvp.Value[0]); } //RebuildScansFromProteins(); Console.WriteLine(" Done building peptide list"); }