Skip to content

Commit ec571a3

Browse files
added no peak picking flag to ignore the thermo native peak picking
1 parent fe5ed21 commit ec571a3

6 files changed

Lines changed: 84 additions & 90 deletions

File tree

MainClass.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Main(string[] args)
2626
var verbose = false;
2727
string bucketName = null;
2828
var ignoreInstrumentErrors = false;
29-
var alwaysUseProfileData = false;
29+
var noPeakPicking = false;
3030

3131
var help = false;
3232

@@ -46,7 +46,7 @@ public static void Main(string[] args)
4646
},
4747
{
4848
"f=|format=",
49-
"The output format for the spectra (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet, 4 for MGF with profile data excluded)",
49+
"The output format for the spectra (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet)",
5050
v => outputFormatString = v
5151
},
5252
{
@@ -56,6 +56,19 @@ public static void Main(string[] args)
5656
{
5757
"g|gzip", "GZip the output file if this flag is specified (without value).",
5858
v => gzip = v != null
59+
},
60+
{
61+
"p|noPeakPicking",
62+
"Don't use the peak picking provided by the native thermo library (by default peak picking is enabled)",
63+
v => noPeakPicking = v != null
64+
},
65+
{
66+
"v|verbose", "Enable verbose logging.",
67+
v => verbose = v != null
68+
},
69+
{
70+
"e|ignoreInstrumentErrors", "Ignore missing properties by the instrument.",
71+
v => ignoreInstrumentErrors = v != null
5972
},
6073
{
6174
"u:|s3_url:",
@@ -76,20 +89,7 @@ public static void Main(string[] args)
7689
"n:|s3_bucketName:",
7790
"S3 bucket name",
7891
v => bucketName = v
79-
},
80-
{
81-
"v|verbose", "Enable verbose logging.",
82-
v => verbose = v != null
83-
},
84-
{
85-
"e|ignoreInstrumentErrors", "Ignore missing properties by the instrument.",
86-
v => ignoreInstrumentErrors = v != null
87-
},
88-
{
89-
"p|profile",
90-
"Always use profile data, even though in some profile scans centroided data is available.",
91-
v => alwaysUseProfileData = v != null
92-
}
92+
}
9393
};
9494

9595
try
@@ -125,7 +125,7 @@ public static void Main(string[] args)
125125
catch (FormatException e)
126126
{
127127
throw new OptionException(
128-
"unknown output format value (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet, 4 for MGF with profile date excluded)",
128+
"unknown output format value (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet)",
129129
"-f, --format");
130130
}
131131

@@ -137,7 +137,7 @@ public static void Main(string[] args)
137137
else
138138
{
139139
throw new OptionException(
140-
"unknown output format value (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet, 4 for MGF with profile date excluded)",
140+
"unknown output format value (0 for MGF, 1 for mzMl, 2 for indexed mzML, 3 for Parquet)",
141141
"-f, --format");
142142
}
143143
}
@@ -197,7 +197,7 @@ public static void Main(string[] args)
197197
}
198198

199199
var parseInput = new ParseInput(rawFilePath, outputDirectory, outputFormat, gzip, outputMetadataFormat,
200-
s3url, s3AccessKeyId, s3SecretAccessKey, bucketName, ignoreInstrumentErrors, alwaysUseProfileData);
200+
s3url, s3AccessKeyId, s3SecretAccessKey, bucketName, ignoreInstrumentErrors, noPeakPicking);
201201
RawFileParser.Parse(parseInput);
202202
}
203203
catch (Exception ex)

OutputFormat.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public enum OutputFormat
66
MzML,
77
IndexMzML,
88
Parquet,
9-
MGFNoProfileData,
109
NONE
1110
}
1211

ParseInput.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public class ParseInput
5050

5151
public bool IgnoreInstrumentErrors { get; }
5252

53-
public bool AlwaysUseProfileData { get; }
53+
public bool NoPeakPicking { get; }
5454

5555
private string bucketName;
5656

