Skip to content
This repository was archived by the owner on Mar 11, 2019. It is now read-only.

Commit 5a7238e

Browse files
Luis Francisco Hernández SánchezLuis Francisco Hernández Sánchez
authored andcommitted
Improved command line interface with options for Neo4j connection, conf, input, output etc.
1 parent 32630b6 commit 5a7238e

File tree

8 files changed

+184
-148
lines changed

8 files changed

+184
-148
lines changed

Config.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//General configuration
2-
inputListFile=./src/main/resources/csv/listFileUniprot.csv
3-
//inputListFile=./src/main/resources/input/maxQuantMatrix.txt
4-
//inputListFile=./src/main/resources/input/peptideList.txt
5-
//inputListFile=./src/main/resources/input/peptideListAndSites.txt
6-
//inputListFile=./src/main/resources/input/peptideListAndModSites.txt
7-
//inputListFile=./src/main/resources/input/uniprotList.txt
8-
//inputListFile=./src/main/resources/input/uniprotListAndSites.txt
9-
//inputListFile=./src/main/resources/input/uniprotListAndModSites.txt
2+
input=./../../src/main/resources/csv/listFileUniprot.csv
3+
//input=./src/main/resources/input/maxQuantMatrix.txt
4+
//input=./src/main/resources/input/peptideList.txt
5+
//input=./src/main/resources/input/peptideListAndSites.txt
6+
//input=./src/main/resources/input/peptideListAndModSites.txt
7+
//input=./src/main/resources/input/uniprotList.txt
8+
//input=./src/main/resources/input/uniprotListAndSites.txt
9+
//input=./src/main/resources/input/uniprotListAndModSites.txt
1010

1111
standarizedFile=./stantarizedFile.csv
1212

nbactions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
1111
</goals>
1212
<properties>
13-
<exec.args>-classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c ./Config.txt -i ..\MOBA_CNV\PathwayAnalysis\obesityProteinList -o ..\MOBA_CNV\PathwayAnalysis\output.csv</exec.args>
13+
<exec.args>-classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c Config.txt -i src\main\resources\input/uniprotList.txt</exec.args>
1414
<exec.executable>java</exec.executable>
1515
</properties>
1616
</action>
@@ -24,7 +24,7 @@
2424
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
2525
</goals>
2626
<properties>
27-
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c ./Config.txt -i ..\MOBA_CNV\PathwayAnalysis\obesityProteinList -o ..\MOBA_CNV\PathwayAnalysis\output.csv</exec.args>
27+
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c Config.txt -i src\main\resources\input/uniprotList.txt</exec.args>
2828
<exec.executable>java</exec.executable>
2929
<jpda.listen>true</jpda.listen>
3030
</properties>
@@ -39,7 +39,7 @@
3939
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
4040
</goals>
4141
<properties>
42-
<exec.args>-classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c ./Config.txt -i ..\MOBA_CNV\PathwayAnalysis\obesityProteinList -o ..\MOBA_CNV\PathwayAnalysis\output.csv</exec.args>
42+
<exec.args>-classpath %classpath no.uib.pathwaymatcher.PathwayMatcher -c Config.txt -i src\main\resources\input/uniprotList.txt</exec.args>
4343
<exec.executable>java</exec.executable>
4444
</properties>
4545
</action>

