Beispiel #1
0
        public void TestStartIndex()
        {
            Modification modification = Modification.CreateNoChanged(new List <string> {
                "aaa", "bbb", "ccc"
            });

            Assert.AreEqual(modification.Primary.StartIndex, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 0);

            ModificationCollection modifications = new ModificationCollection();

            modifications.Add(modification);

            modification = Modification.CreateAdded(new List <string> {
                "ddd", "eee", "fff"
            });

            modifications.Add(modification);

            Assert.AreEqual(modification.Primary.StartIndex, 3);
            Assert.AreEqual(modification.Primary.Length, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 3);
            Assert.AreEqual(modification.Secondary.Length, 3);

            modification = Modification.CreateAdded(new List <string> {
                "ggg", "hhh", "iii"
            });

            modifications.Add(modification);

            Assert.AreEqual(modification.Primary.StartIndex, 3);
            Assert.AreEqual(modification.Primary.Length, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 6);
            Assert.AreEqual(modification.Secondary.Length, 3);
        }
Beispiel #2
0
        public void TestStartIndex()
        {
            Modification modification = Modification.CreateNoChanged(new List<string> {"aaa", "bbb", "ccc"});

            Assert.AreEqual(modification.Primary.StartIndex, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 0);

            ModificationCollection modifications = new ModificationCollection();

            modifications.Add(modification);

            modification = Modification.CreateAdded(new List<string> { "ddd", "eee", "fff" });

            modifications.Add(modification);

            Assert.AreEqual(modification.Primary.StartIndex, 3);
            Assert.AreEqual(modification.Primary.Length, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 3);
            Assert.AreEqual(modification.Secondary.Length, 3);

            modification = Modification.CreateAdded(new List<string> { "ggg", "hhh", "iii" });

            modifications.Add(modification);

            Assert.AreEqual(modification.Primary.StartIndex, 3);
            Assert.AreEqual(modification.Primary.Length, 0);
            Assert.AreEqual(modification.Secondary.StartIndex, 6);
            Assert.AreEqual(modification.Secondary.Length, 3);
        }
Beispiel #3
0
        public void ModificationCollectionTest()
        {
            ModificationCollection a = new ModificationCollection(new OldSchoolModification(1, "Mod1"), new OldSchoolModification(2, "Mod2"));

            double      lala  = 0;
            IEnumerable aasdf = a;

            foreach (var jadfk in aasdf)
            {
                lala += (jadfk as IHasMass).MonoisotopicMass;
            }
            Assert.AreEqual(3, lala);

            Assert.AreEqual("Mod1 | Mod2", a.ToString());
            a.Add(new OldSchoolModification(3, "Mod3"));
            Assert.AreEqual("Mod1 | Mod2 | Mod3", a.ToString());
            Assert.IsTrue(a.Contains(new OldSchoolModification(2, "Mod2")));
            IHasMass[] myArray = new IHasMass[4];
            a.CopyTo(myArray, 1);
            Assert.AreEqual(3, myArray.Sum(b => b == null ? 0 : 1));
            Assert.AreEqual(3, a.Count());
            Assert.IsFalse(a.IsReadOnly);
            a.Remove(new OldSchoolModification(2, "Mod2"));
            Assert.AreEqual("Mod1 | Mod3", a.ToString());
            double ok = 0;

            foreach (var b in a)
            {
                ok += b.MonoisotopicMass;
            }
            Assert.AreEqual(4, ok);

            a.Clear();
            Assert.AreEqual("", a.ToString());
        }
