Skip to content

Commit 528c2ac

Browse files
author
stefanks
authored
Merge pull request #187 from smith-chem-wisc/StefanBranch
hm
2 parents 9ff6ec0 + 50ff8ea commit 528c2ac

30 files changed

+454
-567
lines changed

InternalLogic/AnalysisEngine.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> ApplyPro
223223
foreach (var peptide in bestProteinPeptideList)
224224
{
225225
string peptideBaseSequence = string.Join("", peptide.BaseSequence.Select(b => char.ConvertFromUtf32(b)));
226-
226+
227227
usedPeptides.Add(peptide);
228228
usedBaseSequences.Add(peptideBaseSequence);
229229
}
@@ -389,7 +389,7 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
389389
// match the peptide base sequence to all of its PSMs
390390
foreach (var psm in psmList)
391391
{
392-
CompactPeptide peptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications);
392+
CompactPeptide peptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications, fixedModifications);
393393
string peptideBaseSequence = string.Join("", peptide.BaseSequence.Select(b => char.ConvertFromUtf32(b)));
394394
List<NewPsmWithFdr> psmListHere;
395395

@@ -443,7 +443,7 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
443443
{
444444
bestScoreSoFar = psm.thisPSM.Score;
445445
bestPsm = psm;
446-
bestPeptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications);
446+
bestPeptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications, fixedModifications);
447447
}
448448
}
449449
}
@@ -477,7 +477,7 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
477477
HashSet<CompactPeptide> newUniquePeptideList = new HashSet<CompactPeptide>();
478478
foreach (var psm in proteinGroup.BestPsmList)
479479
{
480-
CompactPeptide peptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications);
480+
CompactPeptide peptide = psm.thisPSM.newPsm.GetCompactPeptide(variableModifications, localizeableModifications, fixedModifications);
481481

482482
newPeptideList.Add(peptide);
483483

@@ -610,7 +610,7 @@ protected override MyResults RunSpecific()
610610
{
611611
var huh = newPsms[j][i];
612612
if (huh != null && huh.score >= 1)
613-
psmsWithProteinHashSet[i] = new PSMwithProteinHashSet(huh, compactPeptideToProteinPeptideMatching[huh.GetCompactPeptide(variableModifications, localizeableModifications)], fragmentTolerance, myMsDataFile, lp);
613+
psmsWithProteinHashSet[i] = new PSMwithProteinHashSet(huh, compactPeptideToProteinPeptideMatching[huh.GetCompactPeptide(variableModifications, localizeableModifications, fixedModifications)], fragmentTolerance, myMsDataFile, lp);
614614
}
615615

616616
var orderedPsmsWithPeptides = psmsWithProteinHashSet.Where(b => b != null).OrderByDescending(b => b.Score);
@@ -678,6 +678,14 @@ private static void IdentifyPsmsWithMaxMods(BinTreeStructure myTreeStructure)
678678
}
679679
}
680680

681+
private static void IdentifyFracWithSingle(BinTreeStructure myTreeStructure)
682+
{
683+
foreach (Bin bin in myTreeStructure.FinalBins)
684+
{
685+
bin.FracWithSingle = (double)bin.uniquePSMs.Values.Where(b => !b.Item3.IsDecoy && b.Item3.thisPSM.peptidesWithSetModifications.Count == 1).Count() / bin.uniquePSMs.Values.Where(b => !b.Item3.IsDecoy).Count();
686+
}
687+
}
688+
681689
private static void IdentifyAAsInCommon(BinTreeStructure myTreeStructure)
682690
{
683691
foreach (Bin bin in myTreeStructure.FinalBins)
@@ -966,7 +974,7 @@ private void AddObservedPeptidesToDictionary()
966974
{
967975
if (psm != null)
968976
{
969-
var cp = psm.GetCompactPeptide(variableModifications, localizeableModifications);
977+
var cp = psm.GetCompactPeptide(variableModifications, localizeableModifications, fixedModifications);
970978
if (!compactPeptideToProteinPeptideMatching.ContainsKey(cp))
971979
compactPeptideToProteinPeptideMatching.Add(cp, new HashSet<PeptideWithSetModifications>());
972980
}
@@ -995,13 +1003,11 @@ private void AddObservedPeptidesToDictionary()
9951003
if (peptide.Length == 1 || peptide.Length > byte.MaxValue - 2) // 2 is for indexing terminal modifications
9961004
continue;
9971005

998-
peptide.SetFixedModifications(fixedModifications);
999-
1000-
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maxModIsoforms, max_mods_for_peptide).ToList();
1006+
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maxModIsoforms, max_mods_for_peptide, fixedModifications).ToList();
10011007
foreach (var yyy in ListOfModifiedPeptides)
10021008
{
10031009
HashSet<PeptideWithSetModifications> v;
1004-
if (local.TryGetValue(new CompactPeptide(yyy, variableModifications, localizeableModifications), out v))
1010+
if (local.TryGetValue(new CompactPeptide(yyy, variableModifications, localizeableModifications, fixedModifications), out v))
10051011
{
10061012
v.Add(yyy);
10071013
}

InternalLogic/Bin.cs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public int LocalizeableTarget
7373
public Dictionary<char, int> AAsInCommon { get; internal set; }
7474
public double FracWithMaxMods { get; internal set; }
7575
public int Overlapping { get; internal set; }
76+
public double FracWithSingle { get; set; }
7677

7778
#endregion Public Properties
7879

InternalLogic/ClassicSearchEngine.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ protected override MyResults RunSpecific()
115115
}
116116
}
117117

