public IEnumerable <Peptide> GenerateAllModificationCombinations() { // Get all the modifications that are isotopologues var isotopologues = GetUniqueModifications <ModificationWithMultiplePossibilitiesCollection>().ToArray(); // Base condition, no more isotopologues to make, so just return if (isotopologues.Length < 1) { yield break; } // Grab the the first isotopologue ModificationWithMultiplePossibilitiesCollection isotopologue = isotopologues[0]; // Loop over each modification in the isotopologue foreach (OldSchoolModification mod in isotopologue) { // Create a clone of the peptide, cloning modifications as well. Peptide peptide = new Peptide(this); // Replace the base isotopologue mod with the specific version peptide.ReplaceModification(isotopologue, mod); // There were more than one isotopologue, so we must go deeper if (isotopologues.Length > 1) { // Call the same rotuine on the newly generate peptide that has one less isotopologue foreach (var subpeptide in peptide.GenerateAllModificationCombinations()) { yield return(subpeptide); } } else { // Return this peptide yield return(peptide); } } }
protected override MetaMorpheusEngineResults RunSpecific() { Status("Extracting data points:"); // The final training point list int numMs1MassChargeCombinationsConsidered = 0; int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = 0; int numMs2MassChargeCombinationsConsidered = 0; int numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = 0; List <LabeledDataPoint> Ms1List = new List <LabeledDataPoint>(); List <LabeledDataPoint> Ms2List = new List <LabeledDataPoint>(); int numIdentifications = GoodIdentifications.Count; // Loop over identifications HashSet <string> sequences = new HashSet <string>(); object lockObj = new object(); object lockObj2 = new object(); Parallel.ForEach(Partitioner.Create(0, numIdentifications), new ParallelOptions { MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile }, (fff, loopState) => { for (int matchIndex = fff.Item1; matchIndex < fff.Item2; matchIndex++) { // Stop loop if canceled if (GlobalVariables.StopLoops) { loopState.Stop(); return; } PeptideSpectralMatch identification = GoodIdentifications[matchIndex]; // Each identification has an MS2 spectrum attached to it. int ms2scanNumber = identification.ScanNumber; int peptideCharge = identification.ScanPrecursorCharge; if (identification.FullSequence == null) { continue; } var representativeSinglePeptide = identification.CompactPeptides.First().Value.Item2.First(); // Get the peptide, don't forget to add the modifications!!!! var SequenceWithChemicalFormulas = representativeSinglePeptide.SequenceWithChemicalFormulas; if (SequenceWithChemicalFormulas == null || representativeSinglePeptide.AllModsOneIsNterminus.Any(b => b.Value.neutralLosses.Count != 1 || b.Value.neutralLosses.First() != 0)) { continue; } Proteomics.AminoAcidPolymer.Peptide coolPeptide = new Proteomics.AminoAcidPolymer.Peptide(SequenceWithChemicalFormulas); var ms2tuple = SearchMS2Spectrum(MyMsDataFile.GetOneBasedScan(ms2scanNumber), identification); lock (lockObj2) { Ms2List.AddRange(ms2tuple); } // Calculate isotopic distribution of the full peptide var dist = IsotopicDistribution.GetDistribution(coolPeptide.GetChemicalFormula(), FineResolutionForIsotopeDistCalculation, 0.001); double[] theoreticalMasses = dist.Masses.ToArray(); double[] theoreticalIntensities = dist.Intensities.ToArray(); Array.Sort(theoreticalIntensities, theoreticalMasses, Comparer <double> .Create((x, y) => y.CompareTo(x))); var ms1tupleBack = SearchMS1Spectra(theoreticalMasses, theoreticalIntensities, ms2scanNumber, -1, peptideCharge, identification); var ms1tupleForward = SearchMS1Spectra(theoreticalMasses, theoreticalIntensities, ms2scanNumber, 1, peptideCharge, identification); lock (lockObj) { Ms1List.AddRange(ms1tupleBack.Item1); numMs1MassChargeCombinationsConsidered += ms1tupleBack.Item2; numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks += ms1tupleBack.Item3; Ms1List.AddRange(ms1tupleForward.Item1); numMs1MassChargeCombinationsConsidered += ms1tupleForward.Item2; numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks += ms1tupleForward.Item3; } } }); // datapoints are ordered because they were acquired in a parallized search and we want repeatable results return(new DataPointAquisitionResults(this, GoodIdentifications, Ms1List.OrderBy(p => p.RetentionTime).ThenBy(p => p.ExperimentalMz).ToList(), Ms2List.OrderBy(p => p.RetentionTime).ThenBy(p => p.ExperimentalMz).ToList(), numMs1MassChargeCombinationsConsidered, numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, numMs2MassChargeCombinationsConsidered, numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks )); }