Esempio n. 1
0
        public EmptyResult MapModuletoApplication(string listId, string attributename, int ordinalposition)
        {
            string token = HttpContext.Session.GetString("access_token");
            List <PatientListModel> listModulesModel  = getListofListModel();
            List <MappedList>       listMappedmodules = APIservice.GetListById <MappedList>(listId.Trim(), "synapsenamespace=meta&synapseentityname=applicationlist&synapseattributename=application_id&attributevalue=", token).OrderBy(o => o.displayorder).ToList();

            MappedList       Model     = new MappedList();
            Guid             id        = Guid.NewGuid();
            PatientListModel moduleobj = listModulesModel.Single(s => s.list_id == attributename);

            Model.applicationlist_id = id.ToString();
            Model.application_id     = listId.Trim();
            Model.listid             = attributename;
            Model.listname           = moduleobj.listname;

            if (listMappedmodules.Count == 0)
            {
                Model.displayorder = 1;
            }
            else
            {
                Model.displayorder = listMappedmodules.Max(x => x.displayorder.Value) + 1;
            }

            string results = APIservice.PostObject <MappedList>(Model, "synapsenamespace=meta&synapseentityname=applicationlist", token);

            listMappedmodules = APIservice.GetListById <MappedList>(listId.Trim(), "synapsenamespace=meta&synapseentityname=applicationlist&synapseattributename=application_id&attributevalue=", token).OrderBy(o => o.displayorder).ToList();;

            return(new EmptyResult());
        }
Esempio n. 2
0
 public static void AddAssetsOfType <T>(Object o, MappedList <T> graphicsList) where T : Object, IUniqueName
 {
     graphicsList.ClearList();
     graphicsList.AddItems(Instance.GetAllAssetsOfType <T>());
     graphicsList.MakeDict();
     EditorUtility.SetDirty(o);
     AssetDatabase.SaveAssets();
 }
 public void CreateMatches(SrmSettings settings, IEnumerable <LibKey> libKeys,
                           MappedList <string, StaticMod> defSetStatic, MappedList <string, StaticMod> defSetHeavy)
 {
     _dictAAMassPairs = new Dictionary <AATermKey, List <byte[]> >();
     _libKeys         = libKeys.GetEnumerator();
     InitMatcherSettings(settings, defSetStatic, defSetHeavy);
     MatcherPepMods = CreateMatcherPeptideSettings();
 }
Esempio n. 4
0
 public InsertQuery(Model model, IEnumerable<string> fields)
 {
     Model = model;
     Fields = new MappedList<string, Field>();
     foreach (var field in fields)
     {
         Fields.Add(Model.Fields[field]);
     }
 }
Esempio n. 5
0
 public GraphicsData()
 {
     teleportGraphics = new MappedList <TeleportGraphics>();
     enemyGraphics    = new MappedList <EnemyGraphics>();
     raceGraphics     = new MappedList <RaceGraphics>();
     itemGraphics     = new MappedList <ItemGraphics>();
     skillGraphics    = new MappedList <SkillGraphics>();
     animationClips   = new MappedList <AnimationClipData>();
 }
Esempio n. 6
0
 public GameData()
 {
     gems    = new MappedList <Gem>();
     worlds  = new MappedList <WorldData>();
     races   = new MappedList <Race>();
     perks   = new MappedList <Perk>();
     skills  = new MappedList <SkillAssetData>();
     combos  = new MappedList <ComboAssetData>();
     items   = new MappedList <ItemAssetData>();
     enemies = new MappedList <EnemyAssetData>();
 }
Esempio n. 7
0
 public void CreateMatches(SrmSettings settings, IEnumerable <string> sequences,
                           MappedList <string, StaticMod> defSetStatic, MappedList <string, StaticMod> defSetHeavy)
 {
     _sequences = sequences.GetEnumerator();
     InitMatcherSettings(settings, defSetStatic, defSetHeavy);
     if (UnmatchedSequences.Count > 0)
     {
         UnmatchedSequences.Sort();
         throw new FormatException(UninterpretedMods);
     }
 }
Esempio n. 8
0
        public IActionResult SaveDisplayName(string listId, string Modelid, string displayname, bool isdefaultmodule)
        {
            string            token        = HttpContext.Session.GetString("access_token");
            List <MappedList> Mappedmodule = APIservice.GetListById <MappedList>(listId.Trim(), "synapsenamespace=meta&synapseentityname=applicationlist&synapseattributename=application_id&attributevalue=", token).OrderBy(o => o.displayorder).ToList();
            MappedList        Model        = Mappedmodule.Single(s => s.applicationlist_id == Modelid);

            Model.listname = displayname;

            string results = APIservice.PostObject <MappedList>(Model, "synapsenamespace=meta&synapseentityname=applicationlist", token);

            return(new EmptyResult());
        }
Esempio n. 9
0
        public void Index_FirstIsLast()
        {
            // arrange
            var list = new MappedList(_testMap);

            list.SetValues(_testValues);

            // act
            var value = list[0];

            // assert
            Assert.Equal("baz", value);
        }
Esempio n. 10
0
        public void Contains_DoesContain_IsTrue()
        {
            // arrange
            var list = new MappedList(_testMap);

            list.SetValues(_testValues);

            // act
            var result = list.Contains("foo");

            // assert
            Assert.True(result);
        }
Esempio n. 11
0
        public void Count_ReturnsCount()
        {
            // arrange
            var list = new MappedList(_testMap);

            list.SetValues(_testValues);

            // act
            var count = list.Count;

            // assert
            Assert.Equal(_testValues.Length, count);
        }
Esempio n. 12
0
        public void Contains_DoesNotContain_IsFalse()
        {
            // arrange
            var list = new MappedList(_testMap);

            list.SetValues(_testValues);

            // act
            var result = list.Contains("bat");

            // assert
            Assert.False(result);
        }
        public static string SaveDisplayName(string listId, string displayname, bool isdefaultmodule)
        {
            if (isdefaultmodule)
            {
            }

            List <MappedList> Mappedmodule = listMappedmodules;
            MappedList        Model        = Mappedmodule.Single(s => s.applicationlist_id == listId);

            Model.listname = displayname;

            string results = APIservice.PostObject <MappedList>(Model, "synapsenamespace=meta&synapseentityname=applicationlist");

            listMappedmodules = APIservice.GetListById <MappedList>(ApplicationId, "synapsenamespace=meta&synapseentityname=applicationlist&synapseattributename=application_id&attributevalue=").OrderBy(o => o.displayorder).ToList();;
            return(results);
        }
Esempio n. 14
0
    public static void AddScriptableObjectWrappedDataOfType <T, TWrapper>(Object o, MappedList <T> dataList)
        where T : IUniqueName
        where TWrapper : ScriptableObjectDataWrapper <T>
    {
        Debug.Assert(dataList != null);
        dataList.ClearList();
        var dataWrappers = Instance.GetAllAssetsOfType <TWrapper>();
        var data         = new List <T>();

        foreach (var dataWrapper in dataWrappers)
        {
            data.Add(dataWrapper.Data);
        }
        dataList.AddItems(data);
        dataList.MakeDict();
        EditorUtility.SetDirty(o);
        AssetDatabase.SaveAssets();
    }
