Skip to content

Commit 9c28cd5

Browse files
committed
Error codes for xic
1 parent 3d899ea commit 9c28cd5

File tree

7 files changed

+66
-13
lines changed

7 files changed

+66
-13
lines changed

MainClass.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private static void XicParametersParsing(string[] args)
9393
"s|stdout",
9494
"Pipes the output into standard output. Logging is being turned off.",
9595
v => parameters.stdout = v != null
96+
},
97+
{
98+
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
99+
v => parameters.Vigilant = v != null
96100
}
97101
};
98102

@@ -207,9 +211,10 @@ private static void XicParametersParsing(string[] args)
207211
try
208212
{
209213
// execute the xic commands
210-
XicExecutor.run(parameters);
214+
XicExecutor.Run(parameters);
211215

212-
exitCode = 0;
216+
Log.Info($"Processing completed {parameters.Errors} errors, {parameters.Warnings} warnings");
217+
exitCode = parameters.Vigilant ? parameters.Errors + parameters.Warnings : parameters.Errors;
213218
}
214219
catch (Exception ex)
215220
{

Query/ProxiSpectrumReader.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public List<ProxiSpectrum> Retrieve()
8484
value: ((int) scanFilter.MSOrder).ToString(CultureInfo.InvariantCulture));
8585

8686
// trailer extra data list
87-
//TODO Switch to Trailer object; check for empty trailerst
8887
ScanTrailer trailerData;
8988
try
9089
{

ThermoRawFileParserTest/XicReaderTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public void testXicReadFullRange()
3232
}
3333
}
3434
};
35-
XicReader.ReadXic(testRawFile, false, xicData);
35+
36+
XicParameters xicparams = new XicParameters();
37+
38+
XicReader.ReadXic(testRawFile, false, xicData, ref xicparams);
3639
XicUnit xicUnit = xicData.Content[0];
3740
Assert.AreEqual(14, ((Array) xicUnit.RetentionTimes).Length);
3841
Assert.AreEqual(14, ((Array) xicUnit.Intensities).Length);
@@ -63,7 +66,10 @@ public void testXicRead()
6366
}
6467
}
6568
};
66-
XicReader.ReadXic(testRawFile, false, xicData);
69+
70+
XicParameters xicparams = new XicParameters();
71+
72+
XicReader.ReadXic(testRawFile, false, xicData, ref xicparams);
6773
XicUnit xicUnit = xicData.Content[0];
6874
Assert.AreEqual(46, ((Array) xicUnit.RetentionTimes).Length);
6975
Assert.AreEqual(46, ((Array) xicUnit.Intensities).Length);
@@ -89,7 +95,7 @@ public void testXicRead()
8995
}
9096
}
9197
};
92-
XicReader.ReadXic(testRawFile, false, xicData);
98+
XicReader.ReadXic(testRawFile, false, xicData, ref xicparams);
9399
xicUnit = xicData.Content[0];
94100
Assert.AreEqual(1, ((Array) xicUnit.RetentionTimes).Length);
95101
Assert.AreEqual(1, ((Array) xicUnit.Intensities).Length);

