Skip to content

Commit 3e33d12

Browse files
Merge branch 'Metadatakeys' of https://github.com/compomics/ThermoRawFileParser into Issue98
Making the JSON and TXT metadata files output the same information
2 parents f7f6baf + 7055f29 commit 3e33d12

28 files changed

+56938
-205
lines changed

MainClass.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private static void RegularParametersParsing(string[] args)
361361
h => help = h != null
362362
},
363363
{
364-
"version", "Prints out the library version.",
364+
"version", "Prints out the version of the executable.",
365365
v => version = v != null
366366
},
367367
{
@@ -383,6 +383,11 @@ private static void RegularParametersParsing(string[] args)
383383
"The output file. Specify this or an output directory -o. Specifying neither writes to the input directory.",
384384
v => parseInput.OutputFile = v
385385
},
386+
{
387+
"s|stdout",
388+
"Write to standard output. Cannot be combined with file or directory output. Implies silent logging, i.e. logging level 0",
389+
v => parseInput.StdOut = v != null
390+
},
386391
{
387392
"f=|format=",
388393
"The spectra output format: 0 for MGF, 1 for mzML, 2 for indexed mzML, 3 for Parquet. Defaults to indexed mzML if no format is specified.",
@@ -467,15 +472,14 @@ private static void RegularParametersParsing(string[] args)
467472

468473
if (!extra.IsNullOrEmpty())
469474
{
470-
throw new OptionException("unexpected extra arguments", null);
475+
throw new OptionException("Unexpected extra arguments", null);
471476
}
472477

473478
if (help)
474479
{
475480
var helpMessage =
476-
$"usage is {Assembly.GetExecutingAssembly().GetName().Name}.exe [subcommand] [options]\noptional subcommands are xic|query (use [subcommand] -h for more info]):";
477-
ShowHelp(helpMessage, null,
478-
optionSet);
481+
$"Usage is {Assembly.GetExecutingAssembly().GetName().Name}.exe [subcommand] [options]\noptional subcommands are xic|query (use [subcommand] -h for more info]):";
482+
ShowHelp(helpMessage, null, optionSet);
479483
return;
480484
}
481485

@@ -516,6 +520,13 @@ private static void RegularParametersParsing(string[] args)
516520
"-d, --input_directory");
517521
}
518522

523+
if (parseInput.StdOut && (parseInput.OutputFile != null || parseInput.OutputDirectory != null))
524+
{
525+
throw new OptionException(
526+
"standard output cannot be combined with file or directory output",
527+
"-s, --stdout");
528+
}
529+
519530
if (parseInput.OutputFile == null && parseInput.OutputDirectory == null)
520531
{
521532
if (parseInput.RawFilePath != null)
@@ -667,6 +678,11 @@ private static void RegularParametersParsing(string[] args)
667678
}
668679
}
669680

681+
if (parseInput.StdOut)
682+
{
683+
parseInput.LogFormat = LogFormat.SILENT;
684+
}
685+
670686
if (parseInput.S3Url != null && parseInput.S3AccessKeyId != null &&
671687
parseInput.S3SecretAccessKey != null && parseInput.BucketName != null)
672688
if (Uri.IsWellFormedUriString(parseInput.S3Url, UriKind.Absolute))

ParseInput.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public string RawFilePath
8181

8282
public bool MgfPrecursor { get; set; }
8383

84+
public bool StdOut { get; set; }
85+
8486
private S3Loader S3Loader { get; set; }
8587

8688
public string S3AccessKeyId { get; set; }
@@ -113,6 +115,7 @@ public ParseInput()
113115
AllDetectors = false;
114116
MsLevel = _allLevels;
115117
MgfPrecursor = false;
118+
StdOut = false;
116119
}
117120

118121
public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat

RawFileParser.cs

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,46 @@ public static void Parse(ParseInput parseInput)
3939
{
4040
parseInput.RawFilePath = filePath;
4141
Log.Info("Started parsing " + parseInput.RawFilePath);
42-
try
43-
{
44-
ProcessFile(parseInput);
45-
}
46-
catch (UnauthorizedAccessException ex)
47-
{
48-
Log.Error(!ex.Message.IsNullOrEmpty()
49-
? ex.Message
50-
: "Attempting to write to an unauthorized location.");
51-
}
52-
catch (Exception ex)
53-
{
54-
if (ex is RawFileParserException)
55-
{
56-
Log.Error(ex.Message);
57-
}
58-
else
59-
{
60-
Log.Error("An unexpected error occured while parsing file:" + parseInput.RawFilePath);
61-
Log.Error(ex.ToString());
62-
}
63-
}
42+
TryProcessFile(parseInput);
6443
}
6544
}
6645
// Input raw file mode
6746
else
6847
{
6948
Log.Info("Started parsing " + parseInput.RawFilePath);
7049

50+
TryProcessFile(parseInput);
51+
}
52+
}
53+
54+
/// <summary>
55+
/// Process and extract the given RAW file and catch IO exceptions.
56+
/// </summary>
57+
/// <param name="parseInput">the parse input object</param>
58+
private static void TryProcessFile(ParseInput parseInput)
59+
{
60+
try
61+
{
7162
ProcessFile(parseInput);
7263
}
64+
catch (UnauthorizedAccessException ex)
65+
{
66+
Log.Error(!ex.Message.IsNullOrEmpty()
67+
? ex.Message
68+
: "Attempting to write to an unauthorized location.");
69+
}
70+
catch (Exception ex)
71+
{
72+
if (ex is RawFileParserException)
73+
{
74+
Log.Error(ex.Message);
75+
}
76+
else
77+
{
78+
Log.Error("An unexpected error occured while parsing file:" + parseInput.RawFilePath);
79+
Log.Error(ex.ToString());
80+
}
81+
}
7382
}
7483

7584
/// <summary>
@@ -111,26 +120,8 @@ private static void ProcessFile(ParseInput parseInput)
111120

112121
if (parseInput.MetadataFormat != MetadataFormat.NONE)
113122
{
114-
MetadataWriter metadataWriter;
115-
if (parseInput.MetadataOutputFile != null)
116-
{
117-
metadataWriter = new MetadataWriter(null, parseInput.MetadataOutputFile);
118-
}
119-
else
120-
{
121-
metadataWriter = new MetadataWriter(parseInput.OutputDirectory,
122-
parseInput.RawFileNameWithoutExtension);
123-
}
124-
125-
switch (parseInput.MetadataFormat)
126-
{
127-
case MetadataFormat.JSON:
128-
metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber);
129-
break;
130-
case MetadataFormat.TXT:
131-
metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber);
132-
break;
133-
}
123+
MetadataWriter metadataWriter = new MetadataWriter(parseInput);
124+
metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber);
134125
}
135126

136127
if (parseInput.OutputFormat != OutputFormat.NONE)

ThermoRawFileParser.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@
217217
</ItemGroup>
218218
<ItemGroup>
219219
<None Include="App.config" />
220+
<None Include="LICENSE">
221+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
222+
</None>
220223
<None Include="packages.config" />
224+
<None Include="THERMO_LICENSE">
225+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
226+
</None>
221227
</ItemGroup>
222228
<ItemGroup>
223229
<Content Include="log4net.config">

0 commit comments

Comments
 (0)