1
- using Chemistry ;
2
- using Fclp ;
1
+ using Fclp ;
2
+ using IO . MzML ;
3
3
using IO . Thermo ;
4
4
using MassSpectrometry ;
5
- using MzLibUtil ;
6
5
using System ;
7
- using System . Collections . Generic ;
8
6
using System . Globalization ;
9
7
using System . IO ;
10
8
using System . Linq ;
@@ -21,177 +19,7 @@ private static void Main(string[] args)
21
19
{
22
20
Loaders . LoadElements ( "elements.dat" ) ;
23
21
24
- if ( args . Length > 0 )
25
- {
26
- DoFileDecon ( args ) ;
27
- }
28
- else { DeconTest ( ) ; }
29
- }
30
-
31
- private static void DeconTest ( )
32
- {
33
- List < string > files = new List < string >
34
- {
35
- //@"C:\Users\stepa\Desktop\Decon\04-29-13_B6_Frac5_4uL.raw",
36
- //@"C:\Users\stepa\Desktop\Decon\12-10-16_A17A_yeast_BU_fract9_rep1_8uL.raw",
37
- @"C:\Users\stepa\Desktop\Decon\120426_Jurkat_highLC_Frac17.raw" ,
38
- //@"C:\Users\stepa\Desktop\Decon\07-26-17_YL_150mins_steeper-grad_yeast.raw",
39
- //@"C:\Users\stepa\Desktop\Decon\07-28-17_19_rep2_mouse.raw",
40
- //@"C:\Users\stepa\Desktop\Decon\09-01-17_iodo_1-4th_rep1_human.raw",
41
- } ;
42
-
43
- var sameMassTolerancePpm = new PpmTolerance ( 10 ) ;
44
-
45
- var intensityRatio = 5 ;
46
- var deconvolutionTolerancePpm = 20 ;
47
- var maxAssumedChargeState = 10 ;
48
-
49
- Tolerance deconvolutionTolerance = new PpmTolerance ( deconvolutionTolerancePpm ) ;
50
-
51
- foreach ( var file in files )
52
- {
53
- Console . WriteLine ( file ) ;
54
- ThermoStaticData a = ThermoStaticData . LoadAllStaticData ( file ) ;
55
- //ThermoDynamicData a = ThermoDynamicData.InitiateDynamicConnection(@"C:\Users\stepa\Desktop\Decon\09-01-17_iodo_1-4th_rep1_human.raw");
56
-
57
- using ( StreamWriter output = new StreamWriter ( @"unmatched.tsv" ) )
58
- {
59
- output . WriteLine ( "Scan\t matchToNewMinusMM\t matchToNewPlusMM\t ThermoMass" ) ;
60
-
61
- //Console.WriteLine("intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState: " + (intensityRatio, deconvolutionTolerancePpm, maxAssumedChargeState));
62
-
63
- //int goodScans = 0;
64
-
65
- int numMatchToOnlyOld = 0 ;
66
- int numMatchToOnlyNew = 0 ;
67
- int numMatchToBoth = 0 ;
68
- int numScansWithThermoMasses = 0 ;
69
-
70
- int numMatchToOld = 0 ;
71
- int numMatchToOldPlusMM = 0 ;
72
- int numMatchToOldMinusMM = 0 ;
73
- int numMatchToNew = 0 ;
74
- int numMatchToNewPlusMM = 0 ;
75
- int numMatchToNewMinusMM = 0 ;
76
-
77
- //output.WriteLine("Scan\tType");
78
- foreach ( var ok in a . OfType < IMsDataScanWithPrecursor < IMzSpectrum < IMzPeak > > > ( ) . Where ( b => b . OneBasedScanNumber == 447 ) )
79
- //foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().Skip(2000))
80
- //foreach (var ok in a.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>())
81
- {
82
- double thermoMz = double . NaN ;
83
- if ( ok . SelectedIonChargeStateGuess . HasValue )
84
- {
85
- thermoMz = ok . SelectedIonMZ ;
86
- if ( ok . SelectedIonMonoisotopicGuessMz . HasValue )
87
- thermoMz = ok . SelectedIonMonoisotopicGuessMz . Value ;
88
- //output.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + thermoMz.ToString("G6"));
89
- //output.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value).ToString("G6"));
90
- }
91
- else
92
- {
93
- //output.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + " ");
94
- //output.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + " ");
95
- }
96
-
97
- var precursorSpectrum = a . GetOneBasedScan ( ok . OneBasedPrecursorScanNumber . Value ) . MassSpectrum ;
98
-
99
- var oldResults = ok . GetIsolatedMassesAndChargesOld ( precursorSpectrum , maxAssumedChargeState , deconvolutionTolerance , intensityRatio ) . OrderBy ( b => b . Item1 . First ( ) . Mz . ToMass ( b . Item2 ) ) . ToList ( ) ;
100
-
101
- //output.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMzs\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToString("G6"))));
102
- //output.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMasses\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToMass(b.Item2).ToString("G6"))));
103
-
104
- var newResults = ok . GetIsolatedMassesAndCharges ( precursorSpectrum , maxAssumedChargeState , deconvolutionTolerancePpm , intensityRatio ) . OrderBy ( b => b . monoisotopicMass ) . ToList ( ) ;
105
-
106
- //output.WriteLine(ok.OneBasedScanNumber + "\tNewLowestObservedMzs\t" + string.Join("\t", newResults.Select(b => b.peaks.OrderBy(c => c.Item1).First().Item1.ToString("G6"))));
107
- //output.WriteLine(ok.OneBasedScanNumber + "\tNewMonoisotopicMasses\t" + string.Join("\t", newResults.Select(b => b.monoisotopicMass.ToString("G6"))));
108
-
109
- if ( ok . SelectedIonChargeStateGuess . HasValue )
110
- {
111
- numScansWithThermoMasses ++ ;
112
- var thermoMass = thermoMz . ToMass ( ok . SelectedIonChargeStateGuess . Value ) ;
113
- bool matchToOld = false ;
114
- bool matchToNew = false ;
115
- bool matchToOldPlusMM = false ;
116
- bool matchToNewPlusMM = false ;
117
- bool matchToOldMinusMM = false ;
118
- bool matchToNewMinusMM = false ;
119
- foreach ( var hm in oldResults )
120
- {
121
- if ( sameMassTolerancePpm . Within ( hm . Item1 . First ( ) . Mz . ToMass ( hm . Item2 ) , thermoMass ) )
122
- {
123
- matchToOld = true ;
124
- }
125
- if ( sameMassTolerancePpm . Within ( hm . Item1 . First ( ) . Mz . ToMass ( hm . Item2 ) + 1.0029 , thermoMass ) )
126
- {
127
- matchToOldPlusMM = true ;
128
- }
129
- if ( sameMassTolerancePpm . Within ( hm . Item1 . First ( ) . Mz . ToMass ( hm . Item2 ) - 1.0029 , thermoMass ) )
130
- {
131
- matchToOldMinusMM = true ;
132
- }
133
- }
134
- foreach ( var hm in newResults )
135
- {
136
- if ( sameMassTolerancePpm . Within ( hm . monoisotopicMass , thermoMass ) )
137
- {
138
- matchToNew = true ;
139
- }
140
- if ( sameMassTolerancePpm . Within ( hm . monoisotopicMass + 1.0029 , thermoMass ) )
141
- {
142
- matchToNewPlusMM = true ;
143
- }
144
- if ( sameMassTolerancePpm . Within ( hm . monoisotopicMass - 1.0029 , thermoMass ) )
145
- {
146
- matchToNewMinusMM = true ;
147
- }
148
- }
149
- numMatchToOld += matchToOld ? 1 : 0 ;
150
- numMatchToOldPlusMM += matchToOldPlusMM ? 1 : 0 ;
151
- numMatchToOldMinusMM += matchToOldMinusMM ? 1 : 0 ;
152
- numMatchToNew += matchToNew ? 1 : 0 ;
153
- numMatchToNewPlusMM += matchToNewPlusMM ? 1 : 0 ;
154
- numMatchToNewMinusMM += matchToNewMinusMM ? 1 : 0 ;
155
- if ( matchToOld && ! matchToNew )
156
- numMatchToOnlyOld ++ ;
157
- if ( matchToNew && ! matchToOld )
158
- numMatchToOnlyNew ++ ;
159
- if ( matchToOld && matchToNew )
160
- numMatchToBoth ++ ;
161
-
162
- if ( ! matchToNew )
163
- {
164
- 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 ) ) ) ;
165
- }
166
- //if (matchToOld && !matchToNew && thermoMz > 500)
167
- //{
168
- // Console.WriteLine(ok.OneBasedScanNumber + "\tThermoMz\t" + thermoMz.ToString("G6"));
169
- // Console.WriteLine(ok.OneBasedScanNumber + "\tThermoMass\t" + thermoMz.ToMass(ok.SelectedIonChargeStateGuess.Value).ToString("G6"));
170
- // Console.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMzs\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToString("G6"))));
171
- // Console.WriteLine(ok.OneBasedScanNumber + "\tOldMonoisotopicMasses\t" + string.Join("\t", oldResults.Select(b => b.Item1.First().Mz.ToMass(b.Item2).ToString("G6"))));
172
- // Console.WriteLine(ok.OneBasedScanNumber + "\tNewLowestObservedMzs\t" + string.Join("\t", newResults.Select(b => b.peaks.OrderBy(c => c.Item1).First().Item1.ToString("G6"))));
173
- // Console.WriteLine(ok.OneBasedScanNumber + "\tNewMonoisotopicMasses\t" + string.Join("\t", newResults.Select(b => b.monoisotopicMass.ToString("G6"))));
174
-
175
- //}
176
- //else
177
- //{
178
- // Console.WriteLine(ok.OneBasedScanNumber + " good ");
179
- }
180
- }
181
-
182
- Console . WriteLine ( "numMatchToOld: " + numMatchToOld ) ;
183
- Console . WriteLine ( "numMatchToOldPlusMM: " + numMatchToOldPlusMM ) ;
184
- Console . WriteLine ( "numMatchToOldMinusMM: " + numMatchToOldMinusMM ) ;
185
- Console . WriteLine ( "numMatchToNew: " + numMatchToNew ) ;
186
- Console . WriteLine ( "numMatchToNewPlusMM: " + numMatchToNewPlusMM ) ;
187
- Console . WriteLine ( "numMatchToNewMinusMM: " + numMatchToNewMinusMM ) ;
188
-
189
- Console . WriteLine ( "numMatchToOnlyOld: " + numMatchToOnlyOld ) ;
190
- Console . WriteLine ( "numMatchToOnlyNew: " + numMatchToOnlyNew ) ;
191
- Console . WriteLine ( "numMatchToBoth: " + numMatchToBoth ) ;
192
- Console . WriteLine ( "numScansWithThermoMasses: " + numScansWithThermoMasses ) ;
193
- }
194
- }
22
+ DoFileDecon ( args ) ;
195
23
}
196
24
197
25
private static void DoFileDecon ( string [ ] args )
@@ -227,12 +55,16 @@ private static void DoFileDecon(string[] args)
227
55
228
56
if ( result . HasErrors == false )
229
57
{
230
- ThermoStaticData a = ThermoStaticData . LoadAllStaticData ( p . Object . FilePath ) ;
58
+ IMsDataFile < IMsDataScan < IMzSpectrum < IMzPeak > > > myMsDataFile ;
59
+ if ( Path . GetExtension ( p . Object . FilePath ) . Equals ( ".mzML" , StringComparison . OrdinalIgnoreCase ) )
60
+ myMsDataFile = Mzml . LoadAllStaticData ( p . Object . FilePath ) ;
61
+ else
62
+ myMsDataFile = ThermoStaticData . LoadAllStaticData ( p . Object . FilePath ) ;
231
63
232
64
using ( StreamWriter output = new StreamWriter ( @"DeconvolutionOutput-" + DateTime . Now . ToString ( "yyyy-MM-dd-HH-mm-ss" , CultureInfo . InvariantCulture ) + ".tsv" ) )
233
65
{
234
66
output . WriteLine ( "Mass\t NumPeaks\t NumScans\t MinScan\t MaxScan\t AverageElutionTime\t Intensity\t ObservedCharges\t MostIntenseCharge\t MostIntenseMz\t NumPeaksInMostIntenseEnvelope" ) ;
235
- 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 ) )
67
+ 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 ) )
236
68
{
237
69
output . WriteLine ( nice . OneLineString ( ) ) ;
238
70
}
0 commit comments