Skip to content

Commit 43b1938

Browse files
author
stefanks
authored
Merge pull request #180 from smith-chem-wisc/StefanBranch
Stefan branch
2 parents 31d1763 + 898b7ca commit 43b1938

File tree

14 files changed

+163
-119
lines changed

14 files changed

+163
-119
lines changed

InternalLogic/AnalysisEngine.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class AnalysisEngine : MyEngine
1616

1717
#region Private Fields
1818

19-
private const double binTol = 0.003;
2019
private const double comboThresholdMultiplier = 3;
2120
private const int max_mods_for_peptide = 3;
21+
private readonly double binTol;
2222
private readonly int maximumMissedCleavages;
2323
private readonly int maxModIsoforms;
2424
private readonly ParentSpectrumMatch[][] newPsms;
@@ -42,7 +42,7 @@ public class AnalysisEngine : MyEngine
4242

4343
#region Public Constructors
4444

45-
public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> compactPeptideToProteinPeptideMatching, List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, List<SearchMode> searchModes, IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, Tolerance fragmentTolerance, Action<BinTreeStructure, string> action1, Action<List<NewPsmWithFdr>, string> action2, Action<List<ProteinGroup>, string> action3, bool doParsimony, int maximumMissedCleavages, int maxModIsoforms, bool doHistogramAnalysis, List<ProductType> lp) : base(2)
45+
public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> compactPeptideToProteinPeptideMatching, List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, List<SearchMode> searchModes, IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, Tolerance fragmentTolerance, Action<BinTreeStructure, string> action1, Action<List<NewPsmWithFdr>, string> action2, Action<List<ProteinGroup>, string> action3, bool doParsimony, int maximumMissedCleavages, int maxModIsoforms, bool doHistogramAnalysis, List<ProductType> lp, double binTol) : base(2)
4646
{
4747
this.doParsimony = doParsimony;
4848
this.doHistogramAnalysis = doHistogramAnalysis;
@@ -62,6 +62,7 @@ public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide
6262
this.maximumMissedCleavages = maximumMissedCleavages;
6363
this.maxModIsoforms = maxModIsoforms;
6464
this.lp = lp;
65+
this.binTol = binTol;
6566
}
6667

6768
#endregion Public Constructors
@@ -568,7 +569,6 @@ protected override MyResults RunSpecific()
568569
//At this point have Spectrum-Sequence matching, without knowing which protein, and without know if target/decoy
569570
Status("Adding observed peptides to dictionary...");
570571
AddObservedPeptidesToDictionary();
571-
572572
List<ProteinGroup> proteinGroups = null;
573573
if (doParsimony)
574574
{
@@ -605,7 +605,7 @@ protected override MyResults RunSpecific()
605605
if (limitedpsms_with_fdr.Any(b => !b.IsDecoy))
606606
{
607607
Status("Running histogram analysis...");
608-
var hm = MyAnalysis(limitedpsms_with_fdr);
608+
var hm = MyAnalysis(limitedpsms_with_fdr, binTol);
609609
writeHistogramPeaksAction(hm, searchModes[j].FileNameAddition);
610610
}
611611
}
@@ -856,7 +856,7 @@ private static void IdentifyMine(BinTreeStructure myTreeStructure, double v)
856856
}
857857
}
858858

