Skip to content

Commit fa59536

Browse files
author
stefanks
authored
Merge pull request #168 from smith-chem-wisc/StefanBranch
ahem
2 parents e56b7ee + 4171a06 commit fa59536

21 files changed

+170
-91
lines changed

InternalLogic/AnalysisEngine.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ public class AnalysisEngine : MyEngine
3535
private readonly Action<List<ProteinGroup>, string> action3;
3636
private readonly bool doParsimony;
3737
private readonly bool doHistogramAnalysis;
38+
private readonly List<ProductType> lp;
3839
private Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> compactPeptideToProteinPeptideMatching;
3940

4041
#endregion Private Fields
4142

4243
#region Public Constructors
4344

44-
public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> compactPeptideToProteinPeptideMatching, List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, List<SearchMode> searchModes, IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, Tolerance fragmentTolerance, Action<BinTreeStructure, string> action1, Action<List<NewPsmWithFdr>, string> action2, Action<List<ProteinGroup>, string> action3, bool doParsimony, int maximumMissedCleavages, int maxModIsoforms, bool doHistogramAnalysis) : base(2)
45+
public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide, HashSet<PeptideWithSetModifications>> compactPeptideToProteinPeptideMatching, List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, List<SearchMode> searchModes, IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, Tolerance fragmentTolerance, Action<BinTreeStructure, string> action1, Action<List<NewPsmWithFdr>, string> action2, Action<List<ProteinGroup>, string> action3, bool doParsimony, int maximumMissedCleavages, int maxModIsoforms, bool doHistogramAnalysis, List<ProductType> lp) : base(2)
4546
{
4647
this.doParsimony = doParsimony;
4748
this.doHistogramAnalysis = doHistogramAnalysis;
@@ -60,6 +61,7 @@ public AnalysisEngine(ParentSpectrumMatch[][] newPsms, Dictionary<CompactPeptide
6061
this.action3 = action3;
6162
this.maximumMissedCleavages = maximumMissedCleavages;
6263
this.maxModIsoforms = maxModIsoforms;
64+
this.lp = lp;
6365
}
6466

6567
#endregion Public Constructors
@@ -417,7 +419,7 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
417419

418420
if (foundPsm)
419421
{
420-
if(psm.qValue <= 0.01)
422+
if (psm.qValue <= 0.01)
421423
thisProteinGroupsPsmList.Add(psm);
422424
}
423425
}
@@ -433,7 +435,7 @@ public void ScoreProteinGroups(List<ProteinGroup> proteinGroups, List<NewPsmWith
433435
newPeptideList.Add(peptide);
434436

435437
if (proteinGroup.UniquePeptideList.Contains(peptide))
436-
{
438+
{
437439
newUniquePeptideList.Add(peptide);
438440
}
439441
}
@@ -504,7 +506,7 @@ protected override MyResults RunSpecific()
504506
{
505507
var huh = newPsms[j][i];
506508
if (huh != null && huh.score >= 1)
507-
psmsWithProteinHashSet[i] = new PSMwithProteinHashSet(huh, compactPeptideToProteinPeptideMatching[huh.GetCompactPeptide(variableModifications, localizeableModifications)], fragmentTolerance, myMsDataFile);
509+
psmsWithProteinHashSet[i] = new PSMwithProteinHashSet(huh, compactPeptideToProteinPeptideMatching[huh.GetCompactPeptide(variableModifications, localizeableModifications)], fragmentTolerance, myMsDataFile, lp);
508510
}
509511

510512
var orderedPsmsWithPeptides = psmsWithProteinHashSet.Where(b => b != null).OrderByDescending(b => b.Score);
@@ -901,4 +903,4 @@ private void AddObservedPeptidesToDictionary()
901903
#endregion Private Methods
902904

903905
}
904-
}
906+
}

InternalLogic/Calibration/CalibrationEngine.cs

