1
1
using Chemistry ;
2
2
using MassSpectrometry ;
3
+ using OldInternalLogic ;
3
4
using Spectra ;
4
5
using System ;
5
6
using System . Collections . Concurrent ;
@@ -26,18 +27,25 @@ public class ModernSearchEngine : MyEngine
26
27
27
28
private readonly List < SearchMode > searchModes ;
28
29
30
+ private readonly List < MorpheusModification > variableModifications ;
31
+ private readonly List < MorpheusModification > localizeableModifications ;
32
+
33
+ private const double tolForModificationMassDiffMatch = 0.003 ;
34
+
29
35
#endregion Private Fields
30
36
31
37
#region Public Constructors
32
38
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 )
34
40
{
35
41
this . myMSDataFile = myMSDataFile ;
36
42
this . peptideIndex = peptideIndex ;
37
43
this . keys = keys ;
38
44
this . fragmentIndex = fragmentIndex ;
39
45
this . fragmentToleranceInDaltons = fragmentToleranceInDaltons ;
40
46
this . searchModes = searchModes ;
47
+ this . variableModifications = variableModifications ;
48
+ this . localizeableModifications = localizeableModifications ;
41
49
}
42
50
43
51
#endregion Public Constructors
@@ -79,40 +87,41 @@ protected override MyResults RunSpecific()
79
87
{
80
88
var consideredScore = fullPeptideScores [ possibleWinningPeptideIndex ] ;
81
89
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 ++ )
88
92
{
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 )
91
97
{
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 )
94
100
{
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
+ }
97
107
}
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 )
103
109
{
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
+ }
106
116
}
107
117
}
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
+ }
108
124
}
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
- }
116
125
}
117
126
for ( int j = 0 ; j < searchModesCount ; j ++ )
118
127
{
@@ -137,6 +146,50 @@ protected override MyResults RunSpecific()
137
146
return new ModernSearchResults ( newPsms , this ) ;
138
147
}
139
148
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
+
140
193
#endregion Protected Methods
141
194
142
195
#region Private Methods
0 commit comments