859-
private static BinTreeStructure MyAnalysis(List<NewPsmWithFdr> limitedpsms_with_fdr)
859+
private static BinTreeStructure MyAnalysis(List<NewPsmWithFdr> limitedpsms_with_fdr, double binTol)
860860
{
861861
var myTreeStructure = new BinTreeStructure();
862862
myTreeStructure.GenerateBins(limitedpsms_with_fdr, binTol);

InternalLogic/BinTreeStructure.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BinTreeStructure
99

1010
#region Private Fields
1111

12-
private const int minNumberInBin = 2;
12+
private const int minAdditionalPsmsInBin = 1;
1313

1414
#endregion Private Fields
1515

@@ -67,7 +67,7 @@ internal void GenerateBins(List<NewPsmWithFdr> targetAndDecoyMatches, double dc)
6767
var prelimBins = new HashSet<double>();
6868
foreach (OkBin okbin in listokbin.OrderByDescending(b => b.p))
6969
{
70-
if (okbin.sigma < dc || okbin.p < minNumberInBin)
70+
if (okbin.sigma < dc || okbin.p < minAdditionalPsmsInBin)
7171
continue;
7272
bool add = true;
7373
foreach (double a in prelimBins)

InternalLogic/ClassicSearchEngine.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class ClassicSearchEngine : MyEngine
1414
#region Private Fields
1515

1616
private const int max_mods_for_peptide = 3;
17+
18+
private const double tolForModificationMassDiffMatch = 0.003;
1719
private readonly int maximumMissedCleavages;
1820
private readonly int maximumVariableModificationIsoforms;
1921
private readonly List<SearchMode> searchModes;
@@ -141,15 +143,18 @@ protected override MyResults RunSpecific()
141143
var searchMode = searchModes[aede];
142144
foreach (LocalMS2Scan scan in GetAcceptableScans(yyy.MonoisotopicMass, searchMode).ToList())
143145
{
144-
var score = PSMwithProteinHashSet.MatchIons(scan.TheScan, productMassTolerance, sortedProductMasses, matchedIonsArray);
145-
var psm = new ClassicSpectrumMatch(yyy, fileName, scan.RetentionTime, scan.MonoisotopicPrecursorIntensity, scan.PrecursorMass, scan.OneBasedScanNumber, scan.MonoisotopicPrecursorCharge, scan.NumPeaks, scan.TotalIonCurrent, scan.MonoisotopicPrecursorMZ, score);
146-
if (psm.score > 1)
146+
if (!ModificationMassDiffMatch(yyy, scan, tolForModificationMassDiffMatch))
147147
{
148-
ClassicSpectrumMatch current_best_psm = psms[aede][scan.OneBasedScanNumber - 1];
149-
if (current_best_psm == null || ClassicSpectrumMatch.FirstIsPreferable(psm, current_best_psm))
148+
var score = PSMwithProteinHashSet.MatchIons(scan.TheScan, productMassTolerance, sortedProductMasses, matchedIonsArray);
149+
var psm = new ClassicSpectrumMatch(yyy, fileName, scan.RetentionTime, scan.MonoisotopicPrecursorIntensity, scan.PrecursorMass, scan.OneBasedScanNumber, scan.MonoisotopicPrecursorCharge, scan.NumPeaks, scan.TotalIonCurrent, scan.MonoisotopicPrecursorMZ, score);
150+
if (psm.score > 1)
150151
{
151-
psms[aede][scan.OneBasedScanNumber - 1] = psm;
152-
matchedIonsArray = new double[sortedProductMasses.Length];
152+
ClassicSpectrumMatch current_best_psm = psms[aede][scan.OneBasedScanNumber - 1];
153+
if (current_best_psm == null || ClassicSpectrumMatch.FirstIsPreferable(psm, current_best_psm))
154+
{
155+
psms[aede][scan.OneBasedScanNumber - 1] = psm;
156+
matchedIonsArray = new double[sortedProductMasses.Length];
157+
}
153158
}
154159
}
155160
}
@@ -181,6 +186,14 @@ protected override MyResults RunSpecific()
181186

182187
#region Private Methods
183188

189+
private bool ModificationMassDiffMatch(PeptideWithSetModifications yyy, LocalMS2Scan scan, double tolForModificationMassDiffMatch)
190+
{
191+
foreach (var kvp in yyy.twoBasedVariableAndLocalizeableModificationss)
192+
if (Math.Abs(yyy.MonoisotopicMass - kvp.Value.MonoisotopicMassShift - scan.PrecursorMass) < tolForModificationMassDiffMatch)
193+
return true;
194+
return false;
195+
}
196+
184197
private IEnumerable<LocalMS2Scan> GetAcceptableScans(double peptideMonoisotopicMass, SearchMode searchMode)
185198
{
186199
foreach (DoubleRange ye in searchMode.GetAllowedPrecursorMassIntervals(peptideMonoisotopicMass).ToList())

InternalLogic/IndexEngine.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ public override string ToString()
5555
sb.AppendLine("Number of proteins: " + proteinList.Count);
5656
sb.AppendLine("Number of fixed mods: " + fixedModifications.Count);
5757
sb.AppendLine("Number of variable mods: " + variableModifications.Count);
58-
sb.AppendLine("Number of localizeable mods: " + localizeableModifications.Count);
58+
sb.AppendLine("Number of localizeable mods known: " + localizeableModifications.Count);
5959
sb.AppendLine("lp: " + string.Join(",", lp));
60-
sb.Append("protease: " + protease);
60+
sb.AppendLine("protease: " + protease);
61+
sb.AppendLine("initiatorMethionineBehavior: " + initiatorMethionineBehavior);
62+
sb.AppendLine("maximumMissedCleavages: " + maximumMissedCleavages);
63+
sb.AppendLine("maximumVariableModificationIsoforms: " + maximumVariableModificationIsoforms);
64+
sb.Append("Localizeable mods: " + proteinList.Select(b=>b.OneBasedPossibleLocalizedModifications.Count).Sum());
6165
return sb.ToString();
6266
}
6367

InternalLogic/ModernSearchEngine.cs

+80-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Chemistry;
22
using MassSpectrometry;
3+
using OldInternalLogic;
34
using Spectra;
45
using System;
56
using System.Collections.Concurrent;
@@ -26,18 +27,25 @@ public class ModernSearchEngine : MyEngine
2627

2728
private readonly List<SearchMode> searchModes;
2829

30+
private readonly List<MorpheusModification> variableModifications;
31+
private readonly List<MorpheusModification> localizeableModifications;
32+
33+
private const double tolForModificationMassDiffMatch = 0.003;
34+
2935
#endregion Private Fields
3036

3137
#region Public Constructors
3238

33-
public ModernSearchEngine(IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, List<CompactPeptide> peptideIndex, float[] keys, List<int>[] fragmentIndex, double fragmentToleranceInDaltons, List<SearchMode> searchModes) : base(2)
39+
public ModernSearchEngine(IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, List<CompactPeptide> peptideIndex, float[] keys, List<int>[] fragmentIndex, double fragmentToleranceInDaltons, List<SearchMode> searchModes, List<MorpheusModification> variableModifications, List<MorpheusModification> localizeableModifications) : base(2)
3440
{
3541
this.myMSDataFile = myMSDataFile;
3642
this.peptideIndex = peptideIndex;
3743
this.keys = keys;
3844
this.fragmentIndex = fragmentIndex;
3945
this.fragmentToleranceInDaltons = fragmentToleranceInDaltons;
4046
this.searchModes = searchModes;
47+
this.variableModifications = variableModifications;
48+
this.localizeableModifications = localizeableModifications;
4149
}
4250

4351
#endregion Public Constructors
@@ -79,40 +87,41 @@ protected override MyResults RunSpecific()
7987
{
8088
var consideredScore = fullPeptideScores[possibleWinningPeptideIndex];
8189
CompactPeptide candidatePeptide = peptideIndex[possibleWinningPeptideIndex];
82-
for (int j = 0; j < searchModesCount; j++)
83-
{
84-
// Check if makes sense to add due to peptidescore!
85-
var searchMode = searchModes[j];
86-
double currentBestScore = bestScores[j];
87-
if (currentBestScore > 1)
90+
if (!MatchModificationsMassShift(candidatePeptide, thisScanprecursorMass))
91+
for (int j = 0; j < searchModesCount; j++)
8892
{
89-
// Existed! Need to compare with old match
90-
if (Math.Abs(currentBestScore - consideredScore) < 1e-9)
93+
// Check if makes sense to add due to peptidescore!
94+
var searchMode = searchModes[j];
95+
double currentBestScore = bestScores[j];
96+
if (currentBestScore > 1)
9197
{
92-
// Score is same, need to see if accepts and if prefer the new one
93-
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass) && FirstIsPreferableWithoutScore(candidatePeptide, bestPeptides[j], thisScanprecursorMass))
98+
// Existed! Need to compare with old match
99+
if (Math.Abs(currentBestScore - consideredScore) < 1e-9)
94100
{
95-
bestPeptides[j] = candidatePeptide;
96-
bestScores[j] = consideredScore;
101+
// Score is same, need to see if accepts and if prefer the new one
102+
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass) && FirstIsPreferableWithoutScore(candidatePeptide, bestPeptides[j], thisScanprecursorMass))
103+
{
104+
bestPeptides[j] = candidatePeptide;
105+
bestScores[j] = consideredScore;
106+
}
97107
}
98-
}
99-
else if (currentBestScore < consideredScore)
100-
{
101-
// Score is better, only make sure it is acceptable
102-
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
108+
else if (currentBestScore < consideredScore)
103109
{
104-
bestPeptides[j] = candidatePeptide;
105-
bestScores[j] = consideredScore;
110+
// Score is better, only make sure it is acceptable
111+
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
112+
{
113+
bestPeptides[j] = candidatePeptide;
114+
bestScores[j] = consideredScore;
115+
}
106116
}
107117
}
118+
// Did not exist! Only make sure that it is acceptable
119+
else if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
120+
{
121+
bestPeptides[j] = candidatePeptide;
122+
bestScores[j] = consideredScore;
123+
}
108124
}
109-
// Did not exist! Only make sure that it is acceptable
110-
else if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
111-
{
112-
bestPeptides[j] = candidatePeptide;
113-
bestScores[j] = consideredScore;
114-
}
115-
}
116125
}
117126
for (int j = 0; j < searchModesCount; j++)
118127
{
@@ -137,6 +146,50 @@ protected override MyResults RunSpecific()
137146
return new ModernSearchResults(newPsms, this);
138147
}
139148

