1
1
using Chemistry ;
2
2
using MassSpectrometry ;
3
3
using MzLibUtil ;
4
- using Proteomics . AminoAcidPolymer ;
5
4
using System ;
6
- using System . Collections . Concurrent ;
7
5
using System . Collections . Generic ;
8
6
using System . Linq ;
9
7
using System . Threading . Tasks ;
@@ -76,13 +74,6 @@ protected override MetaMorpheusEngineResults RunSpecific()
76
74
77
75
var representativeSinglePeptide = identification . BestMatchingBioPolymersWithSetMods . First ( ) . SpecificBioPolymer ;
78
76
79
- // Get the peptide, don't forget to add the modifications!!!!
80
- var SequenceWithChemicalFormulas = representativeSinglePeptide . SequenceWithChemicalFormulas ;
81
- if ( SequenceWithChemicalFormulas == null || representativeSinglePeptide . AllModsOneIsNterminus . Any ( b => b . Value . NeutralLosses != null ) )
82
- continue ;
83
-
84
- Peptide coolPeptide = new Peptide ( SequenceWithChemicalFormulas ) ;
85
-
86
77
List < LabeledDataPoint > ms2tuple = SearchMS2Spectrum ( GoodScans [ matchIndex ] , identification , ProductMassTolerance ) ;
87
78
88
79
lock ( _ms2Lock )
@@ -91,7 +82,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
91
82
}
92
83
93
84
// Calculate theoretical isotopic distribution of the full peptide
94
- var dist = IsotopicDistribution . GetDistribution ( coolPeptide . GetChemicalFormula ( ) , FineResolutionForIsotopeDistCalculation , 0.001 ) ;
85
+ var dist = IsotopicDistribution . GetDistribution ( representativeSinglePeptide . ThisChemicalFormula , FineResolutionForIsotopeDistCalculation , 0.001 ) ;
95
86
96
87
double [ ] theoreticalMasses = dist . Masses . ToArray ( ) ;
97
88
double [ ] theoreticalIntensities = dist . Intensities . ToArray ( ) ;
@@ -137,6 +128,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
137
128
theIndex = direction == 1 ? ms2spectrumIndex + 1 : identification . PrecursorScanNumber ?? ms2spectrumIndex ;
138
129
139
130
bool addedAscan = true ;
131
+ bool positiveMode = identification . ScanPrecursorCharge > 0 ;
140
132
141
133
int highestKnownChargeForThisPeptide = peptideCharge ;
142
134
while ( theIndex >= 1 && theIndex <= MyMsDataFile . NumSpectra && addedAscan ) //as long as we're finding the peptide in ms1 scans
@@ -157,16 +149,26 @@ protected override MetaMorpheusEngineResults RunSpecific()
157
149
break ;
158
150
159
151
bool startingToAddCharges = false ;
160
- int chargeToLookAt = 1 ;
152
+ int chargeToLookAt = positiveMode ? 1 : - 1 ;
153
+ int chargeLimit = positiveMode ? highestKnownChargeForThisPeptide + 1 : highestKnownChargeForThisPeptide - 1 ;
154
+
161
155
do
162
156
{
163
- if ( theoreticalMasses [ 0 ] . ToMz ( chargeToLookAt ) > scanWindowRange . Maximum )
157
+ double mz = theoreticalMasses [ 0 ] . ToMz ( chargeToLookAt ) ;
158
+
159
+ // If m/z is above the scan window, try next charge
160
+ if ( mz > scanWindowRange . Maximum )
164
161
{
165
- chargeToLookAt ++ ;
162
+ chargeToLookAt += positiveMode ? 1 : - 1 ;
166
163
continue ;
167
164
}
168
- if ( theoreticalMasses [ 0 ] . ToMz ( chargeToLookAt ) < scanWindowRange . Minimum )
165
+
166
+ // If m/z is below the scan window, break early, more charge will only make the mz smaller.
167
+ if ( mz < scanWindowRange . Minimum )
168
+ {
169
169
break ;
170
+ }
171
+
170
172
var trainingPointsToAverage = new List < LabeledDataPoint > ( ) ;
171
173
foreach ( double a in theoreticalMasses )
172
174
{
@@ -187,15 +189,17 @@ protected override MetaMorpheusEngineResults RunSpecific()
187
189
var closestPeakIndex = fullMS1spectrum . GetClosestPeakIndex ( theMZ ) ;
188
190
var closestPeakMZ = fullMS1spectrum . XArray [ closestPeakIndex ] ;
189
191
190
- highestKnownChargeForThisPeptide = Math . Max ( highestKnownChargeForThisPeptide , chargeToLookAt ) ;
192
+ highestKnownChargeForThisPeptide = positiveMode
193
+ ? Math . Max ( highestKnownChargeForThisPeptide , chargeToLookAt )
194
+ : Math . Min ( highestKnownChargeForThisPeptide , chargeToLookAt ) ;
191
195
trainingPointsToAverage . Add ( new LabeledDataPoint ( closestPeakMZ , - 1 , double . NaN , double . NaN , Math . Log ( fullMS1spectrum . YArray [ closestPeakIndex ] ) , theMZ , null ) ) ;
192
196
}
193
197
// If started adding and suddenly stopped, go to next one, no need to look at higher charges
194
198
if ( trainingPointsToAverage . Count == 0 && startingToAddCharges )
195
199
{
196
200
break ;
197
201
}
198
- if ( ( trainingPointsToAverage . Count == 0 || ( trainingPointsToAverage . Count == 1 && theoreticalIntensities [ 0 ] < 0.65 ) ) && ( peptideCharge <= chargeToLookAt ) )
202
+ if ( ( trainingPointsToAverage . Count == 0 || ( trainingPointsToAverage . Count == 1 && theoreticalIntensities [ 0 ] < 0.65 ) ) && ( positiveMode ? peptideCharge <= chargeToLookAt : peptideCharge > = chargeToLookAt ) )
199
203
{
200
204
break ;
201
205
}
@@ -213,8 +217,8 @@ protected override MetaMorpheusEngineResults RunSpecific()
213
217
trainingPointsToAverage . Select ( b => b . TheoreticalMz ) . Average ( ) ,
214
218
identification ) ) ;
215
219
}
216
- chargeToLookAt ++ ;
217
- } while ( chargeToLookAt <= highestKnownChargeForThisPeptide + 1 ) ;
220
+ chargeToLookAt += positiveMode ? 1 : - 1 ;
221
+ } while ( positiveMode ? chargeToLookAt <= chargeLimit : chargeToLookAt >= chargeLimit ) ;
218
222
theIndex += direction ;
219
223
}
220
224
return ( result , numMs1MassChargeCombinationsConsidered , numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks ) ;
@@ -240,16 +244,17 @@ private static List<LabeledDataPoint> SearchMS2Spectrum(Ms2ScanWithSpecificMass
240
244
if ( envelopesThatMatch . Count == 0 )
241
245
continue ;
242
246
//only allow one envelope per charge state
243
- bool [ ] chargeStateFound = new bool [ envelopesThatMatch . Max ( x => x . Charge ) + 1 ] ;
247
+ bool [ ] chargeStateFound = new bool [ envelopesThatMatch . Max ( x => Math . Abs ( x . Charge ) ) + 1 ] ;
244
248
245
249
foreach ( var envelopeThatMatched in envelopesThatMatch )
246
250
{
251
+ int charge = Math . Abs ( envelopeThatMatched . Charge ) ;
247
252
//if we haven't seen this charge state already
248
- if ( ! chargeStateFound [ envelopeThatMatched . Charge ] )
253
+ if ( ! chargeStateFound [ charge ] )
249
254
{
250
- chargeStateFound [ envelopeThatMatched . Charge ] = true ;
255
+ chargeStateFound [ charge ] = true ;
251
256
252
- double exptPeakMz = envelopeThatMatched . MonoisotopicMass . ToMz ( envelopeThatMatched . Charge ) ;
257
+ double exptPeakMz = envelopeThatMatched . MonoisotopicMass . ToMz ( charge ) ;
253
258
double exptPeakIntensity = envelopeThatMatched . TotalIntensity ;
254
259
double injTime = ms2DataScan . TheScan . InjectionTime ?? double . NaN ;
255
260
@@ -259,8 +264,8 @@ private static List<LabeledDataPoint> SearchMS2Spectrum(Ms2ScanWithSpecificMass
259
264
ms2DataScan . OneBasedScanNumber ,
260
265
Math . Log ( ms2DataScan . TotalIonCurrent ) ,
261
266
Math . Log ( injTime ) ,
262
- Math . Log ( exptPeakIntensity ) ,
263
- matchedIon . NeutralTheoreticalProduct . NeutralMass . ToMz ( envelopeThatMatched . Charge ) ,
267
+ Math . Log ( exptPeakIntensity ) ,
268
+ matchedIon . NeutralTheoreticalProduct . NeutralMass . ToMz ( charge ) ,
264
269
identification ) ) ;
265
270
}
266
271
}
0 commit comments