Skip to content

Commit 083d5ca

Browse files
author
stefanks
authored
Merge pull request #183 from smith-chem-wisc/StefanBranch
revert
2 parents ec3a212 + 87d9436 commit 083d5ca

File tree

4 files changed

+38
-93
lines changed

4 files changed

+38
-93
lines changed

InternalLogic/ClassicSearchEngine.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,15 @@ protected override MyResults RunSpecific()
143143
var searchMode = searchModes[aede];
144144
foreach (LocalMS2Scan scan in GetAcceptableScans(yyy.MonoisotopicMass, searchMode).ToList())
145145
{
146-
if (!ModificationMassDiffMatch(yyy, scan, tolForModificationMassDiffMatch))
146+
var score = PSMwithProteinHashSet.MatchIons(scan.TheScan, productMassTolerance, sortedProductMasses, matchedIonsArray);
147+
var psm = new ClassicSpectrumMatch(yyy, fileName, scan.RetentionTime, scan.MonoisotopicPrecursorIntensity, scan.PrecursorMass, scan.OneBasedScanNumber, scan.MonoisotopicPrecursorCharge, scan.NumPeaks, scan.TotalIonCurrent, scan.MonoisotopicPrecursorMZ, score);
148+
if (psm.score > 1)
147149
{
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)
150+
ClassicSpectrumMatch current_best_psm = psms[aede][scan.OneBasedScanNumber - 1];
151+
if (current_best_psm == null || ClassicSpectrumMatch.FirstIsPreferable(psm, current_best_psm))
151152
{
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-
}
153+
psms[aede][scan.OneBasedScanNumber - 1] = psm;
154+
matchedIonsArray = new double[sortedProductMasses.Length];
158155
}
159156
}
160157
}

InternalLogic/ModernSearchEngine.cs

+28-80
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Chemistry;
22
using MassSpectrometry;
3-
using OldInternalLogic;
43
using Spectra;
54
using System;
65
using System.Collections.Concurrent;
@@ -15,6 +14,7 @@ public class ModernSearchEngine : MyEngine
1514

1615
#region Private Fields
1716

17+
private const double tolForModificationMassDiffMatch = 0.003;
1818
private readonly List<int>[] fragmentIndex;
1919

2020
private readonly double fragmentToleranceInDaltons;
@@ -27,25 +27,18 @@ public class ModernSearchEngine : MyEngine
2727

2828
private readonly List<SearchMode> searchModes;
2929

30-
private readonly List<MorpheusModification> variableModifications;
31-
private readonly List<MorpheusModification> localizeableModifications;
32-
33-
private const double tolForModificationMassDiffMatch = 0.003;
34-
3530
#endregion Private Fields
3631

3732
#region Public Constructors
3833

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)
34+
public ModernSearchEngine(IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, List<CompactPeptide> peptideIndex, float[] keys, List<int>[] fragmentIndex, double fragmentToleranceInDaltons, List<SearchMode> searchModes) : base(2)
4035
{
4136
this.myMSDataFile = myMSDataFile;
4237
this.peptideIndex = peptideIndex;
4338
this.keys = keys;
4439
this.fragmentIndex = fragmentIndex;
4540
this.fragmentToleranceInDaltons = fragmentToleranceInDaltons;
4641
this.searchModes = searchModes;
47-
this.variableModifications = variableModifications;
48-
this.localizeableModifications = localizeableModifications;
4942
}
5043

