Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pwsm target decoy #769

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class PeptideWithSetModifications : ProteolyticPeptide, IBioPolymerWithSe
{
public string FullSequence { get; private set; } //sequence with modifications
public int NumFixedMods { get; }
// Parameter to store a hash code corresponding to a Decoy or a Target peptide
// Parameter to store the full sequence of the corresponding Target or Decoy peptide
// If the peptide in question is a decoy, this pairs it to the target it was generated from
// If the peptide in question is a target, this pairs it to its corresponding decoy
public int? PairedTargetDecoyHash { get; private set; }
public string PairedTargetDecoySequence { get; private set; }
/// <summary>
/// Dictionary of modifications on the peptide. The N terminus is index 1.
/// The key indicates which residue modification is on (with 1 being N terminus).
Expand All @@ -40,7 +40,7 @@ public class PeptideWithSetModifications : ProteolyticPeptide, IBioPolymerWithSe
/// </summary>
public PeptideWithSetModifications(Protein protein, IDigestionParams digestionParams, int oneBasedStartResidueInProtein,
int oneBasedEndResidueInProtein, CleavageSpecificity cleavageSpecificity, string peptideDescription, int missedCleavages,
Dictionary<int, Modification> allModsOneIsNterminus, int numFixedMods, string baseSequence = null, int? pairedTargetDecoyHash = null)
Dictionary<int, Modification> allModsOneIsNterminus, int numFixedMods, string baseSequence = null, string pairedTargetDecoySequence = null)
: base(protein, oneBasedStartResidueInProtein, oneBasedEndResidueInProtein, missedCleavages, cleavageSpecificity, peptideDescription, baseSequence)
{
_allModsOneIsNterminus = allModsOneIsNterminus;
Expand All @@ -49,7 +49,7 @@ public PeptideWithSetModifications(Protein protein, IDigestionParams digestionPa
FullSequence = this.DetermineFullSequence();
ProteinAccession = protein.Accession;
UpdateCleavageSpecificity();
PairedTargetDecoyHash = pairedTargetDecoyHash; // Added PairedTargetDecoyHash as a nullable integer
PairedTargetDecoySequence = pairedTargetDecoySequence;
}

/// <summary>
Expand All @@ -59,7 +59,7 @@ public PeptideWithSetModifications(Protein protein, IDigestionParams digestionPa
public PeptideWithSetModifications(string sequence, Dictionary<string, Modification> allKnownMods, int numFixedMods = 0,
IDigestionParams digestionParams = null, Protein p = null, int oneBasedStartResidueInProtein = int.MinValue,
int oneBasedEndResidueInProtein = int.MinValue, int missedCleavages = int.MinValue,
CleavageSpecificity cleavageSpecificity = CleavageSpecificity.Full, string peptideDescription = null, int? pairedTargetDecoyHash = null)
CleavageSpecificity cleavageSpecificity = CleavageSpecificity.Full, string peptideDescription = null, string pairedTargetDecoySequence = null)
: base(p, oneBasedStartResidueInProtein, oneBasedEndResidueInProtein, missedCleavages, cleavageSpecificity, peptideDescription)
{
if (sequence.Contains("|"))
Expand All @@ -72,7 +72,7 @@ public PeptideWithSetModifications(string sequence, Dictionary<string, Modificat
GetModsAfterDeserialization(allKnownMods);
NumFixedMods = numFixedMods;
_digestionParams = digestionParams as DigestionParams;
PairedTargetDecoyHash = pairedTargetDecoyHash; // Added PairedTargetDecoyHash as a nullable integer
PairedTargetDecoySequence = pairedTargetDecoySequence;

if (p != null)
{
Expand Down Expand Up @@ -902,14 +902,7 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
if (DigestionParams == null)
{
return FullSequence.GetHashCode();
}
else
{
return FullSequence.GetHashCode() + DigestionParams.DigestionAgent.GetHashCode();
}
return FullSequence.GetHashCode();
}

/// <summary>
Expand Down Expand Up @@ -1140,27 +1133,25 @@ public PeptideWithSetModifications GetReverseDecoyFromTarget(int[] revisedAminoA
Protein decoyProtein = new Protein(proteinSequence, "DECOY_" + this.Protein.Accession, null, new List<Tuple<string, string>>(), new Dictionary<int, List<Modification>>(), null, null, null, true);
DigestionParams d = _digestionParams;

// Creates a hash code corresponding to the target's sequence
int targetHash = GetHashCode();
PeptideWithSetModifications decoyPeptide;
//Make the "peptideDescription" store the corresponding target's sequence
if (newBaseString != this.BaseSequence)
{
decoyPeptide = new PeptideWithSetModifications(decoyProtein, d, this.OneBasedStartResidueInProtein, this.OneBasedEndResidueInProtein, this.CleavageSpecificityForFdrCategory, this.FullSequence, this.MissedCleavages, newModificationsDictionary, this.NumFixedMods, newBaseString);
// Sets PairedTargetDecoyHash of the original target peptie to the hash hode of the decoy sequence
PairedTargetDecoyHash = decoyPeptide.GetHashCode();
PairedTargetDecoySequence = decoyPeptide.FullSequence;
// Sets PairedTargetDecoyHash of the decoy peptide to the hash code of the target sequence
decoyPeptide.PairedTargetDecoyHash = targetHash;
decoyPeptide.PairedTargetDecoySequence = this.FullSequence;
return decoyPeptide;

}
else
{
//The reverse decoy procedure failed to create a PeptideWithSetModificatons with a different sequence. Therefore,
//we retrun the mirror image peptide.
decoyPeptide = this.GetPeptideMirror(revisedAminoAcidOrder);
PairedTargetDecoyHash = decoyPeptide.GetHashCode();
decoyPeptide.PairedTargetDecoyHash = targetHash;
decoyPeptide = this.GetPeptideMirror(revisedAminoAcidOrder);
PairedTargetDecoySequence = decoyPeptide.FullSequence;
decoyPeptide.PairedTargetDecoySequence = this.FullSequence;
return decoyPeptide;
}

Expand Down Expand Up @@ -1318,17 +1309,15 @@ public PeptideWithSetModifications GetScrambledDecoyFromTarget(int[] revisedAmin

Protein decoyProtein = new Protein(proteinSequence, "DECOY_" + this.Protein.Accession, null, new List<Tuple<string, string>>(), new Dictionary<int, List<Modification>>(), null, null, null, true);
DigestionParams d = _digestionParams;
// Creates a hash code corresponding to the target's sequence
int targetHash = GetHashCode();
PeptideWithSetModifications decoyPeptide;
//Make the "peptideDescription" store the corresponding target's sequence
if (newBaseString != this.BaseSequence)
{
decoyPeptide = new PeptideWithSetModifications(decoyProtein, d, this.OneBasedStartResidueInProtein, this.OneBasedEndResidueInProtein, this.CleavageSpecificityForFdrCategory, this.FullSequence, this.MissedCleavages, newModificationsDictionary, this.NumFixedMods, newBaseString);
// Sets PairedTargetDecoyHash of the original target peptie to the hash hode of the decoy sequence
PairedTargetDecoyHash = decoyPeptide.GetHashCode();
PairedTargetDecoySequence = decoyPeptide.FullSequence;
// Sets PairedTargetDecoyHash of the decoy peptide to the hash code of the target sequence
decoyPeptide.PairedTargetDecoyHash = targetHash;
decoyPeptide.PairedTargetDecoySequence = this.FullSequence;
return decoyPeptide;

}
Expand All @@ -1337,8 +1326,8 @@ public PeptideWithSetModifications GetScrambledDecoyFromTarget(int[] revisedAmin
//The reverse decoy procedure failed to create a PeptideWithSetModificatons with a different sequence. Therefore,
//we retrun the mirror image peptide.
decoyPeptide = this.GetPeptideMirror(revisedAminoAcidOrder);
PairedTargetDecoyHash = decoyPeptide.GetHashCode();
decoyPeptide.PairedTargetDecoyHash = targetHash;
PairedTargetDecoySequence = decoyPeptide.FullSequence;
decoyPeptide.PairedTargetDecoySequence = this.FullSequence;
return decoyPeptide;
}
}
Expand Down
15 changes: 8 additions & 7 deletions mzLib/Test/TestPeptideWithSetMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static void TestDifferentProteaseEquals()
Assert.That(pep1.Parent.Equals(pep2.Parent));
Assert.That(!pep1.DigestionParams.DigestionAgent.Equals(pep2.DigestionParams.DigestionAgent));
Assert.That(!pep1.Equals(pep2));
Assert.That(!pep1.GetHashCode().Equals(pep2.GetHashCode()));
// HashCode is only concerned with the full sequence, not the protease. Only the equals method is interested in the protease used
Assert.That(pep1.GetHashCode().Equals(pep2.GetHashCode()));
}

[Test]
Expand Down Expand Up @@ -765,8 +766,8 @@ public static void TestReverseDecoyFromTarget()
int testTargetHash = p.GetHashCode();
// Hash code corresponding to the decoy sequence, should be PairedTargetDecoyHash for target
int testDecoyHash = reverse.GetHashCode();
Assert.AreEqual(reverse.PairedTargetDecoyHash, testTargetHash);
Assert.AreEqual(p.PairedTargetDecoyHash, testDecoyHash);
Assert.AreEqual(reverse.PairedTargetDecoySequence.GetHashCode(), testTargetHash);
Assert.AreEqual(p.PairedTargetDecoySequence.GetHashCode(), testDecoyHash);
Assert.AreEqual("EDITPEPK", reverse.BaseSequence);
Assert.AreEqual(new int[] { 6, 5, 4, 3, 2, 1, 0, 7 }, newAminoAcidPositions);
Assert.IsTrue(reverse.Protein.IsDecoy);
Expand Down Expand Up @@ -841,8 +842,8 @@ public static void TestReverseDecoyFromTarget()
int testMirrorTargetHash = p_tryp.GetHashCode();
// Hash code corresponding to the decoy sequence, should be PairedTargetDecoyHash for target
int testMirrorDecoyHash = p_tryp_reverse.GetHashCode();
Assert.AreEqual(testMirrorTargetHash, p_tryp_reverse.PairedTargetDecoyHash);
Assert.AreEqual(testMirrorDecoyHash, p_tryp.PairedTargetDecoyHash);
Assert.AreEqual(testMirrorTargetHash, p_tryp_reverse.PairedTargetDecoySequence.GetHashCode());
Assert.AreEqual(testMirrorDecoyHash, p_tryp.PairedTargetDecoySequence.GetHashCode());
Assert.AreEqual("RVTRITV", p_tryp_reverse.BaseSequence);
Assert.AreEqual(new int[] { 6, 5, 4, 3, 2, 1, 0 }, newAminoAcidPositions);
Assert.IsTrue(p_tryp_reverse.AllModsOneIsNterminus.ContainsKey(1));//n-term acetyl
Expand Down Expand Up @@ -871,8 +872,8 @@ public static void TestScrambledDecoyFromTarget()
int testTargetHash = p.GetHashCode();
// Hash code corresponding to the decoy sequence, should be PairedTargetDecoyHash for target
int testDecoyHash = testScrambled.GetHashCode();
Assert.AreEqual(testScrambled.PairedTargetDecoyHash, testTargetHash);
Assert.AreEqual(p.PairedTargetDecoyHash, testDecoyHash);
Assert.AreEqual(testScrambled.PairedTargetDecoySequence.GetHashCode(), testTargetHash);
Assert.AreEqual(p.PairedTargetDecoySequence.GetHashCode(), testDecoyHash);
Assert.AreEqual("IDEETPPK", testScrambled.BaseSequence);
Assert.AreEqual(new int[] { 4, 5, 6, 1, 3, 0, 2, 7 }, newAminoAcidPositions);
// Check n-term acetyl
Expand Down
2 changes: 1 addition & 1 deletion mzLib/mzLib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>mzLib</id>
<version>1.0.547</version>
<version>5.0.547.1</version>
<title>mzLib</title>
<authors>Stef S.</authors>
<owners>Stef S.</owners>
Expand Down
Loading