Esempio n. 15
0
        private static IList <ExplicitMod> GetExplicitMods(IList <ComboBox> mods,
                                                           MappedList <string, StaticMod> listSettingsMods)
        {
            List <ExplicitMod> listMods = new List <ExplicitMod>();

            for (int i = 0; i < mods.Count; i++)
            {
                string modName = (string)mods[i].SelectedItem;
                if (!string.IsNullOrEmpty(modName))
                {
                    StaticMod settingsMod;
                    if (listSettingsMods.TryGetValue(modName, out settingsMod))
                    {
                        listMods.Add(new ExplicitMod(i, settingsMod));
                    }
                }
            }
            return(listMods.ToArray());
        }
Esempio n. 16
0
        public void Foreach_ListIsBackwards()
        {
            // arrange
            var expected = new[] { "baz", "bar", "foo" };
            var list     = new MappedList(_testMap);

            list.SetValues(_testValues);

            // act
            var output = new List <string>();

            foreach (var value in list)
            {
                output.Add(value);
            }

            // assert
            var asArray = output.ToArray();

            Assert.Equal(expected, asArray);
        }
        public virtual PeptideModifications GetDocModifications(SrmDocument document)
        {
            var lightMods = new MappedList <string, StaticMod>();

            lightMods.AddRange(DefSetStatic);
            var heavyMods = new MappedList <string, StaticMod>();

            heavyMods.AddRange(DefSetHeavy);
            foreach (var matchPair in Matches)
            {
                var lightMod = matchPair.Value.StructuralMod;
                if (lightMod != null && !lightMods.Contains(lightMod))
                {
                    lightMods.Add(lightMod.ChangeExplicit(true));
                }
                var heavyMod = matchPair.Value.HeavyMod;
                if (heavyMod != null && !heavyMods.Contains(heavyMod))
                {
                    heavyMods.Add(heavyMod.ChangeExplicit(true));
                }
            }
            return(document.Settings.PeptideSettings.Modifications.DeclareExplicitMods(document, lightMods, heavyMods));
        }
Esempio n. 18
0
        private static void UpdateMatcher(
            StaticMod[] docStatMods, StaticMod[] docHeavyMods,
            StaticMod[] globalStatMods, StaticMod[] globalHeavyMods, IEnumerable <string> seqs)
        {
            docStatMods     = docStatMods ?? new StaticMod[0];
            docHeavyMods    = docHeavyMods ?? new StaticMod[0];
            globalStatMods  = globalStatMods ?? new StaticMod[0];
            globalHeavyMods = globalHeavyMods ?? new StaticMod[0];
            MappedList <string, StaticMod> mapGlobalStatMods = new MappedList <string, StaticMod>();

            mapGlobalStatMods.AddRange(docStatMods);
            mapGlobalStatMods.AddRange(globalStatMods);
            MappedList <string, StaticMod> mapGlobalHeavyMods = new MappedList <string, StaticMod>();

            mapGlobalHeavyMods.AddRange(docHeavyMods);
            mapGlobalHeavyMods.AddRange(globalHeavyMods);
            var settings = SrmSettingsList.GetDefault()
                           .ChangePeptideModifications(mods =>
                                                       mods.ChangeStaticModifications(docStatMods));

            settings = settings.ChangePeptideModifications(mods =>
                                                           mods.ChangeModifications(IsotopeLabelType.heavy, docHeavyMods));
            MATCHER.CreateMatches(settings, seqs, mapGlobalStatMods, mapGlobalHeavyMods);
        }
        internal void InitMatcherSettings(SrmSettings settings,
                                          MappedList <string, StaticMod> defSetStatic, MappedList <string, StaticMod> defSetHeavy)
        {
            DefSetStatic = defSetStatic;
            DefSetHeavy  = defSetHeavy;

            Settings = settings;

            var modifications = settings.PeptideSettings.Modifications;

            UserDefinedTypedMods = new Dictionary <StaticMod, IsotopeLabelType>();
            // First add modifications found in document settings, then add modifications found in the global settings.
            foreach (var type in settings.PeptideSettings.Modifications.GetModificationTypes())
            {
                // Set the default heavy type to the first heavy type encountered.
                if (!ReferenceEquals(type, IsotopeLabelType.light) && DocDefHeavyLabelType == null)
                {
                    DocDefHeavyLabelType = type;
                }
                InitUserDefTypedModDict(modifications.GetModificationsByName(type.Name), false);
            }
            InitUserDefTypedModDict(new TypedModifications(IsotopeLabelType.light, DefSetStatic), true);
            InitUserDefTypedModDict(new TypedModifications(DocDefHeavyLabelType, DefSetHeavy), true);

            Matches            = new Dictionary <AAModKey, AAModMatch>();
            UnmatchedSequences = new List <string>();
            _foundHeavyLabels  = new List <StaticMod>();

            while (MoveNextSequence())
            {
                InitModMatches();
            }
            CleanUpMatches();

            Initialized = true;
        }
        public static void MapModuletoApplication(string listId, string attributename, int ordinalposition)
        {
            MappedList       Model     = new MappedList();
            Guid             id        = Guid.NewGuid();
            PatientListModel moduleobj = listModulesModel.Single(s => s.list_id == attributename);

            Model.applicationlist_id = id.ToString();
            Model.application_id     = ApplicationId;
            Model.listid             = attributename;
            Model.listname           = moduleobj.listname;

            if (listMappedmodules.Count == 0)
            {
                Model.displayorder = 1;
            }
            else
            {
                Model.displayorder = listMappedmodules.Max(x => x.displayorder.Value) + 1;
            }

            string results = APIservice.PostObject <MappedList>(Model, "synapsenamespace=meta&synapseentityname=applicationlist");

            listMappedmodules = APIservice.GetListById <MappedList>(ApplicationId, "synapsenamespace=meta&synapseentityname=applicationlist&synapseattributename=application_id&attributevalue=").OrderBy(o => o.displayorder).ToList();;
        }