+16-11
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,28 @@ protected override MyResults RunSpecific()
6262
Status("Calibration round " + calibrationRound);
6363
int numMs1MassChargeCombinationsConsidered = 0;
6464
int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = 0;
65+
int numMs2MassChargeCombinationsConsidered = 0;
66+
int numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = 0;
6567
Status("Getting Training Points");
66-
pointList = GetDataPoints(ref numMs1MassChargeCombinationsConsidered, ref numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
68+
pointList = GetDataPoints(ref numMs1MassChargeCombinationsConsidered, ref numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, ref numMs2MassChargeCombinationsConsidered, ref numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
6769

68-
goodResult.Add(calibrationRound, numMs1MassChargeCombinationsConsidered, numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, pointList.Count);
70+
goodResult.Add(calibrationRound, numMs1MassChargeCombinationsConsidered, numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, pointList.Count, numMs2MassChargeCombinationsConsidered, numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
6971

7072
if (calibrationRound >= 2 && pointList.Count <= trainingPointCounts[calibrationRound - 2])
7173
break;
7274

7375
trainingPointCounts.Add(pointList.Count);
7476

75-
var pointList1 = pointList.Where((b) => b.inputs[0] < 0).ToList();
76-
if (pointList1.Count == 0)
77-
{
78-
return new MyErroredResults(this, "Not enough MS1 training points, identification quality is poor");
79-
}
8077
var pointList2 = pointList.Where((b) => b.inputs[0] > 0).ToList();
8178
if (pointList2.Count == 0)
8279
{
83-
return new MyErroredResults(this, "Not enough MS2 training points, identification quality is poor");
80+
return new MyErroredResults(this, "No MS2 training points, identification quality is poor. Try to change the Fragment tolerance." + goodResult.ToString());
81+
}
82+
83+
var pointList1 = pointList.Where((b) => b.inputs[0] < 0).ToList();
84+
if (pointList1.Count == 0)
85+
{
86+
return new MyErroredResults(this, "No MS1 training points, identification quality is poor. Try to change the Parent tolerance." + goodResult.ToString());
8487
}
8588

8689
CalibrationFunction combinedCalibration = Calibrate(pointList);
@@ -96,7 +99,7 @@ protected override MyResults RunSpecific()
9699

97100
#region Private Methods
98101

99-
private List<LabeledDataPoint> GetDataPoints(ref int numMs1MassChargeCombinationsConsidered, ref int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks)
102+
private List<LabeledDataPoint> GetDataPoints(ref int numMs1MassChargeCombinationsConsidered, ref int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, ref int numMs2MassChargeCombinationsConsidered, ref int numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks)
100103
{
101104
Status("Extracting data points:");
102105
// The final training point list
@@ -133,7 +136,7 @@ private List<LabeledDataPoint> GetDataPoints(ref int numMs1MassChargeCombination
133136
Peptide coolPeptide = null;
134137
coolPeptide = new Peptide(SequenceWithChemicalFormulas);
135138

136-
candidateTrainingPointsForPeptide = SearchMS2Spectrum(myMsDataFile.GetOneBasedScan(ms2spectrumIndex), coolPeptide, peptideCharge, out numFragmentsIdentified);
139+
candidateTrainingPointsForPeptide = SearchMS2Spectrum(myMsDataFile.GetOneBasedScan(ms2spectrumIndex), coolPeptide, peptideCharge, out numFragmentsIdentified, ref numMs2MassChargeCombinationsConsidered, ref numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
137140

138141
// If MS2 has low evidence for peptide, skip and go to next one
139142
if (numFragmentsIdentified < numFragmentsNeededForEveryIdentification)
@@ -441,7 +444,7 @@ private int SearchMS1Spectra(double[] originalMasses, double[] originalIntensiti
441444
return goodIndex;
442445
}
443446

444-
private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>> ms2DataScan, Peptide peptide, int peptideCharge, out int candidateFragmentsIdentified)
447+
private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>> ms2DataScan, Peptide peptide, int peptideCharge, out int candidateFragmentsIdentified, ref int numMs2MassChargeCombinationsConsidered, ref int numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks)
445448
{
446449
var myCandidatePoints = new List<LabeledDataPoint>();
447450

@@ -520,8 +523,10 @@ private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>
520523
{
521524
break;
522525
}
526+
numMs2MassChargeCombinationsConsidered++;
523527
if (npwr > 1)
524528
{
529+
numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks++;
525530
continue;
526531
}
527532
var closestPeak = ms2DataScan.MassSpectrum.GetClosestPeak(theMZ);

InternalLogic/Calibration/CalibrationResults.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class CalibrationResults : MyResults
1414
private List<int> calibrationRoundList;
1515
private List<int> numMs1MassChargeCombinationsConsideredList;
1616
private List<int> numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList;
17+
private List<int> numMs2MassChargeCombinationsConsideredList;
18+
private List<int> numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList;
1719
private List<int> countList;
1820

1921
#endregion Private Fields
@@ -26,6 +28,8 @@ public CalibrationResults(IMsDataFile<IMzSpectrum<MzPeak>> myMSDataFile, Calibra
2628
calibrationRoundList = new List<int>();
2729
numMs1MassChargeCombinationsConsideredList = new List<int>();
2830
numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList = new List<int>();
31+
numMs2MassChargeCombinationsConsideredList = new List<int>();
32+
numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList = new List<int>();
2933
countList = new List<int>();
3034
}
3135

@@ -48,6 +52,9 @@ protected override string StringForOutput
4852
{
4953
sb.AppendLine("\t\tRound " + calibrationRoundList[i]);
5054
sb.AppendLine("\t\t\tTraining points: " + countList[i]);
55+
sb.AppendLine("\t\t\tMs2MassChargeSeen: " + numMs2MassChargeCombinationsConsideredList[i]);
56+
sb.AppendLine("\t\t\tMs2MassChargeSeenAndIgnoredBecause too many: " + numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList[i]);
57+
5158
sb.AppendLine("\t\t\tMs1MassChargeSeen: " + numMs1MassChargeCombinationsConsideredList[i]);
5259
sb.AppendLine("\t\t\tMs1MassChargeSeenAndIgnoredBecause too many: " + numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList[i]);
5360
}
@@ -59,11 +66,13 @@ protected override string StringForOutput
5966

6067
#region Internal Methods
6168

62-
internal void Add(int calibrationRound, int numMs1MassChargeCombinationsConsidered, int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, int count)
69+
internal void Add(int calibrationRound, int numMs1MassChargeCombinationsConsidered, int numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks, int count, int numMs2MassChargeCombinationsConsidered, int numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks)
6370
{
6471
calibrationRoundList.Add(calibrationRound);
6572
numMs1MassChargeCombinationsConsideredList.Add(numMs1MassChargeCombinationsConsidered);
6673
numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList.Add(numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
74+
numMs2MassChargeCombinationsConsideredList.Add(numMs2MassChargeCombinationsConsidered);
75+
numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaksList.Add(numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks);
6776
countList.Add(count);
6877
}
6978

InternalLogic/Calibration/MyErroredResults.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace InternalLogicCalibration
44
{
5-
internal class MyErroredResults : MyResults
5+
public class MyErroredResults : MyResults
66
{
77

88
#region Private Fields
@@ -26,7 +26,7 @@ protected override string StringForOutput
2626
{
2727
get
2828
{
29-
return v;
29+
return "\t\t" + v;
3030
}
3131
}
3232

InternalLogic/ClassicSearchEngine.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ public class ClassicSearchEngine : MyEngine
3535
private readonly int myMsDataFileNumSpectra;
3636
private readonly string fileName;
3737

38+
private readonly List<ProductType> lp;
39+
3840
#endregion Private Fields
3941

4042
#region Public Constructors
4143

42-
public ClassicSearchEngine(LocalMS2Scan[] arrayOfSortedMS2Scans, int myMsDataFileNumSpectra, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<Protein> proteinList, Tolerance productMassTolerance, Protease protease, List<SearchMode> searchModes, int maximumMissedCleavages, int maximumVariableModificationIsoforms, string fileName) : base(2)
44+
public ClassicSearchEngine(LocalMS2Scan[] arrayOfSortedMS2Scans, int myMsDataFileNumSpectra, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<Protein> proteinList, Tolerance productMassTolerance, Protease protease, List<SearchMode> searchModes, int maximumMissedCleavages, int maximumVariableModificationIsoforms, string fileName, List<ProductType> lp) : base(2)
4345
{
4446
this.arrayOfSortedMS2Scans = arrayOfSortedMS2Scans;
4547
this.myScanPrecursorMasses = arrayOfSortedMS2Scans.Select(b => b.PrecursorMass).ToArray();
@@ -53,6 +55,7 @@ public ClassicSearchEngine(LocalMS2Scan[] arrayOfSortedMS2Scans, int myMsDataFil
5355
this.searchModes = searchModes;
5456
this.protease = protease;
5557
this.fileName = fileName;
58+
this.lp = lp;
5659
}
5760

5861
#endregion Public Constructors
@@ -70,10 +73,8 @@ protected override MyResults RunSpecific()
7073
var level3_observed = new HashSet<string>();
7174
var level4_observed = new HashSet<string>();
7275

73-
var lp = new List<ProductType> { ProductType.B, ProductType.Y };
74-
7576
Status("Getting ms2 scans...");
76-
77+
7778
var outerPsms = new ClassicSpectrumMatch[searchModes.Count][];
7879
for (int aede = 0; aede < searchModes.Count; aede++)
7980
outerPsms[aede] = new ClassicSpectrumMatch[myMsDataFileNumSpectra];

InternalLogic/IndexEngine.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ public class IndexEngine : MyEngine
2626
private readonly List<MorpheusModification> localizeableModifications;
2727
private readonly InitiatorMethionineBehavior initiatorMethionineBehavior;
2828

29+
private readonly List<ProductType> lp;
30+
2931
#endregion Private Fields
3032

3133
#region Public Constructors
3234

33-
public IndexEngine(List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, InitiatorMethionineBehavior initiatorMethionineBehavior, int maximumMissedCleavages, int maximumVariableModificationIsoforms) : base(2)
35+
public IndexEngine(List<Protein> proteinList, List<MorpheusModification> variableModifications, List<MorpheusModification> fixedModifications, List<MorpheusModification> localizeableModifications, Protease protease, InitiatorMethionineBehavior initiatorMethionineBehavior, int maximumMissedCleavages, int maximumVariableModificationIsoforms, List<ProductType> lp) : base(2)
3436
{
3537
this.proteinList = proteinList;
3638
this.variableModifications = variableModifications;
@@ -40,6 +42,7 @@ public IndexEngine(List<Protein> proteinList, List<MorpheusModification> variabl
4042
this.initiatorMethionineBehavior = initiatorMethionineBehavior;
4143
this.maximumMissedCleavages = maximumMissedCleavages;
4244
this.maximumVariableModificationIsoforms = maximumVariableModificationIsoforms;
45+
this.lp = lp;
4346
}
4447

4548
#endregion Public Constructors
@@ -70,7 +73,6 @@ protected override MyResults RunSpecific()
7073
var level4_observed = new HashSet<string>();
7174
int proteinsSeen = 0;
7275
int old_progress = 0;
73-
var lp = new List<ProductType> { ProductType.B, ProductType.Y };
7476
Parallel.ForEach(Partitioner.Create(0, totalProteins), fff =>
7577
{
7678
var myInnerDictionary = new Dictionary<float, List<int>>(100000);

InternalLogic/MyEngine.cs

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ protected MyEngine(int Level)
6262

6363
public static event EventHandler<StringEventArgs> OutLabelStatusHandler;
6464

65+
public static event EventHandler<StringEventArgs> WarnHandler;
66+
6567
public static event EventHandler<ProgressEventArgs> OutProgressHandler;
6668

6769
#endregion Public Events
@@ -105,6 +107,11 @@ public MyResults Run()
105107

106108
#region Protected Methods
107109

110+
protected void Warn(string v)
111+
{
112+
WarnHandler?.Invoke(this, new StringEventArgs(v));
113+
}
114+
108115
protected void Status(string v)
109116
{
110117
OutLabelStatusHandler?.Invoke(this, new StringEventArgs(v));

InternalLogic/PSMwithProteinHashSet.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using MassSpectrometry;
33
using OldInternalLogic;
44
using Spectra;
5-
using System;
65
using System.Collections.Generic;
76
using System.Globalization;
87
using System.Linq;
@@ -21,7 +20,7 @@ public class PSMwithProteinHashSet
2120

2221
#region Public Constructors
2322

24-
public PSMwithProteinHashSet(ParentSpectrumMatch newPsm, HashSet<PeptideWithSetModifications> peptidesWithSetModifications, Tolerance fragmentTolerance, IMsDataFile<IMzSpectrum<MzPeak>> myMsDataFile)
23+
public PSMwithProteinHashSet(ParentSpectrumMatch newPsm, HashSet<PeptideWithSetModifications> peptidesWithSetModifications, Tolerance fragmentTolerance, IMsDataFile<IMzSpectrum<MzPeak>> myMsDataFile, List<ProductType> lp)
2524
{
2625
this.newPsm = newPsm;
2726
IsDecoy = peptidesWithSetModifications.Any(b => b.Protein.IsDecoy);
@@ -30,14 +29,13 @@ public PSMwithProteinHashSet(ParentSpectrumMatch newPsm, HashSet<PeptideWithSetM
3029

3130
var representative = peptidesWithSetModifications.First();
3231

33-
var allProductTypes = new List<ProductType> { ProductType.B, ProductType.Y };
3432
IMsDataScan<IMzSpectrum<MzPeak>> theScan;
3533
if (myMsDataFile != null && newPsm.matchedIonsList == null)
3634
{
3735
theScan = myMsDataFile.GetOneBasedScan(newPsm.scanNumber);
3836

3937
var MatchedIonDict = new Dictionary<ProductType, double[]>();
40-
foreach (var huh in allProductTypes)
38+
foreach (var huh in lp)
4139
{
4240
var df = representative.FastSortedProductMasses(new List<ProductType> { huh });
4341
double[] matchedIonList = new double[df.Length];
@@ -56,7 +54,7 @@ public PSMwithProteinHashSet(ParentSpectrumMatch newPsm, HashSet<PeptideWithSetM
5654
{
5755
PeptideWithSetModifications localizedPeptide = representative.Localize(indexToLocalize, ScanPrecursorMass - representative.MonoisotopicMass);
5856

59-
var gg = localizedPeptide.FastSortedProductMasses(allProductTypes);
57+
var gg = localizedPeptide.FastSortedProductMasses(lp);
6058
double[] matchedIonList = new double[gg.Length];
6159
var score = MatchIons(theScan, fragmentTolerance, gg, matchedIonList);
6260
localizedScores.Add(score);

0 commit comments

Comments
 (0)