Пример #1
0
 public bool HasPrecursorCalc(IsotopeLabelType labelType, ExplicitMods mods)
 {
     if (labelType.IsLight)
         return true;
     return TryGetPrecursorCalc(labelType, mods) != null;
 }
Пример #2
0
        public double[] GetRetentionTimes(MsDataFileUri filePath, string peptideSequence, ExplicitMods explicitMods,
            RetentionTimeAlignmentIndex alignmentIndex = null)
        {
            string basename = filePath.GetFileNameWithoutExtension();
            var source = DocumentRetentionTimes.RetentionTimeSources.Find(basename);
            if (source == null)
            {
                return new double[0];
            }
            var library = PeptideSettings.Libraries.GetLibrary(source.Library);
            if (library == null)
            {
                return new double[0];
            }
            var modifiedSequences = GetTypedSequences(peptideSequence, explicitMods)
                .Select(typedSequence => typedSequence.ModifiedSequence);

            int? index = (alignmentIndex != null ? alignmentIndex.FileIndex : null);

            var times = library.GetRetentionTimesWithSequences(source.Name, modifiedSequences, ref index).ToArray();

            if (alignmentIndex != null)
                alignmentIndex.FileIndex = index;
            return times;
        }
Пример #3
0
        public void OkDialog()
        {
            var peptide = NodePeptide.Peptide;
            var explicitModsCurrent = NodePeptide.ExplicitMods;
            var modsDoc = DocSettings.PeptideSettings.Modifications;
            var implicitMods = new ExplicitMods(NodePeptide,
                modsDoc.StaticModifications, Settings.Default.StaticModList,
                modsDoc.GetHeavyModifications(), Settings.Default.HeavyModList);

            // Get static modifications from the dialog, and check for equality with
            // the document implicit modifications.
            TypedExplicitModifications staticTypedMods = null;
            bool isVariableStaticMods = false;
            var staticMods = GetExplicitMods(_listComboStatic, Settings.Default.StaticModList);
            if (ArrayUtil.EqualsDeep(staticMods, implicitMods.StaticModifications))
            {
                if (!NodePeptide.HasVariableMods)
                    staticMods = null;  // Use implicit modifications
                else
                {
                    staticMods = explicitModsCurrent.StaticModifications;
                    isVariableStaticMods = true;
                }
            }
            else if (explicitModsCurrent != null &&
                        ArrayUtil.EqualsDeep(staticMods, explicitModsCurrent.StaticModifications))
            {
                staticMods = explicitModsCurrent.StaticModifications;
            }
            if (staticMods != null)
            {
                staticTypedMods = new TypedExplicitModifications(peptide,
                    IsotopeLabelType.light, staticMods);
            }

            var listHeavyTypedMods = new List<TypedExplicitModifications>();
            for (int i = 0; i < _listLabelTypeHeavy.Count; i++)
            {
                var labelType = _listLabelTypeHeavy[i];
                var heavyMods = GetExplicitMods(_listListComboHeavy[i], Settings.Default.HeavyModList);

                if (ArrayUtil.EqualsDeep(heavyMods, implicitMods.GetModifications(labelType)))
                    continue;

                var heavyTypedMods = new TypedExplicitModifications(peptide, labelType, heavyMods);
                listHeavyTypedMods.Add(heavyTypedMods.AddModMasses(staticTypedMods));
            }

            ExplicitMods explicitMods = null;
            if (staticMods != null || listHeavyTypedMods.Count > 0)
                explicitMods = new ExplicitMods(peptide, staticMods, listHeavyTypedMods, isVariableStaticMods);
            Helpers.AssignIfEquals(ref explicitMods, explicitModsCurrent);
            ExplicitMods = explicitMods;

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #4
0
 public double GetPrecursorMass(IsotopeLabelType labelType, string seq, ExplicitMods mods)
 {
     return GetPrecursorCalc(labelType, mods).GetPrecursorMass(seq);
 }
Пример #5
0
        public RelativeRT GetRelativeRT(IsotopeLabelType labelType, string seq, ExplicitMods mods)
        {
            if (labelType.IsLight)
                return RelativeRT.Matching;
            // Default is matching
            RelativeRT relativeRT = RelativeRT.Matching;
            // One unkown modification makes everything unknown
            // One preceding modification with no unknowns make relative RT preceding
            // Overlapping overrides matching
            if (mods != null && mods.IsModified(labelType))
            {
                foreach (var mod in mods.GetModifications(labelType))
                {
                    if (mod.Modification.RelativeRT == RelativeRT.Unknown)
                        return RelativeRT.Unknown;

                    if (mod.Modification.RelativeRT == RelativeRT.Preceding)
                        relativeRT = RelativeRT.Preceding;
                    else if (mod.Modification.RelativeRT == RelativeRT.Overlapping &&
                             relativeRT == RelativeRT.Matching)
                        relativeRT = RelativeRT.Overlapping;
                }
            }
            else
            {
                foreach (var mod in PeptideSettings.Modifications.GetModifications(labelType))
                {
                    if (!mod.IsMod(seq))
                        continue;
                    if (mod.RelativeRT == RelativeRT.Unknown)
                        return RelativeRT.Unknown;

                    if (mod.RelativeRT == RelativeRT.Preceding)
                        relativeRT = RelativeRT.Preceding;
                    else if (mod.RelativeRT == RelativeRT.Overlapping &&
                             relativeRT == RelativeRT.Matching)
                        relativeRT = RelativeRT.Overlapping;
                }
            }
            return relativeRT;
        }
Пример #6
0
 public IFragmentMassCalc GetFragmentCalc(IsotopeLabelType labelType, ExplicitMods mods)
 {
     var massCalcBase = GetBaseCalc(labelType, mods, _fragmentMassCalcs);
     if (massCalcBase != null)
     {
         // If this type is not explicitly modified, then it must be
         // heavy with explicit light modifications.
         if (!mods.IsModified(labelType))
             labelType = IsotopeLabelType.light;
         if (!labelType.IsLight && !mods.HasModifications(labelType))
             return null;
         return new ExplicitSequenceMassCalc(mods, massCalcBase, labelType);
     }
     return GetMassCalc(labelType, _fragmentMassCalcs);
 }
Пример #7
0
 public string GetModifiedSequence(string seq,
     IsotopeLabelType labelType,
     ExplicitMods mods,
     SequenceModFormatType format = SequenceModFormatType.mass_diff,
     bool useExplicitModsOnly = false)
 {
     return GetPrecursorCalc(labelType, mods).GetModifiedSequence(seq, format, useExplicitModsOnly);
 }
Пример #8
0
        private bool Accept(SrmSettings settings,
            Peptide peptide,
            ExplicitMods mods,
            IList<int> precursorCharges,
            PeptideFilterType filterType,
            out bool allowVariableMods)
        {
            // Assume variable modifications are not allowed until proven otherwise
            allowVariableMods = false;
            // Only filter user specified peptides based on the heuristic
            // filter when explicitly requested.
            bool useFilter = filterType == PeptideFilterType.full;
            if (filterType == PeptideFilterType.fasta)
                useFilter = peptide.Begin.HasValue;

            var libraries = PeptideSettings.Libraries;
            if (!libraries.HasLibraries || libraries.Pick == PeptidePick.filter)
            {
                if (!useFilter)
                {
                    allowVariableMods = true;
                    return true;
                }
                return PeptideSettings.Filter.Accept(settings, peptide, mods, out allowVariableMods);
            }

            // Check if the peptide is in the library for one of the
            // acceptable precursor charges.
            bool inLibrary = false;
            // If the libraries are not fully loaded, then act like nothing
            // could be found in the libraries.  This will be corrected when
            // the libraries are loaded.
            if (libraries.IsLoaded &&
                // Only check the library, if this is a custom ion or a peptide that already has
                // a variable modification, or the library contains some form of the peptide.
                // This is a performance improvement over checking every variable modification
                // of a peptide when it is not even in the library.
                (peptide.IsCustomIon || (mods != null && mods.IsVariableStaticMods) || LibrariesContainAny(peptide.Sequence)))
            {
                // Only allow variable modifications, if the peptide has no modifications
                // or already checking variable modifications, and there is reason to check
                // the library.  Failing to do this check profiled as a performance bottleneck.
                allowVariableMods = mods == null || mods.IsVariableStaticMods;

                inLibrary = LibrariesContainMeasurablePeptide(peptide, precursorCharges, mods);
            }

            switch (libraries.Pick)
            {
                case PeptidePick.library:
                    return inLibrary;
                case PeptidePick.both:
                    return inLibrary && (!useFilter || PeptideSettings.Filter.Accept(settings, peptide, mods, out allowVariableMods));
                default:
                    return inLibrary || (!useFilter || PeptideSettings.Filter.Accept(settings, peptide, mods, out allowVariableMods));
            }
        }
Пример #9
0
 private IEnumerable<IsotopeLabelType> GetHeavyLabelTypes(ExplicitMods mods)
 {
     foreach (var typedMods in PeptideSettings.Modifications.GetHeavyModifications())
     {
         IsotopeLabelType labelType = typedMods.LabelType;
         if (HasPrecursorCalc(labelType, mods))
             yield return labelType;
     }
 }
Пример #10
0
        public bool TryLoadSpectrum(string sequence, int charge, ExplicitMods mods,
            out IsotopeLabelType type, out SpectrumPeaksInfo spectrum)
        {
            var libraries = PeptideSettings.Libraries;
            foreach (var typedSequence in GetTypedSequences(sequence, mods))
            {
                var key = new LibKey(typedSequence.ModifiedSequence, charge);
                if (libraries.TryLoadSpectrum(key, out spectrum))
                {
                    type = typedSequence.LabelType;
                    return true;
                }
            }

            type = IsotopeLabelType.light;
            spectrum = null;
            return false;
        }
Пример #11
0
        private static SequenceMassCalc GetBaseCalc(IsotopeLabelType labelType,
            ExplicitMods mods, IList<TypedMassCalc> massCalcs)
        {
            if (mods == null)
                return null;

            var calcLightImplicit = massCalcs[0].MassCalc;

            // If the light type is not modified
            if (!mods.IsModified(IsotopeLabelType.light))
            {
                // If requesting the light calculator or an unmodified heavy,
                // then no explicit calculator is required.
                if (labelType.IsLight || !mods.IsModified(labelType))
                    return null;

                // Otherwise, use its calculator as the base for a heavy type
                // to make sure the implicit light modifications are included.
                return calcLightImplicit;
            }
            // If the type requested is not modified, it must be a heavy type
            // with the light type modified.  In this case, return the heavy
            // calculator as the base, to which the light explicit modifications
            // may be applied to get modified masses.
            if (!mods.IsModified(labelType))
                return GetMassCalc(labelType, massCalcs);

            // If the light modifications are variable, and this is a type for
            // which explicit modifications exist (including the light type itself),
            // then return the light calculator as base.
            if (mods.IsVariableStaticMods)
                return calcLightImplicit;

            // If both light and this type are modified, then us a base calculator
            // that contains no modifications at all.
            return (calcLightImplicit.MassType == MassType.Monoisotopic ?
                MonoisotopicMassCalc : AverageMassCalc);
        }
Пример #12
0
        public bool TryGetRetentionTimes(string sequence, int charge, ExplicitMods mods, MsDataFileUri filePath,
            out IsotopeLabelType type, out double[] retentionTimes)
        {
            var libraries = PeptideSettings.Libraries;
            foreach (var typedSequence in GetTypedSequences(sequence, mods))
            {
                var key = new LibKey(typedSequence.ModifiedSequence, charge);
                if (libraries.TryGetRetentionTimes(key, filePath, out retentionTimes))
                {
                    type = typedSequence.LabelType;
                    return true;
                }
            }

            type = IsotopeLabelType.light;
            retentionTimes = null;
            return false;
        }
Пример #13
0
        public bool TryGetLibInfo(string sequence, int charge, ExplicitMods mods,
            out IsotopeLabelType type, out SpectrumHeaderInfo libInfo)
        {
            if (sequence == null)
            {
                type = null;
                libInfo = null;
                return false;
            }
            var libraries = PeptideSettings.Libraries;
            foreach (var typedSequence in GetTypedSequences(sequence, mods))
            {
                var key = new LibKey(typedSequence.ModifiedSequence, charge);
                if (libraries.TryGetLibInfo(key, out libInfo))
                {
                    type = typedSequence.LabelType;
                    return true;
                }
            }

            type = IsotopeLabelType.light;
            libInfo = null;
            return false;
        }
Пример #14
0
        public bool LibrariesContainMeasurablePeptide(Peptide peptide, IList<int> precursorCharges, ExplicitMods mods)
        {
            if (LibrariesContainMeasurablePeptide(peptide, IsotopeLabelType.light, precursorCharges, mods))
                return true;

            // If light version not found, try heavy
            foreach (var labelType in GetHeavyLabelTypes(mods))
            {
                if (LibrariesContainMeasurablePeptide(peptide, labelType, precursorCharges, mods))
                    return true;
            }
            return false;
        }
Пример #15
0
 public double[] GetAllRetentionTimes(MsDataFileUri filePath, string peptideSequence, ExplicitMods explicitMods)
 {
     var times = new List<double>();
     times.AddRange(GetRetentionTimes(filePath, peptideSequence, explicitMods));
     times.AddRange(GetAlignedRetentionTimes(filePath, peptideSequence, explicitMods));
     return times.ToArray();
 }
Пример #16
0
        private IEnumerable<TypedSequence> GetTypedSequences(string sequence, ExplicitMods mods)
        {
            var labelType = IsotopeLabelType.light;
            string modifiedSequence = GetModifiedSequence(sequence, labelType, mods);
            yield return new TypedSequence(modifiedSequence, labelType);

            foreach (var labelTypeHeavy in GetHeavyLabelTypes(mods))
            {
                modifiedSequence = GetModifiedSequence(sequence, labelTypeHeavy, mods);
                yield return new TypedSequence(modifiedSequence, labelTypeHeavy);
            }
        }
Пример #17
0
 /// <summary>
 /// Loads a list of all non-redundant spectra found in all loaded libraries 
 /// matching the criteria passed in.
 /// </summary>
 /// <param name="sequence"> The sequence to match. </param>
 /// <param name="charge"> The charge to match. </param>
 /// <param name="mods"> The modifications to match. </param>
 /// <returns> Returns a list of the matching spectra. </returns>
 public IEnumerable<SpectrumInfo> GetBestSpectra(string sequence, int charge, ExplicitMods mods)
 {
     var libraries = PeptideSettings.Libraries;
     return from typedSequence in GetTypedSequences(sequence, mods)
            let key = new LibKey(typedSequence.ModifiedSequence, charge)
            from spectrumInfo in libraries.GetSpectra(key, typedSequence.LabelType, true)
            select spectrumInfo;
 }
Пример #18
0
 private bool LibrariesContainMeasurablePeptide(Peptide peptide, IsotopeLabelType labelType,
     IEnumerable<int> precursorCharges, ExplicitMods mods)
 {
     string sequenceMod = GetModifiedSequence(peptide.Sequence, labelType, mods);
     foreach (int charge in precursorCharges)
     {
         if (LibrariesContain(sequenceMod, charge))
         {
             // Make sure the peptide for the found spectrum is measurable on
             // the current instrument.
             double precursorMass = GetPrecursorMass(labelType, peptide.Sequence, mods);
             if (IsMeasurable(precursorMass, charge))
                 return true;
         }
     }
     return false;
 }
Пример #19
0
 public double GetFragmentMass(IsotopeLabelType labelType, ExplicitMods mods,
     Transition transition, IsotopeDistInfo isotopeDist)
 {
     // Return the singly protonated mass of the peptide fragment, or custom ion mass before electron removal
     IFragmentMassCalc calc = GetFragmentCalc(labelType, mods);
     if (calc == null && transition.IsCustom())
     {
         // Small molecules provide their own ion formula, just use the standard calculator
         calc = GetDefaultFragmentCalc();
     }
     if (calc == null)
     {
         Assume.Fail(string.Format("Unable to locate fragment calculator for isotope label type {0} and mods {1}", // Not L10N
                 labelType == null ? "(null)" : labelType.ToString(), // Not L10N
                 mods == null ? "(null)" : mods.ToString())); // Not L10N
         return 0;   // Keep resharper happy
     }
     return calc.GetFragmentMass(transition, isotopeDist);
 }
Пример #20
0
 public bool Accept(SrmSettings settings, Peptide peptide, ExplicitMods explicitMods, out bool allowVariableMods)
 {
     return Accept(settings,
                   peptide,
                   explicitMods,
                   TransitionSettings.Filter.PrecursorCharges,
                   PeptideFilterType.fasta,
                   out allowVariableMods);
 }
Пример #21
0
 public IPrecursorMassCalc GetPrecursorCalc(IsotopeLabelType labelType, ExplicitMods mods)
 {
     var precursorCalc =  TryGetPrecursorCalc(labelType, mods);
     if (precursorCalc == null)
     {
         // Try to track down this exception:
         // https://skyline.gs.washington.edu/labkey/announcements/home/issues/exceptions/thread.view?entityId=217d79c8-9a84-1032-ae5f-da2025829168&_anchor=19667#row:19667
         throw new InvalidDataException(
             String.Format("unable to locate precursor calculator for isotope label type {0} and mods {1}", // Not L10N
                 labelType == null ? "(null)" : labelType.ToString(), // Not L10N
                 mods == null ? "(null)" : mods.ToString())); // Not L10N
     }
     return precursorCalc;
 }
Пример #22
0
 /// <summary>
 /// This version of Accept is used to select transition groups after the peptide
 /// itself has already been screened.  For this reason, it only applies library
 /// filtering.
 /// </summary>
 public bool Accept(SrmSettings settings, Peptide peptide, ExplicitMods mods, int charge)
 {
     bool allowVariableMods;
     return Accept(settings, peptide, mods, new[] { charge }, PeptideFilterType.library, out allowVariableMods);
 }
Пример #23
0
 /// <summary>
 /// Loads a list of all the spectra found in all loaded libraries 
 /// matching the criteria passed in.
 /// </summary>
 /// <param name="sequence"> The sequence to match. </param>
 /// <param name="charge"> The charge to match. </param>
 /// <param name="labelType">The primary label type to match</param>
 /// <param name="mods"> The modifications to match. </param>
 /// <returns> Returns a list of the matching spectra. </returns>
 public IEnumerable<SpectrumInfo> GetRedundantSpectra(string sequence, int charge, IsotopeLabelType labelType,
     ExplicitMods mods)
 {
     string sequenceMod = GetModifiedSequence(sequence, labelType, mods);
     return PeptideSettings.Libraries.GetSpectra(new LibKey(sequenceMod, charge), labelType, false);
 }
Пример #24
0
        public double[] GetAlignedRetentionTimes(MsDataFileUri filePath, string peptideSequence, ExplicitMods explicitMods)
        {
            string basename = filePath.GetFileNameWithoutExtension();
            var fileAlignments = DocumentRetentionTimes.FileAlignments.Find(basename);

            return GetAlignedRetentionTimes(new RetentionTimeAlignmentIndices(fileAlignments), peptideSequence, explicitMods);
        }
Пример #25
0
 public double[] GetRetentionTimes(string filePath, string peptideSequence, ExplicitMods explicitMods,
     RetentionTimeAlignmentIndex alignmentIndex = null)
 {
     return GetRetentionTimes(MsDataFileUri.Parse(filePath), peptideSequence, explicitMods, alignmentIndex);
 }
Пример #26
0
 public double[] GetAlignedRetentionTimes(RetentionTimeAlignmentIndices alignmentIndices, string peptideSequence, ExplicitMods explicitMods)
 {
     var times = new List<double>();
     if (alignmentIndices != null)
     {
         foreach (var alignmentIndex in alignmentIndices)
         {
             var unalignedTimes = GetRetentionTimes(MsDataFileUri.Parse(alignmentIndex.Alignment.Name), peptideSequence, explicitMods, alignmentIndex);
             foreach (var unalignedTime in unalignedTimes)
             {
                 var alignedTime = alignmentIndex.Alignment.RegressionLine.GetY(unalignedTime);
                 times.Add(alignedTime);
             }
         }
     }
     return times.ToArray();
 }
Пример #27
0
 /// <summary>
 /// Returns the times at which a peptide was found in a particular file.
 /// </summary>
 public double[] GetRetentionTimes(LibraryRetentionTimes retentionTimes, string sequence, ExplicitMods mods)
 {
     return (from typedSequence in GetTypedSequences(sequence, mods)
             from time in retentionTimes.GetRetentionTimes(typedSequence.ModifiedSequence)
             select time)
         .ToArray();
 }
Пример #28
0
 public double[] GetAllRetentionTimes(string filePath, string peptideSequence, ExplicitMods explicitMods)
 {
     return GetAllRetentionTimes(MsDataFileUri.Parse(filePath), peptideSequence, explicitMods);
 }
Пример #29
0
 public void ResetMods()
 {
     // CONSIDER: This means once a peptide with variable modifications is explicitly
     //           modified, it is then treated the same as an unmodified peptide for
     //           future resets.
     var explicitModsOrig = NodePeptide.ExplicitMods;
     if (!NodePeptide.HasVariableMods)
         ExplicitMods = null;
     else if (!explicitModsOrig.HasHeavyModifications)
         ExplicitMods = explicitModsOrig;
     else
     {
         // Construct a new explicit mods with only the variable modifications
         ExplicitMods = new ExplicitMods(NodePeptide.Peptide,
                                         explicitModsOrig.StaticModifications,
                                         new TypedExplicitModifications[0],
                                         true);
     }
     var modifications = DocSettings.PeptideSettings.Modifications;
     for (int i = 0; i < _listComboStatic.Count; i++)
     {
         UpdateComboItems(_listComboStatic[i],
                          StaticList,
                          ExplicitMods != null ? ExplicitMods.StaticModifications : null,
                          modifications.StaticModifications,
                          i,
                          ExplicitMods != null && ExplicitMods.IsVariableStaticMods,
                          true);
     }
     for (int i = 0; i < _listLabelTypeHeavy.Count; i++)
     {
         var labelType = _listLabelTypeHeavy[i];
         var listComboHeavy = _listListComboHeavy[i];
         for (int j = 0; j < listComboHeavy.Count; j++)
         {
             UpdateComboItems(listComboHeavy[j], HeavyList, null,
                 modifications.GetModifications(labelType), j, false, true);
         }
     }
 }
Пример #30
0
 public double[] GetUnalignedRetentionTimes(string peptideSequence, ExplicitMods explicitMods)
 {
     var times = new List<double>();
     var modifiedSequences = GetTypedSequences(peptideSequence, explicitMods)
         .Select(typedSequence => typedSequence.ModifiedSequence).ToArray();
     foreach (var library in PeptideSettings.Libraries.Libraries)
     {
         if (null == library)
         {
             continue;
         }
         foreach (var source in library.ListRetentionTimeSources())
         {
             int? index = null;
             times.AddRange(library.GetRetentionTimesWithSequences(source.Name, modifiedSequences, ref index));
         }
     }
     return times.ToArray();
 }