XIC/XicExecutor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ThermoRawFileParser.XIC
99
{
1010
public static class XicExecutor
1111
{
12-
public static void run(XicParameters parameters)
12+
public static void Run(XicParameters parameters)
1313
{
1414
var jsonString = File.ReadAllText(parameters.jsonFilePath, Encoding.UTF8);
1515
var validationErrors = JSONParser.ValidateJson(jsonString);
@@ -35,7 +35,7 @@ public static void run(XicParameters parameters)
3535
foreach (string rawFile in parameters.rawFileList)
3636
{
3737
var dataInstance = new XicData(xicData);
38-
XicReader.ReadXic(rawFile, parameters.base64, dataInstance);
38+
XicReader.ReadXic(rawFile, parameters.base64, dataInstance, ref parameters);
3939

4040
if (parameters.stdout)
4141
{

XIC/XicParameters.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace ThermoRawFileParser.XIC
44
{
55
public class XicParameters
66
{
7+
private int _errors;
8+
private int _warnings;
9+
710
public bool help { get; set; }
811
public ArrayList rawFileList { get; set; }
912
public string jsonFilePath { get; set; }
@@ -12,7 +15,10 @@ public class XicParameters
1215
public string outputFileName { get; set; }
1316
public bool base64 { get; set; }
1417
public bool stdout { get; set; }
18+
public bool Vigilant { get; set; }
19+
public int Errors { get => _errors; }
1520

21+
public int Warnings { get => _warnings; }
1622

1723
public XicParameters()
1824
{
@@ -24,6 +30,19 @@ public XicParameters()
2430
outputFileName = null;
2531
base64 = false;
2632
stdout = false;
33+
Vigilant = false;
34+
_errors = 0;
35+
_warnings = 0;
36+
}
37+
38+
public void NewError()
39+
{
40+
_errors++;
41+
}
42+
43+
public void NewWarn()
44+
{
45+
_warnings++;
2746
}
2847

2948

@@ -42,6 +61,9 @@ public XicParameters(XicParameters copy)
4261
outputFileName = copy.outputFileName;
4362
base64 = copy.base64;
4463
stdout = copy.stdout;
64+
Vigilant = copy.Vigilant;
65+
_errors = copy.Errors;
66+
_warnings = copy.Warnings;
4567
}
4668
}
4769
}

XIC/XicReader.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.IO;
44
using System.Reflection;
55
using log4net;
6-
using NUnit.Framework.Internal;
76
using ThermoFisher.CommonCore.Data;
87
using ThermoFisher.CommonCore.Data.Business;
98
using ThermoFisher.CommonCore.Data.Interfaces;
@@ -17,7 +16,7 @@ public class XicReader
1716

1817
private const string MsFilter = "ms";
1918

20-
public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
19+
public static void ReadXic(string rawFilePath, bool base64, XicData xicData, ref XicParameters parameters)
2120
{
2221
IRawDataPlus rawFile;
2322
using (rawFile = RawFileReaderFactory.ReadFile(rawFilePath))
@@ -126,17 +125,28 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
126125
{
127126
Log.Warn(
128127
$"Only the minimum or maximum retention time was returned. This is an indication that the provided retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}] lies outside the max. window [{startTime}-{endTime}]");
128+
parameters.NewWarn();
129129
}
130130
}
131131
else
132132
{
133133
Log.Warn(
134134
$"No scans found in retention time range [{xicUnit.Meta.RtStart}-{xicUnit.Meta.RtEnd}]. This is an indication that the provided retention time window lies outside the max. window [{startTime}-{endTime}]");
135+
parameters.NewWarn();
135136
}
136137
}
137138
else
138139
{
139-
data = GetChromatogramData(rawFile, settings, firstScanNumber, lastScanNumber);
140+
try
141+
{
142+
data = GetChromatogramData(rawFile, settings, firstScanNumber, lastScanNumber);
143+
}
144+
145+
catch (Exception ex)
146+
{
147+
Log.Error($"Cannot produce XIC using {xicUnit.GetMeta()} - {ex.Message}\nDetails:\n{ex.StackTrace}");
148+
parameters.NewError();
149+
}
140150
}
141151

142152
if (data != null)
@@ -155,6 +165,11 @@ public static void ReadXic(string rawFilePath, bool base64, XicData xicData)
155165
xicUnit.Intensities = GetBase64String(chromatogramTrace[0].Intensities);
156166
}
157167
}
168+
else
169+
{
170+
Log.Warn($"Empty XIC returned by {xicUnit.GetMeta()}");
171+
parameters.NewWarn();
172+
}
158173
}
159174
}
160175
}
@@ -171,11 +186,12 @@ private static IChromatogramData GetChromatogramData(IRawDataPlus rawFile, IChro
171186
}
172187
catch (InvalidFilterFormatException)
173188
{
174-
Log.Warn($"Invalid filter string {settings.Filter}");
189+
throw new RawFileParserException($"Invalid filter string \"{settings.Filter}\"");
190+
175191
}
176192
catch (InvalidFilterCriteriaException)
177193
{
178-
Log.Warn($"Invalid filter string {settings.Filter}");
194+
throw new RawFileParserException($"Invalid filter string \"{settings.Filter}\"");
179195
}
180196

181197
return data;

XIC/XicUnit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public bool HasValidRanges()
4141
return valid;
4242
}
4343

44+
public string GetMeta()
45+
{
46+
return string.Format("Filter: \"{0}\"; m/z: [{1} - {2}]; RT: [{3} - {4}]", Meta.Filter, Meta.MzStart, Meta.MzEnd, Meta.RtStart, Meta.RtEnd);
47+
}
48+
4449
public XicUnit(XicUnit copy)
4550
{
4651
Meta = new XicMeta(copy.Meta);

0 commit comments

Comments
 (0)