Skip to content

Commit 6176160

Browse files
committed
Merge branch 'Metadatakeys' into unifiedStdout
2 parents 6eeeb9f + 7055f29 commit 6176160

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

MainClass.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ private static void RegularParametersParsing(string[] args)
402402
"The metadata output file. By default the metadata file is written to the output directory.",
403403
v => parseInput.MetadataOutputFile = v
404404
},
405+
{
406+
"D=|deposition_metadata",
407+
"The path to deposition metadata output file.",
408+
v => parseInput.DepositionMetadataFile = v
409+
},
410+
{
411+
"E=|experiment_metadata",
412+
"The path to experiment metadata output file.",
413+
v => parseInput.ExperimentMetadataFile = v
414+
},
405415
{
406416
"g|gzip", "GZip the output file.",
407417
v => parseInput.Gzip = v != null
@@ -472,13 +482,13 @@ private static void RegularParametersParsing(string[] args)
472482

473483
if (!extra.IsNullOrEmpty())
474484
{
475-
throw new OptionException("unexpected extra arguments", null);
485+
throw new OptionException("Unexpected extra arguments", null);
476486
}
477487

478488
if (help)
479489
{
480490
var helpMessage =
481-
$"usage is {Assembly.GetExecutingAssembly().GetName().Name}.exe [subcommand] [options]\noptional subcommands are xic|query (use [subcommand] -h for more info]):";
491+
$"Usage is {Assembly.GetExecutingAssembly().GetName().Name}.exe [subcommand] [options]\noptional subcommands are xic|query (use [subcommand] -h for more info]):";
482492
ShowHelp(helpMessage, null, optionSet);
483493
return;
484494
}
@@ -579,6 +589,13 @@ private static void RegularParametersParsing(string[] args)
579589
parseInput.OutputFormat = OutputFormat.MzML;
580590
}
581591

592+
if (metadataFormatString != null &&
593+
(parseInput.DepositionMetadataFile != null || parseInput.ExperimentMetadataFile != null))
594+
{
595+
throw new OptionException("Metadata format key should not be combined with explicit metadata file options",
596+
"-m, --metadata, -D, -deposition_metadata, -E, --experiment_metadata");
597+
}
598+
582599
if (outputFormatString != null)
583600
{
584601
int outPutFormatInt;

ParseInput.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public string RawFilePath
6060
/// </summary>>
6161
public string MetadataOutputFile { get; set; }
6262

63+
public string DepositionMetadataFile { get; set; }
64+
65+
public string ExperimentMetadataFile { get; set; }
66+
6367
/// <summary>
6468
/// Gzip the output file.
6569
/// </summary>
@@ -96,6 +100,7 @@ public string RawFilePath
96100
/// <summary>
97101
/// The raw file name.
98102
/// </summary>
103+
//NOTE. This field does not seem to be used.
99104
private string rawFileName;
100105

101106
/// <summary>

RawFileParser.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,33 @@ private static void ProcessFile(ParseInput parseInput)
120120

121121
if (parseInput.MetadataFormat != MetadataFormat.NONE)
122122
{
123-
MetadataWriter metadataWriter;
124-
if (parseInput.MetadataOutputFile != null)
125-
{
126-
metadataWriter = new MetadataWriter(null, parseInput.MetadataOutputFile);
127-
}
128-
else
129-
{
130-
metadataWriter = new MetadataWriter(parseInput.OutputDirectory,
131-
parseInput.RawFileNameWithoutExtension);
132-
}
133-
134123
switch (parseInput.MetadataFormat)
135124
{
136125
case MetadataFormat.JSON:
137-
metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber);
126+
parseInput.DepositionMetadataFile = parseInput.MetadataOutputFile != null
127+
? parseInput.MetadataOutputFile
128+
: Path.Combine(parseInput.OutputDirectory, parseInput.RawFileNameWithoutExtension) + "-metadata.json";
138129
break;
139130
case MetadataFormat.TXT:
140-
metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber);
131+
parseInput.ExperimentMetadataFile = parseInput.MetadataOutputFile != null
132+
? parseInput.MetadataOutputFile
133+
: Path.Combine(parseInput.OutputDirectory, parseInput.RawFileNameWithoutExtension) + "-metadata.txt"; ;
141134
break;
142135
}
143136
}
144137

138+
if (parseInput.DepositionMetadataFile != null)
139+
{
140+
MetadataWriter metadataWriter = new MetadataWriter(parseInput.DepositionMetadataFile);
141+
metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber);
142+
}
143+
144+
if (parseInput.ExperimentMetadataFile != null)
145+
{
146+
MetadataWriter metadataWriter = new MetadataWriter(parseInput.ExperimentMetadataFile);
147+
metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber);
148+
}
149+
145150
if (parseInput.OutputFormat != OutputFormat.NONE)
146151
{
147152
SpectrumWriter spectrumWriter;

Writer/MetadataWriter.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ public class MetadataWriter
1414
private static readonly ILog Log =
1515
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1616

17-
private readonly string _outputDirectory;
1817
private readonly string _metadataFileName;
1918

2019
/// <summary>
2120
/// Constructor.
2221
/// </summary>
2322
/// <param name="outputDirectory"></param>
2423
/// <param name="metadataFileName"></param>
25-
public MetadataWriter(string outputDirectory, string metadataFileName)
24+
public MetadataWriter(string metadataFileName)
2625
{
27-
_outputDirectory = outputDirectory;
2826
_metadataFileName = metadataFileName;
2927
}
3028

@@ -76,24 +74,7 @@ public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastSca
7674
};
7775

7876
// Write the meta data to file
79-
string metadataOutputPath;
80-
if (_outputDirectory == null)
81-
{
82-
metadataOutputPath = _metadataFileName;
83-
}
84-
else
85-
{
86-
metadataOutputPath = _outputDirectory + "/" + _metadataFileName + "-metadata.txt";
87-
}
88-
89-
File.WriteAllLines(metadataOutputPath, output.ToArray());
90-
91-
// Write the string array to a new file named "WriteLines.txt".
92-
//using (var outputFile = new StreamWriter(metadataOutputPath))
93-
//{
94-
// foreach (var line in output)
95-
// outputFile.WriteLine(line);
96-
//}
77+
File.WriteAllLines(_metadataFileName, output.ToArray());
9778
}
9879

9980
/// <summary>
@@ -248,17 +229,7 @@ public void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int lastS
248229
var json = JsonConvert.SerializeObject(metadata);
249230
json.Replace("\r\n", "\n");
250231

251-
string metadataOutputPath;
252-
if (_outputDirectory == null)
253-
{
254-
metadataOutputPath = _metadataFileName;
255-
}
256-
else
257-
{
258-
metadataOutputPath = _outputDirectory + "/" + _metadataFileName + "-metadata.json";
259-
}
260-
261-
File.WriteAllText(metadataOutputPath, json);
232+
File.WriteAllText(_metadataFileName, json);
262233
}
263234

264235
private static CVTerm ParseActivationType(ActivationType activation)

0 commit comments

Comments
 (0)