public ImmutableList <byte> GetNewTextId(ChromGroupHeaderInfo chromGroupHeaderInfo) { byte[] textIdBytes = _originalCache.GetTextIdBytes(chromGroupHeaderInfo.TextIdIndex, chromGroupHeaderInfo.TextIdLen); if (textIdBytes == null) { return(null); } const CacheFormatVersion versionNewTextId = CacheFormatVersion.Thirteen; ImmutableList <byte> newTextId; if (_originalCache.Version < versionNewTextId || _cacheFormat.FormatVersion >= versionNewTextId) { newTextId = ImmutableList.ValueOf(textIdBytes); } else { if (textIdBytes[0] == '#') { newTextId = ImmutableList.ValueOf(textIdBytes); } else { var oldKey = new PeptideLibraryKey(Encoding.UTF8.GetString(textIdBytes), 0); var newKey = oldKey.FormatToOneDecimal(); newTextId = ImmutableList.ValueOf(Encoding.UTF8.GetBytes(newKey.ModifiedSequence)); } } return(newTextId); }
public override bool ContainsAny(Target target) { var key = new PeptideLibraryKey(target.Sequence, 0); return(_spectra.SelectMany(fileSpectra => fileSpectra.Value) .Any(spectrum => null != spectrum.DocumentPeptide && key.UnmodifiedSequence == new PeptideLibraryKey(spectrum.DocumentPeptide, 0).UnmodifiedSequence)); }
public static void SelectAndApplyPeak(string modifiedSequence, double?precursorMz, string resultsName, bool subsequent, double rt) { bool found = false; var skylineWindow = Program.MainWindow; var doc = skylineWindow.Document; IdentityPath identityPath = null; var libKeyToMatch = new PeptideLibraryKey(modifiedSequence, 0); foreach (PeptideGroupDocNode nodePepGroup in doc.MoleculeGroups) { foreach (var nodePep in nodePepGroup.Peptides.Where(nodePep => LibKeyIndex.KeysMatch(libKeyToMatch, nodePep.ModifiedTarget.GetLibKey(Adduct.EMPTY)))) { var nodeTranGroup = precursorMz.HasValue ? nodePep.TransitionGroups.First(tranGroup => Math.Abs(tranGroup.PrecursorMz - precursorMz.Value) < 0.01) : nodePep.TransitionGroups.First(); identityPath = new IdentityPath(nodePepGroup.Id, nodePep.Id, nodeTranGroup.Id); IdentityPath path = identityPath; skylineWindow.SelectedPath = path; found = true; break; } if (found) { break; } } if (!found) { Assert.Fail("Could not find peptide {0}", modifiedSequence); } found = false; var chromatograms = doc.Settings.MeasuredResults.Chromatograms; foreach (var chromatogram in chromatograms.Where(chromSet => chromSet.Name.Equals(resultsName))) { found = true; ChromatogramSet chromSet = chromatogram; skylineWindow.SelectedResultsIndex = chromatograms.IndexOf(chromSet); skylineWindow.ModifyDocument("change peak", document => document.ChangePeak(identityPath, chromSet.Name, chromSet.MSDataFilePaths.First(), null, rt, UserSet.TRUE)); break; } if (!found) { Assert.Fail("Could not find results {0}", resultsName); } skylineWindow.ApplyPeak(subsequent); }
public IEnumerable <DbSpectrum> GetSpectraByPeptide(MsDataFileUri file, LibKey libKey) { foreach (var spectrum in GetSpectraByFile(file)) { if (string.IsNullOrWhiteSpace(spectrum.DocumentPeptide)) { continue; } var key = new PeptideLibraryKey(spectrum.DocumentPeptide, spectrum.DocumentPrecursorCharge.GetValueOrDefault()); if (LibKeyIndex.KeysMatch(libKey.LibraryKey, key)) { yield return(spectrum); } } }
/// <summary> /// Transforms an ordinary peptide sequence into a crosslinked peptide composed of three parts attached together /// with the Hydrolysis crosslinker. /// The crosslinked peptide ends up being the middle peptide sequence which has attachments to the left and right parts of /// the peptide sequence. /// /// For example, AVVQDPALKPLALVYGEATSR becomes: /// LKPLALV-AVVQDPA-YGEATSR-[Hydrolysis@1,7,*][Hydrolysis@7,*,1] /// </summary> private string MakeCrosslinkedSequence(string flatPeptideSequence) { var aaMods = TokenizeModifiedSequence(flatPeptideSequence).ToList(); int leftLength = aaMods.Count / 3; int middleLength = (2 * aaMods.Count) / 3 - leftLength; var left = new PeptideLibraryKey(string.Join(string.Empty, aaMods.Take(leftLength)), 0); var middle = new PeptideLibraryKey(string.Join(string.Empty, aaMods.Skip(leftLength).Take(middleLength)), 0); var right = new PeptideLibraryKey(string.Join(string.Empty, aaMods.Skip(leftLength + middleLength)), 0); var crosslinkLibraryKey = new CrosslinkLibraryKey(new [] { middle, left, right }, new [] { new CrosslinkLibraryKey.Crosslink(crosslinkerName, new [] { new[] { 1 }, new [] { leftLength }, Enumerable.Empty <int>() }), new CrosslinkLibraryKey.Crosslink(crosslinkerName, new[] { new[] { middleLength }, Enumerable.Empty <int>(), new [] { 1 } }) }, 0); return(crosslinkLibraryKey.ToString()); }
private IEnumerable <AAModInfo> EnumerateSequenceInfos(PeptideLibraryKey peptideLibraryKey, bool allowDuplicates) { if (peptideLibraryKey == null) { yield break; } string sequence = peptideLibraryKey.ModifiedSequence; bool isSpecificHeavy = !AllAminoAcidsModified(sequence); char? prevAA = null; int indexAA = -1; for (int index = 0; index < sequence.Length; index++) { char b = sequence[index]; if (b != '[') // L10N { if (isSpecificHeavy) { if (index > 0 && prevAA.HasValue) { AddConflictKey(prevAA, null, true); } if (index == 1) { AddConflictKey(prevAA, ModTerminus.N, true); } } prevAA = b; indexAA++; } else { ModTerminus?terminus = null; int startIndex = index + 1; int endIndex = sequence.IndexOf(']', startIndex); if (endIndex == -1) { endIndex = sequence.Length; } if (index == 1) { terminus = ModTerminus.N; } if (endIndex == sequence.Length - 1) { terminus = ModTerminus.C; } // Only if prevAA is an amino acid character should AAModInfo be created // Some libraries, for instance, have been created with the sequence starting // with a modification before any amino acid, as an attempt at a n-terminal modification if (prevAA.HasValue && AminoAcid.IsExAA(prevAA.Value)) { List <string> listMasses; if (!_dictAAMassPairs.TryGetValue(new AATermKey(prevAA, terminus), out listMasses)) { listMasses = new List <string>(); _dictAAMassPairs.Add(new AATermKey(prevAA, terminus), listMasses); } var modArr = sequence.Substring(startIndex, endIndex - startIndex); if (allowDuplicates || !listMasses.Contains(modArr)) { if (!allowDuplicates) { listMasses.Add(modArr); } string massString = modArr; var massModification = MassModification.Parse(massString); if (massModification != null) { yield return(new AAModInfo { IndexAA = indexAA, ModKey = new AAModKey { AA = prevAA.Value, Terminus = terminus, AppearsToBeSpecificMod = isSpecificHeavy, Mass = massModification.Mass, RoundedTo = massModification.Precision } }); } // NistLibraryBase writes [?] for any modification it does not understand else if (!Equals(@"?", massString)) { // Get more information on a failure that was posted to the exception web page throw new FormatException(string.Format(Resources.LibKeyModificationMatcher_EnumerateSequenceInfos_The_number___0___is_not_in_the_correct_format_, massString)); } } } prevAA = null; index = endIndex; } } // If the last AA was not modified, we need to update the conflictingMods array. if (prevAA.HasValue) { AddConflictKey(prevAA, null, true); AddConflictKey(null, ModTerminus.C, true); } }