Пример #1
0
 public static Target FromSerializableString(string val)
 {
     if (!val.StartsWith(@"#"))
     {
         return(new Target(val));
     }
     return(new Target(CustomMolecule.FromSerializableString(val)));
 }
Пример #2
0
        public new static CustomIon FromTSV(string val)
        {
            var lastTab = val.LastIndexOf(TextUtil.SEPARATOR_TSV_STR, StringComparison.Ordinal);
            var adduct  = Adduct.FromStringAssumeChargeOnly(val.Substring(lastTab + 1));
            var mol     = CustomMolecule.FromTSV(val.Substring(0, lastTab));

            if (adduct.IsEmpty && mol.IsEmpty)
            {
                return(EMPTY);
            }
            return(new CustomIon(mol, adduct));
        }
Пример #3
0
 public static bool Equivalent(Transition t, Transition obj)
 {
     if (ReferenceEquals(t, obj))
     {
         return(true);
     }
     return(Equals(obj.IonType, t.IonType) &&
            obj.CleavageOffset == t.CleavageOffset &&
            obj.Charge == t.Charge &&
            obj.MassIndex == t.MassIndex &&
            CustomMolecule.Equivalent(obj.CustomIon, t.CustomIon) && // Looks at unlabeled formula or name only
            (obj.DecoyMassShift.Equals(t.DecoyMassShift) ||
                                                                     // Deal with strange case of mProphet golden standard data set - only a concern for peptides, not small molecules
             (obj.DecoyMassShift.HasValue && t.DecoyMassShift.HasValue &&
              (obj.Group.LabelType.IsLight && obj.DecoyMassShift == 0 && !t.Group.LabelType.IsLight && t.DecoyMassShift != 0) ||
              (!obj.Group.LabelType.IsLight && obj.DecoyMassShift != 0 && t.Group.LabelType.IsLight && t.DecoyMassShift == 0))));
 }
Пример #4
0
        private void Validate()
        {
            if (IsCustomMolecule)
            {
                Assume.IsNull(_fastaSequence);
                Assume.IsNull(Sequence);
                CustomMolecule.Validate();
            }
            else if (_fastaSequence == null)
            {
                if (Begin.HasValue || End.HasValue)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptides_without_a_protein_sequence_do_not_support_the_start_and_end_properties);
                }

                // No FastaSequence checked the sequence, so check it here.
                FastaSequence.ValidateSequence(Target.Sequence);
            }
            else
            {
                // Otherwise, validate the peptide sequence against the group sequence
                if (!Begin.HasValue || !End.HasValue)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptides_from_protein_sequences_must_have_start_and_end_values);
                }
                if (0 > Begin.Value || End.Value > _fastaSequence.Sequence.Length)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptide_sequence_exceeds_the_bounds_of_the_protein_sequence);
                }

                var j = 0;
                for (var i = Begin.Value; i < End.Value;)
                {
                    if (!Equals(Target.Sequence[j++], _fastaSequence.Sequence[i++]))
                    {
                        string sequenceCheck = _fastaSequence.Sequence.Substring(Begin.Value, End.Value - Begin.Value);
                        throw new InvalidDataException(
                                  string.Format(Resources.Peptide_Validate_The_peptide_sequence__0__does_not_agree_with_the_protein_sequence__1__at__2__3__,
                                                Target, sequenceCheck, Begin.Value, End.Value));
                    }
                }
            }
            // CONSIDER: Validate missed cleavages some day?
        }
Пример #5
0
        public Transition(TransitionGroup group, IonType type, int?offset, int?massIndex, Adduct adduct,
                          int?decoyMassShift, CustomMolecule customMolecule = null)
        {
            _group = group;

            IonType        = type;
            CleavageOffset = offset ?? 0;
            MassIndex      = massIndex ?? 0;
            Adduct         = adduct;
            DecoyMassShift = decoyMassShift;
            // Small molecule precursor transition should have same custom molecule as parent
            if (IsPrecursor(type) && group.IsCustomIon)
            {
                CustomIon = new CustomIon(group.CustomMolecule, adduct);
            }
            else if (customMolecule is CustomIon)
            {
                // As with reporter ions
                CustomIon = (CustomIon)customMolecule;
                Assume.IsTrue(Equals(adduct.AdductCharge, CustomIon.Adduct.AdductCharge));
                Adduct = CustomIon.Adduct; // Ion mass is part of formula, so use charge only adduct
            }
            else if (customMolecule != null)
            {
                CustomIon = new CustomIon(customMolecule, adduct);
            }
            // Derived values
            if (!IsCustom(type, group))
            {
                Peptide peptide = group.Peptide;
                Ordinal = OffsetToOrdinal(type, (int)offset, peptide.Length);
                AA      = (IsNTerminal()
                    ? peptide.Sequence[(int)offset]
                    : peptide.Sequence[(int)offset + 1]);
            }
            else
            {
                // caller may have passed in offset = group.Peptide.Length - 1, which for custom ions gives -1
                CleavageOffset = 0;
            }
            Validate();
        }