Esempio n. 21
0
        /// <summary>
        /// Adds a list of PeptideDocNodes found in the library to the current document.
        /// </summary>
        public SrmDocument AddPeptides(SrmDocument document, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath)
        {
            if (toPath != null &&
                toPath.Depth == (int)SrmDocument.Level.MoleculeGroups &&
                ReferenceEquals(toPath.GetIdentity((int)SrmDocument.Level.MoleculeGroups), SequenceTree.NODE_INSERT_ID))
            {
                toPath = null;
            }

            SkippedPeptideCount = 0;
            var dictCopy = new Dictionary <PeptideSequenceModKey, PeptideMatch>();

            // Make heavy mods explicit
            if (PeptideMatches.Values.Contains(match => match.NodePep.HasExplicitMods &&
                                               match.NodePep.ExplicitMods.HeavyModifications != null))
            {
                _matcher.ConvertAllHeavyModsExplicit();
            }

            // Call ensure mods on all peptides to be added to the document.
            var listDefStatMods = new MappedList <string, StaticMod>();

            listDefStatMods.AddRange(Properties.Settings.Default.StaticModList);
            listDefStatMods.AddRange(document.Settings.PeptideSettings.Modifications.StaticModifications);

            var listDefHeavyMods = new MappedList <string, StaticMod>();

            listDefHeavyMods.AddRange(Properties.Settings.Default.HeavyModList);
            listDefHeavyMods.AddRange(document.Settings.PeptideSettings.Modifications.AllHeavyModifications);

            foreach (var key in PeptideMatches.Keys)
            {
                var match         = PeptideMatches[key];
                var nodePepDocSet = match.NodePep;
                if (_matcher.MatcherPepMods != null)
                {
                    nodePepDocSet = match.NodePep.EnsureMods(_matcher.MatcherPepMods,
                                                             document.Settings.PeptideSettings.Modifications,
                                                             listDefStatMods, listDefHeavyMods);
                }
                if (!dictCopy.ContainsKey(nodePepDocSet.SequenceKey))
                {
                    dictCopy.Add(nodePepDocSet.SequenceKey,
                                 new PeptideMatch(nodePepDocSet, match.Proteins,
                                                  match.MatchesFilterSettings));
                }
            }

            if (!Properties.Settings.Default.LibraryPeptidesKeepFiltered)
            {
                // TODO: This removes entire peptides where only a single
                //       precursor does not match.  e.g. the library contains
                //       a singly charged precursor match, but also doubly charged
                dictCopy = dictCopy.Where(match => match.Value.MatchesFilterSettings)
                           .ToDictionary(match => match.Key, match => match.Value);
            }
            SrmDocument newDocument = UpdateExistingPeptides(document, dictCopy, toPath, out selectedPath);

            toPath = selectedPath;

            // If there is an associated background proteome, add peptides that can be
            // matched to the proteins from the background proteom.
            if (_backgroundProteome != null)
            {
                newDocument = AddProteomePeptides(newDocument, dictCopy, broker,
                                                  toPath, out selectedPath);
            }
            toPath = selectedPath;

            // Add all remaining peptides as a peptide list.
            if (_backgroundProteome == null || Properties.Settings.Default.LibraryPeptidesAddUnmatched)
            {
                var listPeptidesToAdd = dictCopy.Values.ToList();
                listPeptidesToAdd.RemoveAll(match => match.Proteins != null && match.Proteins.Count > 0);
                if (listPeptidesToAdd.Count > 0)
                {
                    newDocument = AddPeptidesToLibraryGroup(newDocument, listPeptidesToAdd, broker,
                                                            toPath, out selectedPath);
                    if (listPeptidesToAdd.Count > 1000)
                    {
                        selectedPath = selectedPath.Parent; // Don't force Skyline to open a massive peptide list, if it wouldn't otherwise
                    }
                }
            }

            return(newDocument);
        }
Esempio n. 22
0
 public void CreateMatches(SrmSettings settings, IEnumerable<string> sequences,
     MappedList<string, StaticMod> defSetStatic, MappedList<string, StaticMod> defSetHeavy)
 {
     _sequences = sequences.GetEnumerator();
     InitMatcherSettings(settings, defSetStatic, defSetHeavy);
     if (UnmatchedSequences.Count > 0)
     {
         UnmatchedSequences.Sort();
         throw new FormatException(UninterpretedMods);
     }
 }
 protected void AddScriptableObjectWrappedData <T, TWrapper>(MappedList <T> mappedList)
     where T : IUniqueName
     where TWrapper : ScriptableObjectDataWrapper <T>
 {
     AssetEditor.AddScriptableObjectWrappedDataOfType <T, TWrapper>(this, mappedList);
 }
