Example usage for org.apache.commons.cli CommandLine getOptionValues

List of usage examples for org.apache.commons.cli CommandLine getOptionValues

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValues.

Prototype

public String[] getOptionValues(char opt) 

Source Link

Document

Retrieves the array of values, if any, of an option.

Usage

From source file:com.hdfs.concat.crush.Crush.java

boolean createJobConfAndParseArgs(String... args) throws ParseException, IOException {

    job = new JobConf(getConf(), Crush.class);

    /*/*  w  w w .j a va2s  . co m*/
     * Turn off speculative execution because that's just wasting network io.
     */
    job.setMapSpeculativeExecution(false);
    job.setReduceSpeculativeExecution(false);

    /*
     * Turn off pre-emption because we don't want to kill a task after two hours of network io.
     */
    job.set("mapred.fairscheduler.preemption", "false");

    tmpDir = new Path("tmp/crush-" + UUID.randomUUID());
    outDir = new Path(tmpDir, "out");

    double threshold = 0.75;

    List<String> regexes = asList(".+");
    List<String> replacements = asList("crushed_file-${crush.timestamp}-${crush.task.num}-${crush.file.num}");
    List<String> inFormats = asList(SequenceFileInputFormat.class.getName());
    List<String> outFormats = asList(SequenceFileOutputFormat.class.getName());

    String crushTimestamp;

    Options options = buildOptions();
    CommandLine cli = new GnuParser().parse(options, args);

    if (cli.hasOption("?")) {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(getClass().getClassLoader().getResourceAsStream("help.txt")));

        try {
            String line;

            while (null != (line = reader.readLine())) {
                System.out.println(line);
            }
        } finally {
            reader.close();
        }

        return false;
    }

    if (cli.hasOption("verbose")) {
        console = Verbosity.VERBOSE;
    } else if (cli.hasOption("info")) {
        console = Verbosity.INFO;
    } else {
        console = Verbosity.NONE;
    }

    if (cli.hasOption("ignore-regex")) {
        ignoredFiles = Pattern.compile(cli.getOptionValue("ignore-regex")).matcher("");
    }

    excludeSingleFileDirs = !cli.hasOption("include-single-file-dirs");

    String[] nonOptions = cli.getArgs();

    if (2 == nonOptions.length) {
        /*
         * Stand alone mode accepts two arguments.
         */
        mode = Mode.STAND_ALONE;

        srcDir = new Path(nonOptions[0]);

        dest = new Path(nonOptions[1]);

        if (cli.hasOption("input-format")) {
            inFormats = asList(cli.getOptionValue("input-format"));
        }

        if (cli.hasOption("output-format")) {
            outFormats = asList(cli.getOptionValue("output-format"));
        }

        replacements = asList(dest.getName());

        crushTimestamp = Long.toString(currentTimeMillis());

    } else {
        /*
         * The previous version expected three or four arguments. The third one specified the number of tasks to use, which is an
         * integral number, just like the third argument in the new version, which is a timestamp. We tell the two apart by looking
         * at the value of the argument. A timestamp is going to be a huge, 14-digit number while the number of tasks should be much
         * smaller.
         */

        if ((args.length == 4 || args.length == 3) && args.length == nonOptions.length
                && args[2].length() != 14) {

            int maxTasks = Integer.parseInt(args[2]);

            if (maxTasks <= 0 || maxTasks > 4000) {
                throw new IllegalArgumentException("Tasks must be in the range [1, 4000]: " + maxTasks);
            }

            job.setInt("mapred.reduce.tasks", maxTasks);

            maxFileBlocks = Integer.MAX_VALUE;

            crushTimestamp = Long.toString(currentTimeMillis());

            srcDir = new Path(args[0]);
            dest = new Path(args[1]);

            mode = Mode.CLONE;

            if (args.length == 4) {
                if (args[3].equals("TEXT")) {
                    /*
                     * These are the defaults except with text input and output formats.
                     */
                    inFormats = asList(TextInputFormat.class.getName());
                    outFormats = asList(TextOutputFormat.class.getName());

                } else if (!args[3].equals("SEQUENCE")) {
                    throw new IllegalArgumentException("Type must be either TEXT or SEQUENCE: " + args[3]);
                }
            }
        } else {
            /*
             * V2 style arguments.
             */
            if (cli.hasOption("threshold")) {
                threshold = Double.parseDouble(cli.getOptionValue("threshold"));

                if (0 >= threshold || 1 < threshold || Double.isInfinite(threshold)
                        || Double.isNaN(threshold)) {
                    throw new IllegalArgumentException("Block size threshold must be in (0, 1]: " + threshold);
                }
            }

            if (cli.hasOption("max-file-blocks")) {
                int maxFileBlocksOption = Integer.parseInt(cli.getOptionValue("max-file-blocks"));

                if (0 > maxFileBlocksOption) {
                    throw new IllegalArgumentException(
                            "Maximum file size in blocks must be positive: " + maxFileBlocksOption);
                }

                maxFileBlocks = maxFileBlocksOption;
            } else {
                maxFileBlocks = 8;
            }

            if (cli.hasOption("regex")) {
                regexes = asList(cli.getOptionValues("regex"));
            }

            if (cli.hasOption("replacement")) {
                replacements = asList(cli.getOptionValues("replacement"));
            }

            if (cli.hasOption("input-format")) {
                inFormats = asList(cli.getOptionValues("input-format"));
            }

            if (cli.hasOption("output-format")) {
                outFormats = asList(cli.getOptionValues("output-format"));
            }

            if (3 != nonOptions.length) {
                throw new IllegalArgumentException(
                        "Could not find source directory, out directory, and job timestamp");
            }

            srcDir = new Path(nonOptions[0]);
            dest = new Path(nonOptions[1]);

            crushTimestamp = nonOptions[2];

            if (cli.hasOption("clone")) {
                mode = Mode.CLONE;
            } else {
                mode = Mode.MAP_REDUCE;
            }

            if (!crushTimestamp.matches("\\d{14}")) {
                throw new IllegalArgumentException(
                        "Crush timestamp must be 14 digits yyyymmddhhMMss: " + crushTimestamp);
            }
        }

        dfsBlockSize = parseDfsBlockSize(job);
        maxEligibleSize = (long) (dfsBlockSize * threshold);
    }

    /*
     * Add the crush specs and compression options to the configuration.
     */
    job.set("crush.timestamp", crushTimestamp);

    if (ignoredFiles != null) {
        job.set("crush.ignore-regex", ignoredFiles.pattern().pattern());
    }

    if (regexes.size() != replacements.size() || replacements.size() != inFormats.size()
            || inFormats.size() != outFormats.size()) {
        throw new IllegalArgumentException(
                "Must be an equal number of regex, replacement, in-format, and out-format options");
    }

    job.setInt("crush.num.specs", regexes.size());

    matchers = new ArrayList<Matcher>(regexes.size());

    for (int i = 0; i < regexes.size(); i++) {
        job.set(format("crush.%d.regex", i), regexes.get(i));

        matchers.add(Pattern.compile(regexes.get(i)).matcher("dummy"));

        job.set(format("crush.%d.regex.replacement", i), replacements.get(i));

        String inFmt = inFormats.get(i);

        if ("sequence".equals(inFmt)) {
            inFmt = SequenceFileInputFormat.class.getName();
        } else if ("text".equals(inFmt)) {
            inFmt = TextInputFormat.class.getName();
        } else {
            try {
                if (!FileInputFormat.class.isAssignableFrom(Class.forName(inFmt))) {
                    throw new IllegalArgumentException("Not a FileInputFormat:" + inFmt);
                }
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Not a FileInputFormat:" + inFmt);
            }
        }

        job.set(format("crush.%d.input.format", i), inFmt);

        String outFmt = outFormats.get(i);

        if ("sequence".equals(outFmt)) {
            outFmt = SequenceFileOutputFormat.class.getName();
        } else if ("text".equals(outFmt)) {
            outFmt = TextOutputFormat.class.getName();
        } else {
            try {
                if (!FileOutputFormat.class.isAssignableFrom(Class.forName(outFmt))) {
                    throw new IllegalArgumentException("Not a FileOutputFormat:" + outFmt);
                }
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Not a FileOutputFormat:" + outFmt);
            }
        }

        job.set(format("crush.%d.output.format", i), outFmt);
    }

    String codec = cli.getOptionValue("compress");

    if (null == codec) {
        codec = DefaultCodec.class.getName();
    } else if ("none".equals(codec)) {
        codec = null;
    } else if ("gzip".equals(codec)) {
        codec = GzipCodec.class.getName();
    } else {
        try {
            if (!CompressionCodec.class.isAssignableFrom(Class.forName(codec))) {
                throw new IllegalArgumentException("Not a CompressionCodec: " + codec);
            }
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Not a CompressionCodec: " + codec);
        }
    }

    if (null == codec) {
        job.setBoolean("mapred.output.compress", false);
    } else {
        job.setBoolean("mapred.output.compress", true);
        job.set("mapred.output.compression.type", "BLOCK");
        job.set("mapred.output.compression.codec", codec);

        try {
            CompressionCodec instance = (CompressionCodec) Class.forName(codec).newInstance();
            codecExtension = instance.getDefaultExtension();
        } catch (Exception e) {
            throw new AssertionError();
        }
    }

    return true;
}

From source file:com.oneops.boo.BooCli.java

/**
 * Parse user's input.//from   w  ww. j a  va2s .co  m
 *
 * @param arg the arg
 * @throws ParseException the parse exception
 * @throws BooException the Boo exception
 * @throws OneOpsClientAPIException the one ops client API exception
 */
