1010import java .util .List ;
1111import java .util .Map ;
1212import 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 ;
1515import static no .uib .pathwaymatcher .Conf .options ;
16+ import no .uib .pathwaymatcher .Conf .strVars ;
1617import no .uib .pathwaymatcher .db .ConnectionNeo4j ;
18+ import no .uib .pathwaymatcher .stages .Reporter ;
19+ import no .uib .pathwaymatcher .model .ModifiedProtein ;
1720import no .uib .pathwaymatcher .stages .Filter ;
1821import no .uib .pathwaymatcher .stages .Gatherer ;
1922import no .uib .pathwaymatcher .stages .Matcher ;
2023import no .uib .pathwaymatcher .stages .Preprocessor ;
21- import no .uib .pathwaymatcher .stages .Reporter ;
22- import no .uib .pathwaymatcher .model .ModifiedProtein ;
2324import org .apache .commons .cli .*;
2425import org .neo4j .driver .v1 .AuthTokens ;
2526import 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}
0 commit comments