Skip to content

Commit

Permalink
Ordinal and fix decon tools
Browse files Browse the repository at this point in the history
* Ordinal

* noice
  • Loading branch information
stefanks authored Oct 16, 2017
1 parent ef28b76 commit 824c9d5
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 197 deletions.
2 changes: 1 addition & 1 deletion MS1decon/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
8 changes: 6 additions & 2 deletions MS1decon/MS1decon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>MS1Decon</RootNamespace>
<AssemblyName>MS1Decon</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -40,7 +40,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -73,6 +73,10 @@
<Project>{B208FF5F-5A33-490D-9DDB-7C76F5600FC4}</Project>
<Name>MzLibUtil</Name>
</ProjectReference>
<ProjectReference Include="..\MzML\MzML.csproj">
<Project>{012434FB-88A9-4DEC-B887-5F64C0B481D4}</Project>
<Name>MzML</Name>
</ProjectReference>
<ProjectReference Include="..\Spectra\Spectra.csproj">
<Project>{088E4FCB-D580-4BAD-A811-A1796A7666D2}</Project>
<Name>Spectra</Name>
Expand Down
186 changes: 9 additions & 177 deletions MS1decon/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Chemistry;
using Fclp;
using Fclp;
using IO.MzML;
using IO.Thermo;
using MassSpectrometry;
using MzLibUtil;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -21,177 +19,7 @@ private static void Main(string[] args)
{
Loaders.LoadElements("elements.dat");

if (args.Length > 0)
{
DoFileDecon(args);
}
else { DeconTest(); }
}

