public void Test_modification4_hash_set() { ModificationMotif.TryGetMotif("K", out ModificationMotif motif); ModificationWithMassAndCf m1 = new ModificationWithMassAndCf(null, new Tuple <string, string>("item1", "item2"), motif, ModificationSites.K, new ChemicalFormula(), 1.11111d, new Dictionary <string, IList <string> >(), new List <double> { 2.222222 }, new List <double> { 5.55555 }, "modificationType"); ModificationWithMassAndCf m2 = new ModificationWithMassAndCf(null, new Tuple <string, string>("item1", "item2"), motif, ModificationSites.K, new ChemicalFormula(), 1.11111d, new Dictionary <string, IList <string> >(), new List <double> { 2.222222 }, new List <double> { 5.55555 }, "modificationType"); m1.linksToOtherDbs.Add("key", new List <string> { "value" }); m2.linksToOtherDbs.Add("key", new List <string> { "value" }); HashSet <Modification> mods = new HashSet <Modification>(new Modification[] { m1, m2 }); Assert.AreEqual(1, mods.Count); Assert.True(m1.Equals(m2)); }
public static void Test_ModificationWithNoMassWritten() { ModificationMotif.TryGetMotif("M", out ModificationMotif motif); var mod1 = new ModificationWithMassAndCf("mod", "type", motif, TerminusLocalization.Any, ChemicalFormula.ParseFormula("H"), ChemicalFormula.ParseFormula("H").MonoisotopicMass, null, null, null); var mod1string = mod1.ToString(); Assert.IsTrue(!mod1string.Contains("MM")); var modAfterWriteRead = PtmListLoader.ReadModsFromString(mod1string + Environment.NewLine + "//").First() as ModificationWithMassAndCf; Assert.AreEqual(mod1, modAfterWriteRead); }
public void DoNotWriteSameModTwiceAndDoNotWriteInHeaderSinceDifferent() { Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, "elements2.dat")); var sampleModList = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "z.txt")).ToList(); Protein protein = new Protein("MCSSSSSSSSSS", "accession", "organism", new List <Tuple <string, string> >(), new Dictionary <int, List <Modification> > { { 2, sampleModList.OfType <Modification>().ToList() } }, null, "name", "full_name", false, false, new List <DatabaseReference>(), new List <SequenceVariation>(), new List <DisulfideBond>()); Assert.AreEqual(1, protein.OneBasedPossibleLocalizedModifications[2].OfType <ModificationWithMass>().Count()); Dictionary <string, HashSet <Tuple <int, Modification> > > dictWithThisMod = new Dictionary <string, HashSet <Tuple <int, Modification> > >(); HashSet <Tuple <int, Modification> > value = new HashSet <Tuple <int, Modification> >(); var modReadFromFile = sampleModList.First() as ModificationWithMassAndCf; ModificationMotif.TryGetMotif("C", out ModificationMotif motif); ModificationWithMass newMod = new ModificationWithMassAndCf("Palmitoylation of C", modReadFromFile.modificationType, motif, TerminusLocalization.Any, modReadFromFile.chemicalFormula, modReadFromFile.monoisotopicMass, null, null, null); Assert.AreEqual(newMod, sampleModList.First()); Assert.AreEqual(sampleModList.First(), newMod); value.Add(new Tuple <int, Modification>(2, newMod)); dictWithThisMod.Add("accession", value); var newModResEntries = ProteinDbWriter.WriteXmlDatabase(dictWithThisMod, new List <Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml")); Assert.AreEqual(0, newModResEntries.Count); List <Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"), true, DecoyType.None, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> um); Assert.AreEqual(1, new_proteins.Count); Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.Count); Assert.AreEqual(1, new_proteins[0].OneBasedPossibleLocalizedModifications.SelectMany(kv => kv.Value).Count()); }