@@ -68,7 +68,7 @@ public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide
68
68
69
69
#region Public Methods
70
70
71
- public void ApplyProteinParsimony ( out List < ProteinGroup > proteinGroups )
71
+ public Dictionary < CompactPeptide , HashSet < PeptideWithSetModifications > > ApplyProteinParsimony ( out List < ProteinGroup > proteinGroups )
72
72
{
73
73
Status ( "Applying protein parsimony..." ) ;
74
74
@@ -212,7 +212,9 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
212
212
}
213
213
214
214
if ( currentBestNumNewPeptides == 1 )
215
+ {
215
216
currentBestPeptidesIsOne = true ;
217
+ }
216
218
217
219
// adds the best protein if algo found unaccounted-for peptides
218
220
if ( currentBestNumNewPeptides > 1 )
@@ -221,6 +223,7 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
221
223
foreach ( var peptide in bestProteinPeptideList )
222
224
{
223
225
string peptideBaseSequence = string . Join ( "" , peptide . BaseSequence . Select ( b => char . ConvertFromUtf32 ( b ) ) ) ;
226
+
224
227
usedPeptides . Add ( peptide ) ;
225
228
usedBaseSequences . Add ( peptideBaseSequence ) ;
226
229
}
@@ -259,27 +262,6 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
259
262
}
260
263
}
261
264
262
- // build protein list for each peptide after parsimony has been applied
263
- Dictionary < CompactPeptide , HashSet < Protein > > peptideProteinListMatch = new Dictionary < CompactPeptide , HashSet < Protein > > ( ) ;
264
- foreach ( var kvp in parsimonyDict )
265
- {
266
- foreach ( var peptide in kvp . Value )
267
- {
268
- HashSet < Protein > proteinListHere = new HashSet < Protein > ( ) ;
269
-
270
- if ( ! peptideProteinListMatch . ContainsKey ( peptide ) )
271
- {
272
- proteinListHere . Add ( kvp . Key ) ;
273
- peptideProteinListMatch . Add ( peptide , proteinListHere ) ;
274
- }
275
- else
276
- {
277
- peptideProteinListMatch . TryGetValue ( peptide , out proteinListHere ) ;
278
- proteinListHere . Add ( kvp . Key ) ;
279
- }
280
- }
281
- }
282
-
283
265
// build protein groups after parsimony
284
266
proteinGroups = new List < ProteinGroup > ( ) ;
285
267
foreach ( var kvp in parsimonyDict )
@@ -324,43 +306,74 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
324
306
}
325
307
}
326
308
309
+ // build protein list for each peptide after parsimony has been applied
310
+ Dictionary < CompactPeptide , HashSet < Protein > > peptideProteinListMatch = new Dictionary < CompactPeptide , HashSet < Protein > > ( ) ;
311
+ foreach ( var kvp in parsimonyDict )
312
+ {
313
+ foreach ( var peptide in kvp . Value )
314
+ {
315
+ HashSet < Protein > proteinListHere = new HashSet < Protein > ( ) ;
316
+
317
+ if ( ! peptideProteinListMatch . ContainsKey ( peptide ) )
318
+ {
319
+ proteinListHere . Add ( kvp . Key ) ;
320
+ peptideProteinListMatch . Add ( peptide , proteinListHere ) ;
321
+ }
322
+ else
323
+ {
324
+ peptideProteinListMatch . TryGetValue ( peptide , out proteinListHere ) ;
325
+ proteinListHere . Add ( kvp . Key ) ;
326
+ }
327
+ }
328
+ }
329
+
327
330
// constructs return dictionary (only use parsimony proteins for the new PeptideWithSetModifications list)
328
331
Dictionary < CompactPeptide , HashSet < PeptideWithSetModifications > > answer = new Dictionary < CompactPeptide , HashSet < PeptideWithSetModifications > > ( ) ;
329
332
330
333
foreach ( var kvp in parsimonyDict )
331
334
{
332
335
foreach ( var peptide in kvp . Value )
333
336
{
334
- if ( ! answer . ContainsKey ( peptide ) )
335
- {
336
- HashSet < PeptideWithSetModifications > oldPeptides = new HashSet < PeptideWithSetModifications > ( ) ;
337
- HashSet < PeptideWithSetModifications > newPeptides = new HashSet < PeptideWithSetModifications > ( ) ;
338
- HashSet < Protein > proteinListHere ;
337
+ HashSet < PeptideWithSetModifications > oldPeptides = new HashSet < PeptideWithSetModifications > ( ) ;
338
+ HashSet < PeptideWithSetModifications > newPeptides = new HashSet < PeptideWithSetModifications > ( ) ;
339
+ HashSet < Protein > proteinListHere ;
339
340
340
- // get the CompactPeptide's protein list after parsimony
341
- peptideProteinListMatch . TryGetValue ( peptide , out proteinListHere ) ;
341
+ // get the CompactPeptide's protein list after parsimony
342
+ peptideProteinListMatch . TryGetValue ( peptide , out proteinListHere ) ;
342
343
343
- // find CompactPeptide's original (unparsimonious) peptide matches
344
- compactPeptideToProteinPeptideMatching . TryGetValue ( peptide , out oldPeptides ) ;
344
+ // find CompactPeptide's original (unparsimonious) peptide matches
345
+ compactPeptideToProteinPeptideMatching . TryGetValue ( peptide , out oldPeptides ) ;
345
346
346
- // get the peptides that belong to the post-parsimony protein(s) only
347
- foreach ( var peptide1 in oldPeptides )
347
+ // get the peptides that belong to the post-parsimony protein(s) only
348
+ foreach ( var peptide1 in oldPeptides )
349
+ {
350
+ if ( proteinListHere . Contains ( peptide1 . Protein ) )
348
351
{
349
- if ( proteinListHere . Contains ( peptide1 . Protein ) )
350
- {
351
- newPeptides . Add ( peptide1 ) ;
352
- }
352
+ newPeptides . Add ( peptide1 ) ;
353
353
}
354
+ }
354
355
355
- // make new dictionary using only peptides from parsimonious protein list
356
+ if ( ! answer . ContainsKey ( peptide ) )
357
+ {
356
358
answer . Add ( peptide , newPeptides ) ;
357
359
}
360
+ /*
361
+ else
362
+ {
363
+ HashSet<PeptideWithSetModifications> temp = new HashSet<PeptideWithSetModifications>();
364
+ answer.TryGetValue(peptide, out temp);
365
+ temp.UnionWith(newPeptides);
366
+ }
367
+ */
358
368
}
359
369
}
360
370
361
371
Status ( "Finished Parsimony" ) ;
362
372
363
373
compactPeptideToProteinPeptideMatching = answer ;
374
+
375
+ // returns for test class
376
+ return answer ;
364
377
}
365
378
366
379
public void ScoreProteinGroups ( List < ProteinGroup > proteinGroups , List < NewPsmWithFdr > psmList )
@@ -399,14 +412,17 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
399
412
foreach ( var peptide in proteinGroup . PeptideList )
400
413
{
401
414
string peptideBaseSequence = string . Join ( "" , peptide . BaseSequence . Select ( b => char . ConvertFromUtf32 ( b ) ) ) ;
402
- List < NewPsmWithFdr > psmListForThisBaseSeq = new List < NewPsmWithFdr > ( ) ;
415
+ List < NewPsmWithFdr > psmListForThisBaseSeq ;
403
416
404
417
peptideBaseSeqToPsmMatching . TryGetValue ( peptideBaseSequence , out psmListForThisBaseSeq ) ;
405
- foreach ( var psm in psmListForThisBaseSeq )
418
+ if ( psmListForThisBaseSeq != null )
406
419
{
407
- if ( ! proteinGroup . TotalPsmList . Contains ( psm ) )
420
+ foreach ( var psm in psmListForThisBaseSeq )
408
421
{
409
- proteinGroup . TotalPsmList . Add ( psm ) ;
422
+ if ( ! proteinGroup . TotalPsmList . Contains ( psm ) )
423
+ {
424
+ proteinGroup . TotalPsmList . Add ( psm ) ;
425
+ }
410
426
}
411
427
}
412
428
}
@@ -419,17 +435,23 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
419
435
NewPsmWithFdr bestPsm = null ;
420
436
CompactPeptide bestPeptide = null ;
421
437
422
- foreach ( var psm in kvp . Value )
438
+ if ( kvp . Value != null )
423
439
{
424
- if ( psm . thisPSM . Score > bestScoreSoFar )
440
+ foreach ( var psm in kvp . Value )
425
441
{
426
- bestScoreSoFar = psm . thisPSM . Score ;
427
- bestPsm = psm ;
428
- bestPeptide = psm . thisPSM . newPsm . GetCompactPeptide ( variableModifications , localizeableModifications ) ;
442
+ if ( psm . thisPSM . Score > bestScoreSoFar )
443
+ {
444
+ bestScoreSoFar = psm . thisPSM . Score ;
445
+ bestPsm = psm ;
446
+ bestPeptide = psm . thisPSM . newPsm . GetCompactPeptide ( variableModifications , localizeableModifications ) ;
447
+ }
429
448
}
430
449
}
431
450
432
- peptideToBestPsmMatching . Add ( bestPeptide , bestPsm ) ;
451
+ if ( bestPsm != null )
452
+ {
453
+ peptideToBestPsmMatching . Add ( bestPeptide , bestPsm ) ;
454
+ }
433
455
}
434
456
435
457
// add the best psm per base sequence to the protein group and score the protein group
@@ -501,7 +523,9 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
501
523
foreach ( var kvp in peptideToProteinGroupMatching )
502
524
{
503
525
if ( kvp . Value . Count > 1 )
526
+ {
504
527
allRazorPeptides . Add ( kvp . Key ) ;
528
+ }
505
529
}
506
530
507
531
foreach ( var proteinGroup in proteinGroups )
0 commit comments