/** * Options read from the command line. This class provides a convenient way to pass options to any method. */ package oligo3; import java.io.File; public class ParseOptions { /* * Parse command line arguments. */ static boolean flag = false; public static boolean parseCmdLine(String[] args) { // Check and return command line parsing status if (args.length > 0) { try { for (int i = 0; i < args.length; i++) { // Parse and validate command-line arguments // Input filename has format requirements if (args[i].startsWith("-p")) { Params.parameters_file = args[i].equals("-p")?args[++i]:args[i].substring(2); if (!Params.parameters_file.matches("^\\w[\\w\\s\\(\\)\\.,-]*[\\w\\)]*$")) { System.out.println(Params.parameters_file + ": Invalid file name!"); System.exit(1); } } else if (args[i].startsWith("-f")) { Params.input_genes_file = args[i].equals("-f")?args[++i]:args[i].substring(2); if (!Params.input_genes_file.matches("^\\w[\\w\\s\\(\\)\\.,-]*[\\w\\)]*$")) { System.out.println("\n" + Params.input_genes_file + ": Invalid file name!\n"); System.exit(1); } else { flag = true; } } else if (args[i].equals("-h")) { System.out.println(Params.usage); System.exit(1); } else { System.out.println("Unknown arguments: " + args[i]); System.out.println(Params.usage); System.exit(1); } } } catch (ArrayIndexOutOfBoundsException e) { System.err.println("No parameter found after "+args[Integer.parseInt(e.getMessage())-1]); System.exit(1); } } else { //Use default parameters without using parameters_file //The input file must be named "input-genes.ffn" and placed in user's //current working directory and all output files will be placed there //return false; } return true; } }