public SequenceInfo(ModifiedSequence modifiedSequence) { ModifiedSequence = modifiedSequence; ModificationsByResidue = modifiedSequence.GetModifications().ToLookup(mod => mod.IndexAA); LooplinkSites = ImmutableList.ValueOf(modifiedSequence.GetModifications() .Where(mod => mod.ExplicitMod.LinkedPeptide != null && mod.ExplicitMod.LinkedPeptide.Peptide == null) .Select(mod => mod.ExplicitMod.LinkedPeptide.IndexAa)); }
private ChromatogramRequestDocumentChromatogramGroup MakeChromatogramRequestDocumentChromatogramGroup( ChromSource chromSource, bool calculateMassErrors, IEnumerable <ChromatogramRequestDocumentChromatogramGroupChromatogram> chromatograms) { ChromatogramRequestDocumentChromatogramGroup docFilterPair = new ChromatogramRequestDocumentChromatogramGroup { ModifiedSequence = ModifiedSequence != null?ModifiedSequence.ToString() : null, PrecursorMz = Q1.RawValue, // A negative ion mode precursor will be serialized as a negative mz value MassErrors = calculateMassErrors, }; switch (Extractor) { case ChromExtractor.base_peak: docFilterPair.Extractor = RemoteApi.GeneratedCode.ChromExtractor.BasePeak; break; case ChromExtractor.summed: docFilterPair.Extractor = RemoteApi.GeneratedCode.ChromExtractor.Summed; break; } if (MinTime.HasValue) { docFilterPair.MinTime = MinTime.Value; docFilterPair.MinTimeSpecified = true; } if (MaxTime.HasValue) { docFilterPair.MaxTime = MaxTime.Value; docFilterPair.MaxTimeSpecified = true; } if (MinIonMobilityValue.HasValue && MaxIonMobilityValue.HasValue) { docFilterPair.DriftTime = (MinIonMobilityValue.Value + MaxIonMobilityValue.Value) / 2; if (ChromSource.fragment == chromSource) // Use high energy offset for fragments { docFilterPair.DriftTime += HighEnergyIonMobilityValueOffset; } docFilterPair.DriftTimeSpecified = true; docFilterPair.DriftTimeWindow = MaxIonMobilityValue.Value - MinIonMobilityValue.Value; docFilterPair.DriftTimeWindowSpecified = true; } switch (chromSource) { case ChromSource.ms1: docFilterPair.Source = RemoteApi.GeneratedCode.ChromSource.Ms1; break; case ChromSource.fragment: docFilterPair.Source = RemoteApi.GeneratedCode.ChromSource.Ms2; break; case ChromSource.sim: docFilterPair.Source = RemoteApi.GeneratedCode.ChromSource.Sim; break; } docFilterPair.Chromatogram = chromatograms.ToArray(); return(docFilterPair); }
public override int GetHashCode() { unchecked { var hashCode = ModifiedSequence.GetHashCode(); hashCode = (hashCode * 397) ^ Charge; return(hashCode); } }
/// <summary> /// Sequences are passed to Prosit as an array of indices mapping into an array /// of amino acids (with modifications). Actually throwing exceptions in this method /// slows down constructing inputs (for larger data sets with unknown mods (and aa's)significantly, /// which is why PrositExceptions (only) are set as an output parameter and null is returned. /// </summary> public static int[] EncodeSequence(SrmSettings settings, ISequenceContainer peptide, IsotopeLabelType label, out PrositException exception) { if (!peptide.Target.IsProteomic) { throw new PrositSmallMoleculeException(peptide.ModifiedTarget); } var sequence = peptide.Target.Sequence; if (sequence.Length > PrositConstants.PEPTIDE_SEQ_LEN) { exception = new PrositPeptideTooLongException(peptide.ModifiedTarget); return(null); } var modifiedSequence = ModifiedSequence.GetModifiedSequence(settings, peptide, label); var result = new int[PrositConstants.PEPTIDE_SEQ_LEN]; for (var i = 0; i < sequence.Length; ++i) { if (!PrositConstants.AMINO_ACIDS.TryGetValue(sequence[i], out var prositAA)) { exception = new PrositUnsupportedAminoAcidException(peptide.ModifiedTarget, i); return(null); } var mods = modifiedSequence.ExplicitMods.Where(m => m.IndexAA == i).ToArray(); foreach (var mod in mods) { if (mod.MonoisotopicMass == 0.0) { continue; } var staticMod = UniMod.FindMatchingStaticMod(mod.StaticMod, true) ?? mod.StaticMod; if (!PrositConstants.MODIFICATIONS.TryGetValue(staticMod.Name, out var prositAAMod)) { exception = new PrositUnsupportedModificationException(peptide.ModifiedTarget, mod.StaticMod, mod.IndexAA); return(null); } result[i] = prositAAMod.PrositIndex; break; } if (result[i] == 0) { // Not modified result[i] = prositAA.PrositIndex; } } exception = null; return(result); }
public override int GetHashCode() { unchecked { int hashCode = (ModifiedSequence != null ? ModifiedSequence.GetHashCode() : 0); hashCode = (hashCode * 397) ^ PrecursorMz.GetHashCode(); hashCode = (hashCode * 397) ^ PrecursorCharge.GetHashCode(); return(hashCode); } }
public FragmentedMolecule GetSimplePrecursorMolecule() { if (_precursorMolecule == null) { var modifiedSequence = ModifiedSequence.GetModifiedSequence(Settings, Peptide.Sequence, ExplicitMods, LabelType) .SeverCrosslinks(); _precursorMolecule = FragmentedMolecule.EMPTY.ChangeModifiedSequence(modifiedSequence); } return(_precursorMolecule); }
public PeptideFormatter(SrmSettings srmSettings, ModifiedSequence lightModifiedSequence, IEnumerable <KeyValuePair <IsotopeLabelType, ModifiedSequence> > heavyModifiedSequences, ModFontHolder modFontHolder) { SrmSettings = srmSettings; _lightSequenceInfo = new SequenceInfo(lightModifiedSequence); if (heavyModifiedSequences != null) { _heavySequenceInfos.AddRange(heavyModifiedSequences.Select(entry => Tuple.Create(entry.Key, new SequenceInfo(entry.Value)))); } LightModifiedSequence = lightModifiedSequence; ModFontHolder = modFontHolder; DisplayModificationOption = DisplayModificationOption.NOT_SHOWN; }
public PeptideFormatter(SrmSettings srmSettings, ModifiedSequence lightModifiedSequence, IEnumerable <KeyValuePair <IsotopeLabelType, ModifiedSequence> > heavyModifiedSequences, ModFontHolder modFontHolder) { SrmSettings = srmSettings; _lightSequenceInfo = new SequenceInfo(lightModifiedSequence); if (heavyModifiedSequences != null) { _heavySequenceInfos.AddRange(heavyModifiedSequences.Select(entry => Tuple.Create(entry.Key, new SequenceInfo(entry.Value)))); } LightModifiedSequence = lightModifiedSequence; ModFontHolder = modFontHolder; LinkedPeptides = ImmutableSortedList <ModificationSite, PeptideFormatter> .EMPTY; }
public void TestGetPrecursorFormula() { var modifiedSequence = new ModifiedSequence("PEPTIDE", new ModifiedSequence.Modification[0], MassType.Monoisotopic); var fragmentedMolecule = FragmentedMolecule.EMPTY.ChangeModifiedSequence(modifiedSequence); var precursorFormula = fragmentedMolecule.PrecursorFormula; Assert.AreEqual(0, fragmentedMolecule.PrecursorMassShift); var sequenceMassCalc = new SequenceMassCalc(MassType.Monoisotopic); var expectedFormula = Molecule.Parse(sequenceMassCalc.GetMolecularFormula(modifiedSequence.GetUnmodifiedSequence())); Assert.AreEqual(expectedFormula.Count, precursorFormula.Count); foreach (var entry in expectedFormula) { Assert.AreEqual(entry.Value, precursorFormula.GetElementCount(entry.Key)); } }
private string MakeModifiedSequence(string unmodifiedSequence, IEnumerable <KeyValuePair <int, string> > modifications) { StringBuilder modifiedSequence = new StringBuilder(); int ichUnmodified = 0; foreach (var modification in modifications) { Assume.IsTrue(modification.Key >= ichUnmodified); modifiedSequence.Append(unmodifiedSequence.Substring(ichUnmodified, modification.Key - ichUnmodified + 1)); ichUnmodified = modification.Key + 1; modifiedSequence.Append(ModifiedSequence.Bracket(modification.Value)); } modifiedSequence.Append(unmodifiedSequence.Substring(ichUnmodified)); return(modifiedSequence.ToString()); }
/// <summary> /// Decodes "Prosit-encoded" peptide sequences from a tensor. Only used in testing /// </summary> /// <param name="tensor">Int tensor of shape n x Constants.PEPTIDE_SEQ_LEN</param> /// <returns>A list of modified sequence objects representing the decoded sequences</returns> public static ModifiedSequence[] DecodeSequences2(TensorProto tensor) { var n = tensor.TensorShape.Dim[0].Size; var result = new ModifiedSequence[n]; var encodedSeqs = tensor.IntVal.ToArray(); var seq = new StringBuilder(PrositConstants.PEPTIDE_SEQ_LEN); for (var i = 0; i < n; ++i) { var explicitMods = new List <ExplicitMod>(); var idx = i * PrositConstants.PEPTIDE_SEQ_LEN; for (var j = 0; j < PrositConstants.PEPTIDE_SEQ_LEN; ++j) { if (encodedSeqs[idx + j] == 0) // Essentially a null terminator { break; } // This essentially prioritizes unmodified AA over modified AA (e.g. unmodified C over Carbamidomethyl C) else if (PrositConstants.AMINO_ACIDS_REVERSE.TryGetValue(encodedSeqs[idx + j], out var prositAA)) { seq.Append(prositAA.AA); } // Here a single "first" modification is given precedence over all others for any given AA else if (PrositConstants.MODIFICATIONS_REVERSE.TryGetValue(encodedSeqs[idx + j], out var prositAAMods)) { var prositAAMod = prositAAMods[0]; explicitMods.Add(new ExplicitMod(j, prositAAMod.Mod)); seq.Append(prositAAMod.AA); } else { throw new PrositException(string.Format(@"Unknown Prosit AA index {0}", encodedSeqs[idx + j])); } } var unmodSeq = seq.ToString(); var mods = explicitMods.Select(mod => ModifiedSequence.MakeModification(unmodSeq, mod)); result[i] = new ModifiedSequence(seq.ToString(), mods, MassType.Monoisotopic); seq.Clear(); } return(result); }
public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, Peptide peptide, ExplicitMods explicitMods, ICollection <IsotopeLabelType> heavyLabelTypes, ModFontHolder modFontHolder) { var lightModifiedSequence = ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitMods, IsotopeLabelType.light); var heavyModifiedSequences = new List <KeyValuePair <IsotopeLabelType, ModifiedSequence> >(); foreach (var labelType in srmSettings.PeptideSettings.Modifications.GetHeavyModificationTypes()) { if (!heavyLabelTypes.Contains(labelType)) { continue; } heavyModifiedSequences.Add(new KeyValuePair <IsotopeLabelType, ModifiedSequence>(labelType, ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitMods, labelType))); } var peptideFormatter = new PeptideFormatter(srmSettings, lightModifiedSequence, heavyModifiedSequences, modFontHolder); if (explicitMods != null && explicitMods.HasCrosslinks) { var linkedPeptides = new List <KeyValuePair <ModificationSite, PeptideFormatter> >(); foreach (var entry in explicitMods.Crosslinks) { if (entry.Value.Peptide == null) { continue; } var childFormatter = MakePeptideFormatter(srmSettings, entry.Value.Peptide, entry.Value.ExplicitMods, heavyLabelTypes, modFontHolder) .ChangeCrosslinkedIndexAa(entry.Value.IndexAa); linkedPeptides.Add(new KeyValuePair <ModificationSite, PeptideFormatter>(entry.Key, childFormatter)); } peptideFormatter = peptideFormatter .ChangeLinkedPeptides(ImmutableSortedList.FromValues(linkedPeptides)); } return(peptideFormatter); }
public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, PeptideDocNode peptideDocNode, ModFontHolder modFontHolder) { var lightModifiedSequence = ModifiedSequence.GetModifiedSequence(srmSettings, peptideDocNode, IsotopeLabelType.light); var heavyModifiedSequences = new List <KeyValuePair <IsotopeLabelType, ModifiedSequence> >(); foreach (var labelType in srmSettings.PeptideSettings.Modifications.GetHeavyModificationTypes()) { if (!peptideDocNode.HasChildType(labelType)) { continue; } heavyModifiedSequences.Add(new KeyValuePair <IsotopeLabelType, ModifiedSequence>(labelType, ModifiedSequence.GetModifiedSequence(srmSettings, peptideDocNode, labelType))); } return(new PeptideFormatter(srmSettings, lightModifiedSequence, heavyModifiedSequences, modFontHolder)); }
public void TestLooplink() { var peptide = new Peptide("PEPTIDE"); var srmSettings = SrmSettingsList.GetDefault(); var transitionFilter = srmSettings.TransitionSettings.Filter; transitionFilter = transitionFilter .ChangeFragmentRangeFirstName(TransitionFilter.StartFragmentFinder.ION_1.Name) .ChangeFragmentRangeLastName(@"last ion") .ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y, IonType.b }); srmSettings = srmSettings.ChangeTransitionSettings( srmSettings.TransitionSettings.ChangeFilter(transitionFilter)); var transitionGroup = new TransitionGroup(peptide, Adduct.SINGLY_PROTONATED, IsotopeLabelType.light); var crosslinkerDef = new StaticMod("dss", null, null, "C8H10O2"); var linkedPeptide = new LinkedPeptide(null, 5, null); var crosslinkMod = new ExplicitMod(2, crosslinkerDef).ChangeLinkedPeptide(linkedPeptide); var explicitModsWithCrosslink = new ExplicitMods(peptide, new[] { crosslinkMod }, new TypedExplicitModifications[0]); var transitionGroupDocNode = new TransitionGroupDocNode(transitionGroup, Annotations.EMPTY, srmSettings, explicitModsWithCrosslink, null, ExplicitTransitionGroupValues.EMPTY, null, null, false); var modifiedSequence = ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitModsWithCrosslink, IsotopeLabelType.light); Assert.AreEqual("PEPTIDE-[dss@3-6]", modifiedSequence.FullNames); var choices = transitionGroupDocNode.GetPrecursorChoices(srmSettings, explicitModsWithCrosslink, true) .Cast <TransitionDocNode>().ToArray(); var complexFragmentIons = choices.Select(transition => transition.ComplexFragmentIon.GetName()).ToArray(); // Make sure none of the transitions involve a cleavage in between the two ends of the looplink // PEpTIdE var yOrdinals = complexFragmentIons.Where(ion => ion.IonType == IonType.y).Select(ion => ion.Ordinal) .Distinct().ToList(); var bOrdinals = complexFragmentIons.Where(ion => ion.IonType == IonType.b).Select(ion => ion.Ordinal) .Distinct().ToList(); CollectionAssert.AreEquivalent(new[] { 6, 5, 1 }, yOrdinals); CollectionAssert.AreEquivalent(new[] { 1, 2, 6 }, bOrdinals); }
public SequenceInfo(ModifiedSequence modifiedSequence) { ModifiedSequence = modifiedSequence; ModificationsByResidue = modifiedSequence.GetModifications().ToLookup(mod => mod.IndexAA); }