Skip to content

Commit 9ff6ec0

Browse files
author
stefanks
authored
Merge pull request #185 from rmillikin/master
merge
2 parents bcc707e + a0be807 commit 9ff6ec0

File tree

4 files changed

+155
-126
lines changed

4 files changed

+155
-126
lines changed

InternalLogic/AnalysisEngine.cs

+72-48
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide
6868

6969
#region Public Methods
7070

71-
public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
71+
public Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
7272
{
7373
Status("Applying protein parsimony...");
7474

@@ -212,7 +212,9 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
212212
}
213213

214214
if (currentBestNumNewPeptides == 1)
215+
{
215216
currentBestPeptidesIsOne = true;
217+
}
216218

217219
// adds the best protein if algo found unaccounted-for peptides
218220
if (currentBestNumNewPeptides > 1)
@@ -221,6 +223,7 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
221223
foreach (var peptide in bestProteinPeptideList)
222224
{
223225
string peptideBaseSequence = string.Join("", peptide.BaseSequence.Select(b => char.ConvertFromUtf32(b)));
226+
224227
usedPeptides.Add(peptide);
225228
usedBaseSequences.Add(peptideBaseSequence);
226229
}
@@ -259,27 +262,6 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
259262
}
260263
}
261264

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-
283265
// build protein groups after parsimony
284266
proteinGroups = new List<ProteinGroup>();
285267
foreach (var kvp in parsimonyDict)
@@ -324,43 +306,74 @@ public void ApplyProteinParsimony(out List<ProteinGroup> proteinGroups)
324306
}
325307
}
326308

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+
327330
// constructs return dictionary (only use parsimony proteins for the new PeptideWithSetModifications list)
328331
Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> answer = new Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>>();
329332

330333
foreach (var kvp in parsimonyDict)
331334
{
332335
foreach (var peptide in kvp.Value)
333336
{
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;
339340

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);
342343

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);
345346

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))
348351
{
349-
if (proteinListHere.Contains(peptide1.Protein))
350-
{
351-
newPeptides.Add(peptide1);
352-
}
352+
newPeptides.Add(peptide1);
353353
}
354+
}
354355

355-
// make new dictionary using only peptides from parsimonious protein list
356+
if (!answer.ContainsKey(peptide))
357+
{
356358
answer.Add(peptide, newPeptides);
357359
}
360+
/*
361+
else
362+
{
363+
HashSet<PeptideWithSetModifications> temp = new HashSet<PeptideWithSetModifications>();
364+
answer.TryGetValue(peptide, out temp);
365+
temp.UnionWith(newPeptides);
366+
}
367+
*/
358368
}
359369
}
360370

361371
Status("Finished Parsimony");
362372

363373
compactPeptideToProteinPeptideMatching = answer;
374+
375+
// returns for test class
376+
return answer;
364377
}
365378

366379
public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWithFdr> psmList)
@@ -399,14 +412,17 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
399412
foreach (var peptide in proteinGroup.PeptideList)
400413
{
401414
string peptideBaseSequence = string.Join("", peptide.BaseSequence.Select(b => char.ConvertFromUtf32(b)));
402-
List<NewPsmWithFdr> psmListForThisBaseSeq = new List<NewPsmWithFdr>();
415+
List<NewPsmWithFdr> psmListForThisBaseSeq;
403416

404417
peptideBaseSeqToPsmMatching.TryGetValue(peptideBaseSequence, out psmListForThisBaseSeq);
405-
foreach (var psm in psmListForThisBaseSeq)
418+
if (psmListForThisBaseSeq != null)
406419
{
407-
if (!proteinGroup.TotalPsmList.Contains(psm))
420+
foreach (var psm in psmListForThisBaseSeq)
408421
{
409-
proteinGroup.TotalPsmList.Add(psm);
422+
if (!proteinGroup.TotalPsmList.Contains(psm))
423+
{
424+
proteinGroup.TotalPsmList.Add(psm);
425+
}
410426
}
411427
}
412428
}
@@ -419,17 +435,23 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
419435
NewPsmWithFdr bestPsm = null;
420436
CompactPeptide bestPeptide = null;
421437

422-
foreach (var psm in kvp.Value)
438+
if (kvp.Value != null)
423439
{
424-
if (psm.thisPSM.Score > bestScoreSoFar)
440+
foreach (var psm in kvp.Value)
425441
{
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+
}
429448
}
430449
}
431450

432-
peptideToBestPsmMatching.Add(bestPeptide, bestPsm);
451+
if (bestPsm != null)
452+
{
453+
peptideToBestPsmMatching.Add(bestPeptide, bestPsm);
454+
}
433455
}
434456

435457
// 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
501523
foreach (var kvp in peptideToProteinGroupMatching)
502524
{
503525
if (kvp.Value.Count > 1)
526+
{
504527
allRazorPeptides.Add(kvp.Key);
528+
}
505529
}
506530

507531
foreach (var proteinGroup in proteinGroups)

InternalLogic/ProteinGroup.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public static string TabSeparatedHeader
7070
public List<NewPsmWithFdr> TotalPsmList { get; set; }
7171
public HashSet<CompactPeptide> PeptideList { get; set; }
7272
public HashSet<CompactPeptide> UniquePeptideList { get; set; }
73+
public HashSet<CompactPeptide> RazorPeptideList { get; set; }
7374
public HashSet<PeptideWithSetModifications> PeptideWithSetModsList { get; set; }
7475
public List<double> sequenceCoverage { get; private set; }
75-
public HashSet<CompactPeptide> RazorPeptideList { get; set; }
7676
public double QValue { get; set; }
7777
public int cumulativeTarget { get; set; }
7878
public int cumulativeDecoy { get; set; }
@@ -188,9 +188,12 @@ public void CalculateSequenceCoverage()
188188

189189
foreach(var peptide in PeptideWithSetModsList)
190190
{
191-
for(int i = peptide.OneBasedStartResidueInProtein; i <= peptide.OneBasedEndResidueInProtein; i++)
191+
if (peptide.Protein == protein)
192192
{
193-
coveredResidues.Add(i);
193+
for (int i = peptide.OneBasedStartResidueInProtein; i <= peptide.OneBasedEndResidueInProtein; i++)
194+
{
195+
coveredResidues.Add(i);
196+
}
194197
}
195198
}
196199

MetaMorpheusGUI/MainWindow.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ private void Window_Drop(object sender, DragEventArgs e)
303303
break;
304304

305305
case ".xml":
306+
case ".fasta":
306307
case ".gz":
307308
xmlDBobservableCollection.Add(new XMLdb(file));
308309
break;

0 commit comments

Comments
 (0)