1
1
using Chemistry ;
2
2
using MassSpectrometry ;
3
3
using MzLibUtil ;
4
+ using System ;
4
5
using System . Collections . Generic ;
5
6
using System . Globalization ;
6
7
using System . Linq ;
@@ -36,8 +37,9 @@ public PsmWithMultiplePossiblePeptides(PsmParent newPsm, HashSet<PeptideWithSetM
36
37
var MatchedIonDictPositiveIsMatch = new Dictionary < ProductType , double [ ] > ( ) ;
37
38
foreach ( var huh in lp )
38
39
{
39
- var df = representative . SortedProductMasses ( new List < ProductType > { huh } ) ;
40
+ var df = representative . ProductMassesMightHaveDuplicatesAndNaNs ( new List < ProductType > { huh } ) ;
40
41
double [ ] matchedIonMassesListPositiveIsMatch = new double [ df . Length ] ;
42
+ Array . Sort ( matchedIonMassesListPositiveIsMatch ) ;
41
43
MatchIons ( theScan , fragmentTolerance , df , matchedIonMassesListPositiveIsMatch ) ;
42
44
MatchedIonDictPositiveIsMatch . Add ( huh , matchedIonMassesListPositiveIsMatch ) ;
43
45
}
@@ -53,7 +55,8 @@ public PsmWithMultiplePossiblePeptides(PsmParent newPsm, HashSet<PeptideWithSetM
53
55
{
54
56
PeptideWithSetModifications localizedPeptide = representative . Localize ( indexToLocalize , ScanPrecursorMass - representative . MonoisotopicMass ) ;
55
57
56
- var gg = localizedPeptide . SortedProductMasses ( lp ) ;
58
+ var gg = localizedPeptide . ProductMassesMightHaveDuplicatesAndNaNs ( lp ) ;
59
+ Array . Sort ( gg ) ;
57
60
double [ ] matchedIonMassesListPositiveIsMatch = new double [ gg . Length ] ;
58
61
var score = MatchIons ( theScan , fragmentTolerance , gg , matchedIonMassesListPositiveIsMatch ) ;
59
62
localizedScores . Add ( score ) ;
@@ -161,6 +164,91 @@ internal static string TabSeparatedHeader
161
164
162
165
#region Public Methods
163
166
167
+ public static double MatchIons ( IMsDataScan < IMzSpectrum < IMzPeak > > thisScan , Tolerance productMassTolerance , double [ ] sorted_theoretical_product_masses_for_this_peptide , double [ ] matchedIonMassesListPositiveIsMatch )
168
+ {
169
+ var TotalProductsHere = sorted_theoretical_product_masses_for_this_peptide . Length ;
170
+ if ( TotalProductsHere == 0 )
171
+ return 0 ;
172
+ int MatchingProductsHere = 0 ;
173
+ double MatchingIntensityHere = 0 ;
174
+
175
+ // speed optimizations
176
+ double [ ] experimental_mzs = thisScan . MassSpectrum . XArray ;
177
+ double [ ] experimental_intensities = thisScan . MassSpectrum . YArray ;
178
+ int num_experimental_peaks = experimental_mzs . Length ;
179
+
180
+ int currentTheoreticalIndex = - 1 ;
181
+ double currentTheoreticalMass ;
182
+ do
183
+ {
184
+ currentTheoreticalIndex ++ ;
185
+ currentTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ currentTheoreticalIndex ] ;
186
+ } while ( double . IsNaN ( currentTheoreticalMass ) ) ;
187
+
188
+ double currentTheoreticalMz = currentTheoreticalMass + Constants . protonMass ;
189
+
190
+ int testTheoreticalIndex ;
191
+ double testTheoreticalMZ ;
192
+ double testTheoreticalMass ;
193
+ // Loop over all experimenal indices
194
+ for ( int experimentalIndex = 0 ; experimentalIndex < num_experimental_peaks ; experimentalIndex ++ )
195
+ {
196
+ double currentExperimentalMZ = experimental_mzs [ experimentalIndex ] ;
197
+ // If found match
198
+ if ( productMassTolerance . Within ( currentExperimentalMZ , currentTheoreticalMz ) )
199
+ {
200
+ MatchingProductsHere ++ ;
201
+ MatchingIntensityHere += experimental_intensities [ experimentalIndex ] ;
202
+ matchedIonMassesListPositiveIsMatch [ currentTheoreticalIndex ] = currentTheoreticalMass ;
203
+ currentTheoreticalIndex ++ ;
204
+ if ( currentTheoreticalIndex == TotalProductsHere )
205
+ break ;
206
+ currentTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ currentTheoreticalIndex ] ;
207
+ currentTheoreticalMz = currentTheoreticalMass + Constants . protonMass ;
208
+ }
209
+ // Else if for sure did not reach the next theoretical yet, move to next experimental
210
+ else if ( currentExperimentalMZ < currentTheoreticalMz )
211
+ continue ;
212
+ // Else if for sure passed a theoretical
213
+ else
214
+ {
215
+ // Mark the theoretical as missed
216
+ matchedIonMassesListPositiveIsMatch [ currentTheoreticalIndex ] = - currentTheoreticalMass ;
217
+
218
+ // Move on to next index and never come back!
219
+ currentTheoreticalIndex ++ ;
220
+ if ( currentTheoreticalIndex == TotalProductsHere )
221
+ break ;
222
+ currentTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ currentTheoreticalIndex ] ;
223
+ currentTheoreticalMz = currentTheoreticalMass + Constants . protonMass ;
224
+
225
+ // Start with the current ones
226
+ testTheoreticalIndex = currentTheoreticalIndex ;
227
+ testTheoreticalMZ = currentTheoreticalMz ;
228
+ testTheoreticalMass = currentTheoreticalMass ;
229
+ // Mark the skipped theoreticals as not found. The last one is not for sure, might be flipped!
230
+ while ( currentExperimentalMZ > testTheoreticalMZ )
231
+ {
232
+ matchedIonMassesListPositiveIsMatch [ testTheoreticalIndex ] = - currentTheoreticalMass ;
233
+ // Store old info for possible reuse
234
+ currentTheoreticalMass = testTheoreticalMass ;
235
+ currentTheoreticalMz = testTheoreticalMZ ;
236
+ currentTheoreticalIndex = testTheoreticalIndex ;
237
+
238
+ // Update test stuff!
239
+ testTheoreticalIndex ++ ;
240
+ if ( testTheoreticalIndex == TotalProductsHere )
241
+ break ;
242
+ testTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ testTheoreticalIndex ] ;
243
+ testTheoreticalMZ = testTheoreticalMass + Constants . protonMass ;
244
+ }
245
+
246
+ experimentalIndex -- ;
247
+ }
248
+ }
249
+ return MatchingProductsHere + MatchingIntensityHere / thisScan . TotalIonCurrent ;
250
+ }
251
+
164
252
public override string ToString ( )
165
253
{
166
254
var sb = new StringBuilder ( ) ;
@@ -197,51 +285,5 @@ public override string ToString()
197
285
198
286
#endregion Public Methods
199
287
200
- #region Internal Methods
201
-
202
- internal static double MatchIons ( IMsDataScan < IMzSpectrum < IMzPeak > > thisScan , Tolerance productMassTolerance , double [ ] sorted_theoretical_product_masses_for_this_peptide , double [ ] matchedIonMassesListPositiveIsMatch )
203
- {
204
- var TotalProductsHere = sorted_theoretical_product_masses_for_this_peptide . Length ;
205
- if ( TotalProductsHere == 0 )
206
- return 0 ;
207
- int MatchingProductsHere = 0 ;
208
- double MatchingIntensityHere = 0 ;
209
-
210
- // speed optimizations
211
- double [ ] experimental_mzs = thisScan . MassSpectrum . XArray ;
212
- double [ ] experimental_intensities = thisScan . MassSpectrum . YArray ;
213
- int num_experimental_peaks = experimental_mzs . Length ;
214
-
215
- int theoreticalIndex = 0 ;
216
- double nextTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ 0 ] ;
217
- double nextTheoreticalMZ = nextTheoreticalMass + Constants . protonMass ;
218
-
219
- double currentExperimentalMZ ;
220
- for ( int i = 0 ; i < num_experimental_peaks ; i ++ )
221
- {
222
- currentExperimentalMZ = experimental_mzs [ i ] ;
223
- if ( productMassTolerance . Within ( currentExperimentalMZ , nextTheoreticalMZ ) )
224
- {
225
- MatchingProductsHere ++ ;
226
- MatchingIntensityHere += experimental_intensities [ i ] ;
227
- matchedIonMassesListPositiveIsMatch [ theoreticalIndex ] = nextTheoreticalMass ;
228
- }
229
- else if ( currentExperimentalMZ < nextTheoreticalMZ )
230
- continue ;
231
- else
232
- matchedIonMassesListPositiveIsMatch [ theoreticalIndex ] = - nextTheoreticalMass ;
233
- i -- ;
234
- // Passed a theoretical! Move counter forward
235
- theoreticalIndex ++ ;
236
- if ( theoreticalIndex == TotalProductsHere )
237
- break ;
238
- nextTheoreticalMass = sorted_theoretical_product_masses_for_this_peptide [ theoreticalIndex ] ;
239
- nextTheoreticalMZ = nextTheoreticalMass + Constants . protonMass ;
240
- }
241
- return MatchingProductsHere + MatchingIntensityHere / thisScan . TotalIonCurrent ;
242
- }
243
-
244
- #endregion Internal Methods
245
-
246
288
}
247
289
}
0 commit comments