5757
public ParseInput(string rawFilePath, string outputDirectory, OutputFormat outputFormat, bool gzip,
5858
MetadataFormat outputMetadata, string s3url, string s3AccessKeyId,
5959
string s3SecretAccessKey, string bucketName,
60-
bool ignoreInstrumentErrors, bool alwaysUseProfileData
60+
bool ignoreInstrumentErrors, bool noPeakPicking
6161
)
6262
{
6363
RawFilePath = rawFilePath;
@@ -73,7 +73,7 @@ public ParseInput(string rawFilePath, string outputDirectory, OutputFormat outpu
7373
S3SecretAccessKey = s3SecretAccessKey;
7474
this.bucketName = bucketName;
7575
IgnoreInstrumentErrors = ignoreInstrumentErrors;
76-
AlwaysUseProfileData = alwaysUseProfileData;
76+
NoPeakPicking = noPeakPicking;
7777

7878
if (S3url != null && S3AccessKeyId != null && S3SecretAccessKey != null && bucketName != null)
7979
InitializeS3Bucket();

RawFileParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public static void Parse(ParseInput parseInput)
8383
switch (parseInput.OutputFormat)
8484
{
8585
case OutputFormat.MGF:
86-
case OutputFormat.MGFNoProfileData:
8786
spectrumWriter = new MgfSpectrumWriter(parseInput);
8887
spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber);
8988
break;
@@ -98,6 +97,7 @@ public static void Parse(ParseInput parseInput)
9897
break;
9998
}
10099
}
100+
101101
Log.Info("Finished parsing " + parseInput.RawFilePath);
102102
}
103103
}

