Skip to content

Commit 2e5dbf9

Browse files
xic and spectrum refactoring
1 parent baa1b6a commit 2e5dbf9

36 files changed

Lines changed: 517 additions & 275 deletions

MainClass.cs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class MainClass
1515
private static readonly ILog Log =
1616
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
1717

18-
public const string Version = "1.1.11 ";
18+
public const string Version = "1.2.0 ";
1919

2020
public static void Main(string[] args)
2121
{
@@ -75,7 +75,7 @@ private static void XicParametersParsing(string[] args)
7575
},
7676
{
7777
"p|print_example",
78-
"Printing an examplarily json input file.",
78+
"Show a json input file example.",
7979
v => parameters.printJsonExample = v != null
8080
},
8181
{
@@ -90,7 +90,7 @@ private static void XicParametersParsing(string[] args)
9090
},
9191
{
9292
"s|stdout",
93-
"Pipes the output into standard output. Logging is being turned off",
93+
"Pipes the output into standard output. Logging is being turned off.",
9494
v => parameters.stdout = v != null
9595
}
9696
};
@@ -115,10 +115,10 @@ private static void XicParametersParsing(string[] args)
115115

116116
if (parameters.printJsonExample)
117117
{
118-
string example_json =
118+
var exampleJson =
119119
"[\n {\n \"mz\":673.363,\n \"tolerance\":10,\n \"tolerance_unit\": \"ppm\",\n },\n {\n \"mz\":867.345,\n \"tolerance\": 0.02,\n \"tolerance_unit\": \"da\",\n \"rt_start\":87.56,\n \"rt_end\":99.56\n }\n]";
120120

121-
Console.WriteLine(example_json);
121+
Console.WriteLine(exampleJson);
122122
return;
123123
}
124124

