Exemplo n.º 1
0
 public static void AddMods(IEnumerable <Modification> modifications, bool modsAreFromTheTopOfProteinXml)
 {
     foreach (var mod in modifications)
     {
         if (string.IsNullOrEmpty(mod.ModificationType) || string.IsNullOrEmpty(mod.IdWithMotif))
         {
             ErrorsReadingMods.Add(mod.ToString() + Environment.NewLine + " has null or empty modification type");
             continue;
         }
         if (AllModsKnown.Any(b => b.IdWithMotif.Equals(mod.IdWithMotif) && b.ModificationType.Equals(mod.ModificationType) && !b.Equals(mod)))
         {
             if (modsAreFromTheTopOfProteinXml)
             {
                 _AllModsKnown.RemoveAll(p => p.IdWithMotif.Equals(mod.IdWithMotif) && p.ModificationType.Equals(mod.ModificationType) && !p.Equals(mod));
                 _AllModsKnown.Add(mod);
                 _AllModTypesKnown.Add(mod.ModificationType);
             }
             else
             {
                 ErrorsReadingMods.Add("Modification id and type are equal, but some fields are not! " +
                                       "The following mod was not read in: " + Environment.NewLine + mod.ToString());
             }
             continue;
         }
         else if (AllModsKnown.Any(b => b.IdWithMotif.Equals(mod.IdWithMotif) && b.ModificationType.Equals(mod.ModificationType)))
         {
             // same ID, same mod type, and same mod properties; continue and don't output an error message
             // this could result from reading in an XML database with mods annotated at the top
             // that are already loaded in MetaMorpheus
             continue;
         }
         else if (AllModsKnown.Any(m => m.IdWithMotif == mod.IdWithMotif))
         {
             // same ID but different mod types. This can happen if the user names a mod the same as a UniProt mod
             // this is problematic because if a mod is annotated in the database, all we have to go on is an ID ("description" tag).
             // so we don't know which mod to use, causing unnecessary ambiguity
             if (modsAreFromTheTopOfProteinXml)
             {
                 _AllModsKnown.RemoveAll(p => p.IdWithMotif.Equals(mod.IdWithMotif) && !p.Equals(mod));
                 _AllModsKnown.Add(mod);
                 _AllModTypesKnown.Add(mod.ModificationType);
             }
             else if (!mod.ModificationType.Equals("Unimod"))
             {
                 ErrorsReadingMods.Add("Duplicate mod IDs! Skipping " + mod.ModificationType + ":" + mod.IdWithMotif);
             }
             continue;
         }
         else
         {
             // no errors! add the mod
             _AllModsKnown.Add(mod);
             _AllModTypesKnown.Add(mod.ModificationType);
         }
     }
 }
Exemplo n.º 2
0
 public static void AddMods(IEnumerable <Modification> enumerable)
 {
     foreach (var ye in enumerable)
     {
         if (string.IsNullOrEmpty(ye.modificationType) || string.IsNullOrEmpty(ye.id))
         {
             throw new MetaMorpheusException(ye.ToString() + Environment.NewLine + " has null or empty modification type");
         }
         if (AllModsKnown.Any(b => b.id.Equals(ye.id) && b.modificationType.Equals(ye.modificationType) && !b.Equals(ye)))
         {
             throw new MetaMorpheusException("Modification id and type are equal, but some fields are not! Please modify/remove one of the modifications: " + Environment.NewLine + Environment.NewLine + ye.ToString() + Environment.NewLine + Environment.NewLine + " has same and id and modification type as " + Environment.NewLine + Environment.NewLine + AllModsKnown.First(b => b.id.Equals(ye.id) && b.modificationType.Equals(ye.modificationType)) + Environment.NewLine + Environment.NewLine);
         }
         else if (AllModsKnown.Any(b => b.id.Equals(ye.id) && b.modificationType.Equals(ye.modificationType)))
         {
             continue;
         }
         else
         {
             allModsKnown.Add(ye);
             allModTypesKnown.Add(ye.modificationType);
         }
     }
 }