Пример #6
0
 public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes()
 {
     return(IsCustomMolecule ? CustomMolecule.GetSmallMoleculeLibraryAttributes() : SmallMoleculeLibraryAttributes.EMPTY);
 }
Пример #7
0
 public Transition(TransitionGroup group, Adduct charge, int?massIndex, CustomMolecule customMolecule, IonType type = IonType.custom)
     : this(group, type, null, massIndex, charge, null, customMolecule)
 {
 }
Пример #8
0
 /// <summary>
 /// Creates a precursor transition
 /// </summary>
 /// <param name="group">The <see cref="TransitionGroup"/> which the transition represents</param>
 /// <param name="massIndex">Isotope mass shift</param>
 /// <param name="productAdduct">Adduct on the transition</param>
 /// <param name="customMolecule">Non-null if this is a custom transition</param>
 public Transition(TransitionGroup group, int massIndex, Adduct productAdduct, CustomMolecule customMolecule = null)
     : this(group, IonType.precursor, group.Peptide.Length - 1, massIndex, productAdduct, null, customMolecule)
 {
 }
Пример #9
0
 public Target(CustomMolecule molecule)
 {
     Molecule = molecule;
 }
Пример #10
0
 public Target(SmallMoleculeLibraryAttributes molecule)
 {
     Molecule = new CustomMolecule(molecule);
 }
Пример #11
0
        private TransitionDocNode CreateTransitionNode(int massIndex, TypedMass precursorMassH, TransitionIsotopeDistInfo isotopeDistInfo,
                                                       TransitionLosses losses, IDictionary <double, LibraryRankedSpectrumInfo.RankedMI> transitionRanks, Adduct productAdduct, CustomMolecule customMolecule = null)
        {
            Transition transition = new Transition(this, massIndex, productAdduct, customMolecule);
            var        quantInfo  = TransitionDocNode.TransitionQuantInfo.GetLibTransitionQuantInfo(transition, losses,
                                                                                                    Transition.CalcMass(precursorMassH, losses), transitionRanks).ChangeIsotopeDistInfo(isotopeDistInfo);
            var transitionDocNode = new TransitionDocNode(transition, losses, precursorMassH, quantInfo, ExplicitTransitionValues.EMPTY);

            if (massIndex < 0)
            {
                transitionDocNode = transitionDocNode.ChangeQuantitative(false);
            }
            return(transitionDocNode);
        }
Пример #12
0
        public Peptide(CustomMolecule customMolecule)
        {
            Target = new Target(customMolecule);

            Validate();
        }
Пример #13
0
 public Target(SmallMoleculeLibraryAttributes molecule)
 {
     Molecule = CustomMolecule.FromSmallMoleculeLibraryAttributes(molecule);
 }
