Skip to content

Commit dc399b4

Browse files
trishortsnbollis
andauthored
Revert mod dictionary passage into db writer (#952)
* revert ProteinDbWriter * rename protein to nucleic acid in appropriate method * fixed unit tests QUESTION MARK * ok works --------- Co-authored-by: Nic Bollis <nbollis@comcast.net>
1 parent 0ad8a09 commit dc399b4

File tree

8 files changed

+82
-55
lines changed

8 files changed

+82
-55
lines changed

mzLib/Omics/BioPolymer/SequenceVariation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public SequenceVariation(int oneBasedBeginPosition, int oneBasedEndPosition, str
2121
OriginalSequence = originalSequence ?? "";
2222
VariantSequence = variantSequence ?? "";
2323
Description = new SequenceVariantDescription(description);
24-
OneBasedModifications = oneBasedModifications ?? [];
24+
OneBasedModifications = oneBasedModifications ?? new Dictionary<int, List<Modification>>();
2525
}
2626

2727
/// <summary>

mzLib/Test/DatabaseTests/TestDatabaseLoaders.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static void LoadIsoforms()
6969
Assert.AreEqual("Q14103-2", protein[7].Accession);
7070
Assert.AreEqual("Q14103-3", protein[8].Accession);
7171
Assert.AreEqual("Q14103-4", protein[9].Accession);
72-
ProteinDbWriter.WriteXmlDatabase(protein, Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "IsoformTest.xml"));
72+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), protein, Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "IsoformTest.xml"));
7373
var proteinXml = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "IsoformTest.xml"), true, DecoyType.None, null, false, null, out var unknownMod);
7474
Assert.AreEqual("Q13409", proteinXml[0].Accession);
7575
Assert.AreEqual("Q13409-2", proteinXml[1].Accession);
@@ -456,7 +456,7 @@ public void Modification_read_write_into_proteinDb()
456456
Assert.AreEqual(1, sampleModList.OfType<Modification>().Count());
457457
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>(), disulfideBonds: new List<DisulfideBond>());
458458
Assert.AreEqual(1, protein.OneBasedPossibleLocalizedModifications[2].OfType<Modification>().Count());
459-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"));
459+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"));
460460
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"),
461461
true, DecoyType.None, new List<Modification>(), false, new List<string>(), out Dictionary<string, Modification> um);
462462
Assert.AreEqual(1, new_proteins.Count);
@@ -544,7 +544,7 @@ public void MultiMod_ProteinDbWriter()
544544

545545
Assert.AreEqual(6, protein.OneBasedPossibleLocalizedModifications[2].OfType<Modification>().Count());
546546
Assert.AreEqual(18, protein.OneBasedPossibleLocalizedModifications.SelectMany(kvp => kvp.Value).Count());
547-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein },
547+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein },
548548
Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"));
549549
List<Protein> newProteins = ProteinDbLoader.LoadProteinXML(
550550
Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins.xml"),
@@ -574,7 +574,7 @@ public void MultiMod_ProteinDbWriter()
574574
disulfideBonds: new List<DisulfideBond>());
575575
string shuffledProteinFileName = Path.Combine(TestContext.CurrentContext.TestDirectory,
576576
"test_shuffled_modifications_with_proteins.xml");
577-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { modShuffledProtein }, shuffledProteinFileName);
577+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { modShuffledProtein }, shuffledProteinFileName);
578578
List<Protein> newShuffledProteins = ProteinDbLoader.LoadProteinXML(shuffledProteinFileName,
579579
true, DecoyType.None, new List<Modification>(), false, new List<string>(), out um);
580580

@@ -610,7 +610,7 @@ public static void Test_MetaMorpheusStyleProteinDatabaseWriteAndREad()
610610

611611
Protein prot1 = new Protein("MEDEEK", "prot1", oneBasedModifications: oneBasedModification);
612612
List<Protein> proteinList = new List<Protein> { prot1 };
613-
ProteinDbWriter.WriteXmlDatabase( proteinList, proteinDbFilePath);
613+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), proteinList, proteinDbFilePath);
614614

615615
var lines = File.ReadAllLines(proteinDbFilePath);
616616
List<Protein> newProteinList = ProteinDbLoader.LoadProteinXML(proteinDbFilePath, true, DecoyType.Reverse, new List<Modification>(), false, new List<string>(), out var um, -1);
@@ -639,7 +639,7 @@ public void DoNotWriteSameModTwiceAndDoNotWriteInHeaderSinceDifferent()
639639
value.Add(new Tuple<int, Modification>(2, newMod));
640640

641641
dictWithThisMod.Add("accession", value);
642-
var newModResEntries = ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"));
642+
var newModResEntries = ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"));
643643
Assert.AreEqual(0, newModResEntries.Count);
644644
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, "test_modifications_with_proteins3.xml"),
645645
true, DecoyType.None, new List<Modification>(), false, new List<string>(), out Dictionary<string, Modification> um);
@@ -664,7 +664,7 @@ public void TestWritePtmWithNeutralLoss()
664664
Assert.That(protein.OneBasedPossibleLocalizedModifications.Count == 1);
665665
Assert.That(protein.OneBasedPossibleLocalizedModifications.First().Value.First().NeutralLosses.First().Value.Count == 2);
666666

667-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
667+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
668668

669669
// with passed-in mods
670670
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, filename), true, DecoyType.None, new List<Modification> { m }, false, new List<string>(), out Dictionary<string, Modification> um);
@@ -691,7 +691,7 @@ public void TestWritePtmWithNeutralLoss_AsBioPolymer()
691691
Assert.That(protein.OneBasedPossibleLocalizedModifications.Count == 1);
692692
Assert.That(protein.OneBasedPossibleLocalizedModifications.First().Value.First().NeutralLosses.First().Value.Count == 2);
693693

694-
ProteinDbWriter.WriteXmlDatabase(new List<IBioPolymer> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
694+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<IBioPolymer> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
695695

696696
// with passed-in mods
697697
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, filename), true, DecoyType.None, new List<Modification> { m }, false, new List<string>(), out Dictionary<string, Modification> um);
@@ -718,7 +718,7 @@ public void TestWritePtmWithDiagnosticIons()
718718
Assert.That(protein.OneBasedPossibleLocalizedModifications.Count == 1);
719719
Assert.That(protein.OneBasedPossibleLocalizedModifications.First().Value.First().DiagnosticIons.First().Value.Count == 2);
720720

721-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
721+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
722722

723723
// with passed-in mods
724724
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, filename), true, DecoyType.None, new List<Modification> { m }, false, new List<string>(), out Dictionary<string, Modification> um);
@@ -745,7 +745,7 @@ public void TestWritePtmWithNeutralLossAndDiagnosticIons()
745745
Assert.That(protein.OneBasedPossibleLocalizedModifications.Count == 1);
746746
Assert.That(protein.OneBasedPossibleLocalizedModifications.First().Value.First().NeutralLosses.First().Value.Count == 2);
747747

748-
ProteinDbWriter.WriteXmlDatabase(new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
748+
ProteinDbWriter.WriteXmlDatabase(new Dictionary<string, HashSet<Tuple<int, Modification>>>(), new List<Protein> { protein }, Path.Combine(TestContext.CurrentContext.TestDirectory, filename));
749749

750750
// with passed-in mods
751751
List<Protein> new_proteins = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, filename), true, DecoyType.None, new List<Modification> { m }, false, new List<string>(), out Dictionary<string, Modification> um);

0 commit comments

Comments
 (0)