Esempio n. 24
0
        /// <summary>
        /// Create a new set of explicit modifications on a peptide from a list of desired
        /// modifications of each type, and the global lists of available modifications.
        /// </summary>
        /// <param name="nodePep">The peptide to modify</param>
        /// <param name="staticMods">Static modifications to be applied</param>
        /// <param name="listStaticMods">Global static modifications</param>
        /// <param name="heavyMods">All sets of isotope labeled mods to be applied</param>
        /// <param name="listHeavyMods">Global isotope labeled mods</param>
        /// <param name="implicitOnly">True to create an explicit expression of the implicit modifications</param>
        public ExplicitMods(PeptideDocNode nodePep,
            IList<StaticMod> staticMods, MappedList<string, StaticMod> listStaticMods,
            IEnumerable<TypedModifications> heavyMods, MappedList<string, StaticMod> listHeavyMods,
            bool implicitOnly = false)
        {
            Peptide = nodePep.Peptide;

            var modifications = new List<TypedExplicitModifications>();
            TypedExplicitModifications staticTypedMods = null;
            // Add static mods, if applicable
            if (staticMods != null)
            {
                IList<ExplicitMod> explicitMods = GetImplicitMods(staticMods, listStaticMods);
                // If the peptide has variable modifications, make them all override
                // the modification state of the default implicit mods
                if (!implicitOnly && nodePep.HasVariableMods)
                {
                    explicitMods = MergeExplicitMods(nodePep.ExplicitMods.StaticModifications,
                        explicitMods, staticMods);
                }
                staticTypedMods = new TypedExplicitModifications(Peptide,
                    IsotopeLabelType.light, explicitMods);
                modifications.Add(staticTypedMods);
            }
            foreach (TypedModifications typedMods in heavyMods)
            {
                var explicitMods = GetImplicitMods(typedMods.Modifications, listHeavyMods);
                var typedHeavyMods = new TypedExplicitModifications(Peptide,
                    typedMods.LabelType, explicitMods);
                modifications.Add(typedHeavyMods.AddModMasses(staticTypedMods));
            }
            _modifications = MakeReadOnly(modifications.ToArray());
        }
 public virtual PeptideModifications GetDocModifications(SrmDocument document)
 {
     var lightMods = new MappedList<string, StaticMod>();
     lightMods.AddRange(DefSetStatic);
     var heavyMods = new MappedList<string, StaticMod>();
     heavyMods.AddRange(DefSetHeavy);
     foreach (var matchPair in Matches)
     {
         var lightMod = matchPair.Value.StructuralMod;
         if (lightMod != null && !lightMods.Contains(lightMod))
             lightMods.Add(lightMod.ChangeExplicit(true));
         var heavyMod = matchPair.Value.HeavyMod;
         if (heavyMod != null && !heavyMods.Contains(heavyMod))
             heavyMods.Add(heavyMod.ChangeExplicit(true));
     }
     return document.Settings.PeptideSettings.Modifications.DeclareExplicitMods(document, lightMods, heavyMods);
 }
        /// <summary>
        /// Adds a list of PeptideDocNodes found in the library to the current document.
        /// </summary>
        public SrmDocument AddPeptides(SrmDocument document, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath)
        {
            if (toPath != null &&
                toPath.Depth == (int)SrmDocument.Level.MoleculeGroups &&
                ReferenceEquals(toPath.GetIdentity((int)SrmDocument.Level.MoleculeGroups), SequenceTree.NODE_INSERT_ID))
            {
                toPath = null;
            }

            SkippedPeptideCount = 0;
            var dictCopy = new Dictionary<PeptideSequenceModKey, PeptideMatch>();

            // Make heavy mods explicit
            if (PeptideMatches.Values.Contains(match => match.NodePep.HasExplicitMods
                    && match.NodePep.ExplicitMods.HeavyModifications != null))
            {
                _matcher.ConvertAllHeavyModsExplicit();
            }

            // Call ensure mods on all peptides to be added to the document.
            var listDefStatMods = new MappedList<string, StaticMod>();
            listDefStatMods.AddRange(Properties.Settings.Default.StaticModList);
            listDefStatMods.AddRange(document.Settings.PeptideSettings.Modifications.StaticModifications);

            var listDefHeavyMods = new MappedList<string, StaticMod>();
            listDefHeavyMods.AddRange(Properties.Settings.Default.HeavyModList);
            listDefHeavyMods.AddRange(document.Settings.PeptideSettings.Modifications.HeavyModifications);

            foreach (var key in PeptideMatches.Keys)
            {
                var match = PeptideMatches[key];
                var nodePepDocSet = match.NodePep;
                if (_matcher.MatcherPepMods != null)
                    nodePepDocSet = match.NodePep.EnsureMods(_matcher.MatcherPepMods,
                        document.Settings.PeptideSettings.Modifications,
                        listDefStatMods, listDefHeavyMods);
                if (!dictCopy.ContainsKey(nodePepDocSet.SequenceKey))
                    dictCopy.Add(nodePepDocSet.SequenceKey,
                        new PeptideMatch(nodePepDocSet, match.Proteins,
                        match.MatchesFilterSettings));
            }

            if (!Properties.Settings.Default.LibraryPeptidesKeepFiltered)
            {
                // TODO: This removes entire peptides where only a single
                //       precursor does not match.  e.g. the library contains
                //       a singly charged precursor match, but also doubly charged
                dictCopy = dictCopy.Where(match => match.Value.MatchesFilterSettings)
                                   .ToDictionary(match => match.Key, match => match.Value);
            }
            SrmDocument newDocument = UpdateExistingPeptides(document, dictCopy, toPath, out selectedPath);
            toPath = selectedPath;

            // If there is an associated background proteome, add peptides that can be
            // matched to the proteins from the background proteom.
            if (_backgroundProteome != null)
            {
                newDocument = AddProteomePeptides(newDocument, dictCopy, broker,
                    toPath, out selectedPath);
            }
            toPath = selectedPath;

            // Add all remaining peptides as a peptide list.
            if (_backgroundProteome == null ||  Properties.Settings.Default.LibraryPeptidesAddUnmatched)
            {
                var listPeptidesToAdd = dictCopy.Values.ToList();
                listPeptidesToAdd.RemoveAll(match => match.Proteins != null && match.Proteins.Count > 0);
                if (listPeptidesToAdd.Count > 0)
                {
                    newDocument = AddPeptidesToLibraryGroup(newDocument, listPeptidesToAdd, broker,
                                                            toPath, out selectedPath);
                }
            }

            return newDocument;
        }
 private static void UpdateMatcher(
     StaticMod[] docStatMods, StaticMod[] docHeavyMods,
     StaticMod[] globalStatMods, StaticMod[] globalHeavyMods, IEnumerable<string> seqs)
 {
     docStatMods = docStatMods ?? new StaticMod[0];
     docHeavyMods = docHeavyMods ?? new StaticMod[0];
     globalStatMods = globalStatMods ?? new StaticMod[0];
     globalHeavyMods = globalHeavyMods ?? new StaticMod[0];
     MappedList<string, StaticMod> mapGlobalStatMods = new MappedList<string, StaticMod>();
     mapGlobalStatMods.AddRange(docStatMods);
     mapGlobalStatMods.AddRange(globalStatMods);
     MappedList<string, StaticMod> mapGlobalHeavyMods = new MappedList<string, StaticMod>();
     mapGlobalHeavyMods.AddRange(docHeavyMods);
     mapGlobalHeavyMods.AddRange(globalHeavyMods);
     var settings = SrmSettingsList.GetDefault()
         .ChangePeptideModifications(mods =>
             mods.ChangeStaticModifications(docStatMods));
     settings = settings.ChangePeptideModifications(mods =>
         mods.ChangeHeavyModifications(docHeavyMods));
     MATCHER.CreateMatches(settings, seqs, mapGlobalStatMods, mapGlobalHeavyMods);
 }