@@ -174,12 +174,12 @@ private static void XicParametersParsing(string[] args)
174174
}
175175
else
176176
{
177-
DirectoryInfo d = new DirectoryInfo(Path.GetFullPath(fileDirectory));
178-
FileInfo[] files = d.GetFiles("*", SearchOption.TopDirectoryOnly)
177+
var directoryInfo = new DirectoryInfo(Path.GetFullPath(fileDirectory));
178+
var files = directoryInfo.GetFiles("*", SearchOption.TopDirectoryOnly)
179179
.Where(f => f.Extension.ToLower() == ".raw").ToArray<FileInfo>();
180-
foreach (FileInfo file in files)
180+
foreach (var file in files)
181181
{
182-
parameters.rawFileList.Add(Path.GetFullPath(file.Name));
182+
parameters.rawFileList.Add(file.FullName);
183183
}
184184
}
185185
}
@@ -206,8 +206,9 @@ private static void XicParametersParsing(string[] args)
206206
try
207207
{
208208
// execute the xic commands
209-
XicExecutor executor = new XicExecutor(parameters);
210-
exitCode = executor.run();
209+
XicExecutor.run(parameters);
210+
211+
exitCode = 0;
211212
}
212213
catch (Exception ex)
213214
{
@@ -325,18 +326,6 @@ private static void SpectrumQueryParametersParsing(string[] args)
325326
QueryExecutor.Run(parameters);
326327
exitCode = 0;
327328
}
328-
catch (UnauthorizedAccessException ex)
329-
{
330-
Log.Error(!ex.Message.IsNullOrEmpty()
331-
? ex.Message
332-
: "Attempting to write to an unauthorized location.");
333-
}
334-
catch (Amazon.S3.AmazonS3Exception ex)
335-
{
336-
Log.Error(!ex.Message.IsNullOrEmpty()
337-
? "An Amazon S3 exception occured: " + ex.Message
338-
: "An Amazon S3 exception occured: " + ex);
339-
}
340329
catch (Exception ex)
341330
{
342331
if (ex is RawFileParserException)

ParseInput.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public string RawFilePath
9292
public ParseInput()
9393
{
9494
MetadataFormat = MetadataFormat.NONE;
95+
OutputFormat = OutputFormat.NONE;
9596
Gzip = false;
9697
NoPeakPicking = false;
9798
NoZlibCompression = false;

Query/ProxiSpectrumReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ProxiSpectrumReader
1919
private const string PositivePolarity = "+";
2020
private const string NegativePolarity = "-";
2121

22-
private QueryParameters queryParameters;
22+
private readonly QueryParameters queryParameters;
2323

2424
public ProxiSpectrumReader(QueryParameters _queryParameters)
2525
{

Query/QueryExecutor.cs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ namespace ThermoRawFileParser.Query
1010
{
1111
public class QueryExecutor
1212
{
13-
public static int Run(QueryParameters parameters)
13+
public static void Run(QueryParameters parameters)
1414
{
1515
// parse the scans string
16-
HashSet<int> scanIds = ParseScanIds(parameters.scans);
16+
var scanIds = ParseScanIds(parameters.scans);
1717
parameters.scanNumbers = scanIds;
18-
19-
ProxiSpectrumReader reader = new ProxiSpectrumReader(parameters);
20-
List<PROXISpectrum> results = reader.Retrieve();
18+
19+
var reader = new ProxiSpectrumReader(parameters);
20+
var results = reader.Retrieve();
2121

2222
if (parameters.stdout)
2323
{
2424
StdOutputQueryData(results);
2525
}
26-
else
26+
else
2727
{
2828
string outputFileName;
29+
2930
// if outputFile has been defined, put output there.
3031
if (parameters.outputFile != null)
3132
{
@@ -36,34 +37,35 @@ public static int Run(QueryParameters parameters)
3637
{
3738
outputFileName = Path.GetFullPath(parameters.rawFilePath);
3839
}
39-
string directory = Path.GetDirectoryName(outputFileName);
40-
outputFileName = Path.Combine(directory ?? throw new NoNullAllowedException(), Path.GetFileNameWithoutExtension(outputFileName) + ".JSON");
40+
41+
var directory = Path.GetDirectoryName(outputFileName);
42+
43+
outputFileName = Path.Combine(directory ?? throw new NoNullAllowedException(),
44+
Path.GetFileNameWithoutExtension(outputFileName) + ".json");
45+
4146
OutputQueryData(results, outputFileName);
4247
}
43-
return 0;
4448
}
45-
46-
47-
public static void OutputQueryData(List<PROXISpectrum> outputData, string outputFileName)
49+
50+
51+
private static void OutputQueryData(List<PROXISpectrum> outputData, string outputFileName)
4852
{
49-
string outputString = JsonConvert.SerializeObject(outputData);
53+
var outputString = JsonConvert.SerializeObject(outputData);
5054
File.WriteAllText(outputFileName, outputString);
5155
}
52-
5356

54-
public static void StdOutputQueryData(List<PROXISpectrum> outputData)
57+
58+
private static void StdOutputQueryData(List<PROXISpectrum> outputData)
5559
{
56-
string outputString = JsonConvert.SerializeObject(outputData);
60+
var outputString = JsonConvert.SerializeObject(outputData);
5761
Console.Write(outputString);
5862
}
59-
60-
61-
63+
6264

6365
private static HashSet<int> ParseScanIds(string text)
6466
{
6567
if (text.Length == 0) throw new OptionException("Scan ID string invalid, nothing specified", null);
66-
foreach (char c in text)
68+
foreach (var c in text)
6769
{
6870
int ic = c;
6971
if (!((ic == ',') || (ic == '-') || (ic == ' ') || ('0' <= ic && ic <= '9')))
@@ -72,14 +74,14 @@ private static HashSet<int> ParseScanIds(string text)
7274
}
7375
}
7476

75-
string[] tokens = text.Split(new[] {','}, StringSplitOptions.None);
77+
var tokens = text.Split(new[] {','}, StringSplitOptions.None);
7678

77-
HashSet<int> container = new HashSet<int>();
79+
var container = new HashSet<int>();
7880

79-
for (int i = 0; i < tokens.Length; ++i)
81+
for (var i = 0; i < tokens.Length; ++i)
8082
{
8183
if (tokens[i].Length == 0) throw new OptionException("Scan ID string has invalid format", null);
82-
string[] rangeBoundaries = tokens[i].Split(new[] {'-'}, StringSplitOptions.None);
84+
var rangeBoundaries = tokens[i].Split(new[] {'-'}, StringSplitOptions.None);
8385
if (rangeBoundaries.Length == 1)
8486
{
8587
int rangeStart;
@@ -108,7 +110,7 @@ private static HashSet<int> ParseScanIds(string text)
108110
throw new OptionException("Scan ID string has invalid format", null);
109111
}
110112

111-
for (int l = rangeStart; l <= rangeEnd; ++l)
113+
for (var l = rangeStart; l <= rangeEnd; ++l)
112114
{
113115
container.Add(l);
114116
}
@@ -119,4 +121,4 @@ private static HashSet<int> ParseScanIds(string text)
119121
return container;
120122
}
121123
}
122-
}
124+
}

ThermoRawFileParser.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,23 @@
8080
<HintPath>packages\MathNet.Numerics.4.8.1\lib\net461\MathNet.Numerics.dll</HintPath>
8181
<Private>True</Private>
8282
</Reference>
83+
<Reference Include="Microsoft.CSharp" />
8384
<Reference Include="Mono.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null">
8485
<HintPath>packages\Mono.Options.5.3.0.1\lib\net4-client\Mono.Options.dll</HintPath>
8586
</Reference>
8687
<Reference Include="mscorlib" />
88+
<Reference Include="Namotion.Reflection, Version=1.0.8.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102">
89+
<HintPath>packages\Namotion.Reflection.1.0.8\lib\net45\Namotion.Reflection.dll</HintPath>
90+
<Private>True</Private>
91+
</Reference>
8792
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
8893
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
8994
<Private>True</Private>
9095
</Reference>
96+
<Reference Include="NJsonSchema, Version=10.1.5.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102">
97+
<HintPath>packages\NJsonSchema.10.1.5\lib\net45\NJsonSchema.dll</HintPath>
98+
<Private>True</Private>
99+
</Reference>
91100
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
92101
<HintPath>packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
93102
<Private>True</Private>
@@ -98,6 +107,7 @@
98107
<Reference Include="System" />
99108
<Reference Include="System.ComponentModel.DataAnnotations" />
100109
<Reference Include="System.Core" />
110+
<Reference Include="System.Net" />
101111
<Reference Include="System.Numerics" />
102112
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
103113
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)