public int parse(String[] arg) throws ParseException, BooException, OneOpsClientAPIException {
    CommandLineParser parser = new DefaultParser();
    int exit = 0;
    // CommandLineParser parser = new GnuParser();
    try {

        String assembly = null;
        CommandLine cmd = parser.parse(options, arg);
        /**
         * Handle command without configuration file dependency first.
         */
        if (cmd.hasOption("h")) {
            this.help(null, "");
            return exit;
        }

        if (cmd.hasOption("quiet")) {
            BooCli.setQuiet(Boolean.TRUE);
        }

        if (cmd.hasOption("force")) {
            BooCli.setForced(Boolean.TRUE);
        }
        if (cmd.hasOption("no-deploy")) {
            BooCli.setNoDeploy(Boolean.TRUE);
        }

        if (cmd.hasOption("a")) {
            assembly = cmd.getOptionValue("a");
        }
        /**
         * Get configuration dir or file.
         */
        if (cmd.hasOption("f")) {
            this.configFile = new File(booUtils.getAbsolutePath(cmd.getOptionValue("f")));
            System.out.printf(Constants.CONFIG_FILE, this.configFile);
            System.out.println();
        }

        if (this.configFile == null || !this.configFile.exists()) {
            this.help(null, "No YAML file found.");
            return Constants.EXIT_YAML_NOT_FOUND;
        }

        String yaml = "";

        if (ClientConfig.ONEOPS_CONFIG.exists()) {
            if (cmd.hasOption("profile")) {
                this.profile = cmd.getOptionValue("profile");
            }
            ClientConfigIniReader iniReader = new ClientConfigIniReader();
            if (iniReader.read(ClientConfig.ONEOPS_CONFIG, profile) == null) {
                System.out.format("%n%s is not a valid profile in %s.%n%n", profile,
                        ClientConfig.ONEOPS_CONFIG);
                return Constants.EXIT_INVALID_PROFILE;
            }

            ClientConfigInterpolator interpolator = new ClientConfigInterpolator();
            yaml = interpolator.interpolate(this.configFile, ClientConfig.ONEOPS_CONFIG, this.profile);
        }

        if (cmd.hasOption('v')) {
            System.out.println(yaml);
            if (!ClientConfig.ONEOPS_CONFIG.exists()) {
                System.out.format("%nYou do not have a %s file. No interpolation can be performed.%n%n",
                        ClientConfig.ONEOPS_CONFIG);
            }
            return exit;
        }

        if (cmd.hasOption("m")) {
            this.comment = cmd.getOptionValue("m");
        }

        this.init(this.configFile, assembly, null, comment);
        if (cmd.hasOption("l")) {
            String prefix = cmd.getOptionValue("l");
            if (prefix == null) {
                this.listFiles(config.getYaml().getAssembly().getName());
            } else {
                this.listFiles(prefix.trim());
            }
            return Constants.EXIT_NORMAL;
        }
        /**
         * Handle other commands.
         */
        if (cmd.hasOption("s")) {
            if (!flow.isAssemblyExist()) {
                System.err.printf(Constants.NOTFOUND_ERROR, config.getYaml().getAssembly().getName());
                return Constants.EXIT_ASSEMBLY_NOT_FOUND;
            } else {
                System.out.println(this.getStatus());
            }
        } else if (cmd.hasOption("c")) {
            if (config.getYaml().getAssembly().getAutoGen()) {
                this.initOo(this.config, this.autoGenAssemblyName(config.getYaml().getAssembly().getAutoGen(),
                        config.getYaml().getAssembly().getName()), comment);
                LogUtils.info(Constants.CREATING_ASSEMBLY, config.getYaml().getAssembly().getName());
            }
            this.createPacks(Boolean.FALSE, isNoDeploy);
        } else if (cmd.hasOption("u")) {
            if (!config.getYaml().getAssembly().getAutoGen()) {
                if (flow.isAssemblyExist()) {
                    this.createPacks(Boolean.TRUE, isNoDeploy);
                } else {
                    System.err.printf(Constants.NOTFOUND_ERROR, config.getYaml().getAssembly().getName());
                }
            } else {
                List<String> assemblies = this.listFiles(this.config.getYaml().getAssembly().getName());
                for (String asm : assemblies) {
                    this.initOo(config, asm, comment);
                    this.createPacks(Boolean.TRUE, isNoDeploy);
                }
            }
        } else if (cmd.hasOption("r")) {
            List<String> assemblies;
            if (config.getYaml().getAssembly().getAutoGen()) {
                assemblies = this.listFiles(this.config.getYaml().getAssembly().getName());
            } else {
                assemblies = new ArrayList<String>();
                String asb = this.config.getYaml().getAssembly().getName();
                if (this.flow.isAssemblyExist(asb)) {
                    assemblies.add(asb);
                }
            }
            this.cleanup(assemblies);
        } else if (cmd.hasOption("get-ips")) {
            if (!flow.isAssemblyExist()) {
                System.err.printf(Constants.NOTFOUND_ERROR, config.getYaml().getAssembly().getName());
            } else if (cmd.getOptionValues("get-ips") == null) {
                // if there is no args for get-ips
                getIps0();
            } else if (cmd.getOptionValues("get-ips").length == 1) {
                // if there is one arg for get-ips
                getIps1(cmd.getOptionValues("get-ips")[0]);
            } else if (cmd.getOptionValues("get-ips").length == 2) {
                // if there are two args for get-ips
                getIps2(cmd.getOptionValues("get-ips")[0], cmd.getOptionValues("get-ips")[1]);
            }
        } else if (cmd.hasOption("retry")) {
            this.retryDeployment();
        } else if (cmd.hasOption("procedure")) {
            if (cmd.getOptionValues("procedure").length != 3) {
                System.err.println("Wrong parameters! --prodedure <platformName> <componentName> <actionName>");
                return Constants.EXIT_WRONG_PRAMETER;
            } else {
                String[] args = cmd.getOptionValues("procedure");
                String arglist = "";
                int rollAt = 100;
                if (cmd.hasOption("procedure-arguments")) {
                    arglist = cmd.getOptionValue("procedure-arguments");
                }
                if (cmd.hasOption("procedure-step-size")) {
                    rollAt = Integer.parseInt(cmd.getOptionValue("procedure-step-size"));
                }
                List<String> instances = null;
                if (cmd.hasOption("procedure-instances")) {
                    String ins = cmd.getOptionValue("procedure-instances");
                    if (ins != null && ins.trim().length() > 0) {
                        if (ins.equalsIgnoreCase("list")) {
                            List<String> list = flow.listInstances(args[0], args[1]);
                            if (list != null) {
                                for (String instance : list) {
                                    System.out.println(instance);
                                }
                            }
                            return Constants.EXIT_NORMAL;
                        }
                        instances = Arrays.asList(ins.split(","));
                    }
                }
                if ("list".equalsIgnoreCase(args[2])) {
                    List<String> list = flow.listActions(args[0], args[1]);
                    if (list != null) {
                        for (String instance : list) {
                            System.out.println(instance);
                        }
                    }
                } else {
                    exit = this.executeAction(args[0], args[1], args[2], arglist, instances, rollAt);
                }

            }
        } else {
            System.err.println("Wrong parameters!");
            return Constants.EXIT_WRONG_PRAMETER;
        }
    } catch (ParseException e) {
        exit = Constants.EXIT_PARSE_ERROR;
    } catch (Exception e) {
        exit = Constants.EXIT_UNKOWN;
        e.printStackTrace(new PrintStream(System.err));
    }
    return exit;
}

From source file:com.altiscale.TcpProxy.HostPort.java