Пример #14
0
        public IEnumerable <TransitionDocNode> GetPrecursorTransitions(SrmSettings settings,
                                                                       ExplicitMods mods,
                                                                       IPrecursorMassCalc calcPredictPre,
                                                                       IFragmentMassCalc calcPredict,
                                                                       double precursorMz,
                                                                       IsotopeDistInfo isotopeDist,
                                                                       IList <IList <ExplicitLoss> > potentialLosses,
                                                                       IDictionary <double, LibraryRankedSpectrumInfo.RankedMI> transitionRanks,
                                                                       bool libraryFilter,
                                                                       bool useFilter)
        {
            var      tranSettings = settings.TransitionSettings;
            var      fullScan     = tranSettings.FullScan;
            int      minMz        = tranSettings.Instrument.GetMinMz(precursorMz);
            int      maxMz        = tranSettings.Instrument.MaxMz;
            bool     precursorMS1 = fullScan.IsEnabledMs;
            MassType massType     = tranSettings.Prediction.FragmentMassType;
            MassType massTypeIon  = precursorMS1 ? tranSettings.Prediction.PrecursorMassType : massType;

            var  sequence            = Peptide.Target;
            var  ionTypes            = IsProteomic ? tranSettings.Filter.PeptideIonTypes : tranSettings.Filter.SmallMoleculeIonTypes;
            bool precursorNoProducts = precursorMS1 && !fullScan.IsEnabledMsMs &&
                                       ionTypes.Count == 1 && ionTypes[0] == IonType.precursor;
            var precursorMassPredict = precursorMS1
                ? calcPredictPre.GetPrecursorMass(sequence)
                : calcPredict.GetPrecursorFragmentMass(sequence);

            foreach (var losses in CalcTransitionLosses(IonType.precursor, 0, massType, potentialLosses))
            {
                double ionMz = IsProteomic ?
                               SequenceMassCalc.GetMZ(Transition.CalcMass(precursorMassPredict, losses), PrecursorAdduct) :
                               PrecursorAdduct.MzFromNeutralMass(CustomMolecule.GetMass(massTypeIon), massTypeIon);

                if (losses == null)
                {
                    if (precursorMS1 && isotopeDist != null)
                    {
                        foreach (int i in fullScan.SelectMassIndices(isotopeDist, useFilter))
                        {
                            var precursorMS1Mass = isotopeDist.GetMassI(i, DecoyMassShift);
                            ionMz = SequenceMassCalc.GetMZ(precursorMS1Mass, PrecursorAdduct);
                            if (minMz > ionMz || ionMz > maxMz)
                            {
                                continue;
                            }
                            var isotopeDistInfo = new TransitionIsotopeDistInfo(
                                isotopeDist.GetRankI(i), isotopeDist.GetProportionI(i));
                            yield return(CreateTransitionNode(i, precursorMS1Mass, isotopeDistInfo, null, transitionRanks));
                        }
                        continue;
                    }
                }
                // If there was loss, it is possible (though not likely) that the ion m/z value
                // will now fall below the minimum measurable value for the instrument
                else if (minMz > ionMz)
                {
                    continue;
                }

                // If filtering precursors from MS1 scans, then ranking in MS/MS does not apply
                bool precursorIsProduct = !precursorMS1 || losses != null;
                // Skip product ion precursors, if the should not be included
                if (useFilter && precursorIsProduct && precursorNoProducts)
                {
                    continue;
                }
                if (!useFilter || !precursorIsProduct ||
                    !libraryFilter || IsMatched(transitionRanks, ionMz, IonType.precursor,
                                                PrecursorAdduct, losses))
                {
                    yield return(CreateTransitionNode(0, precursorMassPredict, null, losses,
                                                      precursorIsProduct ? transitionRanks : null));
                }
            }
        }