Writer/MgfSpectrumWriter.cs

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,86 +74,82 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
7474
goto default;
7575
}
7676
default:
77-
if (scanEvent.ScanData == ScanDataType.Centroid ||
78-
(scanEvent.ScanData == ScanDataType.Profile &&
79-
(scan.HasCentroidStream ||
80-
ParseInput.OutputFormat != OutputFormat.MGFNoProfileData)))
81-
{
82-
Writer.WriteLine("BEGIN IONS");
83-
Writer.WriteLine($"TITLE={ConstructSpectrumTitle(scanNumber)}");
84-
Writer.WriteLine($"SCANS={scanNumber}");
85-
Writer.WriteLine(
86-
$"RTINSECONDS={(time * 60).ToString(CultureInfo.InvariantCulture)}");
77+
Writer.WriteLine("BEGIN IONS");
78+
Writer.WriteLine($"TITLE={ConstructSpectrumTitle(scanNumber)}");
79+
Writer.WriteLine($"SCANS={scanNumber}");
80+
Writer.WriteLine(
81+
$"RTINSECONDS={(time * 60).ToString(CultureInfo.InvariantCulture)}");
8782

88-
if (reaction != null)
89-
{
90-
var precursorMass = reaction.PrecursorMass;
91-
Writer.WriteLine("PEPMASS=" +
92-
precursorMass.ToString("0.0000000",
93-
CultureInfo.InvariantCulture));
94-
//var precursorIntensity = 0.0;
95-
//GetPrecursorIntensity(rawFile, _precursorScanNumber, precursorMass);
96-
//Writer.WriteLine(precursorIntensity != null
97-
// ? $"PEPMASS={precursorMass:F7} {precursorIntensity}"
98-
// : $"PEPMASS={precursorMass:F7}");
99-
}
83+
if (reaction != null)
84+
{
85+
var precursorMass = reaction.PrecursorMass;
86+
Writer.WriteLine("PEPMASS=" +
87+
precursorMass.ToString("0.0000000",
88+
CultureInfo.InvariantCulture));
89+
//var precursorIntensity = 0.0;
90+
//GetPrecursorIntensity(rawFile, _precursorScanNumber, precursorMass);
91+
//Writer.WriteLine(precursorIntensity != null
92+
// ? $"PEPMASS={precursorMass:F7} {precursorIntensity}"
93+
// : $"PEPMASS={precursorMass:F7}");
94+
}
10095

101-
// trailer extra data list
102-
var trailerData = rawFile.GetTrailerExtraInformation(scanNumber);
103-
for (var i = 0; i < trailerData.Length; i++)
96+
// trailer extra data list
97+
var trailerData = rawFile.GetTrailerExtraInformation(scanNumber);
98+
for (var i = 0; i < trailerData.Length; i++)
99+
{
100+
if (trailerData.Labels[i] == "Charge State:")
104101
{
105-
if (trailerData.Labels[i] == "Charge State:")
102+
if (Convert.ToInt32(trailerData.Values[i]) > 0)
106103
{
107-
if (Convert.ToInt32(trailerData.Values[i]) > 0)
108-
{
109-
Writer.WriteLine($"CHARGE={trailerData.Values[i]}+");
110-
}
104+
Writer.WriteLine($"CHARGE={trailerData.Values[i]}+");
111105
}
112106
}
107+
}
113108

114-
// write the filter string
115-
//Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}");
109+
// write the filter string
110+
//Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}");
116111

117-
// Check if the scan has a centroid stream
118-
if (scan.HasCentroidStream)
119-
{
120-
var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
121-
if (scan.CentroidScan.Length > 0)
122-
{
123-
for (var i = 0; i < centroidStream.Length; i++)
124-
{
125-
Writer.WriteLine(
126-
centroidStream.Masses[i].ToString("0.0000000",
127-
CultureInfo.InvariantCulture)
128-
+ " "
129-
+ centroidStream.Intensities[i].ToString("0.0000000",
130-
CultureInfo.InvariantCulture));
131-
}
132-
}
133-
}
134-
// Otherwise take the profile data
135-
else
112+
// Check if the scan has a centroid stream
113+
if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
114+
(scanEvent.ScanData == ScanDataType.Profile &&
115+
!ParseInput.NoPeakPicking)))
116+
{
117+
var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
118+
if (scan.CentroidScan.Length > 0)
136119
{
137-
// Get the scan statistics from the RAW file for this scan number
138-
var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
139-
140-
// Get the segmented (low res and profile) scan data
141-
var segmentedScan =
142-
rawFile.GetSegmentedScanFromScanNumber(scanNumber, scanStatistics);
143-
for (var i = 0; i < segmentedScan.Positions.Length; i++)
120+
for (var i = 0; i < centroidStream.Length; i++)
144121
{
145122
Writer.WriteLine(
146-
segmentedScan.Positions[i].ToString("0.0000000",
123+
centroidStream.Masses[i].ToString("0.0000000",
147124
CultureInfo.InvariantCulture)
148125
+ " "
149-
+ segmentedScan.Intensities[i].ToString("0.0000000000",
126+
+ centroidStream.Intensities[i].ToString("0.0000000",
150127
CultureInfo.InvariantCulture));
151128
}
152129
}
130+
}
131+
// Otherwise take the profile data
132+
else
133+
{
134+
// Get the scan statistics from the RAW file for this scan number
135+
var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
153136

154-
Writer.WriteLine("END IONS");
137+
// Get the segmented (low res and profile) scan data
138+
var segmentedScan =
139+
rawFile.GetSegmentedScanFromScanNumber(scanNumber, scanStatistics);
140+
for (var i = 0; i < segmentedScan.Positions.Length; i++)
141+
{
142+
Writer.WriteLine(
143+
segmentedScan.Positions[i].ToString("0.0000000",
144+
CultureInfo.InvariantCulture)
145+
+ " "
146+
+ segmentedScan.Intensities[i].ToString("0.0000000000",
147+
CultureInfo.InvariantCulture));
148+
}
155149
}
156150

151+
Writer.WriteLine("END IONS");
152+
157153
break;
158154
}
159155
}

Writer/MzMlSpectrumWriter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,10 @@ private SpectrumType ConstructSpectrum(int scanNumber)
968968
double? highestObservedMz = null;
969969
double[] masses = null;
970970
double[] intensities = null;
971-
if (scan.HasCentroidStream){
972-
// if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
973-
// (scanEvent.ScanData == ScanDataType.Profile &&
974-
// !ParseInput.AlwaysUseProfileData)))
975-
// {
971+
if (scan.HasCentroidStream && (scanEvent.ScanData == ScanDataType.Centroid ||
972+
(scanEvent.ScanData == ScanDataType.Profile &&
973+
!ParseInput.NoPeakPicking)))
974+
{
976975
var centroidStream = _rawFile.GetCentroidStream(scanNumber, false);
977976
if (scan.CentroidScan.Length > 0)
978977
{

0 commit comments

Comments
 (0)