-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportGeneratorCLI.java
116 lines (100 loc) · 3.18 KB
/
ReportGeneratorCLI.java
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
package cl;
import org.pharmgkb.*;
import org.pharmgkb.exception.PgkbException;
import org.pharmgkb.util.CliHelper;
import org.pharmgkb.util.HibernateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* This class is the command line utility for generating reports based on data that's stored in the ICPC database.
*
* @author Ryan Whaley
*/
public class ReportGeneratorCLI {
private static final Logger sf_logger = LoggerFactory.getLogger(ReportGeneratorCLI.class);
private File m_outputDirectory = null;
private Integer m_project = null;
private String m_report = null;
public static void main(String args[]) {
try {
HibernateUtils.init();
ReportGeneratorCLI generator = new ReportGeneratorCLI();
generator.parseCommandLineArgs(args);
generator.make();
}
catch (Exception ex) {
sf_logger.error("Couldn't make report", ex);
System.exit(1);
}
finally {
HibernateUtils.shutdown();
}
System.exit(0);
}
private void parseCommandLineArgs(String args[]) throws Exception{
CliHelper cliHelper = new CliHelper(getClass(), false);
cliHelper.addOption("r", "report", "which report to generate: combined, gwas, fndz, or mace", "report", true);
cliHelper.addOption("d", "directory", "directory path to write to", "pathToDirectory", true);
cliHelper.addOption("p", "project", "project to output", "projectId", false);
try {
cliHelper.parse(args);
if (cliHelper.isHelpRequested()) {
cliHelper.printHelp();
System.exit(1);
}
} catch (Exception ex) {
throw new Exception("Error parsing arguments", ex);
}
if (cliHelper.hasOption("-r")) {
m_report = cliHelper.getValue("-r");
}
if (cliHelper.hasOption("-d")) {
File file = new File(cliHelper.getValue("-d"));
setOutputDirectory(file);
}
if (cliHelper.hasOption("-p")) {
setProject(cliHelper.getIntValue("-p"));
}
}
/**
* Makes the report by kicking off the {@link org.pharmgkb.CombinedDataReport} generate method and outputs to the
* specified file
* @throws PgkbException
*/
private void make() throws PgkbException {
AbstractReport report;
if (m_report.equalsIgnoreCase("combined")) {
report = new CombinedDataReport(getOutputDirectory(), getProject());
}
else if (m_report.equalsIgnoreCase("gwas")) {
report = new GwasReport(getOutputDirectory());
}
else if (m_report.equalsIgnoreCase("fndz")) {
report = new FndzReport(getOutputDirectory());
}
else if (m_report.equalsIgnoreCase("mace")) {
report = new MaceReport(getOutputDirectory());
}
else {
throw new PgkbException("No report type found for "+m_report);
}
report.generate();
}
/**
* Gets the file to output to, will be overwritten if it already exists
* @return the file to output to
*/
public File getOutputDirectory() {
return m_outputDirectory;
}
public void setOutputDirectory(File outputDirectory) {
m_outputDirectory = outputDirectory;
}
public Integer getProject() {
return m_project;
}
public void setProject(Integer project) {
m_project = project;
}
}