Skip to content

Commit

Permalink
Output ObservedCharges
Browse files Browse the repository at this point in the history
* uhuh

* Make shared reading

* fix

* fixup

* uuuh

* fixup

* packages

* packages

* rename

* Update README.md

* gloff

* gaahf

* gahh

* gaaah

* sdafdsfasdf

* cool

* gahh

* gahh

* What

* Whatwhat

* glahaha

* ah

* hmhm

* aha!

* glaahj

* gloof

* aha
  • Loading branch information
stefanks authored Oct 2, 2017
1 parent 1ac95f5 commit 7f3739d
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 121 deletions.
231 changes: 119 additions & 112 deletions ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,136 +54,143 @@ private static void DeconTest()
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(@"output.tsv"))
//{
//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 >= 8356))
//foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().Skip(2000))
foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
using (StreamWriter output = new StreamWriter(@"unmatched.tsv"))
{
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;
output.WriteLine("Scan\tmatchToNewMinusMM\tmatchToNewPlusMM\tThermoMass");

var oldResults = ok.GetIsolatedMassesAndChargesOld(precursorSpectrum, maxAssumedChargeState, deconvolutionTolerance, intensityRatio).OrderBy(b => b.Item1.First().Mz.ToMass(b.Item2)).ToList();
//Console.WriteLine("intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState: " + (intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState));

//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"))));
//int goodScans = 0;

var newResults = ok.GetIsolatedMassesAndCharges(precursorSpectrum, maxAssumedChargeState, deconvolutionTolerancePpm, intensityRatio).OrderBy(b => b.monoisotopicMass).ToList();
int numMatchToOnlyOld = 0;
int numMatchToOnlyNew = 0;
int numMatchToBoth = 0;
int numScansWithThermoMasses = 0;

//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"))));
int numMatchToOld = 0;
int numMatchToOldPlusMM = 0;
int numMatchToOldMinusMM = 0;
int numMatchToNew = 0;
int numMatchToNewPlusMM = 0;
int numMatchToNewMinusMM = 0;

if (ok.SelectedIonChargeStateGuess.HasValue)
//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>>>())
{
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)
double thermoMz = double.NaN;
if (ok.SelectedIonChargeStateGuess.HasValue)
{
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;
}
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"));
}
foreach (var hm in newResults)
else
{
if (sameMassTolerancePpm.Within(hm.monoisotopicMass, thermoMass))
//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)
{
matchToNew = true;
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;
}
}
if (sameMassTolerancePpm.Within(hm.monoisotopicMass + 1.0029, thermoMass))
foreach (var hm in newResults)
{
matchToNewPlusMM = true;
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;
}
}
if (sameMassTolerancePpm.Within(hm.monoisotopicMass - 1.0029, thermoMass))
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)
{
matchToNewMinusMM = true;
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 ");
}
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 (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);
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);
}
}
}

Expand Down Expand Up @@ -224,7 +231,7 @@ private static void DoFileDecon(string[] args)

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\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");
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))
{
output.WriteLine(nice.OneLineString());
Expand Down
2 changes: 1 addition & 1 deletion MS2decon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void Main(string[] args)

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\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");
output.WriteLine("Mass\tNumPeaks\tNumScans\tMinScan\tMaxScan\tAverageElutionTime\tIntensity\tObservedCharges\tMostIntenseCharge\tMostIntenseMz\tNumPeaksInMostIntenseEnvelope");

foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
{
Expand Down
2 changes: 2 additions & 0 deletions MassSpectrometry/DeconvolutionFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal class DeconvolutionFeature

public IsotopicEnvelope MostIntenseEnvelope { get { return isotopicEnvelopes.OrderByDescending(b => b.totalIntensity).First(); } }

public IEnumerable<int> AllCharges { get { return isotopicEnvelopes.Select(b => b.charge).ToList(); } }

#endregion Public Properties

#region Public Methods
Expand Down
Loading

0 comments on commit 7f3739d

Please sign in to comment.