Esempio n. 28
0
        public void TestModificationMatcher()
        {
            InitSeqs();

            var carbC = StaticModList.GetDefaultsOn()[0];

            // Test exception thrown if unable to match - mass.
            UpdateMatcherFail(STR_FAIL_MASS);
            UpdateMatcherFail(STR_FAIL_NOT_A_NUMBER);
            // Test exception thrown if unable to match - name.
            UpdateMatcherFail(STR_FAIL_NAME);
            // Can't match empty modifications.
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD);
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD2);
            // Can't match double modifications.
            UpdateMatcherFail(STR_FAIL_DOUBLE_MOD);
            // Test exception thrown if unimod not specified correctly
            UpdateMatcherFail(STR_FAIL_UNIMOD);
            UpdateMatcherFail(STR_UNKNOWN_UNIMOD);
            // Can't phosphorylate tryptophan
            UpdateMatcherFail(STR_FAIL_WRONG_AA_UNIMOD);
            // Can't put C-terminal modification in middle of peptide
            UpdateMatcherFail(STR_FAIL_UNIMOD_TERMINUS);

            // Test mods in UniMod match correctly.
            UpdateMatcher(StaticModList.GetDefaultsOn(), HeavyModList.GetDefaultsOn(), null, null);
            // A sequence with no modifications should not be explicitly modified.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_NO_MODS).HasExplicitMods);
            var nodeCysOxi = MATCHER.GetModifiedNode(STR_CYS_AND_OXI);

            Assert.IsTrue(nodeCysOxi.HasExplicitMods);
            Assert.IsFalse(nodeCysOxi.ExplicitMods.HasHeavyModifications);
            // Modifications should match by name.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                             Equals(mod.Modification.Name, "Phospho (ST)")));
            // Test can find terminal modification
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_TERM_ONLY).ExplicitMods.HeavyModifications.Contains(mod =>
                                                                                                          mod.Modification.EquivalentAll(UniMod.GetModification("Label:13C(6) (C-term R)", false))));
            // Test can find matches on terminus that are not terminal
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                             mod.Modification.Terminus == null));
            // Test matching negative masses
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_AMMONIA_LOSS).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                              mod.Modification.EquivalentAll(UniMod.GetModification("Ammonia-loss (N-term C)", true))));

            // General and specific
            // If all AAs modified, try for most general modification.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15)
                          .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.Equivalent(LABEL15_N)));

            // Updating the settings.
            // Peptide settings should change to include new mods.
            var          docNew = new SrmDocument(SrmSettingsList.GetDefault());
            IdentityPath firstAdded;
            IdentityPath nextAdded;

            docNew = docNew.AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(), "PepGroup1", "",
                                                                             new[] { MATCHER.GetModifiedNode(STR_MOD_BY_NAME) }) }, true, null, out firstAdded, out nextAdded);
            var pepSetNew = MATCHER.GetDocModifications(docNew);

            Assert.IsTrue(pepSetNew.StaticModifications.Contains(UniMod.GetModification("Phospho (ST)", true).ChangeExplicit(true)));
            // Update the document to the new settings.
            var pepSetNew1      = pepSetNew;
            var settingsNew2    = docNew.Settings.ChangePeptideModifications(mods => pepSetNew1);
            var lightGlobalMods = new MappedList <string, StaticMod>();

            lightGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.StaticModifications);
            var heavyGlobalMods = new MappedList <string, StaticMod>();

            heavyGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.AllHeavyModifications);
            // Match again. Test FoundMatches string should now be empty.
            MATCHER.CreateMatches(docNew.Settings.ChangePeptideModifications(mods => pepSetNew1),
                                  new List <string> {
                STR_MOD_BY_NAME
            }, lightGlobalMods, heavyGlobalMods);
            Assert.IsTrue(string.IsNullOrEmpty(MATCHER.FoundMatches));

            // Adding 15N to the settings.
            UpdateMatcher(new[] { carbC }, new[] { LABEL15_N }, null, null);
            // Test sequences with only explicit heavy mods should not have explicit light mods
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_ONLY).ExplicitMods.StaticModifications);

            // Test sequences with only explicit light mods should not have explicit heavy mods
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_LIGHT_ONLY).ExplicitMods.HasHeavyModifications);

            // Test global mods take precendence over UniMod
            UpdateMatcher(new[] { carbC }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.StaticModifications
                          .Contains(mod => Equals(mod.Modification, OXIDATION_M_GLOBAL)));

            // Test document mods take precendence over UniMod
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);

            // Test exception thrown if match doesn't make sense - wrong AA.
            UpdateMatcherFail(STR_FAIL_OX_ON_D);
            // Test exception thrown if match doesn't make sense - wrong terminus.
            _seqs.Add(STR_FAIL_OX_TERM);
            AssertEx.ThrowsException <FormatException>(() => UpdateMatcher(new[] { OXIDATION_M_C_TERM }, null, null, null));
            _seqs.Remove(STR_FAIL_OX_TERM);

            // Heavy 15N - All AAs.
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, new[] { LABEL15_N }, null, null);
            // Node should be created from document settings if possible.
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_15).ExplicitMods);
            // Heavy 15N - specific AA.
            // If only a specific AA is modified, there must be an explicit mod.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).HasExplicitMods);

            // Test variable mods match correctly.
            // Put variable mod in global mod and not on doc - make sure don't get variable mod,
            // should get explicit mod in that case.
            var variableMetOx = METHIONINE_OXIDATION.ChangeVariable(true);

            UpdateMatcher(new[] { carbC }, null, new[] { variableMetOx }, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);
            // Add variable mod to doc
            UpdateMatcher(new[] { carbC, variableMetOx }, null, null, null);
            // Mod can be created by the settings.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.IsVariableStaticMods);
            // Mod cannot be created by the settings.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);

            // Add Met Ox to global. Test: +16 finds it.
            UpdateMatcher(new[] { carbC }, null, new[] { MET_OX_ROUNDED }, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                          ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Test: +15.99 finds UniMod.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_HEAVY_15).
                           ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Add Methionine Oxidation before Met Ox. Test: +16 finds it.
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                           ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                          ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test long masses rounded.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_METOX_LONG_MASS).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                                 Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test UniMod label types
            var node = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);

            Assert.IsNotNull(node);
            Assert.IsNull(node.ExplicitMods.StaticModifications);
            Assert.IsTrue(node.ExplicitMods.HeavyModifications.Contains(mod =>
                                                                        Equals(mod.Modification, N_TERM_LABEL)));
            UpdateMatcherWithNoSequences(new[] { carbC }, new[] { N_TERM_LABEL }, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            var nodeNew = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);

            Assert.IsNotNull(nodeNew);
            Assert.IsTrue(nodeNew.TransitionGroups.Any(group => Equals(group.TransitionGroup.LabelType, IsotopeLabelType.heavy)));
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);

            // Test case where there are lots of unimod labels
            var nodeUniAll = MATCHER.GetModifiedNode(STR_UNIMOD_ALL);

            Assert.AreEqual(nodeUniAll.ExplicitMods.HeavyModifications.Count, 10);
            Assert.IsNull(nodeUniAll.ExplicitMods.StaticModifications);
            foreach (var mod in nodeUniAll.ExplicitMods.HeavyModifications)
            {
                Assert.AreEqual(mod.Modification.ShortName, "+01");
                Assert.AreEqual(mod.Modification.UnimodId, 994);
            }

            // Test unimod terminal label
            var nodeUniTerm = MATCHER.GetModifiedNode(STR_UNIMOD_TERMINUS);

            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications.Count, 1);
            Assert.IsNull(nodeUniTerm.ExplicitMods.StaticModifications);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.Terminus, ModTerminus.C);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.UnimodId, 298);

            // Basic multi-label test
            var heavyLabelType2 = new IsotopeLabelType("Heavy2", 1);
            var typedMod        = new TypedModifications(heavyLabelType2, new List <StaticMod> {
                LABEL15_N
            });
            var peptideMods = new PeptideModifications(new List <StaticMod>(), new List <TypedModifications> {
                typedMod
            });
            var settingsMultiLabel = SrmSettingsList.GetDefault().ChangePeptideModifications(mods => peptideMods);
            var defSetSetLight     = new MappedList <string, StaticMod>();

            defSetSetLight.AddRange(StaticModList.GetDefaultsOn());
            var defSetHeavy = new MappedList <string, StaticMod>();

            defSetHeavy.AddRange(HeavyModList.GetDefaultsOn());
            defSetHeavy.Add(LABEL15_N);
            MATCHER.CreateMatches(settingsMultiLabel, new List <string> {
                STR_HEAVY_15_F
            }, defSetSetLight, defSetHeavy);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).ExplicitMods.GetHeavyModifications().Contains(mod => Equals(mod.LabelType, heavyLabelType2)));
            // Peptide settings should not change.
            var docNew0 = new SrmDocument(settingsMultiLabel).AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(),
                                                                                                               "PepGroup1", "", new[] { MATCHER.GetModifiedNode(STR_HEAVY_15_F) }) }, true, null, out firstAdded, out nextAdded);
            var settingsNew = MATCHER.GetDocModifications(docNew0);

            Assert.AreEqual(settingsMultiLabel.PeptideSettings.Modifications.ChangeHasHeavyModifications(false),
                            settingsNew.ChangeHasHeavyModifications(false));

            // Finding specific modifications.
            // If only specific AA modified, try for most specific modification.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_F });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F)
                          .ExplicitMods.HeavyModifications.Contains(mod =>
                                                                    mod.Modification.AminoAcids.Contains(c => c == 'F')));
            // If only some AAs modified, try for most specific modifications.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_NOT_ALL });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_NOT_ALL)
                          .ExplicitMods.HeavyModifications.Contains(mod =>
                                                                    mod.Modification.AminoAcids.Contains(c => c == 'I')));


            using (var testDir = new TestFilesDir(TestContext, ZIP_FILE))
                using (var modMatchDocContainer = InitMatchDocContainer(testDir))
                {
                    var libkeyModMatcher = new LibKeyModificationMatcher();
                    var anlLibSpec       = new BiblioSpecLiteSpec("ANL_Combo", testDir.GetTestPath("ANL_Combined.blib"));
                    var yeastLibSpec     = new BiblioSpecLiteSpec("Yeast", testDir.GetTestPath("Yeast_atlas_small.blib"));
                    modMatchDocContainer.ChangeLibSpecs(new[] { anlLibSpec, yeastLibSpec });
                    var docLibraries  = modMatchDocContainer.Document.Settings.PeptideSettings.Libraries.Libraries;
                    int anlLibIndex   = docLibraries.IndexOf(library => Equals(library.Name, anlLibSpec.Name));
                    int yeastLibIndex = docLibraries.IndexOf(library => Equals(library.Name, yeastLibSpec.Name));

                    libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                                                   docLibraries[anlLibIndex].Keys, defSetSetLight, defSetHeavy);

                    // Test can match 15N
                    Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                                                                           match.HeavyMod != null && match.HeavyMod.Equivalent(LABEL15_N)));

                    var uniModMetOx = UniMod.GetModification("Oxidation (M)", true);

                    // Test can match Met Ox
                    Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                                                                           match.StructuralMod != null && match.StructuralMod.Equivalent(uniModMetOx)));

                    // Test can match 15N and Met ox!
                    Assert.IsTrue(libkeyModMatcher.Matches.Contains(match => match.Key.Mass == 17 &&
                                                                    match.Value.StructuralMod != null && match.Value.StructuralMod.Equivalent(uniModMetOx) &&
                                                                    match.Value.HeavyMod != null && match.Value.HeavyMod.Equivalent(LABEL15_N)));

                    // Test can match Cysteine (Implicit) and Met Ox (variable)
                    libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                                                   docLibraries[yeastLibIndex].Keys, defSetSetLight, defSetHeavy);
                    Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                                                                                               mod.Formula.Equals(UniMod.GetModification(StaticModList.DEFAULT_NAME, true).Formula) && !mod.IsVariable));
                    Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                                                                                               mod.Formula.Equals("O") && mod.IsVariable));
                }
        }
 public void CreateMatches(SrmSettings settings, IEnumerable<LibKey> libKeys,
     MappedList<string, StaticMod> defSetStatic, MappedList<string, StaticMod> defSetHeavy)
 {
     _dictAAMassPairs = new Dictionary<AATermKey, List<byte[]>>();
     _libKeys = libKeys.GetEnumerator();
     InitMatcherSettings(settings, defSetStatic, defSetHeavy);
     MatcherPepMods = CreateMatcherPeptideSettings();
 }
