-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
114 lines (94 loc) · 4.3 KB
/
Copy pathProgram.cs
File metadata and controls
114 lines (94 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.IO;
using PRISM;
using PRISM.Logging;
namespace MaxQuantParamFileModExtractor
{
/// <summary>
/// Main processing class
/// </summary>
internal static class Program
{
// Ignore Spelling: Conf, Quant
public const string PROGRAM_DATE = "July 2, 2026";
public static int Main(string[] args)
{
var programName = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Name;
var exePath = AppUtils.GetAppPath();
var exeName = Path.GetFileName(exePath);
var parser = new CommandLineParser<ModExtractorOptions>(programName, GetAppVersion())
{
ProgramInfo = ConsoleMsgUtils.WrapParagraph(
"This program parses a MaxQuant parameter file (XML-based) to extract the nodes that define static and dynamic mods. " +
"Alternatively, it can be used to add/remove/replace parameters in a MaxQuant parameter file created by an older version of MaxQuant."),
ContactInfo = "Program written by Matthew Monroe for PNNL (Richland, WA)" + Environment.NewLine +
"E-mail: matthew.monroe@pnnl.gov or proteomics@pnnl.gov" + Environment.NewLine +
"Website: https://github.com/PNNL-Comp-Mass-Spec/ or https://www.pnnl.gov/integrative-omics"
};
// ReSharper disable StringLiteralTypo
parser.UsageExamples.Add(exeName + " MaxQuant_Tryp_Stat_CysAlk_Dyn_MetOx_NTermAcet_20ppmParTol.xml");
parser.UsageExamples.Add(exeName + " MaxQuant_Tryp_Stat_CysAlk_Dyn_MetOx_NTermAcet_20ppmParTol.xml /Update");
parser.UsageExamples.Add(exeName + " /I:MaxQuant*.xml");
parser.UsageExamples.Add(exeName + " /I:MaxQuant*.xml /Update");
// ReSharper restore StringLiteralTypo
// The default argument name for parameter files is /ParamFile or -ParamFile
// Also allow /Conf or /P
parser.AddParamFileKey("Conf");
parser.AddParamFileKey("P");
var result = parser.ParseArgs(args);
var options = result.ParsedResults;
if (!result.Success || !options.Validate())
{
if (parser.CreateParamFileProvided)
{
return 0;
}
// Delay for 750 msec in case the user double-clicked this file from within Windows Explorer (or started the program via a shortcut)
System.Threading.Thread.Sleep(750);
return -1;
}
try
{
var extractor = new MaxQuantModExtractor(options);
RegisterEvents(extractor);
var success = extractor.ProcessFile(options.InputFilePath);
if (success)
{
return 0;
}
return -1;
}
catch (Exception ex)
{
ConsoleMsgUtils.ShowError("Error occurred in Program->Main", ex);
return -1;
}
}
private static string GetAppVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + " (" + PROGRAM_DATE + ")";
}
/// <summary>Use this method to chain events between classes</summary>
/// <param name="sourceClass"></param>
private static void RegisterEvents(IEventNotifier sourceClass)
{
// Ignore: sourceClass.DebugEvent += OnDebugEvent;
sourceClass.StatusEvent += OnStatusEvent;
sourceClass.ErrorEvent += OnErrorEvent;
sourceClass.WarningEvent += OnWarningEvent;
// Ignore: sourceClass.ProgressUpdate += OnProgressUpdate;
}
private static void OnErrorEvent(string message, Exception ex)
{
ConsoleMsgUtils.ShowError(message, ex);
}
private static void OnStatusEvent(string message)
{
Console.WriteLine(message);
}
private static void OnWarningEvent(string message)
{
ConsoleMsgUtils.ShowWarning(message);
}
}
}