Skip to content

Commit

Permalink
Handled edge case with digestion product having a null parent (#763)
Browse files Browse the repository at this point in the history
* handled edge case with digestion product having a null parent

* Added more test cases

* Adjusted conditionals to get full coverage
  • Loading branch information
nbollis authored Feb 21, 2024
1 parent 4790e3e commit 90b177e
Showing 2 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mzLib/Omics/Digestion/DigestionProduct.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -28,9 +29,11 @@ protected DigestionProduct(IBioPolymer parent, int oneBasedStartResidue, int one
public int OneBasedStartResidue { get; }// the residue number at which the peptide begins (the first residue in a protein is 1)
public int OneBasedEndResidue { get; }// the residue number at which the peptide ends
public int MissedCleavages { get; } // the number of missed cleavages this peptide has with respect to the digesting protease
public virtual char PreviousResidue => OneBasedStartResidue > 1 ? Parent[OneBasedStartResidue - 2] : '-';

public virtual char NextResidue => OneBasedEndResidue < Parent.Length ? Parent[OneBasedEndResidue] : '-';
public virtual char PreviousResidue => Parent is null ? '-' : OneBasedStartResidue > 1 ? Parent[OneBasedStartResidue - 2] : '-';

public virtual char NextResidue => Parent is null ? '-' : OneBasedEndResidue < Parent.Length ? Parent[OneBasedEndResidue] : '-';

public string BaseSequence =>
_baseSequence ??= Parent.BaseSequence.Substring(OneBasedStartResidue - 1,
OneBasedEndResidue - OneBasedStartResidue + 1);
35 changes: 35 additions & 0 deletions mzLib/Test/TestPeptideWithSetMods.cs
Original file line number Diff line number Diff line change
@@ -1143,5 +1143,40 @@ public static void TestPeptideWithSetModsFullSequence()
var expectedFullStringsWithMassShifts = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "DatabaseTests", "fullSequencesWithMassShift.txt"));
CollectionAssert.AreEquivalent(expectedFullStringsWithMassShifts, allSequences.ToArray());
}

[Test]
public static void TestPeptideWithSetModsNoParentProtein()
{
// null parent
DigestionParams dParams = new DigestionParams();
var pwsm = new PeptideWithSetModifications("P", null,
digestionParams: dParams, p: null);
Assert.AreEqual('-', pwsm.PreviousAminoAcid);
Assert.AreEqual('-', pwsm.PreviousResidue);
Assert.AreEqual('-', pwsm.NextAminoAcid);
Assert.AreEqual('-', pwsm.NextResidue);

// non-null parent
Protein protein = new("MQLLRCFSIFSVIASVLAQELTTICEQIPSPTLESTPYSLSTTTILANGKAMQGVFEYYKSVTFVSNCGSHPSTTSKGSPINTQYVF", "P32781");
var pwsMods = protein.Digest(new DigestionParams(), new List<Modification>(), new List<Modification>()).ToList();

var first = pwsMods.First(p => p.BaseSequence == "MQLLRCFSIFSVIASVLAQELTTICEQIPSPTLESTPYSLSTTTILANGK");
Assert.AreEqual('-', first.PreviousAminoAcid);
Assert.AreEqual('-', first.PreviousResidue);
Assert.AreEqual('A', first.NextAminoAcid);
Assert.AreEqual('A', first.NextResidue);

var middle = pwsMods.First(p => p.BaseSequence == "SVTFVSNCGSHPSTTSK");
Assert.AreEqual('K', middle.PreviousAminoAcid);
Assert.AreEqual('K',middle.PreviousResidue);
Assert.AreEqual('G',middle.NextAminoAcid);
Assert.AreEqual('G',middle.NextResidue);

var last = pwsMods.First(p => p.BaseSequence == "GSPINTQYVF");
Assert.AreEqual('K', last.PreviousAminoAcid);
Assert.AreEqual('K', last.PreviousResidue);
Assert.AreEqual('-', last.NextAminoAcid);
Assert.AreEqual('-', last.NextResidue);
}
}
}

0 comments on commit 90b177e

Please sign in to comment.