Esempio n. 30
0
        /// <summary>
        /// Builds a list of <see cref="ExplicitMod"/> objects from the implicit modifications
        /// on the document.
        /// </summary>
        /// <param name="mods">Implicit modifications on the document</param>
        /// <param name="listSettingsMods">All modifications available in the settings</param>
        /// <returns>List of <see cref="ExplicitMod"/> objects for the implicit modifications</returns>
        private ExplicitMod[] GetImplicitMods(IList<StaticMod> mods, MappedList<string, StaticMod> listSettingsMods)
        {
            List<ExplicitMod> listImplicitMods = new List<ExplicitMod>();

            if (!Peptide.IsCustomIon)
            {
                string seq = Peptide.Sequence;
                for (int i = 0; i < seq.Length; i++)
                {
                    char aa = seq[i];
                    foreach (StaticMod mod in mods)
                    {
                        // Skip explicit mods, since only considering implicit
                        if (mod.IsExplicit || !mod.IsMod(aa, i, seq.Length))
                            continue;
                        // Always use the modification from the settings to ensure expected
                        // equality comparisons.
                        StaticMod modAdd;
                        if (listSettingsMods.TryGetValue(mod.Name, out modAdd))
                            listImplicitMods.Add(new ExplicitMod(i, modAdd));
                    }
                }
            }

            return listImplicitMods.ToArray();
        }
Esempio n. 31
0
 private void AddAssets <T>(MappedList <T> mappedList) where T : Object, IUniqueName
 {
     AssetEditor.AddAssetsOfType(this, mappedList);
 }
Esempio n. 32
0
 public InsertQuery(Model model, MappedList<string, Field> fields)
 {
     Model = model;
     Fields = fields;
 }
        internal void InitMatcherSettings(SrmSettings settings,
            MappedList<string, StaticMod> defSetStatic, MappedList<string, StaticMod> defSetHeavy)
        {
            DefSetStatic = defSetStatic;
            DefSetHeavy = defSetHeavy;

            Settings = settings;

            var modifications = settings.PeptideSettings.Modifications;

            UserDefinedTypedMods = new Dictionary<StaticMod, IsotopeLabelType>();
            // First add modifications found in document settings, then add modifications found in the global settings.
            foreach (var type in settings.PeptideSettings.Modifications.GetModificationTypes())
            {
                // Set the default heavy type to the first heavy type encountered.
                if (!ReferenceEquals(type, IsotopeLabelType.light) && DocDefHeavyLabelType == null)
                    DocDefHeavyLabelType = type;
                InitUserDefTypedModDict(modifications.GetModificationsByName(type.Name), false);
            }
            InitUserDefTypedModDict(new TypedModifications(IsotopeLabelType.light, DefSetStatic), true);
            InitUserDefTypedModDict(new TypedModifications(DocDefHeavyLabelType, DefSetHeavy), true);

            Matches = new Dictionary<AAModKey, AAModMatch>();
            UnmatchedSequences = new List<string>();
            _foundHeavyLabels = new List<StaticMod>();

            while (MoveNextSequence())
            {
                InitModMatches();
            }
            CleanUpMatches();

            Initialized = true;
        }
Esempio n. 34
0
 private static IList<ExplicitMod> GetExplicitMods(IList<ComboBox> mods,
     MappedList<string, StaticMod> listSettingsMods)
 {
     List<ExplicitMod> listMods = new List<ExplicitMod>();
     for (int i = 0; i < mods.Count; i++)
     {
         string modName = (string) mods[i].SelectedItem;
         if (!string.IsNullOrEmpty(modName))
         {
             StaticMod settingsMod;
             if (listSettingsMods.TryGetValue(modName, out settingsMod))
                 listMods.Add(new ExplicitMod(i, settingsMod));
         }
     }
     return listMods.ToArray();
 }