5144
#endregion Public Constructors
@@ -87,41 +80,40 @@ protected override MyResults RunSpecific()
8780
{
8881
var consideredScore = fullPeptideScores[possibleWinningPeptideIndex];
8982
CompactPeptide candidatePeptide = peptideIndex[possibleWinningPeptideIndex];
90-
if (!MatchModificationsMassShift(candidatePeptide, thisScanprecursorMass))
91-
for (int j = 0; j < searchModesCount; j++)
83+
for (int j = 0; j < searchModesCount; j++)
84+
{
85+
// Check if makes sense to add due to peptidescore!
86+
var searchMode = searchModes[j];
87+
double currentBestScore = bestScores[j];
88+
if (currentBestScore > 1)
9289
{
93-
// Check if makes sense to add due to peptidescore!
94-
var searchMode = searchModes[j];
95-
double currentBestScore = bestScores[j];
96-
if (currentBestScore > 1)
90+
// Existed! Need to compare with old match
91+
if (Math.Abs(currentBestScore - consideredScore) < 1e-9)
9792
{
98-
// Existed! Need to compare with old match
99-
if (Math.Abs(currentBestScore - consideredScore) < 1e-9)
93+
// Score is same, need to see if accepts and if prefer the new one
94+
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass) && FirstIsPreferableWithoutScore(candidatePeptide, bestPeptides[j], thisScanprecursorMass))
10095
{
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-
}
107-
}
108-
else if (currentBestScore < consideredScore)
109-
{
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-
}
96+
bestPeptides[j] = candidatePeptide;
97+
bestScores[j] = consideredScore;
11698
}
11799
}
118-
// Did not exist! Only make sure that it is acceptable
119-
else if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
100+
else if (currentBestScore < consideredScore)
120101
{
121-
bestPeptides[j] = candidatePeptide;
122-
bestScores[j] = consideredScore;
102+
// Score is better, only make sure it is acceptable
103+
if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
104+
{
105+
bestPeptides[j] = candidatePeptide;
106+
bestScores[j] = consideredScore;
107+
}
123108
}
124109
}
110+
// Did not exist! Only make sure that it is acceptable
111+
else if (searchMode.Accepts(thisScanprecursorMass, candidatePeptide.MonoisotopicMass))
112+
{
113+
bestPeptides[j] = candidatePeptide;
114+
bestScores[j] = consideredScore;
115+
}
116+
}
125117
}
126118
for (int j = 0; j < searchModesCount; j++)
127119
{
@@ -146,50 +138,6 @@ protected override MyResults RunSpecific()
146138
return new ModernSearchResults(newPsms, this);
147139
}
148140

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-
193141
#endregion Protected Methods
194142

195143
#region Private Methods

InternalLogicWithFileIO/SearchTask/SearchTask.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected override MyResults RunSpecific()
212212
}
213213
else
214214
{
215-
modernSearchEngine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, ProductMassTolerance.Value, searchModesS, variableModifications, localizeableModifications);
215+
modernSearchEngine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, ProductMassTolerance.Value, searchModesS);
216216

217217
modernSearchResults = (ModernSearchResults)modernSearchEngine.Run();
218218
for (int i = 0; i < searchModesS.Count; i++)

Test/SearchEngineTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public static void TestModernSearchEngine()
9393
var keys = fragmentIndexDict.OrderBy(b => b.Key).Select(b => b.Key).ToArray();
9494
var fragmentIndex = fragmentIndexDict.OrderBy(b => b.Key).Select(b => b.Value).ToArray();
9595

96-
var engine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, productMassTolerance.Value, searchModes, variableModifications, localizeableModifications);
96+
var engine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, productMassTolerance.Value, searchModes);
9797
var searchResults = (ModernSearchResults)engine.Run();
9898

9999
// Single search mode
@@ -128,7 +128,7 @@ public static void TestModernSearchEngineWithWeirdPeptide()
128128
var keys = fragmentIndexDict.OrderBy(b => b.Key).Select(b => b.Key).ToArray();
129129
var fragmentIndex = fragmentIndexDict.OrderBy(b => b.Key).Select(b => b.Value).ToArray();
130130

131-
var engine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, productMassTolerance.Value, searchModes, variableModifications, localizeableModifications);
131+
var engine = new ModernSearchEngine(myMsDataFile, peptideIndex, keys, fragmentIndex, productMassTolerance.Value, searchModes);
132132
var searchResults = (ModernSearchResults)engine.Run();
133133

134134
// Single search mode

0 commit comments

Comments
 (0)