Skip to content

Commit 31d1763

Browse files
author
stefanks
authored
Merge pull request #177 from smith-chem-wisc/StefanBranch
cool
2 parents 96f078e + 17710ab commit 31d1763

21 files changed

+184
-163
lines changed

InternalLogic/Calibration/CalibrationEngine.cs

+14-18
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ private List<LabeledDataPoint> GetDataPoints(ref int numMs1MassChargeCombination
144144

145145
// Calculate isotopic distribution of the full peptide
146146

147-
var dist = new IsotopicDistribution(coolPeptide.GetChemicalFormula(), fineResolutionForIsotopeDistCalculation, 0.001);
147+
var dist = IsotopicDistribution.GetDistribution(coolPeptide.GetChemicalFormula(), fineResolutionForIsotopeDistCalculation, 0.001);
148148

149-
double[] masses = new double[dist.Masses.Count];
150-
double[] intensities = new double[dist.Intensities.Count];
151-
for (int i = 0; i < dist.Masses.Count; i++)
149+
double[] masses = new double[dist.masses.Length];
150+
double[] intensities = new double[dist.intensities.Length];
151+
for (int i = 0; i < dist.masses.Length; i++)
152152
{
153-
masses[i] = dist.Masses[i];
154-
intensities[i] = dist.Intensities[i];
153+
masses[i] = dist.masses[i];
154+
intensities[i] = dist.intensities[i];
155155
}
156156
Array.Sort(intensities, masses, Comparer<double>.Create((x, y) => y.CompareTo(x)));
157157

@@ -318,12 +318,10 @@ private void CalibrateSpectra(CalibrationFunction bestCf)
318318

319319
double newMonoisotopicMZ = monoisotopicMZ - bestCf.Predict(new double[] { -1, monoisotopicMZ, precursorScan.RetentionTime, monoisotopicIntensity, precursorScan.TotalIonCurrent, precursorScan.InjectionTime });
320320

321-
int SelectedIonGuessChargeStateGuess;
322-
a.TryGetSelectedIonGuessChargeStateGuess(out SelectedIonGuessChargeStateGuess);
323321
double IsolationMZ;
324322
a.TryGetIsolationMZ(out IsolationMZ);
325323

326-
Func<MzPeak, double> theFunc = x => x.Mz - bestCf.Predict(new double[] { 1, x.Mz, a.RetentionTime, x.Intensity, a.TotalIonCurrent, a.InjectionTime, SelectedIonGuessChargeStateGuess, IsolationMZ, (x.Mz - a.ScanWindowRange.Minimum) / (a.ScanWindowRange.Maximum - a.ScanWindowRange.Minimum) });
324+
Func<MzPeak, double> theFunc = x => x.Mz - bestCf.Predict(new double[] { 1, x.Mz, a.RetentionTime, x.Intensity, a.TotalIonCurrent, a.InjectionTime, IsolationMZ, (x.Mz - a.ScanWindowRange.Minimum) / (a.ScanWindowRange.Maximum - a.ScanWindowRange.Minimum) });
327325
a.TranformByApplyingFunctionsToSpectraAndReplacingPrecursorMZs(theFunc, newSelectedMZ, newMonoisotopicMZ);
328326
}
329327
else
@@ -451,8 +449,6 @@ private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>
451449
// Key: mz value, Value: error
452450
var addedPeaks = new Dictionary<double, double>();
453451

454-
int SelectedIonGuessChargeStateGuess;
455-
ms2DataScan.TryGetSelectedIonGuessChargeStateGuess(out SelectedIonGuessChargeStateGuess);
456452
double IsolationMZ;
457453
ms2DataScan.TryGetIsolationMZ(out IsolationMZ);
458454