Esempio n. 35
0
        public PeptideDocNode EnsureMods(PeptideModifications source, PeptideModifications target,
            MappedList<string, StaticMod> defSetStat, MappedList<string, StaticMod> defSetHeavy)
        {
            // Create explicit mods matching the implicit mods on this peptide for each document.
            var sourceImplicitMods = new ExplicitMods(this, source.StaticModifications, defSetStat, source.GetHeavyModifications(), defSetHeavy);
            var targetImplicitMods = new ExplicitMods(this, target.StaticModifications, defSetStat, target.GetHeavyModifications(), defSetHeavy);

            // If modifications match, no need to create explicit modifications for the peptide.
            if (sourceImplicitMods.Equals(targetImplicitMods))
                return this;

            // Add explicit mods if static mods not implicit in the target document.
            IList<ExplicitMod> newExplicitStaticMods = null;
            bool preserveVariable = HasVariableMods;
            // Preserve non-variable explicit modifications
            if (!preserveVariable && HasExplicitMods && ExplicitMods.StaticModifications != null)
            {
                // If they are not the same as the implicit modifications in the new document
                if (!ArrayUtil.EqualsDeep(ExplicitMods.StaticModifications, targetImplicitMods.StaticModifications))
                    newExplicitStaticMods = ExplicitMods.StaticModifications;
            }
            else if (!ArrayUtil.EqualsDeep(sourceImplicitMods.StaticModifications, targetImplicitMods.StaticModifications))
            {
                preserveVariable = false;
                newExplicitStaticMods = sourceImplicitMods.StaticModifications;
            }
            else if (preserveVariable)
            {
                newExplicitStaticMods = ExplicitMods.StaticModifications;
            }

            // Drop explicit mods if matching implicit mods are found in the target document.
            IList<TypedExplicitModifications> newExplicitHeavyMods = new List<TypedExplicitModifications>();
            // For each heavy label type, add explicit mods if static mods not found in the target document.
            var newTypedStaticMods = newExplicitStaticMods != null
                ? new TypedExplicitModifications(Peptide, IsotopeLabelType.light, newExplicitStaticMods)
                : null;
            foreach (TypedExplicitModifications targetDocMod in targetImplicitMods.GetHeavyModifications())
            {
                // Use explicit modifications when available.  Otherwise, compare against new implicit modifications
                IList<ExplicitMod> heavyMods = (HasExplicitMods ? ExplicitMods.GetModifications(targetDocMod.LabelType) : null) ??
                    sourceImplicitMods.GetModifications(targetDocMod.LabelType);
                if (heavyMods != null && !ArrayUtil.EqualsDeep(heavyMods, targetDocMod.Modifications) && heavyMods.Count > 0)
                {
                    var newTypedHeavyMods = new TypedExplicitModifications(Peptide, targetDocMod.LabelType, heavyMods);
                    newTypedHeavyMods = newTypedHeavyMods.AddModMasses(newTypedStaticMods);
                    newExplicitHeavyMods.Add(newTypedHeavyMods);
                }
            }

            if (newExplicitStaticMods != null || newExplicitHeavyMods.Count > 0)
                return ChangeExplicitMods(new ExplicitMods(Peptide, newExplicitStaticMods, newExplicitHeavyMods, preserveVariable));
            return ChangeExplicitMods(null);
        }