Пример #15
0
        public PeptideDocNode GetModifiedNode(LibKey key, SrmSettings settings, SrmSettingsDiff diff)
        {
            var     smallMoleculeKey = key.LibraryKey as MoleculeLibraryKey;
            var     peptideKey       = key.LibraryKey as PeptideLibraryKey;
            Peptide peptide;

            if (smallMoleculeKey != null)
            {
                peptide = new Peptide(CustomMolecule.FromSmallMoleculeLibraryAttributes(smallMoleculeKey.SmallMoleculeLibraryAttributes));
            }
            else if (peptideKey != null)
            {
                peptide = new Peptide(null, peptideKey.UnmodifiedSequence, null, null,
                                      settings.PeptideSettings.Enzyme.CountCleavagePoints(peptideKey.UnmodifiedSequence));
            }
            else
            {
                return(null);
            }
            // First try and create the match from the settings created to match the library explorer.
            Settings = HasMatches
                ? settings.ChangePeptideModifications(mods => MatcherPepMods)
                : settings;
            TransitionGroupDocNode nodeGroup;
            var nodePep = CreateDocNodeFromSettings(key, peptide, diff, out nodeGroup);

            if (nodePep != null)
            {
                if (diff == null)
                {
                    nodePep = (PeptideDocNode)nodePep.ChangeAutoManageChildren(false);
                }
                else
                {
                    // Keep only the matching transition group, so that modifications
                    // will be highlighted differently for light and heavy forms.
                    // Only performed when getting peptides for display in the explorer.
                    nodePep = (PeptideDocNode)nodePep.ChangeChildrenChecked(
                        new DocNode[] { nodeGroup });
                }
                return(nodePep);
            }
            else if (Matches == null)
            {
                return(null);
            }
            bool hasHeavy;

            // Create explicit mods from the found matches.
            nodePep = CreateDocNodeFromMatches(new PeptideDocNode(peptide),
                                               EnumerateSequenceInfos(key.LibraryKey as PeptideLibraryKey, true), false, out hasHeavy);

            if (nodePep == null)
            {
                return(null);
            }

            // Call change settings with the matched modification settings to enumerate the children.
            nodePep = nodePep.ChangeSettings(settings.ChangePeptideModifications(mods =>
                                                                                 !HasMatches ? settings.PeptideSettings.Modifications : MatcherPepMods), diff ?? SrmSettingsDiff.ALL);
            if (nodePep.Children.Count == 0)
            {
                return(null);
            }
            // Select the correct child, only for use with the library explorer.
            if (diff != null && nodePep.Children.Count > 1)
            {
                nodePep =
                    (PeptideDocNode)
                    nodePep.ChangeChildrenChecked(new List <DocNode> {
                    nodePep.Children[hasHeavy ? 1 : 0]
                });
            }
            if (diff == null)
            {
                nodePep = (PeptideDocNode)nodePep.ChangeAutoManageChildren(false);
            }
            return(nodePep);
        }
Пример #16
0
        private TransitionDocNode CreateTransitionNode(IonType type, int cleavageOffset, Adduct charge, TypedMass massH,
                                                       TransitionLosses losses, IDictionary <double, LibraryRankedSpectrumInfo.RankedMI> transitionRanks, CustomMolecule customMolecule = null)
        {
            Transition transition = new Transition(this, type, cleavageOffset, 0, charge, null, customMolecule);
            var        info       = TransitionDocNode.TransitionQuantInfo.GetLibTransitionQuantInfo(transition, losses, Transition.CalcMass(massH, losses), transitionRanks);

            return(new TransitionDocNode(transition, losses, massH, info));
        }
Пример #17
0
        private TransitionDocNode CreateTransitionNode(int massIndex, TypedMass precursorMassH, TransitionIsotopeDistInfo isotopeDistInfo,
                                                       TransitionLosses losses, IDictionary <double, LibraryRankedSpectrumInfo.RankedMI> transitionRanks, CustomMolecule customMolecule = null)
        {
            Transition transition = new Transition(this, massIndex, customMolecule);
            var        quantInfo  = TransitionDocNode.TransitionQuantInfo.GetLibTransitionQuantInfo(transition, losses,
                                                                                                    Transition.CalcMass(precursorMassH, losses), transitionRanks).ChangeIsotopeDistInfo(isotopeDistInfo);

            return(new TransitionDocNode(transition, losses, precursorMassH, quantInfo));
        }
Пример #18
0
 public CustomIon(CustomMolecule mol, Adduct adduct)
     : this(mol.Formula, adduct, mol.MonoisotopicMass, mol.AverageMass, mol.Name)
 {
 }