@@ -484,14 +480,14 @@ private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>
484480
{
485481
if (!computedIsotopologues)
486482
{
487-
var dist = new IsotopicDistribution(fragment.ThisChemicalFormula, fineResolutionForIsotopeDistCalculation, 0.001);
483+
var dist = IsotopicDistribution.GetDistribution(fragment.ThisChemicalFormula, fineResolutionForIsotopeDistCalculation, 0.001);
488484

489-
masses = new double[dist.Masses.Count];
490-
intensities = new double[dist.Intensities.Count];
491-
for (int i = 0; i < dist.Masses.Count; i++)
485+
masses = new double[dist.masses.Length];
486+
intensities = new double[dist.intensities.Length];
487+
for (int i = 0; i < dist.masses.Length; i++)
492488
{
493-
masses[i] = dist.Masses[i];
494-
intensities[i] = dist.Intensities[i];
489+
masses[i] = dist.masses[i];
490+
intensities[i] = dist.intensities[i];
495491
}
496492
Array.Sort(intensities, masses, Comparer<double>.Create((x, y) => y.CompareTo(x)));
497493
computedIsotopologues = true;
@@ -557,7 +553,7 @@ private List<LabeledDataPoint> SearchMS2Spectrum(IMsDataScan<IMzSpectrum<MzPeak>
557553

558554
double addedMZ = trainingPointsToAverage.Select(b => b.dp.mz).Average();
559555
double relativeMZ = (addedMZ - ms2DataScan.ScanWindowRange.Minimum) / (ms2DataScan.ScanWindowRange.Maximum - ms2DataScan.ScanWindowRange.Minimum);
560-
double[] inputs = { 1, addedMZ, ms2DataScan.RetentionTime, trainingPointsToAverage.Select(b => b.dp.intensity).Average(), ms2DataScan.TotalIonCurrent, ms2DataScan.InjectionTime, SelectedIonGuessChargeStateGuess, IsolationMZ, relativeMZ };
556+
double[] inputs = { 1, addedMZ, ms2DataScan.RetentionTime, trainingPointsToAverage.Select(b => b.dp.intensity).Average(), ms2DataScan.TotalIonCurrent, ms2DataScan.InjectionTime, IsolationMZ, relativeMZ };
561557
var a = new LabeledDataPoint(inputs, trainingPointsToAverage.Select(b => b.l).Median());
562558

563559
myCandidatePoints.Add(a);

InternalLogic/GPTMDEngine.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public class GptmdEngine : MyEngine
1414
private readonly IEnumerable<Tuple<double, double>> combos;
1515
private readonly List<MorpheusModification> gptmdModifications;
1616
private readonly bool isotopeErrors;
17-
private readonly double tol;
17+
private readonly double tolInDaltons;
1818

1919
#endregion Private Fields
2020

2121
#region Public Constructors
2222

23-
public GptmdEngine(List<NewPsmWithFdr> allResultingIdentifications, bool isotopeErrors, List<MorpheusModification> gptmdModifications, IEnumerable<Tuple<double, double>> combos, double tol) : base(2)
23+
public GptmdEngine(List<NewPsmWithFdr> allResultingIdentifications, bool isotopeErrors, List<MorpheusModification> gptmdModifications, IEnumerable<Tuple<double, double>> combos, double tolInDaltons) : base(2)
2424
{
2525
this.allResultingIdentifications = allResultingIdentifications;
2626
this.isotopeErrors = isotopeErrors;
2727
this.gptmdModifications = gptmdModifications;
2828
this.combos = combos;
29-
this.tol = tol;
29+
this.tolInDaltons = tolInDaltons;
3030
}
3131

3232
#endregion Public Constructors
@@ -47,7 +47,7 @@ protected override MyResults RunSpecific()
4747
var peptide = theDict.First();
4848
var baseSequence = ye.thisPSM.BaseSequence;
4949
double massDiff = ye.thisPSM.ScanPrecursorMass - ye.thisPSM.PeptideMonoisotopicMass;
50-
foreach (MorpheusModification mod in GetMod(massDiff, isotopeErrors, gptmdModifications, combos, tol))
50+
foreach (MorpheusModification mod in GetMod(massDiff, isotopeErrors, gptmdModifications, combos, tolInDaltons))
5151
{
5252
int proteinLength = peptide.Protein.Length;
5353
var proteinAcession = peptide.Protein.Accession;
@@ -95,17 +95,17 @@ private static bool ModFits(MorpheusModification attemptToLocalize, char v1, cha
9595
return true;
9696
}
9797

98-
private static IEnumerable<MorpheusModification> GetMod(double massDiff, bool isotopeErrors, IEnumerable<MorpheusModification> allMods, IEnumerable<Tuple<double, double>> combos, double tol)
98+
private static IEnumerable<MorpheusModification> GetMod(double massDiff, bool isotopeErrors, IEnumerable<MorpheusModification> allMods, IEnumerable<Tuple<double, double>> combos, double tolInDaltons)
9999
{
100100
foreach (var Mod in allMods)
101101
{
102-
if (Mod.MonoisotopicMassShift > massDiff - tol && Mod.MonoisotopicMassShift < massDiff + tol)
102+
if (Mod.MonoisotopicMassShift > massDiff - tolInDaltons && Mod.MonoisotopicMassShift < massDiff + tolInDaltons)
103103
yield return Mod;
104-
if (isotopeErrors && Mod.MonoisotopicMassShift > massDiff - tol - 1.003 && Mod.MonoisotopicMassShift < massDiff + tol - 1.003)
104+
if (isotopeErrors && Mod.MonoisotopicMassShift > massDiff - tolInDaltons - 1.003 && Mod.MonoisotopicMassShift < massDiff + tolInDaltons - 1.003)
105105
yield return Mod;
106-
if (!double.IsNaN(Mod.AlternativeMassShift) && Mod.AlternativeMassShift > massDiff - tol && Mod.AlternativeMassShift < massDiff + tol)
106+
if (!double.IsNaN(Mod.AlternativeMassShift) && Mod.AlternativeMassShift > massDiff - tolInDaltons && Mod.AlternativeMassShift < massDiff + tolInDaltons)
107107
yield return Mod;
108-
if (!double.IsNaN(Mod.AlternativeMassShift) && isotopeErrors && Mod.AlternativeMassShift > massDiff - tol - 1.003 && Mod.AlternativeMassShift < massDiff + tol - 1.003)
108+
if (!double.IsNaN(Mod.AlternativeMassShift) && isotopeErrors && Mod.AlternativeMassShift > massDiff - tolInDaltons - 1.003 && Mod.AlternativeMassShift < massDiff + tolInDaltons - 1.003)
109109
yield return Mod;
110110
}
111111

@@ -114,18 +114,18 @@ private static IEnumerable<MorpheusModification> GetMod(double massDiff, bool is
114114
var m1 = combo.Item1;
115115
var m2 = combo.Item2;
116116
var combined = m1 + m2;
117-
if (combined > massDiff - tol && combined < massDiff + tol)
117+
if (combined > massDiff - tolInDaltons && combined < massDiff + tolInDaltons)
118118
{
119-
foreach (var mod in GetMod(m1, isotopeErrors, allMods, combos, tol))
119+
foreach (var mod in GetMod(m1, isotopeErrors, allMods, combos, tolInDaltons))
120120
yield return mod;
121-
foreach (var mod in GetMod(m2, isotopeErrors, allMods, combos, tol))
121+
foreach (var mod in GetMod(m2, isotopeErrors, allMods, combos, tolInDaltons))
122122
yield return mod;
123123
}
124-
if (isotopeErrors && combined > massDiff - tol - 1.003 && combined < massDiff + tol - 1.003)
124+
if (isotopeErrors && combined > massDiff - tolInDaltons - 1.003 && combined < massDiff + tolInDaltons - 1.003)
125125
{
126-
foreach (var mod in GetMod(m1, isotopeErrors, allMods, combos, tol))
126+
foreach (var mod in GetMod(m1, isotopeErrors, allMods, combos, tolInDaltons))
127127
yield return mod;
128-
foreach (var mod in GetMod(m2, isotopeErrors, allMods, combos, tol))
128+
foreach (var mod in GetMod(m2, isotopeErrors, allMods, combos, tolInDaltons))
129129
yield return mod;
130130
}
131131
}

InternalLogic/InternalLogicEngineLayer.csproj

+16-16
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,32 @@
3434
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3535
</PropertyGroup>
3636
<ItemGroup>
37-
<Reference Include="Chemistry, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
38-
<HintPath>..\packages\mzLib.1.0.73\lib\Chemistry.dll</HintPath>
37+
<Reference Include="Chemistry, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
38+
<HintPath>..\packages\mzLib.1.0.77\lib\Chemistry.dll</HintPath>
3939
<Private>True</Private>
4040
</Reference>
41-
<Reference Include="MassSpectrometry, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
42-
<HintPath>..\packages\mzLib.1.0.73\lib\MassSpectrometry.dll</HintPath>
41+
<Reference Include="MassSpectrometry, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
42+
<HintPath>..\packages\mzLib.1.0.77\lib\MassSpectrometry.dll</HintPath>
4343
<Private>True</Private>
4444
</Reference>
4545
<Reference Include="MathNet.Numerics, Version=3.17.0.0, Culture=neutral, processorArchitecture=MSIL">
4646
<HintPath>..\packages\MathNet.Numerics.3.17.0\lib\net40\MathNet.Numerics.dll</HintPath>
4747
<Private>True</Private>
4848
</Reference>
49-
<Reference Include="mzIdentML, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
50-
<HintPath>..\packages\mzLib.1.0.73\lib\mzIdentML.dll</HintPath>
49+
<Reference Include="mzIdentML, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
50+
<HintPath>..\packages\mzLib.1.0.77\lib\mzIdentML.dll</HintPath>
5151
<Private>True</Private>
5252
</Reference>
53-
<Reference Include="MzML, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
54-
<HintPath>..\packages\mzLib.1.0.73\lib\MzML.dll</HintPath>
53+
<Reference Include="MzML, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
54+
<HintPath>..\packages\mzLib.1.0.77\lib\MzML.dll</HintPath>
5555
<Private>True</Private>
5656
</Reference>
57-
<Reference Include="Proteomics, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
58-
<HintPath>..\packages\mzLib.1.0.73\lib\Proteomics.dll</HintPath>
57+
<Reference Include="Proteomics, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
58+
<HintPath>..\packages\mzLib.1.0.77\lib\Proteomics.dll</HintPath>
5959
<Private>True</Private>
6060
</Reference>
61-
<Reference Include="Spectra, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
62-
<HintPath>..\packages\mzLib.1.0.73\lib\Spectra.dll</HintPath>
61+
<Reference Include="Spectra, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
62+
<HintPath>..\packages\mzLib.1.0.77\lib\Spectra.dll</HintPath>
6363
<Private>True</Private>
6464
</Reference>
6565
<Reference Include="System" />
@@ -70,12 +70,12 @@
7070
<Reference Include="System.Data" />
7171
<Reference Include="System.Net.Http" />
7272
<Reference Include="System.Xml" />
73-
<Reference Include="Thermo, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
74-
<HintPath>..\packages\mzLib.1.0.73\lib\Thermo.dll</HintPath>
73+
<Reference Include="Thermo, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
74+
<HintPath>..\packages\mzLib.1.0.77\lib\Thermo.dll</HintPath>
7575
<Private>True</Private>
7676
</Reference>
77-
<Reference Include="UsefulProteomicsDatabases, Version=1.0.73.0, Culture=neutral, processorArchitecture=AMD64">
78-
<HintPath>..\packages\mzLib.1.0.73\lib\UsefulProteomicsDatabases.dll</HintPath>
77+
<Reference Include="UsefulProteomicsDatabases, Version=1.0.77.0, Culture=neutral, processorArchitecture=AMD64">
78+
<HintPath>..\packages\mzLib.1.0.77\lib\UsefulProteomicsDatabases.dll</HintPath>
7979
<Private>True</Private>
8080
</Reference>
8181
<Reference Include="Zlib.Portable, Version=1.11.0.0, Culture=neutral, processorArchitecture=MSIL">

InternalLogic/LocalMs2Scan.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace InternalLogicEngineLayer
66
{
77
public class LocalMS2Scan
88
{
9+
910
#region Public Constructors
1011

1112
public LocalMS2Scan(IMsDataScan<IMzSpectrum<MzPeak>> b)
@@ -15,9 +16,9 @@ public LocalMS2Scan(IMsDataScan<IMzSpectrum<MzPeak>> b)
1516
b.TryGetSelectedIonGuessMonoisotopicMZ(out monoisotopicPrecursorMZhere);
1617
MonoisotopicPrecursorMZ = monoisotopicPrecursorMZhere;
1718

18-
int monoisotopicPrecursorChargehere;
19+
int? monoisotopicPrecursorChargehere;
1920
b.TryGetSelectedIonGuessChargeStateGuess(out monoisotopicPrecursorChargehere);
20-
MonoisotopicPrecursorCharge = monoisotopicPrecursorChargehere;
21+
MonoisotopicPrecursorCharge = monoisotopicPrecursorChargehere.Value;
2122

2223
PrecursorMass = MonoisotopicPrecursorMZ.ToMass(MonoisotopicPrecursorCharge);
2324

InternalLogic/MyEngine.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public static IEnumerable<LocalMS2Scan> GetMs2Scans(IMsDataFile<IMzSpectrum<MzPe
8383
{
8484
foreach (var heh in myMSDataFile)
8585
{
86-
int chargeState = 0;
87-
if (heh.TryGetSelectedIonGuessChargeStateGuess(out chargeState) && chargeState > 0)
86+
int? chargeState;
87+
if (heh.TryGetSelectedIonGuessChargeStateGuess(out chargeState) && chargeState.HasValue)
8888
{
8989
yield return new LocalMS2Scan(heh);
9090
}

InternalLogic/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="MathNet.Numerics" version="3.17.0" targetFramework="net451" />
4-
<package id="mzLib" version="1.0.73" targetFramework="net451" />
4+
<package id="mzLib" version="1.0.77" targetFramework="net451" />
55
<package id="Zlib.Portable" version="1.11.0" targetFramework="net451" />
66
</packages>

InternalLogicWithFileIO/GPTMDTask/GPTMDTask.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class GptmdTask : MyTaskEngine
2121
#region Public Fields
2222

2323
public List<ModListForGPTMDTask> listOfModListsForGPTMD;
24-
public Tolerance precursorMassTolerance;
2524

2625
#endregion Public Fields
2726

@@ -45,9 +44,8 @@ public GptmdTask(ObservableCollection<ModList> modList)
4544
listOfModListsForGPTMD[2].Localize = true;
4645
listOfModListsForGPTMD[3].Gptmd = true;
4746
listOfModListsForGPTMD[4].Gptmd = true;
48-
precursorMassTolerance = new Tolerance(ToleranceUnit.PPM, 10);
4947
TaskType = MyTask.Gptmd;
50-
Tol = 0.003;
48+
TolInDaltons = 0.01;
5149
IsotopeErrors = false;
5250
MaxNumPeaksPerScan = 400;
5351
}
@@ -57,7 +55,7 @@ public GptmdTask(ObservableCollection<ModList> modList)
5755
#region Public Properties
5856

5957
public Tolerance ProductMassTolerance { get; set; }
60-
public double Tol { get; set; }
58+
public double TolInDaltons { get; set; }
6159
public bool IsotopeErrors { get; set; }
6260

6361
#endregion Public Properties
@@ -74,9 +72,8 @@ protected override string SpecificTaskInfo
7472
sb.AppendLine("Variable mod lists: " + string.Join(",", listOfModListsForGPTMD.Where(b => b.Variable).Select(b => b.FileName)));
7573
sb.AppendLine("Localized mod lists: " + string.Join(",", listOfModListsForGPTMD.Where(b => b.Localize).Select(b => b.FileName)));
7674
sb.AppendLine("GPTMD mod lists: " + string.Join(",", listOfModListsForGPTMD.Where(b => b.Gptmd).Select(b => b.FileName)));
77-
sb.AppendLine("precursorMassTolerance: " + precursorMassTolerance);
7875
sb.AppendLine("productMassTolerance: " + ProductMassTolerance);
79-
sb.Append("tol: " + Tol);
76+
sb.Append("TolInDaltons: " + TolInDaltons);
8077
return sb.ToString();
8178
}
8279
}
@@ -190,7 +187,7 @@ protected override MyResults RunSpecific()
190187
IEnumerable<Tuple<double, double>> combos = LoadCombos().ToList();
191188

192189
// Do not remove the zero!!! It's needed here
193-
SearchMode searchMode = new DotSearchMode("", gptmdModifications.Select(b => b.MonoisotopicMassShift).Concat(combos.Select(b => b.Item1 + b.Item2)).Concat(new List<double> { 0 }).OrderBy(b => b), precursorMassTolerance);
190+
SearchMode searchMode = new DotSearchMode("", gptmdModifications.Select(b => b.MonoisotopicMassShift).Concat(combos.Select(b => b.Item1 + b.Item2)).Concat(new List<double> { 0 }).OrderBy(b => b), new Tolerance(ToleranceUnit.Absolute, TolInDaltons));
194191
var searchModes = new List<SearchMode> { searchMode };
195192

196193
List<ParentSpectrumMatch>[] allPsms = new List<ParentSpectrumMatch>[1];
@@ -238,7 +235,7 @@ protected override MyResults RunSpecific()
238235
//output(analysisResults.ToString());
239236
}
240237

241-
var gptmdEngine = new GptmdEngine(analysisResults.AllResultingIdentifications[0], IsotopeErrors, gptmdModifications, combos, Tol);
238+
var gptmdEngine = new GptmdEngine(analysisResults.AllResultingIdentifications[0], IsotopeErrors, gptmdModifications, combos, TolInDaltons);
242239
var gptmdResults = (GptmdResults)gptmdEngine.Run();
243240

244241
//output(gptmdResults.ToString());

0 commit comments

Comments
 (0)