Esempio n. 36
0
 public UpdateQuery(Model model, MappedList<string, Field> fields)
 {
     Model = model;
     Fields = fields;
 }
        public void TestModificationMatcher()
        {
            InitSeqs();

            var carbC = StaticModList.GetDefaultsOn()[0];

            // Test exception thrown if unable to match - mass.
            UpdateMatcherFail(STR_FAIL_MASS);
            UpdateMatcherFail(STR_FAIL_NOT_A_NUMBER);
            // Test exception thrown if unable to match - name.
            UpdateMatcherFail(STR_FAIL_NAME);
            // Can't match empty modifications.
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD);
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD2);
            // Can't match double modifications.
            UpdateMatcherFail(STR_FAIL_DOUBLE_MOD);
            // Test exception thrown if unimod not specified correctly
            UpdateMatcherFail(STR_FAIL_UNIMOD);
            UpdateMatcherFail(STR_UNKNOWN_UNIMOD);
            // Can't phosphorylate tryptophan
            UpdateMatcherFail(STR_FAIL_WRONG_AA_UNIMOD);
            // Can't put C-terminal modification in middle of peptide
            UpdateMatcherFail(STR_FAIL_UNIMOD_TERMINUS);

            // Test mods in UniMod match correctly.
            UpdateMatcher(StaticModList.GetDefaultsOn(), HeavyModList.GetDefaultsOn(), null, null);
            // A sequence with no modifications should not be explicitly modified.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_NO_MODS).HasExplicitMods);
            var nodeCysOxi = MATCHER.GetModifiedNode(STR_CYS_AND_OXI);
            Assert.IsTrue(nodeCysOxi.HasExplicitMods);
            Assert.IsFalse(nodeCysOxi.ExplicitMods.HasHeavyModifications);
            // Modifications should match by name.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                Equals(mod.Modification.Name,  "Phospho (ST)")));
            // Test can find terminal modification
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_TERM_ONLY).ExplicitMods.HeavyModifications.Contains(mod =>
                mod.Modification.EquivalentAll(UniMod.GetModification("Label:13C(6) (C-term R)", false))));
            // Test can find matches on terminus that are not terminal
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                mod.Modification.Terminus == null));
            // Test matching negative masses
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_AMMONIA_LOSS).ExplicitMods.StaticModifications.Contains(mod =>
                mod.Modification.EquivalentAll(UniMod.GetModification("Ammonia-loss (N-term C)", true))));

            // General and specific
            // If all AAs modified, try for most general modification.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15)
                .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.Equivalent(LABEL15_N)));

            // Updating the settings.
            // Peptide settings should change to include new mods.
            var docNew = new SrmDocument(SrmSettingsList.GetDefault());
            IdentityPath firstAdded;
            IdentityPath nextAdded;
            docNew = docNew.AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(), "PepGroup1", "",
                new[] {MATCHER.GetModifiedNode(STR_MOD_BY_NAME)})}, true, null, out firstAdded, out nextAdded);
            var pepSetNew = MATCHER.GetDocModifications(docNew);
            Assert.IsTrue(pepSetNew.StaticModifications.Contains(UniMod.GetModification("Phospho (ST)", true).ChangeExplicit(true)));
            // Update the document to the new settings.
            var pepSetNew1 = pepSetNew;
            var settingsNew2 = docNew.Settings.ChangePeptideModifications(mods => pepSetNew1);
            var lightGlobalMods = new MappedList<string, StaticMod>();
            lightGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.StaticModifications);
            var heavyGlobalMods = new MappedList<string, StaticMod>();
            heavyGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.HeavyModifications);
            // Match again. Test FoundMatches string should now be empty.
            MATCHER.CreateMatches(docNew.Settings.ChangePeptideModifications(mods => pepSetNew1),
                new List<string> { STR_MOD_BY_NAME }, lightGlobalMods, heavyGlobalMods);
            Assert.IsTrue(string.IsNullOrEmpty(MATCHER.FoundMatches));

            // Adding 15N to the settings.
            UpdateMatcher(new[] { carbC }, new[] { LABEL15_N }, null, null);
            // Test sequences with only explicit heavy mods should not have explicit light mods
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_ONLY).ExplicitMods.StaticModifications);

            // Test sequences with only explicit light mods should not have explicit heavy mods
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_LIGHT_ONLY).ExplicitMods.HasHeavyModifications);

            // Test global mods take precendence over UniMod
            UpdateMatcher(new[] { carbC }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.StaticModifications
                .Contains(mod => Equals(mod.Modification, OXIDATION_M_GLOBAL)));

            // Test document mods take precendence over UniMod
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);

            // Test exception thrown if match doesn't make sense - wrong AA.
            UpdateMatcherFail(STR_FAIL_OX_ON_D);
            // Test exception thrown if match doesn't make sense - wrong terminus.
            _seqs.Add(STR_FAIL_OX_TERM);
            AssertEx.ThrowsException<FormatException>(() => UpdateMatcher(new[] {OXIDATION_M_C_TERM}, null, null, null));
            _seqs.Remove(STR_FAIL_OX_TERM);

            // Heavy 15N - All AAs.
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, new[] {LABEL15_N}, null, null);
            // Node should be created from document settings if possible.
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_15).ExplicitMods);
            // Heavy 15N - specific AA.
            // If only a specific AA is modified, there must be an explicit mod.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).HasExplicitMods);

            // Test variable mods match correctly.
            // Put variable mod in global mod and not on doc - make sure don't get variable mod,
            // should get explicit mod in that case.
            var variableMetOx = METHIONINE_OXIDATION.ChangeVariable(true);
            UpdateMatcher(new[] { carbC }, null, new[] { variableMetOx }, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);
            // Add variable mod to doc
            UpdateMatcher(new[] { carbC, variableMetOx }, null, null, null);
            // Mod can be created by the settings.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.IsVariableStaticMods);
            // Mod cannot be created by the settings.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);

            // Add Met Ox to global. Test: +16 finds it.
            UpdateMatcher(new[] {carbC}, null, new[] {MET_OX_ROUNDED}, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Test: +15.99 finds UniMod.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_HEAVY_15).
                ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Add Methionine Oxidation before Met Ox. Test: +16 finds it.
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test long masses rounded.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_METOX_LONG_MASS).ExplicitMods.StaticModifications.Contains(mod =>
                Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test UniMod label types
            var node = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);
            Assert.IsNotNull(node);
            Assert.IsNull(node.ExplicitMods.StaticModifications);
            Assert.IsTrue(node.ExplicitMods.HeavyModifications.Contains(mod =>
                Equals(mod.Modification, N_TERM_LABEL)));
            UpdateMatcherWithNoSequences(new[] { carbC }, new[] { N_TERM_LABEL }, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            var nodeNew = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);
            Assert.IsNotNull(nodeNew);
            Assert.IsTrue(nodeNew.TransitionGroups.Any(group => Equals(group.TransitionGroup.LabelType, IsotopeLabelType.heavy)));
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);

            // Test case where there are lots of unimod labels
            var nodeUniAll = MATCHER.GetModifiedNode(STR_UNIMOD_ALL);
            Assert.AreEqual(nodeUniAll.ExplicitMods.HeavyModifications.Count, 10);
            Assert.IsNull(nodeUniAll.ExplicitMods.StaticModifications);
            foreach (var mod in nodeUniAll.ExplicitMods.HeavyModifications)
            {
                Assert.AreEqual(mod.Modification.ShortName, "+01");
                Assert.AreEqual(mod.Modification.UnimodId, 994);
            }

            // Test unimod terminal label
            var nodeUniTerm = MATCHER.GetModifiedNode(STR_UNIMOD_TERMINUS);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications.Count, 1);
            Assert.IsNull(nodeUniTerm.ExplicitMods.StaticModifications);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.Terminus, ModTerminus.C);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.UnimodId, 298);

            // Basic multi-label test
            var heavyLabelType2 = new IsotopeLabelType("Heavy2", 1);
            var typedMod = new TypedModifications(heavyLabelType2, new List<StaticMod> { LABEL15_N });
            var peptideMods = new PeptideModifications(new List<StaticMod>(), new List<TypedModifications> { typedMod });
            var settingsMultiLabel = SrmSettingsList.GetDefault().ChangePeptideModifications(mods => peptideMods);
            var defSetSetLight = new MappedList<string, StaticMod>();
            defSetSetLight.AddRange(StaticModList.GetDefaultsOn());
            var defSetHeavy = new MappedList<string, StaticMod>();
            defSetHeavy.AddRange(HeavyModList.GetDefaultsOn());
            defSetHeavy.Add( LABEL15_N );
            MATCHER.CreateMatches(settingsMultiLabel, new List<string> { STR_HEAVY_15_F }, defSetSetLight, defSetHeavy);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).ExplicitMods.GetHeavyModifications().Contains(mod => Equals(mod.LabelType, heavyLabelType2)));
            // Peptide settings should not change.
            var docNew0 = new SrmDocument(settingsMultiLabel).AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(),
                "PepGroup1", "", new[] {MATCHER.GetModifiedNode(STR_HEAVY_15_F)})}, true, null, out firstAdded, out nextAdded);
            var settingsNew = MATCHER.GetDocModifications(docNew0);
            Assert.AreEqual(settingsMultiLabel.PeptideSettings.Modifications, settingsNew);

            // Finding specific modifications.
            // If only specific AA modified, try for most specific modification.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_F});
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F)
                .ExplicitMods.HeavyModifications.Contains(mod =>
                    mod.Modification.AminoAcids.Contains(c => c == 'F')));
            // If only some AAs modified, try for most specific modifications.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_NOT_ALL });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_NOT_ALL)
                .ExplicitMods.HeavyModifications.Contains(mod =>
                mod.Modification.AminoAcids.Contains(c => c == 'I')));

            using (var testDir = new TestFilesDir(TestContext, ZIP_FILE))
            {
                var modMatchDocContainer = InitMatchDocContainer(testDir);
                var libkeyModMatcher = new LibKeyModificationMatcher();
                var anlLibSpec = new BiblioSpecLiteSpec("ANL_Combo", testDir.GetTestPath("ANL_Combined.blib"));
                var yeastLibSpec = new BiblioSpecLiteSpec("Yeast", testDir.GetTestPath("Yeast_atlas_small.blib"));
                modMatchDocContainer.ChangeLibSpecs(new[] { anlLibSpec, yeastLibSpec });
                var docLibraries = modMatchDocContainer.Document.Settings.PeptideSettings.Libraries.Libraries;
                int anlLibIndex = docLibraries.IndexOf(library => Equals(library.Name, anlLibSpec.Name));
                int yeastLibIndex = docLibraries.IndexOf(library => Equals(library.Name, yeastLibSpec.Name));

                libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                    docLibraries[anlLibIndex].Keys, defSetSetLight, defSetHeavy);

                // Test can match 15N
                Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                    match.HeavyMod != null && match.HeavyMod.Equivalent(LABEL15_N)));

                var uniModMetOx = UniMod.GetModification("Oxidation (M)", true);

                // Test can match Met Ox
                Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                    match.StructuralMod != null && match.StructuralMod.Equivalent(uniModMetOx)));

                // Test can match 15N and Met ox!
                Assert.IsTrue(libkeyModMatcher.Matches.Contains(match => match.Key.Mass == 17
                    && match.Value.StructuralMod != null && match.Value.StructuralMod.Equivalent(uniModMetOx)
                    && match.Value.HeavyMod != null && match.Value.HeavyMod.Equivalent(LABEL15_N)));

                // Test can match Cysteine (Implicit) and Met Ox (variable)
                libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                    docLibraries[yeastLibIndex].Keys, defSetSetLight, defSetHeavy);
                Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                    mod.Formula.Equals(UniMod.GetModification(StaticModList.DEFAULT_NAME, true).Formula) && !mod.IsVariable));
                Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                    mod.Formula.Equals("O") && mod.IsVariable));
            }
        }