Skip to content

Commit

Permalink
Fixed bug where pwsm.ChemicalFormula threw null reference exception (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Sol committed May 31, 2023
1 parent df3035c commit b0f82ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ public ChemicalFormula FullChemicalFormula
ChemicalFormula fullChemicalFormula = new Proteomics.AminoAcidPolymer.Peptide(BaseSequence).GetChemicalFormula();
foreach (var mod in AllModsOneIsNterminus.Values)
{
fullChemicalFormula.Add(mod.ChemicalFormula);
if (mod.ChemicalFormula != null)
{
fullChemicalFormula.Add(mod.ChemicalFormula);
}
else
{
fullChemicalFormula = null;
break;
}
}

_fullChemicalFormula = fullChemicalFormula;
Expand Down
14 changes: 14 additions & 0 deletions mzLib/Test/TestPeptideWithSetMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,20 @@ public static void CheckFullChemicalFormula()
PeptideWithSetModifications large_pep_mod = new PeptideWithSetModifications(new Protein("PEPSIDEKRNSPEPTIDEKECUEIRQUV", "ACCESSION"), new DigestionParams(protease: "trypsin"), 1, 28, CleavageSpecificity.Full, null, 0, modDict_large, 0, null);
ChemicalFormula large_pep_mod_cf = ChemicalFormula.ParseFormula("C135H223N38O57P2S1Se2");
Assert.AreEqual(large_pep_mod.FullChemicalFormula, large_pep_mod_cf);

ModificationMotif.TryGetMotif("C", out var motif_c);
ModificationMotif.TryGetMotif("G", out var motif_g);
Dictionary<string, Modification> modDict =
new()
{
{ "Carbamidomethyl on C", new Modification(_originalId: "Carbamidomethyl", _modificationType: "Common Fixed",
_target: motif_c, _locationRestriction: "Anywhere.", _chemicalFormula: ChemicalFormula.ParseFormula("C2H3ON")) },
{ "BS on G" , new Modification(_originalId: "BS on G", _modificationType: "BS", _target: motif_g, _monoisotopicMass: 96.0875)}
};
PeptideWithSetModifications pwsmWithMissingCfMods = new PeptideWithSetModifications(
"ENQGDETQG[Speculative:BS on G]C[Common Fixed:Carbamidomethyl on C]PPQR", modDict, p: new Protein("ENQGDETQGCPPQR", "FakeProtein"), digestionParams: new DigestionParams(),
oneBasedStartResidueInProtein: 1, oneBasedEndResidueInProtein: 14);
Assert.Null(pwsmWithMissingCfMods.FullChemicalFormula);
}

[Test]
Expand Down

0 comments on commit b0f82ea

Please sign in to comment.