private static void DeconTest()
{
List<string> files = new List<string>
{
//@"C:\Users\stepa\Desktop\Decon\04-29-13_B6_Frac5_4uL.raw",
//@"C:\Users\stepa\Desktop\Decon\12-10-16_A17A_yeast_BU_fract9_rep1_8uL.raw",
@"C:\Users\stepa\Desktop\Decon\120426_Jurkat_highLC_Frac17.raw",
//@"C:\Users\stepa\Desktop\Decon\07-26-17_YL_150mins_steeper-grad_yeast.raw",
//@"C:\Users\stepa\Desktop\Decon\07-28-17_19_rep2_mouse.raw",
//@"C:\Users\stepa\Desktop\Decon\09-01-17_iodo_1-4th_rep1_human.raw",
};

var sameMassTolerancePpm = new PpmTolerance(10);

var intensityRatio = 5;
var deconvolutionTolerancePpm = 20;
var maxAssumedChargeState = 10;

Tolerance deconvolutionTolerance = new PpmTolerance(deconvolutionTolerancePpm);

foreach (var file in files)
{
Console.WriteLine(file);
ThermoStaticData a = ThermoStaticData.LoadAllStaticData(file);
//ThermoDynamicData a = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Desktop\Decon\09-01-17_iodo_1-4th_rep1_human.raw");

using (StreamWriter output = new StreamWriter(@"unmatched.tsv"))
{
output.WriteLine("Scan\tmatchToNewMinusMM\tmatchToNewPlusMM\tThermoMass");

//Console.WriteLine("intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState: " + (intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState));

//int goodScans = 0;

int numMatchToOnlyOld = 0;
int numMatchToOnlyNew = 0;
int numMatchToBoth = 0;
int numScansWithThermoMasses = 0;

int numMatchToOld = 0;
int numMatchToOldPlusMM = 0;
int numMatchToOldMinusMM = 0;
int numMatchToNew = 0;
int numMatchToNewPlusMM = 0;
int numMatchToNewMinusMM = 0;

//output.WriteLine("Scan\tType");
foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().Where(b => b.OneBasedScanNumber == 447))
//foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().Skip(2000))
//foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
{
double thermoMz = double.NaN;
if (ok.SelectedIonChargeStateGuess.HasValue)
{
thermoMz = ok.SelectedIonMZ;
if (ok.SelectedIonMonoisotopicGuessMz.HasValue)
thermoMz = ok.SelectedIonMonoisotopicGuessMz.Value;
//output.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + thermoMz.ToString("G6"));
//output.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value).ToString("G6"));
}
else
{
//output.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + " ");
//output.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + " ");
}

var precursorSpectrum = a.GetOneBasedScan(ok.OneBasedPrecursorScanNumber.Value).MassSpectrum;

var oldResults = ok.GetIsolatedMassesAndChargesOld(precursorSpectrum, maxAssumedChargeState, deconvolutionTolerance, intensityRatio).OrderBy(b => b.Item1.First().Mz.ToMass(b.Item2)).ToList();

//output.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMzs\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToString("G6"))));
//output.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMasses\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToMass(b.Item2).ToString("G6"))));

var newResults = ok.GetIsolatedMassesAndCharges(precursorSpectrum, maxAssumedChargeState, deconvolutionTolerancePpm, intensityRatio).OrderBy(b => b.monoisotopicMass).ToList();

//output.WriteLine(ok.OneBasedScanNumber + "\tNewLowestObservedMzs\t" + string.Join("\t", newResults.Select(b => b.peaks.OrderBy(c => c.Item1).First().Item1.ToString("G6"))));
//output.WriteLine(ok.OneBasedScanNumber + "\tNewMonoisotopicMasses\t" + string.Join("\t", newResults.Select(b => b.monoisotopicMass.ToString("G6"))));

if (ok.SelectedIonChargeStateGuess.HasValue)
{
numScansWithThermoMasses++;
var thermoMass = thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value);
bool matchToOld = false;
bool matchToNew = false;
bool matchToOldPlusMM = false;
bool matchToNewPlusMM = false;
bool matchToOldMinusMM = false;
bool matchToNewMinusMM = false;
foreach (var hm in oldResults)
{
if (sameMassTolerancePpm.Within(hm.Item1.First().Mz.ToMass(hm.Item2), thermoMass))
{
matchToOld = true;
}
if (sameMassTolerancePpm.Within(hm.Item1.First().Mz.ToMass(hm.Item2) + 1.0029, thermoMass))
{
matchToOldPlusMM = true;
}
if (sameMassTolerancePpm.Within(hm.Item1.First().Mz.ToMass(hm.Item2) - 1.0029, thermoMass))
{
matchToOldMinusMM = true;
}
}
foreach (var hm in newResults)
{
if (sameMassTolerancePpm.Within(hm.monoisotopicMass, thermoMass))
{
matchToNew = true;
}
if (sameMassTolerancePpm.Within(hm.monoisotopicMass + 1.0029, thermoMass))
{
matchToNewPlusMM = true;
}
if (sameMassTolerancePpm.Within(hm.monoisotopicMass - 1.0029, thermoMass))
{
matchToNewMinusMM = true;
}
}
numMatchToOld += matchToOld ? 1 : 0;
numMatchToOldPlusMM += matchToOldPlusMM ? 1 : 0;
numMatchToOldMinusMM += matchToOldMinusMM ? 1 : 0;
numMatchToNew += matchToNew ? 1 : 0;
numMatchToNewPlusMM += matchToNewPlusMM ? 1 : 0;
numMatchToNewMinusMM += matchToNewMinusMM ? 1 : 0;
if (matchToOld && !matchToNew)
numMatchToOnlyOld++;
if (matchToNew && !matchToOld)
numMatchToOnlyNew++;
if (matchToOld && matchToNew)
numMatchToBoth++;

if (!matchToNew)
{
output.WriteLine(ok.OneBasedScanNumber + "\t" + matchToNewMinusMM + "\t" + matchToNewPlusMM + "\t" + thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value).ToString("G6") + "\t" + string.Join("\t", newResults.Select(b => b.monoisotopicMass)));
}
//if (matchToOld && !matchToNew && thermoMz > 500)
//{
// Console.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + thermoMz.ToString("G6"));
// Console.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value).ToString("G6"));
// Console.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMzs\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToString("G6"))));
// Console.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMasses\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToMass(b.Item2).ToString("G6"))));
// Console.WriteLine(ok.OneBasedScanNumber + "\tNewLowestObservedMzs\t" + string.Join("\t", newResults.Select(b => b.peaks.OrderBy(c => c.Item1).First().Item1.ToString("G6"))));
// Console.WriteLine(ok.OneBasedScanNumber + "\tNewMonoisotopicMasses\t" + string.Join("\t", newResults.Select(b => b.monoisotopicMass.ToString("G6"))));

//}
//else
//{
// Console.WriteLine(ok.OneBasedScanNumber + " good ");
}
}

Console.WriteLine("numMatchToOld: " + numMatchToOld);
Console.WriteLine("numMatchToOldPlusMM: " + numMatchToOldPlusMM);
Console.WriteLine("numMatchToOldMinusMM: " + numMatchToOldMinusMM);
Console.WriteLine("numMatchToNew: " + numMatchToNew);
Console.WriteLine("numMatchToNewPlusMM: " + numMatchToNewPlusMM);
Console.WriteLine("numMatchToNewMinusMM: " + numMatchToNewMinusMM);

Console.WriteLine("numMatchToOnlyOld: " + numMatchToOnlyOld);
Console.WriteLine("numMatchToOnlyNew: " + numMatchToOnlyNew);
Console.WriteLine("numMatchToBoth: " + numMatchToBoth);
Console.WriteLine("numScansWithThermoMasses: " + numScansWithThermoMasses);
}
}
DoFileDecon(args);
}

private static void DoFileDecon(string[] args)
Expand Down Expand Up @@ -227,12 +55,16 @@ private static void DoFileDecon(string[] args)