Пример #19
0
        public static TransitionDocNode FromTransitionProto(AnnotationScrubber scrubber, SrmSettings settings,
                                                            TransitionGroup group, ExplicitMods mods, IsotopeDistInfo isotopeDist, ExplicitTransitionValues pre422ExplicitTransitionValues,
                                                            SkylineDocumentProto.Types.Transition transitionProto)
        {
            var         stringPool  = scrubber.StringPool;
            IonType     ionType     = DataValues.FromIonType(transitionProto.FragmentType);
            MeasuredIon measuredIon = null;

            if (transitionProto.MeasuredIonName != null)
            {
                measuredIon = settings.TransitionSettings.Filter.MeasuredIons.SingleOrDefault(
                    i => i.Name.Equals(transitionProto.MeasuredIonName.Value));
                if (measuredIon == null)
                {
                    throw new InvalidDataException(string.Format(Resources.TransitionInfo_ReadXmlAttributes_The_reporter_ion__0__was_not_found_in_the_transition_filter_settings_, transitionProto.MeasuredIonName));
                }
                ionType = IonType.custom;
            }
            bool           isCustom    = Transition.IsCustom(ionType, group);
            bool           isPrecursor = Transition.IsPrecursor(ionType);
            CustomMolecule customIon   = null;

            if (isCustom)
            {
                if (measuredIon != null)
                {
                    customIon = measuredIon.SettingsCustomIon;
                }
                else if (isPrecursor)
                {
                    customIon = group.CustomMolecule;
                }
                else
                {
                    var formula      = DataValues.FromOptional(transitionProto.Formula);
                    var moleculeID   = MoleculeAccessionNumbers.FromString(DataValues.FromOptional(transitionProto.MoleculeId)); // Tab separated list of InChiKey, CAS etc
                    var monoMassH    = DataValues.FromOptional(transitionProto.MonoMassH);
                    var averageMassH = DataValues.FromOptional(transitionProto.AverageMassH);
                    var monoMass     = DataValues.FromOptional(transitionProto.MonoMass) ?? monoMassH;
                    var averageMass  = DataValues.FromOptional(transitionProto.AverageMass) ?? averageMassH;
                    customIon = new CustomMolecule(formula,
                                                   new TypedMass(monoMass.Value, monoMassH.HasValue ? MassType.MonoisotopicMassH : MassType.Monoisotopic),
                                                   new TypedMass(averageMass.Value, averageMassH.HasValue ? MassType.AverageMassH : MassType.Average),
                                                   DataValues.FromOptional(transitionProto.CustomIonName), moleculeID);
                }
            }
            Transition transition;
            var        adductString = DataValues.FromOptional(transitionProto.Adduct);
            var        adduct       = string.IsNullOrEmpty(adductString)
                ? Adduct.FromChargeProtonated(transitionProto.Charge)
                : Adduct.FromStringAssumeChargeOnly(adductString);

            if (isCustom)
            {
                transition = new Transition(group, isPrecursor ? group.PrecursorAdduct :adduct, transitionProto.MassIndex, customIon, ionType);
            }
            else if (isPrecursor)
            {
                transition = new Transition(group, ionType, group.Peptide.Length - 1, transitionProto.MassIndex,
                                            group.PrecursorAdduct, DataValues.FromOptional(transitionProto.DecoyMassShift));
            }
            else
            {
                int offset = Transition.OrdinalToOffset(ionType, transitionProto.FragmentOrdinal,
                                                        group.Peptide.Length);
                transition = new Transition(group, ionType, offset, transitionProto.MassIndex, adduct, DataValues.FromOptional(transitionProto.DecoyMassShift));
            }
            var losses          = TransitionLosses.FromLossProtos(settings, transitionProto.Losses);
            var mass            = settings.GetFragmentMass(group, mods, transition, isotopeDist);
            var isotopeDistInfo = GetIsotopeDistInfo(transition, losses, isotopeDist);

            if (group.DecoyMassShift.HasValue && transitionProto.DecoyMassShift == null)
            {
                throw new InvalidDataException(Resources.SrmDocument_ReadTransitionXml_All_transitions_of_decoy_precursors_must_have_a_decoy_mass_shift);
            }

            TransitionLibInfo libInfo = null;

            if (transitionProto.LibInfo != null)
            {
                libInfo = new TransitionLibInfo(transitionProto.LibInfo.Rank, transitionProto.LibInfo.Intensity);
            }
            var annotations = scrubber.ScrubAnnotations(Annotations.FromProtoAnnotations(transitionProto.Annotations), AnnotationDef.AnnotationTarget.transition);
            var results     = TransitionChromInfo.FromProtoTransitionResults(scrubber, settings, transitionProto.Results);
            var explicitTransitionValues = pre422ExplicitTransitionValues ?? ExplicitTransitionValues.Create(
                DataValues.FromOptional(transitionProto.ExplicitCollisionEnergy),
                DataValues.FromOptional(transitionProto.ExplicitIonMobilityHighEnergyOffset),
                DataValues.FromOptional(transitionProto.ExplicitSLens),
                DataValues.FromOptional(transitionProto.ExplicitConeVoltage),
                DataValues.FromOptional(transitionProto.ExplicitDeclusteringPotential));

            return(new TransitionDocNode(transition, annotations, losses, mass, new TransitionQuantInfo(isotopeDistInfo, libInfo, !transitionProto.NotQuantitative), explicitTransitionValues, results));
        }