-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCLIHelper.java
More file actions
272 lines (240 loc) · 11.8 KB
/
Copy pathCLIHelper.java
File metadata and controls
272 lines (240 loc) · 11.8 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package gred.nucleus.cli;
import gred.nucleus.files.Directory;
import gred.nucleus.files.OutputTextFile;
import gred.nucleus.mains.Version;
import org.apache.commons.cli.HelpFormatter;
/** Class to generate helper */
public final class CLIHelper {
private CLIHelper() {
// DO NOTHING
}
/**
* Main method
*
* @param args command line arguments
*/
public static void run(String[] args) {
if (args.length == 2) {
specificAction(args[1]);
} else {
cmdHelpFull();
}
}
/**
* Method get help for command line with example command line
*/
private static void cmdHelpFull() {
String exampleCommand = "java -jar nucleusj-" + Version.get() + ".jar ";
String exampleArgument = "-action segmentation " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ ";
String[] exampleCMD = exampleArgument.split(" ");
CLIActionOptionCmdLine command = new CLIActionOptionCmdLine(exampleCMD);
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + " " + exampleArgument + "\n\n");
String exampleArgumentOMERO = "-omero " +
"-action segmentation " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ " +
"-hostname omero-server-address " +
"-port 0 " +
"-group 000";
String[] exampleOMEROCMD = exampleArgumentOMERO.split(" ");
CLIActionOptionOMERO commandOMERO = new CLIActionOptionOMERO(exampleOMEROCMD);
formatter.printHelp("NucleusJ3 OMERO MODE: ", commandOMERO.getOptions());
System.console().writer().println("\nCommand line example : \n\n" +
exampleCommand + " " + exampleArgumentOMERO);
System.exit(1);
}
/**
* Helper for specific action.
*
* @param action action
*/
private static void specificAction(String action) {
String exampleCommand = "java -jar nucleusj-" + Version.get() + ".jar ";
String exampleArgument;
String[] exampleCMD;
HelpFormatter formatter;
CLIActionOptionCmdLine command;
switch (action) {
case "segmentation":
exampleArgument = "-action segmentation " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 segmentation cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
String exampleArgumentOMERO = "-omero " +
"-action segmentation " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ " +
"-hostname omero-server-address " +
"-port 0 " +
"-group 000";
String[] exampleOMEROCMD = exampleArgumentOMERO.split(" ");
CLIActionOptionOMERO commandOMERO = new CLIActionOptionOMERO(exampleOMEROCMD);
formatter.printHelp("NucleusJ3 segmentation OMERO MODE: ", commandOMERO.getOptions());
System.console().writer().println("\nCommand line example : \n\n" +
exampleCommand + " " + exampleArgumentOMERO);
break;
case "autocrop":
exampleArgument = "-action autocrop " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 autocrop cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
exampleArgumentOMERO = "-omero " +
"-action autocrop " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ " +
"-hostname omero-server-address " +
"-port 0 " +
"-group 000";
exampleOMEROCMD = exampleArgumentOMERO.split(" ");
commandOMERO = new CLIActionOptionOMERO(exampleOMEROCMD);
formatter.printHelp("NucleusJ3 autocrop OMERO MODE: ", commandOMERO.getOptions());
System.console().writer().println("\nCommand line example : \n\n" +
exampleCommand + exampleArgumentOMERO);
break;
case "computeParameters":
exampleArgument = "-action computeParameters " +
"-input path/to/raw/image/folder/ " +
"-input2 path/to/segmented/image/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 computeParameters cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
break;
case "computeParametersDL":
exampleArgument = "-action computeParametersDL " +
"-input path/to/raw/image/folder/ " +
"-input2 path/to/segmented/image/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 computeParametersDL cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
break;
case "generateProjection":
exampleArgument = "-action generateProjection " +
"-input path/to/coordinate/file/folder/ " +
"-input2 path/to/raw/image/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 generateProjection cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
break;
case "generateProjectionFiltered":
exampleArgument = "-action generateProjectionFiltered " +
"-input path/to/coordinate/file/folder/ " +
"-input2 path/to/segmented/image/folder/ " +
"-input3 path/to/ZProjection/folder/";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 generateProjectionFiltered cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
break;
case "CropFromCoordinate":
exampleArgument = "-action CropFromCoordinate " +
"-input path/to/coordinate/file/folder/ ";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 CropFromCoordinate cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
break;
case "GenerateOverlay":
exampleArgument = "-action GenerateOverlay " +
"-input path/to/input/zprojection/ " +
"-input2 path/to/input/dic_images/";
exampleCMD = exampleArgument.split(" ");
command = new CLIActionOptionCmdLine(exampleCMD);
formatter = new HelpFormatter();
formatter.printHelp("NucleusJ3 GenerateOverlay cli : ", command.getOptions());
System.console().writer().println("\nCommand line example : \n" +
exampleCommand + exampleArgument + "\n\n");
exampleArgumentOMERO = "-omero " +
"-action GenerateOverlay " +
"-input ZProjection_dataset_ID " +
"-input2 DIC_dataset_ID " +
"-output output_project_ID " +
"-port 0 " +
"-group 000";
exampleOMEROCMD = exampleArgumentOMERO.split(" ");
commandOMERO = new CLIActionOptionOMERO(exampleOMEROCMD);
formatter.printHelp("NucleusJ3 GenerateOverlay OMERO MODE: ", commandOMERO.getOptions());
System.console().writer().println("\nCommand line example : \n\n" +
exampleCommand + exampleArgumentOMERO);
///
break;
case "configFileExample":
String autocropConfigOption = "xCropBoxSize:40\n" +
"yCropBoxSize:40\n" +
"zCropBoxSize:20\n" +
"minVolumeNucleus:1\n" +
"maxVolumeNucleus:2147483647\n" +
"thresholdOTSUComputing:20\n" +
"channelToComputeThreshold:0\n" +
"slicesOTSUComputing:0\n" +
"boxesPercentSurfaceToFilter:50\n" +
"boxesRegrouping:10\n" +
"xCal:1\n" +
"yCal:1\n" +
"zCal:1";
String segConfigOption =
"thresholdOTSUComputing:20\n" +
"ConvexHullDetection:true\n" +
"xCal:1\n" +
"yCal:1\n" +
"zCal:1";
System.console().writer().println("Two config file with default parameters generate: \n");
saveFile(autocropConfigOption, "autocropConfigListParameters");
saveFile(segConfigOption, "segmentationConfigListParameters");
System.console().writer().println("autocrop parameters details: " +
"https://github.com/GReD-Clermont/NucleusJ/wiki/Autocrop#list-of-available-parameters \n" +
"segmentation parameters details: " +
"https://github.com/GReD-Clermont/NucleusJ/wiki/Autocrop#list-of-available-parameters");
break;
default:
exampleArgument = "-action segmentation " +
"-input path/to/input/folder/ " +
"-output path/to/output/folder/ ";
exampleCMD = exampleArgument.split(" ");
CLIActionOptions wrongAction = new CLIActionOptions(exampleCMD);
System.console().writer().println("Invalid action \"" + action + "\" :\n");
System.console().writer().println(CLIActionOptions.getHelperInfo());
break;
}
}
/**
* Save information use to save config file parameter example.
*
* @param text text to save
* @param fileName file name
*/
public static void saveFile(String text, String fileName) {
Directory dirOutput = new Directory(System.getProperty("user.dir"));
OutputTextFile resultFileOutputOTSU = new OutputTextFile(dirOutput.getDirPath() +
dirOutput.getSeparator() +
fileName);
resultFileOutputOTSU.saveTextFile(text, true);
}
}