118-
peptide.SetFixedModifications(fixedModifications);
119-
120-
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maximumVariableModificationIsoforms, max_mods_for_peptide).ToList();
118+
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maximumVariableModificationIsoforms, max_mods_for_peptide, fixedModifications).ToList();
121119
foreach (var yyy in ListOfModifiedPeptides)
122120
{
123121
if (peptide.OneBasedPossibleLocalizedModifications.Count > 0)
@@ -182,15 +180,7 @@ protected override MyResults RunSpecific()
182180
#endregion Protected Methods
183181

184182
#region Private Methods
185-
186-
private bool ModificationMassDiffMatch(PeptideWithSetModifications yyy, LocalMS2Scan scan, double tolForModificationMassDiffMatch)
187-
{
188-
foreach (var kvp in yyy.twoBasedVariableAndLocalizeableModificationss)
189-
if (Math.Abs(yyy.MonoisotopicMass - kvp.Value.MonoisotopicMassShift - scan.PrecursorMass) < tolForModificationMassDiffMatch)
190-
return true;
191-
return false;
192-
}
193-
183+
194184
private IEnumerable<LocalMS2Scan> GetAcceptableScans(double peptideMonoisotopicMass, SearchMode searchMode)
195185
{
196186
foreach (DoubleRange ye in searchMode.GetAllowedPrecursorMassIntervals(peptideMonoisotopicMass).ToList())

InternalLogic/ClassicSpectrumMatch.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ClassicSpectrumMatch : ParentSpectrumMatch
1515

1616
#region Private Fields
1717

18+
private const double tolInDaForPreferringHavingMods = 0.03;
1819
private CompactPeptide compactPeptide;
1920

2021
#endregion Private Fields
@@ -30,10 +31,10 @@ public ClassicSpectrumMatch(PeptideWithSetModifications ps, string fileName, dou
3031

3132
#region Public Methods
3233

33-
public override CompactPeptide GetCompactPeptide(List<MorpheusModification> variableModifications, List<MorpheusModification> localizeableModifications)
34+
public override CompactPeptide GetCompactPeptide(List<MorpheusModification> variableModifications, List<MorpheusModification> localizeableModifications, List<MorpheusModification> fixedModifications)
3435
{
3536
if (compactPeptide == null)
36-
compactPeptide = new CompactPeptide(ps, variableModifications, localizeableModifications);
37+
compactPeptide = new CompactPeptide(ps, variableModifications, localizeableModifications, fixedModifications);
3738
return compactPeptide;
3839
}
3940

@@ -62,9 +63,9 @@ internal static bool FirstIsPreferable(ClassicSpectrumMatch psm, ClassicSpectrum
6263

6364
private static bool FirstIsPreferableWithoutScore(PeptideWithSetModifications first, PeptideWithSetModifications second, double pm)
6465
{
65-
if (Math.Abs(first.MonoisotopicMass - pm) < 0.5 && Math.Abs(second.MonoisotopicMass - pm) > 0.5)
66+
if (Math.Abs(first.MonoisotopicMass - pm) < tolInDaForPreferringHavingMods && Math.Abs(second.MonoisotopicMass - pm) > tolInDaForPreferringHavingMods)
6667
return true;
67-
if (Math.Abs(first.MonoisotopicMass - pm) > 0.5 && Math.Abs(second.MonoisotopicMass - pm) < 0.5)
68+
if (Math.Abs(first.MonoisotopicMass - pm) > tolInDaForPreferringHavingMods && Math.Abs(second.MonoisotopicMass - pm) < tolInDaForPreferringHavingMods)
6869
return false;
6970

7071
if (first.NumVariableMods < second.NumVariableMods)

InternalLogic/CompactPeptide.cs

+30-6
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ public class CompactPeptide
1818
public readonly byte varMod2Loc;
1919
public readonly ushort varMod3Type;
2020
public readonly byte varMod3Loc;
21-
public float MonoisotopicMass;
21+
public float MonoisotopicMassIncludingFixedMods;
2222

2323
#endregion Public Fields
2424

2525
#region Public Constructors
2626

27-
public CompactPeptide(PeptideWithSetModifications yyy, List<MorpheusModification> variableModifications, List<MorpheusModification> localizeableModifications)
27+
public CompactPeptide(PeptideWithSetModifications yyy, List<MorpheusModification> variableModifications, List<MorpheusModification> localizeableModifications, List<MorpheusModification> fixedModifications)
2828
{
2929
varMod1Type = 0;
3030
varMod1Loc = 0;
3131
varMod2Type = 0;
3232
varMod2Loc = 0;
3333
varMod3Type = 0;
3434
varMod3Loc = 0;
35-
foreach (var kvpp in yyy.twoBasedVariableAndLocalizeableModificationss)
35+
foreach (var kvpp in yyy.allModsOneIsNterminus)
3636
{
3737
int twoBasedLoc = kvpp.Key;
3838
var mod = kvpp.Value;
@@ -41,28 +41,52 @@ public CompactPeptide(PeptideWithSetModifications yyy, List<MorpheusModification
4141
{
4242
// Set first
4343
if (variableModifications.Contains(mod))
44+
{
4445
varMod1Type = (ushort)(variableModifications.IndexOf(mod) + 1);
46+
varMod1Loc = (byte)twoBasedLoc;
47+
}
48+
else if (fixedModifications.Contains(mod))
49+
{
50+
}
4551
else
52+
{
4653
varMod1Type = (ushort)(32767 + localizeableModifications.IndexOf(mod) + 1);
47-
varMod1Loc = (byte)twoBasedLoc;
54+
varMod1Loc = (byte)twoBasedLoc;
55+
}
4856
}
4957
else if (varMod2Type == 0)
5058
{
5159
// Set second
5260
if (variableModifications.Contains(mod))
61+
{
5362
varMod2Type = (ushort)(variableModifications.IndexOf(mod) + 1);
63+
varMod2Loc = (byte)twoBasedLoc;
64+
}
65+
else if (fixedModifications.Contains(mod))
66+
{
67+
}
5468
else
69+
{
5570
varMod2Type = (ushort)(32767 + localizeableModifications.IndexOf(mod) + 1);
56-
varMod2Loc = (byte)twoBasedLoc;
71+
varMod2Loc = (byte)twoBasedLoc;
72+
}
5773
}
5874
else
5975
{
6076
// Set third
6177
if (variableModifications.Contains(mod))
78+
{
6279
varMod3Type = (ushort)(variableModifications.IndexOf(mod) + 1);
80+
varMod3Loc = (byte)twoBasedLoc;
81+
}
82+
else if (fixedModifications.Contains(mod))
83+
{
84+
}
6385
else
86+
{
6487
varMod3Type = (ushort)(32767 + localizeableModifications.IndexOf(mod) + 1);
65-
varMod3Loc = (byte)twoBasedLoc;
88+
varMod3Loc = (byte)twoBasedLoc;
89+
}
6690
}
6791
}
6892

InternalLogic/GPTMDEngine.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public GptmdEngine(List<NewPsmWithFdr> allResultingIdentifications, bool isotope
3535

3636
protected override MyResults RunSpecific()
3737
{
38-
var Mods = new Dictionary<string, HashSet<Tuple<int, string>>>();
38+
var Mods = new Dictionary<string, HashSet<Tuple<int, string, string>>>();
3939

4040
int modsAdded = 0;
4141
foreach (var ye in allResultingIdentifications.Where(b => b.qValue <= 0.01 && !b.IsDecoy))
@@ -58,8 +58,8 @@ protected override MyResults RunSpecific()
5858
if (ModFits(mod, baseSequence[i], i > 0 ? baseSequence[i - 1] : peptide.PreviousAminoAcid, i + 1, baseSequence.Length, indexInProtein, proteinLength))
5959
{
6060
if (!Mods.ContainsKey(proteinAcession))
61-
Mods[proteinAcession] = new HashSet<Tuple<int, string>>();
62-
var theTuple = new Tuple<int, string>(indexInProtein, mod.NameInXml);
61+
Mods[proteinAcession] = new HashSet<Tuple<int, string, string>>();
62+
var theTuple = new Tuple<int, string, string>(indexInProtein, mod.NameInXml, mod.Database);
6363
if (!Mods[proteinAcession].Contains(theTuple))
6464
{
6565
Mods[proteinAcession].Add(theTuple);
@@ -99,13 +99,9 @@ private static IEnumerable<MorpheusModification> GetMod(double massDiff, bool is
9999
{
100100
foreach (var Mod in allMods)
101101
{
102-
if (Mod.MonoisotopicMassShift > massDiff - tolInDaltons && Mod.MonoisotopicMassShift < massDiff + tolInDaltons)
102+
if (Mod.ObservedMassShift > massDiff - tolInDaltons && Mod.ObservedMassShift < massDiff + tolInDaltons)
103103
yield return Mod;
104-
if (isotopeErrors && Mod.MonoisotopicMassShift > massDiff - tolInDaltons - 1.003 && Mod.MonoisotopicMassShift < massDiff + tolInDaltons - 1.003)
105-
yield return Mod;
106-
if (!double.IsNaN(Mod.AlternativeMassShift) && Mod.AlternativeMassShift > massDiff - tolInDaltons && Mod.AlternativeMassShift < massDiff + tolInDaltons)
107-
yield return Mod;
108-
if (!double.IsNaN(Mod.AlternativeMassShift) && isotopeErrors && Mod.AlternativeMassShift > massDiff - tolInDaltons - 1.003 && Mod.AlternativeMassShift < massDiff + tolInDaltons - 1.003)
104+
if (isotopeErrors && Mod.ObservedMassShift > massDiff - tolInDaltons - 1.003 && Mod.ObservedMassShift < massDiff + tolInDaltons - 1.003)
109105
yield return Mod;
110106
}
111107

InternalLogic/GPTMDResults.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GptmdResults : MyResults
1515

1616
#region Public Constructors
1717

18-
public GptmdResults(MyEngine s, Dictionary<string, HashSet<Tuple<int, string>>> mods, int modsAdded) : base(s)
18+
public GptmdResults(MyEngine s, Dictionary<string, HashSet<Tuple<int, string, string>>> mods, int modsAdded) : base(s)
1919
{
2020
this.Mods = mods;
2121
this.modsAdded = modsAdded;
@@ -25,7 +25,7 @@ public GptmdResults(MyEngine s, Dictionary<string, HashSet<Tuple<int, string>>>
2525

2626
#region Public Properties
2727

28-
public Dictionary<string, HashSet<Tuple<int, string>>> Mods { get; private set; }
28+
public Dictionary<string, HashSet<Tuple<int, string, string>>> Mods { get; private set; }
2929

3030
#endregion Public Properties
3131

InternalLogic/IndexEngine.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override string ToString()
6161
sb.AppendLine("initiatorMethionineBehavior: " + initiatorMethionineBehavior);
6262
sb.AppendLine("maximumMissedCleavages: " + maximumMissedCleavages);
6363
sb.AppendLine("maximumVariableModificationIsoforms: " + maximumVariableModificationIsoforms);
64-
sb.Append("Localizeable mods: " + proteinList.Select(b=>b.OneBasedPossibleLocalizedModifications.Count).Sum());
64+
sb.Append("Localizeable mods: " + proteinList.Select(b => b.OneBasedPossibleLocalizedModifications.Count).Sum());
6565
return sb.ToString();
6666
}
6767

@@ -102,9 +102,7 @@ protected override MyResults RunSpecific()
102102
}
103103
}
104104

105-
peptide.SetFixedModifications(fixedModifications);
106-
107-
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maximumVariableModificationIsoforms, max_mods_for_peptide).ToList();
105+
var ListOfModifiedPeptides = peptide.GetPeptideWithSetModifications(variableModifications, maximumVariableModificationIsoforms, max_mods_for_peptide, fixedModifications).ToList();
108106
foreach (var yyy in ListOfModifiedPeptides)
109107
{
110108
if (peptide.OneBasedPossibleLocalizedModifications.Count > 0)
@@ -119,7 +117,7 @@ protected override MyResults RunSpecific()
119117
}
120118
}
121119

122-
var ps = new CompactPeptide(yyy, variableModifications, localizeableModifications);
120+
var ps = new CompactPeptide(yyy, variableModifications, localizeableModifications, fixedModifications);
123121

124122
int index;
125123
lock (myDictionary)
@@ -139,7 +137,7 @@ protected override MyResults RunSpecific()
139137
else
140138
myInnerDictionary.Add(rounded, new List<int> { index });
141139
}
142-
ps.MonoisotopicMass = (float)yyy.MonoisotopicMass;
140+
ps.MonoisotopicMassIncludingFixedMods = (float)yyy.MonoisotopicMass;
143141
}
144142
}
145143
}

0 commit comments

Comments
 (0)