src/main/java/no/uib/pathwaymatcher/Conf.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Conf {
1919
public static HashMap<String, Integer> intMap;
2020

2121
public enum strVars {
22-
configPath, inputPath, inputType, outputType, outputPath, host, username, password, standardFilePath
22+
conf, input, inputType, outputType, output, host, username, password, standardFilePath
2323
}
2424

2525
public enum intVars {
@@ -69,12 +69,12 @@ public static void setDefaultValues() {
6969
strMap = new HashMap<String, String>();
7070

7171
// Set general configuration
72-
strMap.put(strVars.configPath.toString(), "./Config.txt");
72+
strMap.put(strVars.conf.toString(), "./Config.txt");
7373
strMap.put(strVars.standardFilePath.toString(), "./standardFile.txt");
74-
strMap.put(strVars.inputPath.toString(), "./input.txt");
74+
strMap.put(strVars.input.toString(), "./input.txt");
7575
strMap.put(strVars.inputType.toString(), InputTypeEnum.uniprotList.toString());
7676

77-
strMap.put(strVars.outputPath.toString(), "./output.txt");
77+
strMap.put(strVars.output.toString(), "./output.txt");
7878
strMap.put(strVars.outputType.toString(), OutputTypeEnum.fullTable.toString());
7979

8080
boolMap.put(boolVars.verbose.toString(), Boolean.TRUE);
@@ -89,7 +89,7 @@ public static void setDefaultValues() {
8989
strMap.put(strVars.password.toString(), "neo4j2");
9090
}
9191

92-
// public static String inputPath = "./src/main/resources/csv/listBjorn.csv";
92+
// public static String input = "./src/main/resources/csv/listBjorn.csv";
9393
public enum ProteinType {
9494
ewas, uniprot
9595
}

src/main/java/no/uib/pathwaymatcher/PathwayMatcher.java

Lines changed: 111 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
import java.util.List;
1111
import java.util.Map;
1212
import java.util.Set;
13-
import java.util.logging.Level;
14-
import java.util.logging.Logger;
13+
import no.uib.pathwaymatcher.Conf.boolVars;
14+
import no.uib.pathwaymatcher.Conf.intVars;
1515
import static no.uib.pathwaymatcher.Conf.options;
16+
import no.uib.pathwaymatcher.Conf.strVars;
1617
import no.uib.pathwaymatcher.db.ConnectionNeo4j;
18+
import no.uib.pathwaymatcher.stages.Reporter;
19+
import no.uib.pathwaymatcher.model.ModifiedProtein;
1720
import no.uib.pathwaymatcher.stages.Filter;
1821
import no.uib.pathwaymatcher.stages.Gatherer;
1922
import no.uib.pathwaymatcher.stages.Matcher;
2023
import no.uib.pathwaymatcher.stages.Preprocessor;
21-
import no.uib.pathwaymatcher.stages.Reporter;
22-
import no.uib.pathwaymatcher.model.ModifiedProtein;
2324
import org.apache.commons.cli.*;
2425
import org.neo4j.driver.v1.AuthTokens;
2526
import org.neo4j.driver.v1.GraphDatabase;
@@ -73,81 +74,112 @@ public static void main(String args[]) throws IOException {
7374
// Define and parse command line options
7475
Conf.options = new Options();
7576

76-
Option input = new Option("i", "inputPath", true, "input file path");
77+
Option input = new Option("i", strVars.input.toString(), true, "input file path");
7778
input.setRequired(false);
7879
options.addOption(input);
7980

80-
Option config = new Option("c", "configPath", true, "config file path");
81+
Option config = new Option("c", strVars.conf.toString(), true, "config file path");
8182
config.setRequired(false);
8283
options.addOption(config);
8384

84-
Option output = new Option("o", "outputPath", true, "output file path");
85+
Option output = new Option("o", strVars.conf.toString(), true, "output file path");
8586
output.setRequired(false);
8687
options.addOption(output);
8788

88-
Option max = new Option("m", "maxNumProt", true, "maximum number of indentifiers");
89+
Option max = new Option("m", intVars.maxNumProt.toString(), true, "maximum number of indentifiers");
8990
max.setRequired(false);
9091
options.addOption(max);
9192

92-
Option reactionsFile = new Option("r", "reactionsFile", false, "create a file with list of reactions containing the input");
93+
Option reactionsFile = new Option("r", boolVars.reactionsFile.toString(), false, "create a file with list of reactions containing the input");
9394
reactionsFile.setRequired(false);
9495
options.addOption(reactionsFile);
9596

96-
Option pathwaysFile = new Option("p", "pathwaysFile", false, "create a file with list of pathways containing the input");
97+
Option pathwaysFile = new Option("p", boolVars.pathwaysFile.toString(), false, "create a file with list of pathways containing the input");
9798
pathwaysFile.setRequired(false);
9899
options.addOption(pathwaysFile);
99100

101+
Option host = new Option("h", strVars.host.toString(), true, "Url of the Neo4j database with Reactome");
102+
host.setRequired(false);
103+
options.addOption(host);
104+
105+
Option username = new Option("u", strVars.username.toString(), true, "Username to access the database with Reactome");
106+
username.setRequired(false);
107+
options.addOption(username);
108+
109+
Option password = new Option("p", strVars.password.toString(), true, "Password related to the username provided to access the database with Reactome");
110+
password.setRequired(false);
111+
options.addOption(password);
112+
100113
CommandLineParser parser = new DefaultParser();
101114
HelpFormatter formatter = new HelpFormatter();
102115
CommandLine cmd;
103116

104117
try {
105118
cmd = parser.parse(options, args);
119+
120+
// If an option is specified in the command line and in the configuration file, the command line value is used
121+
/* For the configuration path
122+
- If a command line value is sent, it is used
123+
- If a command line value is not sent, it searches in the current folder for config.txt
124+
- If a command line value es not sent and there is no file in the current folder, then the program finishes
125+
*/
126+
if (cmd.hasOption("conf")) {
127+
Conf.setValue(strVars.conf.toString(), cmd.getOptionValue("conf").replace("\\", "/"));
128+
}
129+
130+
readConfigurationFromFile(); //Read configuration options from config.txt file
131+
132+
if (cmd.hasOption(strVars.input.toString())) {
133+
Conf.setValue(strVars.input.toString(), cmd.getOptionValue("input").replace("\\", "/"));
134+
}
135+
if (cmd.hasOption(strVars.output.toString())) {
136+
Conf.setValue(strVars.output.toString(), cmd.getOptionValue("output").replace("\\", "/"));
137+
}
138+
if (cmd.hasOption(intVars.maxNumProt.toString())) {
139+
Conf.setValue(intVars.maxNumProt.toString(), cmd.getOptionValue("maxNumProt"));
140+
}
141+
Conf.setValue(boolVars.reactionsFile.toString(), cmd.hasOption("reactionsFile"));
142+
Conf.setValue(boolVars.pathwaysFile.toString(), cmd.hasOption("pathwaysFile"));
143+
144+
if (cmd.hasOption(strVars.host.toString())) {
145+
Conf.setValue(strVars.host.toString(), cmd.getOptionValue(strVars.host.toString()));
146+
}
147+
if (cmd.hasOption(strVars.username.toString())) {
148+
Conf.setValue(strVars.username.toString(), cmd.getOptionValue(strVars.username.toString()));
149+
}
150+
if (cmd.hasOption(strVars.password.toString())) {
151+
Conf.setValue(strVars.password.toString(), cmd.getOptionValue(strVars.password.toString()));
152+
}
153+
106154
} catch (ParseException e) {
155+
107156
System.out.println(e.getMessage());
108157
formatter.printHelp("utility-name", options);
109158

110159
System.exit(1);
111160
return;
112161
}
113162

114-
if (cmd.hasOption("configPath")) {
115-
Conf.setValue(Conf.strVars.configPath.toString(), cmd.getOptionValue("configPath"));
116-
}
117-
if (cmd.hasOption(Conf.strVars.inputPath.toString())) {
118-
Conf.setValue(Conf.strVars.inputPath.toString(), cmd.getOptionValue("inputPath"));
119-
}
120-
if (cmd.hasOption(Conf.strVars.outputPath.toString())) {
121-
Conf.setValue(Conf.strVars.outputPath.toString(), cmd.getOptionValue("outputPath"));
122-
}
123-
if (cmd.hasOption(Conf.intVars.maxNumProt.toString())) {
124-
Conf.setValue(Conf.intVars.maxNumProt.toString(), cmd.getOptionValue("maxNumProt"));
125-
}
126-
Conf.setValue(Conf.boolVars.reactionsFile.toString(), cmd.hasOption("reactionsFile"));
127-
Conf.setValue(Conf.boolVars.pathwaysFile.toString(), cmd.hasOption("pathwaysFile"));
163+
// Iterator it = Conf.strMap.entrySet().iterator();
164+
// while (it.hasNext()) {
165+
// Map.Entry pair = (Map.Entry) it.next();
166+
// println(pair.getKey() + " = " + pair.getValue());
167+
// }
168+
//
169+
// it = Conf.boolMap.entrySet().iterator();
170+
// while (it.hasNext()) {
171+
// Map.Entry pair = (Map.Entry) it.next();
172+
// println(pair.getKey() + " = " + pair.getValue());
173+
// }
174+
//
175+
// it = Conf.intMap.entrySet().iterator();
176+
// while (it.hasNext()) {
177+
// Map.Entry pair = (Map.Entry) it.next();
178+
// println(pair.getKey() + " = " + pair.getValue());
179+
// }
180+
181+
initialize(); //Initialize objects
128182

129-
Iterator it = Conf.strMap.entrySet().iterator();
130-
while (it.hasNext()) {
131-
Map.Entry pair = (Map.Entry) it.next();
132-
println(pair.getKey() + " = " + pair.getValue());
133-
}
134-
135-
it = Conf.boolMap.entrySet().iterator();
136-
while (it.hasNext()) {
137-
Map.Entry pair = (Map.Entry) it.next();
138-
println(pair.getKey() + " = " + pair.getValue());
139-
}
140-
141-
it = Conf.intMap.entrySet().iterator();
142-
while (it.hasNext()) {
143-
Map.Entry pair = (Map.Entry) it.next();
144-
println(pair.getKey() + " = " + pair.getValue());
145-
}
146-
147-
//Read configuration options and initialize objects
148-
if (initialize() == 1) {
149-
return;
150-
}
151183
//System.out.println("Working Directory = " + System.getProperty("user.dir"));
152184
//Read and convert input to standard format
153185
println("Preprocessing input file...");
@@ -168,15 +200,40 @@ public static void main(String args[]) throws IOException {
168200
println("Filtering pathways and reactions....");
169201
Filter.getFilteredPathways();
170202
println("Filtering pathways and reactions complete.");
171-
172203
Reporter.createReports();
173204
}
174205

175206
private static int initialize() {
176207

208+
MPs = new ArrayList<ModifiedProtein>(Conf.intMap.get(intVars.maxNumProt.toString()));
209+
210+
ConnectionNeo4j.driver = GraphDatabase.driver(
211+
Conf.strMap.get(strVars.host.toString()),
212+
AuthTokens.basic(Conf.strMap.get(
213+
strVars.username.toString()),
214+
Conf.strMap.get(strVars.password.toString())
215+
)
216+
);
217+
218+
return 0;
219+
}
220+
221+
public static void println(String phrase) {
222+
if (Conf.boolMap.get(boolVars.verbose.toString())) {
223+
System.out.println(phrase);
224+
}
225+
}
226+
227+
private static int readConfigurationFromFile() {
228+
229+
if (Conf.strMap.get(strVars.conf.toString()).endsWith("/")) {
230+
System.out.println("The name for the configuration file was not specified.\n\n Examples: ./folder1/folder2/fileName.txt");
231+
System.exit(1);
232+
}
233+
177234
try {
178235
//Read and set configuration values from file
179-
BufferedReader configBR = new BufferedReader(new FileReader(Conf.strMap.get(Conf.strVars.configPath.toString())));
236+
BufferedReader configBR = new BufferedReader(new FileReader(Conf.strMap.get(strVars.conf.toString())));
180237

181238
//For every valid variable found in the config.txt file, the variable value gets updated
182239
String line;
@@ -196,33 +253,17 @@ private static int initialize() {
196253
}
197254
}
198255
} catch (FileNotFoundException ex) {
199-
System.out.println("Configuration file not found at: " + Conf.strMap.get(Conf.strVars.configPath.toString()));
200-
System.out.println(System.getProperty("user.dir") );
201-
Logger.getLogger(PathwayMatcher.class.getName()).log(Level.SEVERE, null, ex);
256+
System.out.println("The Configuration file specified was not found: " + Conf.strMap.get(strVars.conf.toString()));
257+
System.out.println("The starting location is: " + System.getProperty("user.dir"));
258+
//Logger.getLogger(PathwayMatcher.class.getName()).log(Level.SEVERE, null, ex);
202259
System.exit(1);
203260
return 1;
204261
} catch (IOException ex) {
205-
System.out.println("Not possible to read the configuration file: " + Conf.strMap.get(Conf.strVars.configPath.toString()));
206-
Logger.getLogger(PathwayMatcher.class.getName()).log(Level.SEVERE, null, ex);
262+
System.out.println("Not possible to read the configuration file: " + Conf.strMap.get(strVars.conf.toString()));
263+
//Logger.getLogger(PathwayMatcher.class.getName()).log(Level.SEVERE, null, ex);
207264
System.exit(1);
265+
return 1;
208266
}
209-
210-
MPs = new ArrayList<ModifiedProtein>(Conf.intMap.get(Conf.intVars.maxNumProt.toString()));
211-
212-
ConnectionNeo4j.driver = GraphDatabase.driver(
213-
Conf.strMap.get(Conf.strVars.host.toString()),
214-
AuthTokens.basic(Conf.strMap.get(
215-
Conf.strVars.username.toString()),
216-
Conf.strMap.get(Conf.strVars.password.toString())
217-
)
218-
);
219-
220267
return 0;
221268
}
222-
223-
public static void println(String phrase) {
224-
if (Conf.boolMap.get(Conf.boolVars.verbose.toString())) {
225-
System.out.println(phrase);
226-
}
227-
}
228269
}

src/main/java/no/uib/pathwaymatcher/SomeTool.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)