Skip to content

Commit f116a85

Browse files
committed
Add stdout option
1 parent e1894e2 commit f116a85

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

MainClass.cs

Lines changed: 19 additions & 3 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 mzML if no format is specified.",
@@ -474,8 +479,7 @@ private static void RegularParametersParsing(string[] args)
474479
{
475480
var helpMessage =
476481
$"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);
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; }
@@ -112,6 +114,7 @@ public ParseInput()
112114
IgnoreInstrumentErrors = false;
113115
AllDetectors = false;
114116
MsLevel = allLevels;
117+
StdOut = false;
115118
}
116119

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

RawFileParser.cs

Lines changed: 31 additions & 22 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>

Writer/SpectrumWriter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ protected SpectrumWriter(ParseInput parseInput)
5555
/// <param name="extension">The extension of the output file</param>
5656
protected void ConfigureWriter(string extension)
5757
{
58+
if (ParseInput.StdOut)
59+
{
60+
Writer = new StreamWriter(Console.OpenStandardOutput());
61+
Writer.AutoFlush = true;
62+
return;
63+
}
64+
5865
if (ParseInput.OutputFile == null)
5966
{
6067
var fullExtension = ParseInput.Gzip ? extension + ".gzip" : extension;

0 commit comments

Comments
 (0)