Beispiel #4
0
        private void miDelete_Click(object sender, EventArgs e)
        {
#if CHECKERS
            if (IsSelectionEmpty)
            {
                throw new InvalidOperationException();
            }
#endif
            var  b       = new StringBuilder();
            bool isFirst = true;
            foreach (var c in _selectionList)
            {
                if (!isFirst)
                {
                    b.Append(", ");
                }
                else
                {
                    isFirst = false;
                }
                b.Append(c.Owner.Title);
            }

            if (Extenders.ConfirmDelete(b.ToString()))
            {
                var list = _selectionList.ToArray();
                UnSelectAll();
                var mg = new ModificationCollection <HtmlControlModification>();
                foreach (var c in list)
                {
                    FreeResources(c.Owner);
                    HtmlDesignMovableControl owner = c.Owner;
                    owner.NotifyDelete();

                    mg.Add(HtmlControlModification.GetRemoved(owner));

                    owner.Parent = null;
                }
                if (mg.Count > 0)
                {
                    HtmlPage.AddUndoOperation(mg.Count == 1 ? (IModification)mg[0] : mg);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                UpdateUndoRedoState();
            }
        }
Beispiel #5
0
        private void Control_EndMove(HtmlDesignMovableControl c)
        {
            IModification m;

            if (_selectionList.Count == 1)
            {
                HtmlDesignMovableControl o = _selectionList[0].Owner;
                Point previousLocation     = _PreviousLocations[o];
                m = previousLocation != o.Control.Location ? HtmlControlModification.GetMoved(o, previousLocation) : (IModification)null;
            }
            else
            {
                var list = new ModificationCollection <HtmlControlModification>();
                foreach (var bc in _selectionList)
                {
                    HtmlDesignMovableControl o = bc.Owner;
                    Point previousLocation     = _PreviousLocations[o];
                    if (previousLocation != o.Control.Location)
                    {
                        list.Add(HtmlControlModification.GetMoved(o, previousLocation));
                    }
                }
                if (list.Count == 1)
                {
                    m = list[0];
                }
                else
                {
                    m = list.Count > 0 ? list : null;
                }
            }
            if (m != null)
            {
                HtmlPage.AddUndoOperation(m);
                UpdateUndoRedoState();
            }
            c.Control.LocationChanged -= Control_LocationChanged;
        }
Beispiel #6
0
        private void miDelete_Click(object sender, EventArgs e)
        {
#if CHECKERS
            if (IsSelectionEmpty)
            {
                throw new InvalidOperationException();
            }
#endif
            var b = new StringBuilder();
            bool isFirst = true;
            foreach (var c in _selectionList)
            {
                if (!isFirst)
                {
                    b.Append(", ");
                }
                else
                {
                    isFirst = false;
                }
                b.Append(c.Owner.Title);
            }

            if (Extenders.ConfirmDelete(b.ToString()))
            {
                var list = _selectionList.ToArray();
                UnSelectAll();
                var mg = new ModificationCollection<HtmlControlModification>();
                foreach (var c in list)
                {
                    FreeResources(c.Owner);
                    HtmlDesignMovableControl owner = c.Owner;
                    owner.NotifyDelete();

                    mg.Add(HtmlControlModification.GetRemoved(owner));

                    owner.Parent = null;
                }
                if (mg.Count > 0)
                {
                    HtmlPage.AddUndoOperation(mg.Count == 1 ? (IModification)mg[0] : mg);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                UpdateUndoRedoState();
            }
        }
Beispiel #7
0
        public static IEnumerable<Peptide> GetUniquePeptides(Peptide peptide)
        {
            QuantitationChannelSet quantSetMod;
            IMass mod;
            ModificationCollection modCol;
            HashSet<QuantitationChannelSet> sets = new HashSet<QuantitationChannelSet>();
            Dictionary<IQuantitationChannel, HashSet<int>> locations = new Dictionary<IQuantitationChannel, HashSet<int>>();
            HashSet<int> residues;

            IMass[] mods = peptide.Modifications;
            int modLength = mods.Length;

            for (int i = 0; i < modLength; i++)
            {
                if (mods[i] != null)
                {
                    mod = mods[i];

                    List<QuantitationChannelSet> channelsets = new List<QuantitationChannelSet>();

                    if ((modCol = mod as ModificationCollection) != null)
                    {
                        foreach (IMass mod2 in modCol)
                        {
                            if ((quantSetMod = mod2 as QuantitationChannelSet) != null)
                            {
                                channelsets.Add(quantSetMod);
                            }
                        }
                    }
                    else if ((quantSetMod = mod as QuantitationChannelSet) != null)
                    {
                        channelsets.Add(quantSetMod);
                    }

                    foreach (QuantitationChannelSet channelset in channelsets)
                    {
                        sets.Add(channelset);
                        foreach (IQuantitationChannel channel in channelset.GetChannels())
                        {
                            if (locations.TryGetValue(channel, out residues))
                            {
                                residues.Add(i);
                            }
                            else
                            {
                                residues = new HashSet<int>() { i };
                                locations.Add(channel, residues);
                            }
                        }
                    }
                }
            }

            if (sets.Count == 0)
            {
                yield return new Peptide(peptide, true);
            }
            else if (sets.Count == 1)
            {
                foreach (QuantitationChannelSet set in sets)
                {
                    foreach (IQuantitationChannel channel in set.GetChannels())
                    {
                        Peptide toReturn = new Peptide(peptide, true);
                        foreach (int residue in locations[channel])
                        {
                            toReturn.SetModification(channel, residue);
                        }
                        yield return toReturn;
                    }
                }
            }
            else
            {
                List<HashSet<IQuantitationChannel>> quantChannels = new List<HashSet<IQuantitationChannel>>();

                GetUniquePeptides_helper(sets.ToList(), 0, new HashSet<IQuantitationChannel>(), quantChannels);

                foreach (HashSet<IQuantitationChannel> channelset in quantChannels)
                {
                    Peptide toReturn = new Peptide(peptide, true);
                    Dictionary<int, IMass> modsToAdd = new Dictionary<int, IMass>();
                    IMass modToAdd;
                    foreach (IQuantitationChannel channel in channelset)
                    {
                        foreach (int residue in locations[channel])
                        {
                            if (modsToAdd.TryGetValue(residue, out modToAdd))
                            {
                                ModificationCollection col = new ModificationCollection(channel, modToAdd);
                                col.Add(channel);
                                col.Add(modToAdd);
                                modsToAdd[residue] = col;
                            }
                            else
                            {
                                modsToAdd.Add(residue, channel);
                            }
                        }
                    }
                    foreach (KeyValuePair<int, IMass> kvp in modsToAdd)
                    {
                        toReturn.SetModification(kvp.Value, kvp.Key);
                    }
                    yield return toReturn;
                }
            }
            yield break;
        }
Beispiel #8
0
 private void Control_EndMove(HtmlDesignMovableControl c)
 {
     IModification m;
     if (_selectionList.Count == 1)
     {
         HtmlDesignMovableControl o = _selectionList[0].Owner;
         Point previousLocation = _PreviousLocations[o];
         m = previousLocation != o.Control.Location ? HtmlControlModification.GetMoved(o, previousLocation) : (IModification)null;
     }
     else
     {
         var list = new ModificationCollection<HtmlControlModification>();
         foreach (var bc in _selectionList)
         {
             HtmlDesignMovableControl o = bc.Owner;
             Point previousLocation = _PreviousLocations[o];
             if (previousLocation != o.Control.Location)
             {
                 list.Add(HtmlControlModification.GetMoved(o, previousLocation));
             }
         }
         if (list.Count == 1)
         {
             m = list[0];
         }
         else
         {
             m = list.Count > 0 ? list : null;    
         }
     }
     if(m != null)
     {
         HtmlPage.AddUndoOperation(m);
         UpdateUndoRedoState();
     }
     c.Control.LocationChanged -= Control_LocationChanged;
 }