Beispiel #1
0
        public static TransitionLosses FromLossProtos(SrmSettings settings,
                                                      IEnumerable <SkylineDocumentProto.Types.TransitionLoss> lossProtos)
        {
            var      staticMods = settings.PeptideSettings.Modifications.StaticModifications;
            MassType massType   = settings.TransitionSettings.Prediction.FragmentMassType;

            var listLosses = new List <TransitionLoss>();

            foreach (var loss in lossProtos)
            {
                String nameMod = loss.ModificationName;
                if (string.IsNullOrEmpty(nameMod))
                {
                    listLosses.Add(new TransitionLoss(null,
                                                      new FragmentLoss(loss.Formula, loss.MonoisotopicMass,
                                                                       loss.AverageMass, DataValues.FromLossInclusion(loss.LossInclusion)),
                                                      massType));
                }
                else
                {
                    int indexLoss = loss.LossIndex;
                    int indexMod  = staticMods.IndexOf(mod => Equals(nameMod, mod.Name));
                    if (indexMod == -1)
                    {
                        throw new InvalidDataException(
                                  string.Format(Resources.TransitionInfo_ReadTransitionLosses_No_modification_named__0__was_found_in_this_document,
                                                nameMod));
                    }
                    StaticMod modLoss = staticMods[indexMod];
                    if (!modLoss.HasLoss || indexLoss >= modLoss.Losses.Count)
                    {
                        throw new InvalidDataException(
                                  string.Format(Resources.TransitionInfo_ReadTransitionLosses_Invalid_loss_index__0__for_modification__1__,
                                                indexLoss, nameMod));
                    }
                    listLosses.Add(new TransitionLoss(modLoss, modLoss.Losses[indexLoss], massType));
                }
            }
            if (listLosses.Any())
            {
                return(new TransitionLosses(listLosses, massType));
            }
            return(null);
        }