private static SequenceMods GetShuffledPeptideSequence(SequenceMods seqMods) { string sequence = seqMods.Sequence; char finalA = sequence.Last(); string sequencePrefix = sequence.Substring(0, sequence.Length - 1); int lenPrefix = sequencePrefix.Length; // Calculate a random shuffling of the current positions int[] newIndices = new int[lenPrefix]; do { for (int i = 0; i < lenPrefix; i++) newIndices[i] = i; for (int i = 0; i < lenPrefix; i++) Helpers.Swap(ref newIndices[RANDOM.Next(newIndices.Length)], ref newIndices[RANDOM.Next(newIndices.Length)]); // Move the amino acids to their new positions char[] shuffledArray = new char[lenPrefix]; for (int i = 0; i < lenPrefix; i++) shuffledArray[newIndices[i]] = sequencePrefix[i]; seqMods.Sequence = new string(shuffledArray) + finalA; } // Make sure random shuffling did not just result in the same sequence while (seqMods.Sequence.Equals(sequence)); if (seqMods.Mods != null) { var shuffledStaticMods = GetShuffledMods(seqMods.Mods.StaticModifications, lenPrefix, newIndices); var typedStaticMods = GetStaticTypedMods(seqMods.Peptide, shuffledStaticMods); seqMods.Mods = new ExplicitMods(seqMods.Peptide, shuffledStaticMods, GetShuffledHeavyMods(seqMods, typedStaticMods, lenPrefix, newIndices), seqMods.Mods.IsVariableStaticMods); } return seqMods; }
private static SequenceMods GetReversedPeptideSequence(SequenceMods seqMods) { string sequence = seqMods.Sequence; char finalA = sequence.Last(); sequence = sequence.Substring(0, sequence.Length - 1); int lenSeq = sequence.Length; char[] reversedArray = sequence.ToCharArray(); Array.Reverse(reversedArray); seqMods.Sequence = new string(reversedArray) + finalA; if (seqMods.Mods != null) { var reversedStaticMods = GetReversedMods(seqMods.Mods.StaticModifications, lenSeq); var typedStaticMods = GetStaticTypedMods(seqMods.Peptide, reversedStaticMods); seqMods.Mods = new ExplicitMods(seqMods.Peptide, reversedStaticMods, GetReversedHeavyMods(seqMods, typedStaticMods, lenSeq), seqMods.Mods.IsVariableStaticMods); } return seqMods; }
private static IEnumerable<TypedExplicitModifications> GetShuffledHeavyMods(SequenceMods seqMods, TypedExplicitModifications typedStaticMods, int lenSeq, int[] newIndices) { var shuffledHeavyMods = seqMods.Mods.GetHeavyModifications().Select(typedMod => new TypedExplicitModifications(seqMods.Peptide, typedMod.LabelType, GetShuffledMods(typedMod.Modifications, lenSeq, newIndices))); foreach (var typedMods in shuffledHeavyMods) { yield return typedMods.AddModMasses(typedStaticMods); } }
private static SrmDocument GenerateDecoysFunc(SrmDocument document, int numDecoys, bool multiCycle, Func<SequenceMods, SequenceMods> genDecoySequence) { // Loop through the existing tree in random order creating decoys var settings = document.Settings; var enzyme = settings.PeptideSettings.Enzyme; var decoyNodePepList = new List<PeptideDocNode>(); var setDecoyKeys = new HashSet<PeptideModKey>(); while (numDecoys > 0) { int startDecoys = numDecoys; foreach (var nodePep in document.Peptides.ToArray().RandomOrder()) { if (numDecoys == 0) break; // Decoys should not be based on standard peptides if (nodePep.GlobalStandardType != null) continue; // If the non-terminal end of the peptide sequence is all a single character, skip this peptide, // since it can't support decoy generation. var sequence = nodePep.Peptide.Sequence; if (genDecoySequence != null && sequence.Substring(0, sequence.Length - 1).Distinct().Count() == 1) continue; var seqMods = new SequenceMods(nodePep); if (genDecoySequence != null) { seqMods = genDecoySequence(seqMods); } var peptide = nodePep.Peptide; var decoyPeptide = new Peptide(null, seqMods.Sequence, null, null, enzyme.CountCleavagePoints(seqMods.Sequence), true); if (seqMods.Mods != null) seqMods.Mods = seqMods.Mods.ChangePeptide(decoyPeptide); foreach (var comparableGroups in PeakFeatureEnumerator.ComparableGroups(nodePep)) { var decoyNodeTranGroupList = GetDecoyGroups(nodePep, decoyPeptide, seqMods.Mods, comparableGroups, document, Equals(seqMods.Sequence, peptide.Sequence)); if (decoyNodeTranGroupList.Count == 0) continue; var nodePepNew = new PeptideDocNode(decoyPeptide, settings, seqMods.Mods, null, nodePep.ExplicitRetentionTime, decoyNodeTranGroupList.ToArray(), false); if (!Equals(nodePep.ModifiedSequence, nodePepNew.ModifiedSequence)) { var sourceKey = new ModifiedSequenceMods(nodePep.ModifiedSequence, nodePep.ExplicitMods); nodePepNew = nodePepNew.ChangeSourceKey(sourceKey); } // Avoid adding duplicate peptides if (setDecoyKeys.Contains(nodePepNew.Key)) continue; setDecoyKeys.Add(nodePepNew.Key); decoyNodePepList.Add(nodePepNew); numDecoys--; } } // Stop if not multi-cycle or the number of decoys has not changed. if (!multiCycle || startDecoys == numDecoys) break; } var decoyNodePepGroup = new PeptideGroupDocNode(new PeptideGroup(true), Annotations.EMPTY, PeptideGroup.DECOYS, null, decoyNodePepList.ToArray(), false); decoyNodePepGroup = decoyNodePepGroup.ChangeSettings(document.Settings, SrmSettingsDiff.ALL); return (SrmDocument)document.Add(decoyNodePepGroup); }