149+
private bool MatchModificationsMassShift(CompactPeptide candidatePeptide, double thisScanprecursorMass)
150+
{
151+
if (candidatePeptide.varMod1Loc != 0)
152+
{
153+
if (candidatePeptide.varMod1Type<32767)
154+
{
155+
if (Math.Abs(candidatePeptide.MonoisotopicMass - variableModifications[candidatePeptide.varMod1Type - 1].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
156+
return true;
157+
}
158+
else
159+
{
160+
if (Math.Abs(candidatePeptide.MonoisotopicMass - localizeableModifications[candidatePeptide.varMod1Type - 1- 32767].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
161+
return true;
162+
}
163+
}
164+
if (candidatePeptide.varMod2Loc != 0)
165+
{
166+
if (candidatePeptide.varMod2Type < 32767)
167+
{
168+
if (Math.Abs(candidatePeptide.MonoisotopicMass - variableModifications[candidatePeptide.varMod2Type - 1].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
169+
return true;
170+
}
171+
else
172+
{
173+
if (Math.Abs(candidatePeptide.MonoisotopicMass - localizeableModifications[candidatePeptide.varMod2Type - 1 - 32767].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
174+
return true;
175+
}
176+
}
177+
if (candidatePeptide.varMod3Loc != 0)
178+
{
179+
if (candidatePeptide.varMod3Type < 32767)
180+
{
181+
if (Math.Abs(candidatePeptide.MonoisotopicMass - variableModifications[candidatePeptide.varMod3Type - 1].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
182+
return true;
183+
}
184+
else
185+
{
186+
if (Math.Abs(candidatePeptide.MonoisotopicMass - localizeableModifications[candidatePeptide.varMod3Type - 1 - 32767].MonoisotopicMassShift - thisScanprecursorMass) < tolForModificationMassDiffMatch)
187+
return true;
188+
}
189+
}
190+
return false;
191+
}
192+
140193
#endregion Protected Methods
141194

142195
#region Private Methods

0 commit comments

Comments
 (0)