private static ProxyConfiguration assembleConfigFromCommandLine(Options options, String[] args) {
    CommandLine commandLine = null;
    try {/*from  ww  w  . j a  v  a 2 s.c  o m*/
        commandLine = new GnuParser().parse(options, args);
    } catch (org.apache.commons.cli.ParseException e) {
        LOG.info("Parsing exception" + e.getMessage());
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("h")) {
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("version")) {
        LOG.info("Transfer Accelerator Version " + getProxyVersion());
        System.exit(1);
    }

    if (commandLine.hasOption("verbose")) {
        LogManager.getRootLogger().setLevel(Level.DEBUG);
    }

    ProxyConfiguration conf = new ProxyConfiguration();

    if (commandLine.hasOption("port")) {
        conf.listeningPort = Integer.parseInt(commandLine.getOptionValue("port"));
    }

    if (commandLine.hasOption("webstatus_port")) {
        conf.statusPort = Integer.parseInt(commandLine.getOptionValue("webstatus_port"));
    }

    // Maybe add jumphost.
    HostPort jumphostSshd = null;
    if (commandLine.hasOption("jumphost")) {
        String jumphostString = commandLine.getOptionValue("jumphost");
        try {
            jumphostSshd = conf.parseServerString(jumphostString);
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception for jumphost: " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Add jumphostServer if we have a jumphost.
    HostPort jumphostServer = null;
    if (commandLine.hasOption("jumphost_server")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_server.");
            printHelp(options);
            System.exit(1);
        }
        String jumphostServerString = commandLine.getOptionValue("jumphost_server");
        try {
            jumphostServer = conf.parseServerString(jumphostServerString);
            if (jumphostServer.port == -1) {
                throw new URISyntaxException(jumphostServerString, "Jumphost server parameter missing port.");
            }
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception for jumphost_server:" + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Maybe add jumphostUser if we have a jumphost.
    String jumphostUser = null;
    if (commandLine.hasOption("jumphost_user")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_user.");
            printHelp(options);
            System.exit(1);
        }
        jumphostUser = commandLine.getOptionValue("jumphost_user");
    }

    // Maybe add jumphostCredentials if we have a jumphost.
    String jumphostCredentials = null;
    if (commandLine.hasOption("jumphost_credentials")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_credentials.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCredentials = commandLine.getOptionValue("jumphost_credentials");
    }

    // Maybe set jumphostCompression if we have a jumphost.
    boolean jumphostCompression = false;
    if (commandLine.hasOption("jumphost_compression")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_compression.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCompression = true;
    }

    // Maybe add jumphostCiphers if we have a jumphost.
    String jumphostCiphers = null;
    if (commandLine.hasOption("jumphost_ciphers")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify jumphost_ciphers.");
            printHelp(options);
            System.exit(1);
        }
        jumphostCiphers = commandLine.getOptionValue("jumphost_ciphers");
    }

    // Maybe add sshBinary if we have a jumphost.
    String sshBinary = null;
    if (commandLine.hasOption("ssh_binary")) {
        if (!commandLine.hasOption("jumphost")) {
            LOG.error("You need to specify jumphost if you specify ssh_binary.");
            printHelp(options);
            System.exit(1);
        }
        sshBinary = commandLine.getOptionValue("ssh_binary");
    }
    boolean openInterfaces = false;
    if (commandLine.hasOption("openInterfaces")) {
        openInterfaces = true;
    }

    // Add jumphost to the config.
    if (null != jumphostSshd && null != jumphostServer) {
        conf.jumphost = new JumpHost(jumphostSshd, jumphostServer, jumphostUser, jumphostCredentials,
                jumphostCompression, jumphostCiphers, sshBinary, openInterfaces);
    }

    if (!commandLine.hasOption("num_servers") && !commandLine.hasOption("servers")) {
        LOG.error("You need to specify one of the num_servers or servers flags.");
        printHelp(options);
        System.exit(1);
    }

    if (commandLine.hasOption("num_servers") && commandLine.hasOption("servers")) {
        LOG.error("You need to specify one of the num_servers or servers flags, not both.");
        printHelp(options);
        System.exit(1);
    }

    // Add servers.
    if (commandLine.hasOption("num_servers")) {
        try {
            int num_servers = Integer.parseInt(commandLine.getOptionValue("num_servers"));
            if (num_servers > TcpProxyServer.MAX_NUM_SERVERS) {
                throw new Exception("Please specify -servers.");
            }
            for (int i = 0; i < num_servers; i++) {
                conf.parseServerStringAndAdd("localhost:" + (TcpProxyServer.START_PORT_RANGE + i));
            }
        } catch (Exception e) {
            LOG.error("num_servers parsing exception " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("servers")) {
        String[] servers = commandLine.getOptionValues("servers");
        try {
            for (String server : servers) {
                conf.parseServerStringAndAdd(server);
            }
        } catch (URISyntaxException e) {
            LOG.error("Server path parsing exception " + e.getMessage());
            printHelp(options);
            System.exit(1);
        }
    }

    // Maybe set load balancer.
    if (commandLine.hasOption("load_balancer")) {
        HashSet<String> loadBalancers = new HashSet<String>(
                Arrays.asList("RoundRobin", "LeastUsed", "UniformRandom"));
        conf.loadBalancerString = commandLine.getOptionValue("load_balancer");
        if (!loadBalancers.contains(conf.loadBalancerString)) {
            LOG.error("Bad load_balancer value.");
            printHelp(options);
            System.exit(1);
        }
    }
    return conf;
}

From source file:admixture.parameter.Parameter.java

public void commandListenor(String[] args) {
    CommandLine cl = null;
    try {/* w  w w  .j a va  2  s  . co  m*/
        cl = parser.parse(ops, args);
    } catch (ParseException E) {
        System.err.println(E.getMessage());
        System.exit(0);
    }
    if (cl.hasOption(cmd_help)) {
        help = true;
    }
    if (cl.hasOption(cmd_trans)) {
        transFlag = true;
    }
    if (cl.hasOption(cmd_out)) {
        out = cl.getOptionValue(cmd_out);
    }

    if (cl.hasOption(cmd_collapse)) {
        collapseFlag = true;
    }

    if (cl.hasOption(cmd_cc)) {
        ccFlag = true;

        piFlag = false;
        piiFlag = false;
        uiFlag = false;
        uiiFlag = false;
    }
    if (cl.hasOption(cmd_pi)) {
        piFlag = true;

        ccFlag = false;
        piiFlag = false;
        uiFlag = false;
        uiiFlag = false;
    }
    if (cl.hasOption(cmd_pii)) {
        piiFlag = true;

        ccFlag = false;
        piFlag = false;
        uiFlag = false;
        uiiFlag = false;
    }
    if (cl.hasOption(cmd_ui)) {
        uiFlag = true;

        ccFlag = false;
        piFlag = false;
        piiFlag = false;
        uiiFlag = false;
    }
    if (cl.hasOption(cmd_uii)) {
        uiiFlag = true;

        ccFlag = false;
        piFlag = false;
        piiFlag = false;
        uiFlag = false;
    }

    // file
    if (cl.hasOption(cmd_file)) {
        StringBuffer sb1 = new StringBuffer();
        StringBuffer sb2 = new StringBuffer();
        sb1.append(cl.getOptionValue(cmd_file));
        sb1.append(".ped");

        sb2.append(cl.getOptionValue(cmd_file));
        sb2.append(".map");

        ped = sb1.toString();
        map = sb2.toString();
    }
    //      if (cl.hasOption(cmd_ped)) {
    //         ped = cl.getOptionValue(cmd_ped);
    //      }
    //      if (cl.hasOption(cmd_map)) {
    //         map = cl.getOptionValue(cmd_map);
    //      }
    if (ped != null && map != null) {
        File fped = new File(ped);
        if (!fped.exists()) {
            System.err.println("could not open " + ped + ".");
            Test.LOG.append("could not open " + ped + ".\n");
            Test.printLog();
            System.exit(0);
        }
        File fmap = new File(map);
        if (!fmap.exists()) {
            System.err.println("could not open " + map + ".");
            Test.LOG.append("could not open " + map + ".\n");
            Test.printLog();
            System.exit(0);
        }
        fileFlag = true;
    }

    // bfile
    if (cl.hasOption(cmd_bfile)) {
        StringBuffer sb1 = new StringBuffer();
        StringBuffer sb2 = new StringBuffer();
        StringBuffer sb3 = new StringBuffer();
        sb1.append(cl.getOptionValue(cmd_bfile));
        sb1.append(".bed");

        sb2.append(cl.getOptionValue(cmd_bfile));
        sb2.append(".bim");

        sb3.append(cl.getOptionValue(cmd_bfile));
        sb3.append(".fam");

        bed = sb1.toString();
        bim = sb2.toString();
        fam = sb3.toString();
    }
    //      if (cl.hasOption(cmd_bed)) {
    //         bed = cl.getOptionValue(cmd_bed);
    //      }
    //      if (cl.hasOption(cmd_bim)) {
    //         bim = cl.getOptionValue(cmd_bim);
    //      }
    //      if (cl.hasOption(cmd_fam)) {
    //         fam = cl.getOptionValue(cmd_fam);
    //      }
    if (bed != null && bim != null && fam != null) {
        File fbed = new File(bed);
        if (!fbed.exists()) {
            System.err.println("could not open " + bed + ".");
            Test.LOG.append("could not open " + bed + ".\n");
            Test.printLog();
            System.exit(0);
        }
        File fbim = new File(bim);
        if (!fbim.exists()) {
            System.err.println("could not open " + bim + ".");
            Test.LOG.append("could not open " + bim + ".\n");
            Test.printLog();
            System.exit(0);
        }
        File ffam = new File(fam);
        if (!ffam.exists()) {
            System.err.println("could not open " + fam + ".");
            Test.LOG.append("could not open " + fam + ".\n");
            Test.printLog();
            System.exit(0);
        }
        bfileFlag = true;
    }

    if (cl.hasOption(cmd_covar)) {
        pheno = cl.getOptionValue(cmd_covar);
        File fpheno = new File(pheno);
        if (!fpheno.exists()) {
            System.err.println("could not open " + fpheno + ".");
            Test.LOG.append("could not open " + fpheno + ".\n");
            Test.printLog();
            System.exit(0);
        }
    }

    if (cl.hasOption(cmd_covar_header)) {
        covar_header_flag = true;
    }

    if (cl.hasOption(cmd_header)) {
        header = true;
    }

    if (cl.hasOption(cmd_linear)) {
        linkfunction = 0;
    }

    if (cl.hasOption(cmd_logistic)) {
        linkfunction = 1;
    }
    if (cl.hasOption(cmd_pheno_number)) {
        response = Integer.parseInt(cl.getOptionValue(cmd_pheno_number)) - 1;
        if (response < -1) {
            System.err.println("bad parameter for --" + cmd_pheno_number_long + ": " + (response + 1) + ".");
            Test.LOG.append("bad parameter for --" + cmd_pheno_number_long + ": " + (response + 1) + ".\n");
            Test.printLog();
            System.exit(0);
        }
    }

    if (cl.hasOption(cmd_covar_number)) {
        String[] p = cl.getOptionValues(cmd_covar_number);
        HashSet<Integer> idx = NewIt.newHashSet();
        for (int i = 0, len = p.length; i < len; i++) {
            if (p[i].contains("-")) {
                String[] pp = p[i].split("-");
                if (pp.length != 2) {
                    System.err
                            .println("bad parameter for option --" + cmd_covar_number_long + ": " + p[i] + ".");
                    Test.LOG.append(
                            "bad parameter for option --" + cmd_covar_number_long + ": " + p[i] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                for (int j = Integer.parseInt(pp[0]); j <= Integer.parseInt(pp[1]); j++) {
                    idx.add(new Integer(j));
                }
            } else {
                idx.add(new Integer(Integer.parseInt(p[i])));
            }
        }
        predictor = new int[idx.size()];
        int c = 0;
        for (Iterator<Integer> e = idx.iterator(); e.hasNext();) {
            predictor[c] = e.next().intValue() - 1;
            if (predictor[c] < 0) {
                System.err.println(
                        "bad parameter for option --" + cmd_covar_number_long + ": " + predictor[c] + ".");
                Test.LOG.append(
                        "bad parameter for option --" + cmd_covar_number_long + ": " + predictor[c] + ".\n");
                Test.printLog();
                System.exit(0);
            }
            c++;
        }
    }

    //      if (cl.hasOption(cmd_covar_name)) {
    //         HashSet<String> cn = NewIt.newHashSet();
    //         String[] p = cl.getOptionValues(cmd_covar_name);
    //         for (int i = 0; i < p.length; i++) {
    //            if (p[i].contains("-")) {
    //               String[] pp = predictor_name[i].split("-");
    //               if (pp.length != 2) {
    //                  System.err.println("bad parameter for option --" + cmd_covar_name_long + ": " + p[i] + ".");
    //                  Test.LOG.append("bad parameter for option --" + cmd_covar_name_long + ": " + p[i] + ".\n");
    //                  Test.printLog();
    //                  System.exit(0);
    //               }
    //               for (int j = 0; j < pp.length; j++) {
    //                  cn.add(pp[j]);
    //               }
    //            } else {
    //               cn.add(p[i]);
    //            }
    //         }
    //         predictor_name = (String[]) cn.toArray(new String[0]);
    //      }

    if (cl.hasOption(cmd_bgsnp)) {
        String[] bg = cl.getOptionValues(cmd_bgsnp);
        HashSet<String> bgSet = NewIt.newHashSet();
        for (int i = 0; i < bg.length; i++) {
            bgSet.add(bg[i]);
        }
        if (bgSet.size() != bg.length) {
            System.err.println("bad parameter for --" + cmd_bgsnp + ".");
            Test.LOG.append("bad parameter for --" + cmd_bgsnp + ".\n");
            Test.printLog();
            System.exit(0);
        }
        bgsnp = cl.getOptionValues(cmd_bgsnp);
        bgsnpFlag = true;
    }

    if (cl.hasOption(cmd_hg18)) {
        hg18Flag = true;
        hg19Flag = false;
        hgFile = "/gene36.txt";
    }

    if (cl.hasOption(cmd_hg19)) {
        hg19Flag = true;
        hg18Flag = false;
        hgFile = "/gene37.txt";
    }

    if (cl.hasOption(cmd_hg)) {
        hg19Flag = false;
        hg18Flag = false;
        hgFile = cl.getOptionValue(cmd_hg);
    }

    if (cl.hasOption(cmd_snp2genelist)) {
        snp2genefileFlag = true;
    }

    if (cl.hasOption(cmd_snp2genemlist)) {
        snp2genefilesFlag = true;
    }

    if (cl.hasOption(cmd_region)) {
        String[] r = cl.getOptionValues(cmd_region);
        ArrayList<String> chr = NewIt.newArrayList();
        ArrayList<String> b = NewIt.newArrayList();
        ArrayList<String> e = NewIt.newArrayList();

        for (int i = 0; i < r.length; i++) {
            String[] s = r[i].split(",");
            if (s.length != 3) {
                System.err.println("bad parameter for --" + cmd_region + ": " + r[i] + ".");
                Test.LOG.append("bad parameter for --" + cmd_region + ": " + r[i] + ".\n");
                Test.printLog();
                System.exit(0);
            }
            chr.add(s[0]);
            b.add(s[1]);
            e.add(s[2]);
        }
        chr_reg = (String[]) chr.toArray(new String[0]);
        begin = new double[b.size()];
        end = new double[e.size()];
        for (int i = 0; i < r.length; i++) {
            begin[i] = Double.parseDouble(b.get(i));
            end[i] = Double.parseDouble(e.get(i));
        }
        regionFlag = true;
    }

    if (cl.hasOption(cmd_gene_list)) {
        String gl = cl.getOptionValue(cmd_gene_list);

        File f = new File(gl);
        if (!f.exists()) {
            System.err.println("could not find file for --option " + cmd_gene_list_long + ": " + gl + ".");
            Test.LOG.append("could not find file for --option " + cmd_gene_list_long + ": " + gl + ".\n");
            Test.printLog();
            System.exit(0);
        }
        BufferedReader reader0 = null;
        try {
            reader0 = new BufferedReader(new FileReader(f));
        } catch (IOException E) {
            System.err.println("could not open gene list " + gl + ".");
            Test.LOG.append("could not open gene list " + gl + ".\n");
            Test.printLog();
            System.exit(0);
        }
        String line0 = null;
        HashSet<String> gSet = NewIt.newHashSet();
        try {
            while ((line0 = reader0.readLine()) != null) {
                String[] gn = line0.split(delim);
                gSet.add(gn[0]);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        String[] g = (String[]) gSet.toArray(new String[0]);
        boolean[] gflag = new boolean[gSet.size()];
        Arrays.fill(gflag, false);
        ArrayList<String> ge = NewIt.newArrayList();
        ArrayList<String> g_chr = NewIt.newArrayList();
        ArrayList<String> g_begin = NewIt.newArrayList();
        ArrayList<String> g_end = NewIt.newArrayList();

        BufferedReader reader = null;
        if (hg18Flag || hg19Flag) {
            InputStream is = getClass().getResourceAsStream(hgFile);
            DataInputStream in = new DataInputStream(is);
            reader = new BufferedReader(new InputStreamReader(in));
        } else {
            File fhg = new File(hgFile);
            if (!fhg.exists()) {
                System.err.println("could not find file for --option " + cmd_hg + ": " + hgFile + ".");
                Test.LOG.append("could not find file for --option " + cmd_hg + ": " + hgFile + ".\n");
                Test.printLog();
                System.exit(0);
            }

            try {
                reader = new BufferedReader(new FileReader(fhg));
            } catch (IOException E) {
                System.err.println("could not open gene list " + hgFile + ".");
                Test.LOG.append("could not open gene list " + hgFile + ".\n");
                Test.printLog();
                System.exit(0);
            }

        }

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {

                String[] s = line.split("\\s+");
                //               System.err.println(line);
                if (s.length != 4) {
                    continue;
                }

                for (int i = 0; i < g.length; i++) {
                    if (s[0].compareTo(g[i]) == 0) {
                        ge.add(s[0]);
                        g_chr.add(s[1]);
                        g_begin.add(s[2]);
                        g_end.add(s[3]);
                        gflag[i] = true;
                    }
                }
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag = true;
        int count = 0;
        for (int i = 0; i < gflag.length; i++) {
            if (!gflag[i]) {
                System.err.println("could not fine gene " + g[i] + ".");
                Test.LOG.append("could not find gene " + g[i] + ".\n");
                flag = false;
                count++;
            }
        }

        System.err.println("of " + gflag.length + " genes " + (gflag.length - count) + " was found.");
        Test.LOG.append("of " + gflag.length + " genes " + (gflag.length - count) + " was found.\n");

        if (!snp2genefileFlag && !snp2genefilesFlag) {
            if (!flag) {
                Test.printLog();
                System.exit(0);
            }
        }

        gene = (String[]) ge.toArray(new String[0]);
        gene_chr = (String[]) g_chr.toArray(new String[0]);
        gene_begin = new double[gene_chr.length];
        gene_end = new double[gene_chr.length];

        for (int i = 0; i < gene_chr.length; i++) {
            gene_begin[i] = Double.parseDouble(g_begin.get(i)) / 1000;
            gene_end[i] = Double.parseDouble(g_end.get(i)) / 1000;
            System.err.println(
                    gene[i] + ": chr" + gene_chr[i] + " " + gene_begin[i] + "k ~ " + gene_end[i] + "k.");
            Test.LOG.append(
                    gene[i] + ": chr" + gene_chr[i] + " " + gene_begin[i] + "k ~ " + gene_end[i] + "k.\n");
        }
        geneFlag = true;
    }

    if (cl.hasOption(cmd_gene_window)) {
        double gw = Double.parseDouble(cl.getOptionValue(cmd_gene_window));
        if (gw < 0) {
            System.err.println("bad parameter for option --" + cmd_gene_window_long + ": " + gw + ".");
            Test.LOG.append("bad parameter for option --" + cmd_gene_window_long + ": " + gw + ".\n");
            Test.printLog();
            System.exit(0);
        }
        genewindow = gw;
    }

    //      if (cl.hasOption(cmd_gene)) {
    //         String[] g = cl.getOptionValues(cmd_gene);
    //         boolean[] gflag = new boolean[g.length];
    //         Arrays.fill(gflag, false);
    //         ArrayList<String> ge = NewIt.newArrayList();
    //         ArrayList<String> g_chr = NewIt.newArrayList();
    //         ArrayList<String> g_begin = NewIt.newArrayList();
    //         ArrayList<String> g_end = NewIt.newArrayList();
    //         
    //         BufferedReader reader = null;
    //         if(hg18Flag || hg19Flag) {
    //            InputStream is = getClass().getResourceAsStream(hgFile);
    //            DataInputStream in = new DataInputStream(is);
    //            reader = new BufferedReader(new InputStreamReader(in));
    //         } else {
    //            File fhg = new File(hgFile);
    //            if (!fhg.exists()) {
    //               System.err.println("could not find file for --option " + cmd_hg + ": " + hgFile +".");
    //               Test.LOG.append("could not find file for --option " + cmd_hg + ": " + hgFile + ".\n");
    //               Test.printLog();
    //               System.exit(0);
    //            }
    //            try {
    //               reader = new BufferedReader(new FileReader(fhg));
    //            } catch (IOException E) {
    //               System.err.println("could not open gene list " + hgFile + ".");
    //               Test.LOG.append("could not open gene list " + hgFile + ".\n");
    //               Test.printLog();
    //               System.exit(0);
    //            }
    //
    //         }
    //
    //         String line = null;
    //         try {
    //            while ((line = reader.readLine()) != null) {
    //
    //               String[] s = line.split("\\s+");
    ////               System.err.println(line);
    //               if (s.length != 4) {
    //                  continue;
    //               }
    //
    //               for (int i = 0; i < g.length; i++) {
    //                  if (s[0].compareTo(g[i]) == 0) {
    //                     ge.add(s[0]);
    //                     g_chr.add(s[1]);
    //                     g_begin.add(s[2]);
    //                     g_end.add(s[3]);
    //                     gflag[i] = true;
    //                  }
    //               }
    //
    //            }
    //            reader.close();
    //         } catch (IOException e) {
    //            e.printStackTrace();
    //         }
    //         boolean flag = true;
    //         int count = 0;
    //         for(int i = 0; i < gflag.length; i++) {
    //            if(!gflag[i]) {
    //               System.err.println("could not find gene " + g[i] + ".");
    //               Test.LOG.append("could not find gene " + g[i] + ".\n");
    //               flag = false;
    //               count++;
    //            }
    //         }
    //         System.err.println("of " + gflag.length + " genes " + (gflag.length - count) + " was found.");
    //         Test.LOG.append("of " + gflag.length + " genes " + (gflag.length - count) + " was found.\n");
    //         if (!snp2genefileFlag && !snp2genefilesFlag) {
    //            if(!flag) {
    //               Test.printLog();
    //               System.exit(0);
    //            }
    //         }
    //
    //         gene = (String[]) ge.toArray(new String[0]);
    //         gene_chr = (String[]) g_chr.toArray(new String[0]);
    //         gene_begin = new double[gene_chr.length];
    //         gene_end = new double[gene_chr.length];
    //
    //         for (int i = 0; i < gene_chr.length; i++) {
    //            gene_begin[i] = Double.parseDouble(g_begin.get(i)) / 1000;
    //            gene_end[i] = Double.parseDouble(g_end.get(i)) / 1000;
    //            System.err.println(gene[i] + ": chr" + gene_chr[i] + " " +gene_begin[i] + "k ~ " + gene_end[i] + "k");
    //            Test.LOG.append(gene[i] + ": chr" + gene_chr[i] + " " +gene_begin[i] + "k ~ " + gene_end[i] + "k.\n");
    //         }
    //         geneFlag = true;
    //      }

    if (cl.hasOption(cmd_extract)) {

        if (!transFlag) {
            includesnpFile = cl.getOptionValues(cmd_extract);
            ArrayList<String> includesnpList = NewIt.newArrayList();
            for (int h = 0; h < includesnpFile.length; h++) {
                File f = new File(includesnpFile[h]);
                if (!f.exists()) {
                    System.err.println("could not find --" + cmd_extract + ": " + includesnpFile[h] + ".");
                    Test.LOG.append("could not fine --" + cmd_extract + ": " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new FileReader(f));
                } catch (IOException E) {
                    System.err.println("could not read --" + cmd_extract + ": " + includesnpFile[h] + ".");
                    Test.LOG.append("could not read --" + cmd_extract + ": " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                ArrayList<String> snp = NewIt.newArrayList();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        String[] s = line.split(delim);
                        snp.add(s[0]);
                    }
                    reader.close();
                } catch (IOException E) {
                    System.err.println("bad lines in " + includesnpFile[h] + ".");
                    Test.LOG.append("bad lines in " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                if (snp.size() > 0) {
                    ArrayList<String> insnp = NewIt.newArrayList();
                    for (int i = 0; i < snp.size(); i++) {
                        String subSNP = snp.get(i);
                        insnp.add(subSNP);
                    }

                    if (insnp.size() > 0) {
                        includesnpList.addAll(insnp);
                        snpFlag = true;
                    }
                }
                if (includesnpList.size() > 0) {
                    includesnp = (String[]) includesnpList.toArray(new String[0]);
                }

            }
        } else {
            includesnpFile = cl.getOptionValues(cmd_extract);
            xincludesnp = new String[includesnpFile.length][];
            for (int h = 0; h < includesnpFile.length; h++) {
                File f = new File(includesnpFile[h]);
                if (!f.exists()) {
                    System.err.println("could not find " + includesnpFile[h] + ".");
                    Test.LOG.append("could not find " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new FileReader(f));
                } catch (IOException E) {

                    System.err.println("could not read " + includesnpFile[h] + ".");
                    Test.LOG.append("could not read " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                ArrayList<String> snp = NewIt.newArrayList();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        String[] s = line.split(delim);
                        snp.add(s[0]);
                    }
                    reader.close();
                } catch (IOException E) {

                    System.err.println("bad lines in " + includesnpFile[h] + ".");
                    Test.LOG.append("bad lines in " + includesnpFile[h] + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                if (snp.size() > 0) {
                    ArrayList<String> insnp = NewIt.newArrayList();

                    for (int i = 0; i < snp.size(); i++) {
                        String subSNP = snp.get(i);
                        insnp.add(subSNP);
                    }
                    if (insnp.size() > 0) {
                        xincludesnp[h] = (String[]) insnp.toArray(new String[0]);
                        snpFlag = true;
                    }
                }
            }
        }
    }

    if (cl.hasOption(cmd_exclude)) {

        if (!transFlag) {
            String snps_file = cl.getOptionValue(cmd_exclude);
            ArrayList<String> excludesnpList = NewIt.newArrayList();
            for (int h = 0; h < 1; h++) {
                File f = new File(snps_file);
                if (!f.exists()) {
                    System.err.println("could not find --" + cmd_extract + ": " + snps_file + ".");
                    Test.LOG.append("could not fine --" + cmd_extract + ": " + snps_file + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new FileReader(f));
                } catch (IOException E) {
                    System.err.println("could not read --" + cmd_extract + ": " + snps_file + ".");
                    Test.LOG.append("could not read --" + cmd_extract + ": " + snps_file + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                ArrayList<String> snp = NewIt.newArrayList();
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        String[] s = line.split(delim);
                        snp.add(s[0]);
                    }
                    reader.close();
                } catch (IOException E) {
                    System.err.println("bad lines in " + snps_file + ".");
                    Test.LOG.append("bad lines in " + snps_file + ".\n");
                    Test.printLog();
                    System.exit(0);
                }
                if (snp.size() > 0) {
                    ArrayList<String> exsnp = NewIt.newArrayList();
                    for (int i = 0; i < snp.size(); i++) {
                        String subSNP = snp.get(i);
                        exsnp.add(subSNP);
                    }
                    if (exsnp.size() > 0) {
                        excludesnpList.addAll(exsnp);
                        snpFlag = true;
                    }
                }
                if (excludesnpList.size() > 0) {
                    excludesnp = (String[]) excludesnpList.toArray(new String[0]);
                }
            }
        }

    }

    if (cl.hasOption(cmd_keep_male)) {
        keep_maleFlag = true;
    }
    if (cl.hasOption(cmd_keep_female)) {
        keep_femaleFlag = true;
    }
    if (cl.hasOption(cmd_ex_nosex)) {
        ex_nosexFlag = true;
    }
    if (cl.hasOption(cmd_remove)) {
        String file = cl.getOptionValue(cmd_remove);
        File f = new File(file);
        if (!f.exists()) {
            System.err.println("could not open " + file + ".");
            Test.LOG.append("could not open " + file + ".\n");
            Test.printLog();
            System.exit(0);
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(new File(file)));
        } catch (IOException E) {
            System.err.println("could not read " + file + ".");
            Test.LOG.append("coudl not read " + file + ".\n");
            Test.printLog();
            System.exit(0);
        }
        ArrayList<String> famList = NewIt.newArrayList();
        ArrayList<String> indList = NewIt.newArrayList();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                String[] l = line.split(MDRConstant.delim);
                if (l.length < 2)
                    continue;
                famList.add(l[0]);
                indList.add(l[1]);
            }
        } catch (IOException e) {
            e.printStackTrace(System.err);
            System.exit(0);
        }
        ex_family = new String[2][];
        ex_family[0] = (String[]) famList.toArray(new String[0]);
        ex_family[1] = (String[]) indList.toArray(new String[0]);
        removeFlag = true;
    }

    if (cl.hasOption(cmd_keep)) {
        String file = cl.getOptionValue(cmd_keep);
        File f = new File(file);
        if (!f.exists()) {
            System.err.println("could not open " + file + ".");
            Test.LOG.append("could not open " + file + ".\n");
            Test.printLog();
            System.exit(0);
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(new File(file)));
        } catch (IOException E) {
            System.err.println("could not read " + file + ".");
            Test.LOG.append("coudl not read " + file + ".\n");
            Test.printLog();
            System.exit(0);
        }
        ArrayList<String> famList = NewIt.newArrayList();
        ArrayList<String> indList = NewIt.newArrayList();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                String[] l = line.split(MDRConstant.delim);
                if (l.length < 2)
                    continue;
                famList.add(l[0]);
                indList.add(l[1]);
            }
        } catch (IOException e) {
            e.printStackTrace(System.err);
            System.exit(0);
        }
        indKeep = new String[2][];
        indKeep[0] = (String[]) famList.toArray(new String[0]);
        indKeep[1] = (String[]) indList.toArray(new String[0]);
        keepFlag = true;
    }

    if (cl.hasOption(cmd_chr)) {

        String[] chr = cl.getOptionValues(cmd_chr);
        HashSet<String> chrSet = NewIt.newHashSet();
        HashSet<String> exSet = NewIt.newHashSet();
        for (int i = 0; i < chr.length; i++) {
            if (chr[i].startsWith("-")) {
                exSet.add(chr[i].substring(1, chr[i].length()));
            } else {
                chrSet.add(chr[i]);
            }
        }
        if (chr.length != chrSet.size() + exSet.size()) {
            System.err.println("bad parameter for optin --" + cmd_chr + ".");
            Test.LOG.append("bad parameter for option --" + cmd_chr + ".\n");
            Test.printLog();
            System.exit(0);
        }
        if (chrSet.size() > 0) {
            in_chr = (String[]) chrSet.toArray(new String[0]);
            inchrFlag = true;
        }
        if (exSet.size() > 0) {
            ex_chr = (String[]) exSet.toArray(new String[0]);
            exchrFlag = true;
        }
    }

    if (cl.hasOption(cmd_snpwindow)) {
        String[] s = cl.getOptionValues(cmd_snpwindow);
        snpwindow = new String[s.length];
        snp_window = new double[s.length][2];
        for (int i = 0; i < s.length; i++) {
            String[] ss = s[i].split(incommand_separator);
            if (ss.length != 3) {
                System.err.println("bad parameter for optin --" + cmd_snpwindow_long + " " + s[i] + ".");
                Test.LOG.append("bad parameter for option --" + cmd_snpwindow_long + " " + s[i] + ".\n");
                Test.printLog();
                System.exit(0);
            }
            snpwindow[i] = ss[0];
            snp_window[i][0] = Double.parseDouble(ss[1]) * -1000;
            if (Double.parseDouble(ss[2]) > 0) {
                snp_window[i][1] = Double.parseDouble(ss[2]) * 1000;
            } else {
                snp_window[i][1] = Double.MAX_VALUE;
            }
        }
        snpwindowFlag = true;
    }

    if (cl.hasOption(cmd_maf)) {
        maf = Double.parseDouble(cl.getOptionValue(cmd_maf));
        if (maf < 0) {

            System.err.println("bad parameter for optin --" + cmd_maf + " " + maf + ".");
            Test.LOG.append("bad parameter for option --" + cmd_maf + " " + maf + ".\n");
            Test.printLog();
            System.exit(0);
        }
        mafFlag = true;
    }

    if (cl.hasOption(cmd_max_maf)) {
        max_maf = Double.parseDouble(cl.getOptionValue(cmd_max_maf));
        if (max_maf < 0) {
            System.err.println("bad parameter for optin --" + cmd_max_maf_long + " " + max_maf + ".");
            Test.LOG.append("bad parameter for option --" + cmd_max_maf_long + " " + max_maf + ".\n");
            Test.printLog();
            System.exit(0);
        }
        maxmafFlag = true;
    }

    if (cl.hasOption(cmd_geno)) {
        geno = Double.parseDouble(cl.getOptionValue(cmd_geno));
        if (geno < 0) {

            System.err.println("bad parameter for optin --" + cmd_geno + " " + geno + ".");
            Test.LOG.append("bad parameter for option --" + cmd_geno + " " + geno + ".\n");
            Test.printLog();
            System.exit(0);
        }
        genoFlag = true;
    }
    //
    // if (cl.hasOption(cmd_hwe)) {
    // hwe = Double.parseDouble(cl.getOptionValue(cmd_hwe));
    // if (hwe < 0) {
    // throw new IllegalArgumentException("bad parameter for --hwe: " +
    // hwe);
    // }
    // hweFlag = true;
    // }

    //      if (cl.hasOption(cmd_reg)) {
    //         linkfunction = Integer.parseInt(cl.getOptionValue(cmd_reg));
    //      }
    if (cl.hasOption(cmd_cv)) {
        cv = Integer.parseInt(cl.getOptionValue(cmd_cv));
        if (cv < 2) {

            System.err.println("bad parameter for optin --" + cmd_cv + " " + cv + ".");
            Test.LOG.append("bad parameter for option --" + cmd_cv + " " + cv + ".\n");
            Test.printLog();
            System.exit(0);
        }
        cvFlag = true;
    }
    // if (cl.hasOption(cmd_trgroup)) {
    // trgroup = Double.parseDouble(cl.getOptionValue(cmd_trgroup));
    // trgroupFlag = true;
    // }
    // if (cl.hasOption(cmd_trsex)) {
    // trsex = Integer.parseInt(cl.getOptionValue(cmd_trsex));
    // if (trsex != 1 && trsex != 2) {
    // throw new
    // IllegalArgumentException("unknown value for option --trsex.");
    // }
    // trsexFlag = true;
    // }
    // if (cl.hasOption(cmd_ttfile)) {
    // String tf = cl.getOptionValue(cmd_ttfile);
    // File ttfile = new File(tf);
    // if (!ttfile.exists()) {
    // throw new IllegalArgumentException("could not open ttfile " + tf);
    // }
    //
    // ArrayList<String> Farray = NewIt.newArrayList();
    // ArrayList<String> Iarray = NewIt.newArrayList();
    // BufferedReader reader = null;
    // try {
    // reader = new BufferedReader(new FileReader(new File(tf)));
    // } catch (IOException E) {
    // throw new IllegalArgumentException("failed in reading " + tf);
    // }
    // String line = null;
    // try {
    // while ((line = reader.readLine()) != null) {
    // String[] l = line.split(delim);
    // Farray.add(l[0]);
    // Iarray.add(l[1]);
    // }
    // } catch (IOException e) {
    // e.printStackTrace();
    // }
    //
    // ttArray = new String[2][Farray.size()];
    // ttArray[0] = (String[]) Farray.toArray(new String[0]);
    // ttArray[1] = (String[]) Iarray.toArray(new String[0]);
    // ttfileFlag = true;
    // }
    // if (cl.hasOption(cmd_border)) {
    // String[] h = cl.getOptionValues(cmd_border);
    // if (h.length != 2) {
    // throw new
    // IllegalArgumentException("bad parameter for option --border.");
    // }
    // boolean rflag = false;
    // if (h[0].startsWith("-")) {
    // border_fid = h[0].substring(1, h[0].length());
    // rflag = true;
    // } else {
    // border_fid = h[0];
    // }
    // if (h[1].startsWith("-")) {
    // border_iid = h[1].substring(1, h[1].length());
    // rflag = true;
    // } else {
    // border_iid = h[1];
    // }
    // borderFlag = true;
    // reverseborderFlag = rflag;
    // }
    if (cl.hasOption(cmd_seed)) {
        seed = Integer.parseInt(cl.getOptionValue(cmd_seed));
    }
    if (cl.hasOption(cmd_tie)) {
        String t = cl.getOptionValue(cmd_tie);
        if (t.compareTo("h") == 0) {
            tie = 1;
        } else if (t.compareTo("l") == 0) {
            tie = 0;
        } else {
            tie = -1;
        }
    }
    // if (cl.hasOption(cmd_simu)) {
    // simu = Integer.parseInt(cl.getOptionValue(cmd_simu));
    // }
    if (cl.hasOption(cmd_perm)) {
        perm = Integer.parseInt(cl.getOptionValue(cmd_perm));
        permFlag = true;
    }
    /*
    if (cl.hasOption(cmd_ep)) {
       ep = Double.parseDouble(cl.getOptionValue(cmd_ep));
       if (ep >= 1 || ep < 0) {
            
    System.err.println("bad parameter for optin --" + ep + " " + ep + ".");
    Test.LOG.append("bad parameter for option --" + ep + " " + ep + ".\n");
    Test.printLog();
    System.exit(0);
       }
       epFlag = true;
    }
    */
    // if (cl.hasOption(cmd_perm_scheme)) {
    // permu_scheme = true;
    // }
    // if (cl.hasOption(cmd_unrelated_only)) {
    // unrelated_only = true;
    // }
    if (cl.hasOption(cmd_order)) {
        order = Integer.parseInt(cl.getOptionValue(cmd_order));
    }
    if (cl.hasOption(cmd_thin)) {
        thin = Double.parseDouble(cl.getOptionValue(cmd_thin));
        if (thin < 0) {

            System.err.println("bad parameter for optin --" + cmd_thin + " " + thin + ".");
            Test.LOG.append("bad parameter for option --" + cmd_thin + " " + thin + ".\n");
            Test.printLog();
            System.exit(0);
        }
    }
    if (cl.hasOption(cmd_slice)) {
        String[] s = cl.getOptionValue(cmd_slice).split("/");
        slice = Integer.parseInt(s[0]);
        sliceN = Integer.parseInt(s[1]);
        if (slice <= 0 || sliceN <= 0 || slice > sliceN) {

            System.err.println("bad parameter for optin --" + cmd_slice + " " + slice + ".");
            Test.LOG.append("bad parameter for option --" + cmd_slice + " " + slice + ".\n");
            Test.printLog();
            System.exit(0);
        }
        sliceFlag = true;
    }
    if (cl.hasOption(cmd_missing_phenotype)) {
        String[] s = cl.getOptionValues(cmd_missing_phenotype);
        na = s;
        //         missing_phenotype = cl.getOptionValue(cmd_missing_phenotype);
    }
    // if (cl.hasOption(cmd_missing_genotype)) {
    // missing_genotype = cl.getOptionValue(cmd_missing_genotype);
    // }
    if (cl.hasOption(cmd_missing_allele)) {
        missing_allele = cl.getOptionValue(cmd_missing_allele);
    }
    if (cl.hasOption(cmd_status_shift)) {
        status_shift = 0;
        status_shiftFlag = true;
    }
    /*
    if (cl.hasOption(cmd_Vc)) {
       vc = Double.parseDouble(cl.getOptionValue(cmd_Vc));
       vcFlag = true;
    }
    if (cl.hasOption(cmd_training)) {
       threshold_training = Double.parseDouble(cl
       .getOptionValue(cmd_training));
       trainingFlag = true;
    }
    if (cl.hasOption(cmd_testing)) {
       threshold_testing = Double.parseDouble(cl
       .getOptionValue(cmd_testing));
       testingFlag = true;
    }
    */
    if (cl.hasOption(cmd_version)) {
        System.err.println();
        Test.printLog();
        System.exit(1);
    }
    if (cl.hasOption(cmd_testdrive)) {
        testdrive = true;
    }
    if (cl.hasOption(cmd_node)) {
        node = Integer.parseInt(cl.getOptionValue(cmd_node));
        nodeFlag = true;
        clusterFlag = true;
    }
    if (cl.hasOption(cmd_email)) {
        email = cl.getOptionValue(cmd_email);
        emailFlag = true;
        clusterFlag = true;
    }
    if (cl.hasOption(cmd_memory)) {
        memory = cl.getOptionValue(cmd_memory);
        memoryFlag = true;
        clusterFlag = true;
    }
    if (cl.hasOption(cmd_walltime)) {
        walltime = Integer.parseInt(cl.getOptionValue(cmd_walltime));
        walltimeFlag = true;
        clusterFlag = true;
    }
    if (cl.hasOption(cmd_submit)) {
        submit = true;
        clusterFlag = true;
    }
    if (help) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("UGMDR", ops);
        System.exit(1);
    }

}

From source file:net.volcore.wtvcache.WTVCache.java

/** Use apache CLI to parse the command line */
protected static Config parseOptions(String[] args) {
    // Build options
    options = new Options();

    options.addOption("h", "help", false, "print this message");
    options.addOption("m", "master", true,
            "master server, format is <addr>:<port>, can be set 16 times , for multiple master servers");
    options.getOption("m").setArgs(16);
    options.addOption("p", "port", true, "port to run the cache on");
    options.addOption("l", "accesslog", true, "Directory of accesslog");

    // Parse the command line options
    CommandLineParser parser = new PosixParser();

    CommandLine line;
    try {//  w  ww . j  av  a 2  s .co  m
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (org.apache.commons.cli.ParseException exp) {
        // oops, something went wrong
        logger.error("Parsing failed.  Reason: " + exp.getMessage());
        return null;
    }

    // Process the parsed options
    if (line.hasOption("help")) {
        formatter.printHelp("wtvcache", options);
        return null;
    }

    Config config = new Config();

    if (line.hasOption('p'))
        config.listenPort = Integer.parseInt(line.getOptionValue('p'));

    if (line.hasOption('l'))
        config.accessLogDir = line.getOptionValue('l');

    if (line.hasOption('m')) {
        String[] v = line.getOptionValues('m');

        config.master = new SocketAddress[v.length];

        for (int i = 0; i < v.length; ++i) {
            String[] spl = v[i].split(":");
            String addr = spl[0];
            int port = Integer.parseInt(spl[1]);
            config.master[i] = new InetSocketAddress(addr, port);
        }
    }

    return config;
}

From source file:nl.imvertor.common.Configurator.java

/**
 * Create parameters from arguments passed to the java application. 
 * Arguments are parsed by CLI conventions. 
 * Existing argument parameters are replaced.
 * //from w  w w .j a  v a2 s  .  c om
 * Parameters set from command line option are placed in /config/cli subelement and take the form 
 * /config/cli/parameter[@name]/text()  
 * 
 * @param options Command line options
 * @throws Exception 
 */
public void setParmsFromOptions(String[] args) throws Exception {
    CommandLine commandLine = null;
    File curFile = baseFolder;
    try {
        BasicParser parser = new BasicParser();
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption("help"))
            dieOnCli(commandLine.getOptionValue("help"));
    } catch (ParseException e) {
        runner.error(logger, e.getMessage());
        dieOnCli("error");
    }

    @SuppressWarnings("unchecked")
    Iterator<Option> it = commandLine.iterator();
    while (it.hasNext()) {
        Option option = it.next();
        String optionName = option.getOpt();
        String[] v = commandLine.getOptionValues(optionName); // same option many times returns array of values.
        if (v.length > 1)
            throw new Exception("Duplicate argument -" + optionName + " on command line");
        if (optionName.equals("arguments"))
            loadFromPropertyFiles(curFile, v[0]);
        setParm(workConfiguration, "cli", optionName, v[0], true);
        setOptionIsReady(optionName, true);
    }

    String missing = checkOptionsAreReady();
    if (!missing.equals("")) {
        runner.error(logger, "Missing required parameters: " + missing);
        dieOnCli("program");
    }

    // record the metamodel used
    metamodel = getParm(workConfiguration, "cli", "metamodel", false);
    metamodel = (metamodel == null) ? DEFAULT_METAMODEL : metamodel;

    // schema rules used
    schemarules = getParm(workConfiguration, "cli", "schemarules", false);
    schemarules = (schemarules == null) ? DEFAULT_SCHEMARULES : schemarules;

    // set the task
    setParm(workConfiguration, "appinfo", "task", getParm(workConfiguration, "cli", "task", true), true);

    // If forced compilation, try all steps irrespective of any errors
    forceCompile = isTrue(getParm(workConfiguration, "cli", "forcecompile", true));

    // If documentation release, set the suffix for the application id
    String docReleaseString = getParm(workConfiguration, "cli", "docrelease", false);

    // if warnings should be signaled
    suppressWarnings = isTrue("cli", "suppresswarnings", false);

    docRelease = docReleaseString != null && !docReleaseString.equals("00000000");
    if (docRelease) {
        setParm("system", "documentation-release", "-" + docReleaseString);
    } else {
        setParm("system", "documentation-release", "");
    }

}

From source file:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.EQTLInteractionAnalyser.java

public static void main(String[] args) throws IOException, Exception {
    System.out.println("Starting interaction analysis");
    System.out.println("Current date and time: " + DATE_TIME_FORMAT.format(currentDataTime));
    System.out.println();// w  w  w  .j  av a2 s . c o m

    String inputDir, outputDir, eqtlFile = null, annotationFile = null;
    final File snpsToSwapFile;
    int maxNumCovariatesToRegress = 20;
    int numThreads;
    final boolean interpret, chi2sumDiff, permute, preproces;
    final int startRoundCompareChi2, threshold;

    HashMap hashSamples;

    final String[] covariates;
    final String[] covariates2;
    final String[] cohorts;
    final String[] covariatesToTest;
    final File ensgAnnotationFile;
    final File snpsToTestFile;
    final boolean skipNormalization;
    final boolean skipCovariateNormalization;
    final boolean convertMatrix;
    final String eqtlFileCovariates;

    try {
        final CommandLine commandLine = new PosixParser().parse(OPTIONS, args, false);

        inputDir = commandLine.getOptionValue("i");
        outputDir = commandLine.getOptionValue("o");

        if (commandLine.hasOption('e')) {
            eqtlFile = commandLine.getOptionValue("e");
        }

        eqtlFileCovariates = commandLine.getOptionValue("ec", null);

        if (commandLine.hasOption('n')) {
            maxNumCovariatesToRegress = Integer.parseInt(commandLine.getOptionValue("n"));
        }
        if (commandLine.hasOption("thr")) {
            threshold = Integer.parseInt(commandLine.getOptionValue("thr"));
        } else {
            threshold = 3;
        }

        interpret = commandLine.hasOption("it");
        chi2sumDiff = commandLine.hasOption("dif");
        permute = commandLine.hasOption("perm");
        preproces = commandLine.hasOption("p");
        convertMatrix = commandLine.hasOption("cm");

        if (commandLine.hasOption('s')) {
            startRoundCompareChi2 = Integer.parseInt(commandLine.getOptionValue("s"));
        } else if (chi2sumDiff) {
            throw new Exception("Set -s");
        } else {
            startRoundCompareChi2 = 0;
        }

        if (commandLine.hasOption('a')) {
            annotationFile = commandLine.getOptionValue("a");
        }

        if (commandLine.hasOption("cf")) {
            TextFile covFile = new TextFile(commandLine.getOptionValue("cf"), false);
            covariates = covFile.readAsArray();
            covFile.close();
        } else if (commandLine.hasOption("c")) {
            covariates = commandLine.getOptionValues("c");
        } else {
            covariates = new String[0];
        }

        if (commandLine.hasOption("c2")) {
            covariates2 = commandLine.getOptionValues("c2");
        } else {
            covariates2 = new String[0];
        }

        if (commandLine.hasOption("ch")) {
            cohorts = commandLine.getOptionValues("ch");
        } else {
            cohorts = null;
        }

        if (commandLine.hasOption("ct")) {
            covariatesToTest = commandLine.getOptionValues("ct");
        } else {
            covariatesToTest = null;
        }

        if (commandLine.hasOption("sw")) {
            snpsToSwapFile = new File(commandLine.getOptionValue("sw"));
        } else {
            snpsToSwapFile = null;
        }

        if (commandLine.hasOption("snps")) {
            snpsToTestFile = new File(commandLine.getOptionValue("snps"));
        } else {
            snpsToTestFile = null;
        }

        skipNormalization = commandLine.hasOption("nn");
        if (skipNormalization && maxNumCovariatesToRegress != 1) {
            System.err.println("n must be one if normalization is turned off");
            System.exit(-1);
        }

        skipCovariateNormalization = commandLine.hasOption("ncn");
        if (skipCovariateNormalization && maxNumCovariatesToRegress != 1) {
            System.err.println("n must be one if covariate normalization is turned off");
            System.exit(-1);
        }

        if (commandLine.hasOption("is")) {
            File samplesToIncludeFile = new File(commandLine.getOptionValue("is"));
            System.out.println("Samples to include file: " + samplesToIncludeFile.getAbsolutePath());
            hashSamples = new HashMap();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(samplesToIncludeFile), "UTF-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                hashSamples.put(line, null);
                hashSamples.put(line + "_exp", null);
                hashSamples.put(line + "_dosage", null);
            }
        } else {
            hashSamples = null;
        }

        if (commandLine.hasOption("ga")) {
            ensgAnnotationFile = new File(commandLine.getOptionValue("ga"));
        } else {
            ensgAnnotationFile = null;
        }
        if (commandLine.hasOption("nt")) {
            numThreads = Integer.parseInt(commandLine.getOptionValue("nt"));
        } else {
            numThreads = Runtime.getRuntime().availableProcessors();
        }

    } catch (ParseException ex) {
        System.err.println("Invalid command line arguments: ");
        System.err.println(ex.getMessage());
        System.err.println();
        new HelpFormatter().printHelp(" ", OPTIONS);
        System.exit(1);
        return;
    }

    if (preproces) {
        TestEQTLDatasetForInteractions interactor = new TestEQTLDatasetForInteractions(inputDir, outputDir);
        interactor.preprocessData();
    } else if (interpret) {
        TestEQTLDatasetForInteractions interactor = new TestEQTLDatasetForInteractions(inputDir, outputDir);
        interactor.interpretInteractionZScoreMatrix(maxNumCovariatesToRegress, startRoundCompareChi2,
                threshold);
    } else if (chi2sumDiff) {
        TestEQTLDatasetForInteractions interactor = new TestEQTLDatasetForInteractions(inputDir, outputDir);
        interactor.findChi2SumDifferences(maxNumCovariatesToRegress, startRoundCompareChi2, ensgAnnotationFile);
    } else if (convertMatrix) {
        System.out.println("input file: " + inputDir);
        System.out.println("output file: " + outputDir);
        if (inputDir.equals(outputDir)) {
            System.err.println("input == output");
            System.exit(1);
        }
        new ExpressionDataset(inputDir).save(outputDir);
    } else {
        new TestEQTLDatasetForInteractions(inputDir, outputDir, eqtlFile, maxNumCovariatesToRegress,
                annotationFile, covariates, covariates2, snpsToSwapFile, permute, covariatesToTest, hashSamples,
                numThreads, cohorts, snpsToTestFile, skipNormalization, skipCovariateNormalization,
                eqtlFileCovariates);
    }
}

From source file:nor.core.Nor.java

/**
 * ??/*from   w  w w  .j a  va 2  s  . com*/
 * @param args ?????
 * @throws MalformedURLException
 */
@SuppressWarnings("static-access")
public static void main(final String[] args) {
    LOGGER.info("main", "Start up...");

    final Options ops = new Options();
    ops.addOption(OptionBuilder.withArgName("dir").hasArg()
            .withDescription("set directory which has config files").create("config"));

    ops.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("use given configu file for logging system").create("log"));

    final Option pluginsPath = OptionBuilder.withArgName("dir").hasArg()
            .withDescription("use given directory for a serch path of plugins").create("plugin_dir");
    ops.addOption(pluginsPath);

    final Option plugins = OptionBuilder.withArgName("file").hasArg().withDescription("use given plugin file")
            .create("plugin");
    ops.addOption(plugins);

    ops.addOption("help", false, "show this help");

    try {

        final Parser parser = new BasicParser();
        final CommandLine cmd = parser.parse(ops, args);

        if (cmd.hasOption("help")) {

            final HelpFormatter help = new HelpFormatter();
            help.printHelp("nor", ops, true);
            System.exit(0);

        }

        // Configure about logging system.
        InputStream logStream;
        if (cmd.hasOption("log")) {

            logStream = new FileInputStream(cmd.getOptionValue("log"));

        } else {

            final String file = System.getProperty("nor.log", LoggindConfigFile);
            logStream = Nor.class.getResourceAsStream(file);

        }
        Logger.loadConfig(logStream);
        logStream.close();

        // Create the application instance by given config directory
        if (cmd.hasOption("config")) {

            Nor.nor = new Nor(cmd.getOptionValue("config"));

        } else {

            Nor.nor = new Nor(System.getProperty("nor.config", "config"));

        }

        // Load plugins
        final List<URL> pluginJar = new ArrayList<URL>();
        if (cmd.hasOption("plugin")) {

            for (final String filename : cmd.getOptionValues("plugin")) {

                final File f = new File(filename);
                pluginJar.add(f.toURI().toURL());

            }

        }
        if (cmd.hasOption("plugin_dir")) {

            for (final String dirname : cmd.getOptionValues("plugin_dir")) {

                final File dir = new File(dirname);
                if (dir.isDirectory()) {

                    for (final String filename : dir.list()) {

                        final File f = new File(dir, filename);
                        pluginJar.add(f.toURI().toURL());

                    }

                }

            }

        }
        nor.init(pluginJar);

        nor.start();

        // Waiting for end
        System.in.read();

        // Closing
        nor.close();

    } catch (final UnrecognizedOptionException e) {

        final HelpFormatter help = new HelpFormatter();
        help.printHelp("nor", ops, true);

    } catch (final Exception e) {

        LOGGER.catched(Level.SEVERE, "main", e);

    }

    LOGGER.info("main", "End.");

}

From source file:norbert.mynemo.ui.ImportCommandParser.java

/**
 * Parses and checks the given arguments, then calls
 * {@link FileImporter#convert(String, java.util.Collection, Optional, Optional, Optional, Optional)
 * FileImporter.convert()}./*from w ww .java  2 s  .  c om*/
 */
public static void parse(String[] args) throws ParseException, IOException {
    CommandLineParser parser = new BasicParser();

    Options options = getOptions();

    CommandLine commandLine = parser.parse(options, args);

    String outputFilepath = commandLine.getOptionValue(OUT_LONG_OPTION);
    String[] ratingsFilepaths = commandLine.getOptionValues(RATINGS_LONG_OPTION);
    String[] moviesFilepath = Optional.fromNullable(commandLine.getOptionValues(MOVIES_LONG_OPTION))
            .or(new String[0]);
    Optional<String> user = Optional.fromNullable(commandLine.getOptionValue(USER_LONG_OPTION));
    Optional<Integer> maxUsers = parseMaxUser(commandLine.getOptionValue(MAX_USERS_LONG_OPTION));
    Optional<Integer> minRatingsByMovie = parseMinRatingsByMovie(
            commandLine.getOptionValue(MIN_RATINGS_BY_MOVIE_LONG_OPTION));
    Optional<Integer> minCommonRatings = parseMinCommonRatings(
            commandLine.getOptionValue(MIN_COMMON_RATINGS_LONG_OPTION));
    Optional<UserSimilarityType> similarityType = parseSimilarityType(
            commandLine.getOptionValue(SIMILARITY_LONG_OPTION));

    check(outputFilepath, ratingsFilepaths, moviesFilepath, maxUsers, minCommonRatings, user, similarityType);

    FileImporter.convert(outputFilepath, Arrays.asList(ratingsFilepaths), Arrays.asList(moviesFilepath), user,
            maxUsers, minRatingsByMovie, minCommonRatings, similarityType);
}

From source file:norbert.mynemo.ui.ScrapeCommandParser.java

/**
 * Parses and checks the given arguments, then runs the scraper.
 *//*from   w  ww  .  ja v a2 s .  c  o  m*/
public static void parse(String[] args)
        throws ParseException, IOException, TasteException, InterruptedException {

    CommandLine commandLine = new BasicParser().parse(getOptions(), args);

    // parse the options
    String outMoviesFilepath = commandLine.getOptionValue(OUT_MOVIES_LONG_OPTION);
    String outRatingsFilepath = commandLine.getOptionValue(OUT_RATINGS_LONG_OPTION);
    String[] inputFilepaths = commandLine.getOptionValues(IN_LONG_OPTION);
    List<String> userAgents = parseUserAgents(commandLine.getOptionValue(USERAGENTS_LONG_OPTION));
    String movieBlacklistFilepath = commandLine.getOptionValue(MOVIE_BLACKLIST_LONG_OPTION);
    String userBlacklistFilepath = commandLine.getOptionValue(USER_BLACKLIST_LONG_OPTION);

    // check
    check(outMoviesFilepath, outRatingsFilepath, inputFilepaths, movieBlacklistFilepath);

    // run
    execute(outMoviesFilepath, outRatingsFilepath, inputFilepaths, userAgents, movieBlacklistFilepath,
            userBlacklistFilepath);
}