if (result.HasErrors == false)
{
ThermoStaticData a = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);
IMsDataFile<IMsDataScan<IMzSpectrum<IMzPeak>>> myMsDataFile;
if (Path.GetExtension(p.Object.FilePath).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
myMsDataFile = Mzml.LoadAllStaticData(p.Object.FilePath);
else
myMsDataFile = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);

using (StreamWriter output = new StreamWriter(@"DeconvolutionOutput-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) + ".tsv"))
{
output.WriteLine("Mass\tNumPeaks\tNumScans\tMinScan\tMaxScan\tAverageElutionTime\tIntensity\tObservedCharges\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");
foreach (var nice in a.Deconvolute(p.Object.MinScan, p.Object.MaxScan, p.Object.MaxAssumedChargeState, p.Object.DeconvolutionTolerancePpm, p.Object.IntensityRatioLimit, p.Object.AggregationTolerancePpm, b => b.MsnOrder == 1).OrderByDescending(b => b.TotalIntensity))
foreach (var nice in myMsDataFile.Deconvolute(p.Object.MinScan, p.Object.MaxScan, p.Object.MaxAssumedChargeState, p.Object.DeconvolutionTolerancePpm, p.Object.IntensityRatioLimit, p.Object.AggregationTolerancePpm, b => b.MsnOrder == 1).OrderByDescending(b => b.TotalIntensity))
{
output.WriteLine(nice.OneLineString());
}
Expand Down
2 changes: 1 addition & 1 deletion MS1decon/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentCommandLineParser" version="1.4.3" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
2 changes: 1 addition & 1 deletion MS2decon/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
8 changes: 6 additions & 2 deletions MS2decon/MS2decon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>MS2decon</RootNamespace>
<AssemblyName>MS2decon</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -40,7 +40,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -65,6 +65,10 @@
<Project>{B208FF5F-5A33-490D-9DDB-7C76F5600FC4}</Project>
<Name>MzLibUtil</Name>
</ProjectReference>
<ProjectReference Include="..\MzML\MzML.csproj">
<Project>{012434FB-88A9-4DEC-B887-5F64C0B481D4}</Project>
<Name>MzML</Name>
</ProjectReference>
<ProjectReference Include="..\Spectra\Spectra.csproj">
<Project>{088E4FCB-D580-4BAD-A811-A1796A7666D2}</Project>
<Name>Spectra</Name>
Expand Down
9 changes: 7 additions & 2 deletions MS2decon/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Fclp;
using IO.MzML;
using IO.Thermo;
using MassSpectrometry;
using System;
Expand Down Expand Up @@ -47,13 +48,17 @@ private static void Main(string[] args)

if (result.HasErrors == false)
{
ThermoStaticData a = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);
IMsDataFile<IMsDataScan<IMzSpectrum<IMzPeak>>> myMsDataFile;
if (Path.GetExtension(p.Object.FilePath).Equals(".mzML", StringComparison.OrdinalIgnoreCase))
myMsDataFile = Mzml.LoadAllStaticData(p.Object.FilePath);
else
myMsDataFile = ThermoStaticData.LoadAllStaticData(p.Object.FilePath);

using (StreamWriter output = new StreamWriter(@"MS2DeconvolutionOutput-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) + ".tsv"))
{
output.WriteLine("Mass\tNumPeaks\tNumScans\tMinScan\tMaxScan\tAverageElutionTime\tIntensity\tObservedCharges\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");

foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
foreach (var ok in myMsDataFile.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
{
if ((!p.Object.MinScan.HasValue || ok.OneBasedScanNumber >= p.Object.MinScan) && (!p.Object.MaxScan.HasValue || ok.OneBasedScanNumber <= p.Object.MaxScan))
{
Expand Down
2 changes: 1 addition & 1 deletion MS2decon/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentCommandLineParser" version="1.4.3" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
2 changes: 1 addition & 1 deletion ManagedThermoHelperLayer/ClassLibrary1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Keyword>ManagedCProj</Keyword>
<RootNamespace>ClassLibrary1</RootNamespace>
<ProjectName>ManagedThermoHelperLayer</ProjectName>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
Expand Down
2 changes: 1 addition & 1 deletion MzLibUtil/Tolerance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected Tolerance(double value)
public static Tolerance ParseToleranceString(string s)
{
Match m = StringRegex.Match(s);
if (m.Groups[3].Value.Equals("PPM", StringComparison.InvariantCultureIgnoreCase))
if (m.Groups[3].Value.Equals("PPM", StringComparison.OrdinalIgnoreCase))
return new PpmTolerance(double.Parse(m.Groups[2].Value));
else
return new AbsoluteTolerance(double.Parse(m.Groups[2].Value));
Expand Down
Loading

0 comments on commit 824c9d5

Please sign in to comment.