Search in sources :

Example 16 with Arguments

use of dr.app.util.Arguments in project beast-mcmc by beast-dev.

the class MixtureModelLogAnalyser method main.

//Main method
public static void main(String[] args) throws IOException, TraceException {
    printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in'"), new Arguments.StringOption("discreteVariable", "variable_name", "indicates the name of a variable that is actually discrete in nature"), new Arguments.Option("help", "option to print this message") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.out.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    int burnin = -1;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    }
    String discreteVariableName = null;
    if (arguments.hasOption("discreteVariable")) {
        discreteVariableName = arguments.getStringOption("discreteVariable");
    }
    String inputFileName = null;
    String outputFileName = null;
    String[] args2 = arguments.getLeftoverArguments();
    if (args2.length > 2) {
        System.err.println("Unknown option: " + args2[2]);
        System.err.println();
        printUsage(arguments);
        System.exit(1);
    }
    if (args2.length > 0) {
        inputFileName = args2[0];
    }
    if (args2.length > 1) {
        outputFileName = args2[1];
    }
    if (inputFileName == null) {
        // No input file name was given so throw up a dialog box...
        inputFileName = Utils.getLoadFileName("MixtureModelLogAnalyser " + version.getVersionString() + " - Select log file to analyse");
    }
    if (burnin == -1) {
        System.out.println("Enter number of trees to burn-in (integer): ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        burnin = Integer.parseInt(br.readLine());
    }
    if (discreteVariableName == null) {
        System.out.println("Enter name of discrete variable: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        discreteVariableName = br.readLine();
    }
    new MixtureModelLogAnalyser(burnin, inputFileName, outputFileName, discreteVariableName);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 17 with Arguments

use of dr.app.util.Arguments in project beast-mcmc by beast-dev.

the class TopologyTracer method main.

public static void main(String[] args) {
    // There is a major issue with languages that use the comma as a decimal separator.
    // To ensure compatibility between programs in the package, enforce the US locale.
    Locale.setDefault(Locale.US);
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in' [default = none]"), new Arguments.StringOption("tree", "tree file name", "a focal tree provided by the user [default = first tree in .trees file]"), new Arguments.RealOption("lambda", "the lambda value to be used for the 'Kendall-Colijn metric' [default = {0,0.5,1}]"), new Arguments.Option("help", "option to print this message") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.out.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    int burnin = 0;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    }
    ArrayList<Double> lambdaValues = new ArrayList<Double>();
    lambdaValues.add(0.0);
    lambdaValues.add(0.5);
    lambdaValues.add(1.0);
    if (arguments.hasOption("lambda")) {
        lambdaValues.add(arguments.getRealOption("lambda"));
    }
    String providedFileName = "";
    if (arguments.hasOption("tree")) {
        providedFileName = arguments.getStringOption("tree");
    }
    String inputFileName = null;
    String outputFileName = null;
    String[] args2 = arguments.getLeftoverArguments();
    if (args2.length > 3) {
        System.err.println("Unknown option: " + args2[2]);
        System.err.println();
        printUsage(arguments);
        System.exit(1);
    }
    if (args2.length > 0) {
        inputFileName = args2[0];
    }
    if (args2.length > 1) {
        outputFileName = args2[1];
    }
    if (inputFileName == null) {
        // No input file name was given so throw up a dialog box...
        inputFileName = Utils.getLoadFileName("TopologyTracer " + version.getVersionString() + " - Select log file to analyse");
    }
    new TopologyTracer(burnin, inputFileName, providedFileName, outputFileName, lambdaValues);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments) ArrayList(java.util.ArrayList)

Example 18 with Arguments

use of dr.app.util.Arguments in project beast-mcmc by beast-dev.

the class DensityPlotter method main.

//Main method
public static void main(String[] args) throws IOException {
    String inputFileName = null;
    String outputFileName = null;
    printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in' [default = 0]"), new Arguments.StringOption("trait", "trait_name", "specifies an attribute to use to create a density map [default = rate]"), new Arguments.StringOption("trait2", "trait_name", "specifies a second attribute to use to create a density map [default = rate]"), new Arguments.IntegerOption("time_bins", "the number of bins for the time axis of the density map [default = 100]"), new Arguments.IntegerOption("value_bins", "the number of bins for the value axis of the density map [default = 20]"), new Arguments.RealOption("time_upper", "the upper time bound for the density map [default = max tree age]"), new Arguments.RealOption("time_lower", "the lower time bound for the density map [default = 0]"), new Arguments.RealOption("value_upper", "the upper value bound for the density map [default = max value]"), new Arguments.RealOption("value_lower", "the lower value bound for the density map [default = min value]"), new Arguments.RealOption("value2_upper", "the upper second value bound for the density map [default = max value]"), new Arguments.RealOption("value2_lower", "the lower second value bound for the density map [default = min value]"), new Arguments.StringOption("headers", "with_headers", "prints row/column labels in output [default = true"), new Arguments.Option("tiff", "output in TIFF format"), new Arguments.Option("help", "option to print this message"), new Arguments.Option("logScale", "transform trait to log scale") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.out.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    int burnin = -1;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    }
    String trait1AttributeName = "rate";
    String trait2AttributeName = null;
    int timeBinCount = 100;
    int valueBinCount = 25;
    int value2BinCount = 25;
    double timeUpper = Double.POSITIVE_INFINITY;
    double timeLower = Double.NEGATIVE_INFINITY;
    double valueUpper = Double.POSITIVE_INFINITY;
    double valueLower = Double.NEGATIVE_INFINITY;
    double value2Upper = Double.POSITIVE_INFINITY;
    double value2Lower = Double.NEGATIVE_INFINITY;
    boolean logScale = false;
    if (arguments.hasOption("logScale"))
        logScale = true;
    if (arguments.hasOption("trait")) {
        trait1AttributeName = arguments.getStringOption("trait");
    }
    if (arguments.hasOption("trait2")) {
        trait2AttributeName = arguments.getStringOption("trait2");
    }
    if (arguments.hasOption("time_bins")) {
        timeBinCount = arguments.getIntegerOption("time_bins");
    }
    if (arguments.hasOption("value_bins")) {
        valueBinCount = arguments.getIntegerOption("value_bins");
    }
    value2BinCount = valueBinCount;
    if (arguments.hasOption("value2_bins")) {
        value2BinCount = arguments.getIntegerOption("value2_bins");
    }
    if (arguments.hasOption("time_upper")) {
        timeUpper = arguments.getRealOption("time_upper");
    }
    if (arguments.hasOption("time_lower")) {
        timeLower = arguments.getRealOption("time_lower");
    }
    if (arguments.hasOption("value_upper")) {
        valueUpper = arguments.getRealOption("value_upper");
    }
    if (arguments.hasOption("value_lower")) {
        valueLower = arguments.getRealOption("value_lower");
    }
    if (arguments.hasOption("value2_upper")) {
        value2Upper = arguments.getRealOption("value2_upper");
    }
    if (arguments.hasOption("value2_lower")) {
        value2Lower = arguments.getRealOption("value2_lower");
    }
    boolean printHeaders = true;
    if (arguments.hasOption("headers")) {
        String text = arguments.getStringOption("headers");
        if (text.toUpperCase().compareTo("FALSE") == 0)
            printHeaders = false;
    }
    boolean outputTIFF = false;
    if (arguments.hasOption("tiff"))
        outputTIFF = true;
    String[] args2 = arguments.getLeftoverArguments();
    if (args2.length > 2) {
        System.err.println("Unknown option: " + args2[2]);
        System.err.println();
        printUsage(arguments);
        System.exit(1);
    }
    if (args2.length == 2) {
        inputFileName = args2[0];
        outputFileName = args2[1];
    } else {
        System.err.println("Missing input or output file name");
        printUsage(arguments);
        System.exit(1);
    }
    new DensityPlotter(burnin, inputFileName, outputFileName, trait1AttributeName, trait2AttributeName, timeBinCount, valueBinCount, value2BinCount, timeUpper, timeLower, valueUpper, valueLower, value2Upper, value2Lower, printHeaders, outputTIFF, logScale);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 19 with Arguments

use of dr.app.util.Arguments in project beast-mcmc by beast-dev.

the class BeastMain method main.

//Main method
public static void main(String[] args) throws java.io.IOException {
    // There is a major issue with languages that use the comma as a decimal separator.
    // To ensure compatibility between programs in the package, enforce the US locale.
    Locale.setDefault(Locale.US);
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("verbose", "Give verbose XML parsing messages"), new Arguments.Option("warnings", "Show warning messages about BEAST XML file"), new Arguments.Option("strict", "Fail on non-conforming BEAST XML file"), new Arguments.Option("window", "Provide a console window"), new Arguments.Option("options", "Display an options dialog"), new Arguments.Option("working", "Change working directory to input file's directory"), new Arguments.LongOption("seed", "Specify a random number generator seed"), new Arguments.StringOption("prefix", "PREFIX", "Specify a prefix for all output log filenames"), new Arguments.Option("overwrite", "Allow overwriting of log files"), new Arguments.IntegerOption("errors", "Specify maximum number of numerical errors before stopping"), new Arguments.IntegerOption("threads", "The number of computational threads to use (default auto)"), new Arguments.Option("java", "Use Java only, no native implementations"), new Arguments.RealOption("threshold", 0.0, Double.MAX_VALUE, "Full evaluation test threshold (default 0.1)"), new Arguments.Option("beagle_off", "Don't use the BEAGLE library"), new Arguments.Option("beagle", "Use BEAGLE library if available (default on)"), new Arguments.Option("beagle_info", "BEAGLE: show information on available resources"), new Arguments.StringOption("beagle_order", "order", "BEAGLE: set order of resource use"), new Arguments.IntegerOption("beagle_instances", "BEAGLE: divide site patterns amongst instances"), new Arguments.Option("beagle_CPU", "BEAGLE: use CPU instance"), new Arguments.Option("beagle_GPU", "BEAGLE: use GPU instance if available"), new Arguments.Option("beagle_SSE", "BEAGLE: use SSE extensions if available"), new Arguments.Option("beagle_SSE_off", "BEAGLE: turn off use of SSE extensions"), new Arguments.Option("beagle_cuda", "BEAGLE: use CUDA parallization if available"), new Arguments.Option("beagle_opencl", "BEAGLE: use OpenCL parallization if available"), new Arguments.Option("beagle_single", "BEAGLE: use single precision if available"), new Arguments.Option("beagle_double", "BEAGLE: use double precision if available"), new Arguments.Option("beagle_async", "BEAGLE: use asynchronous kernels if available"), new Arguments.StringOption("beagle_scaling", new String[] { "default", "dynamic", "delayed", "always", "none" }, false, "BEAGLE: specify scaling scheme to use"), new Arguments.Option("beagle_delay_scaling_off", "BEAGLE: don't wait until underflow for scaling option"), new Arguments.LongOption("beagle_rescale", "BEAGLE: frequency of rescaling (dynamic scaling only)"), new Arguments.Option("mpi", "Use MPI rank to label output"), new Arguments.IntegerOption("mc3_chains", 1, Integer.MAX_VALUE, "number of chains"), new Arguments.RealOption("mc3_delta", 0.0, Double.MAX_VALUE, "temperature increment parameter"), new Arguments.RealArrayOption("mc3_temperatures", -1, "a comma-separated list of the hot chain temperatures"), new Arguments.LongOption("mc3_swap", 1, Integer.MAX_VALUE, "frequency at which chains temperatures will be swapped"), new Arguments.StringOption("load_dump", "FILENAME", "Specify a filename to load a dumped state from"), new Arguments.LongOption("dump_state", "Specify a state at which to write a dump file"), new Arguments.LongOption("dump_every", "Specify a frequency to write a dump file"), new Arguments.StringOption("save_dump", "FILENAME", "Specify a filename to save a dumped state to"), new Arguments.StringOption("citations_file", "FILENAME", "Specify a filename to write a citation list to"), new Arguments.Option("version", "Print the version and credits and stop"), new Arguments.Option("help", "Print this information and stop") });
    int argumentCount = 0;
    StringBuilder commandLine = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        if (i > 0) {
            commandLine.append(" ");
        }
        commandLine.append(args[i]);
    }
    System.setProperty("command_line", commandLine.toString());
    try {
        argumentCount = arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.out.println();
        System.out.println(ae.getMessage());
        System.out.println();
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("version")) {
        printTitle();
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
    }
    if (arguments.hasOption("version") || arguments.hasOption("help")) {
        System.exit(0);
    }
    List<String> additionalParsers = new ArrayList<String>();
    final boolean verbose = arguments.hasOption("verbose");
    if (verbose) {
        System.setProperty("verbose_output", Boolean.toString(true));
    }
    // if dev, then auto turn on, otherwise default to turn off
    final boolean warnings = arguments.hasOption("warnings");
    if (warnings) {
        System.setProperty("show_warnings", Boolean.toString(true));
    }
    final boolean strictXML = arguments.hasOption("strict");
    final boolean window = arguments.hasOption("window");
    final boolean options = arguments.hasOption("options") || (argumentCount == 0);
    final boolean working = arguments.hasOption("working");
    String fileNamePrefix = null;
    boolean allowOverwrite = arguments.hasOption("overwrite");
    boolean useMPI = arguments.hasOption("mpi");
    long seed = MathUtils.getSeed();
    boolean useJava = false;
    if (arguments.hasOption("threshold")) {
        double evaluationThreshold = arguments.getRealOption("threshold");
        System.setProperty("mcmc.evaluation.threshold", Double.toString(evaluationThreshold));
    }
    int threadCount = -1;
    if (arguments.hasOption("java")) {
        useJava = true;
    }
    if (arguments.hasOption("prefix")) {
        fileNamePrefix = arguments.getStringOption("prefix");
    }
    // ============= MC^3 settings =============
    int chainCount = 1;
    if (arguments.hasOption("mc3_chains")) {
        chainCount = arguments.getIntegerOption("mc3_chains");
    } else if (arguments.hasOption("mc3_temperatures")) {
        chainCount = 1 + arguments.getRealArrayOption("mc3_temperatures").length;
    }
    double delta = DEFAULT_DELTA;
    if (arguments.hasOption("mc3_delta")) {
        if (arguments.hasOption("mc3_temperatures")) {
            System.err.println("Either the -mc3_delta or the -mc3_temperatures option should be used, not both");
            System.err.println();
            printUsage(arguments);
            System.exit(1);
        }
        delta = arguments.getRealOption("mc3_delta");
    }
    double[] chainTemperatures = new double[chainCount];
    chainTemperatures[0] = 1.0;
    if (arguments.hasOption("mc3_temperatures")) {
        double[] hotChainTemperatures = arguments.getRealArrayOption("mc3_temperatures");
        assert hotChainTemperatures.length == chainCount - 1;
        System.arraycopy(hotChainTemperatures, 0, chainTemperatures, 1, chainCount - 1);
    } else {
        for (int i = 1; i < chainCount; i++) {
            chainTemperatures[i] = 1.0 / (1.0 + (delta * i));
        }
    }
    int swapChainsEvery = DEFAULT_SWAP_CHAIN_EVERY;
    if (arguments.hasOption("mc3_swap")) {
        swapChainsEvery = arguments.getIntegerOption("mc3_swap");
    }
    boolean useMC3 = chainCount > 1;
    // ============= BEAGLE settings =============
    long beagleFlags = 0;
    boolean beagleShowInfo = arguments.hasOption("beagle_info");
    // if any beagle flag is specified then use beagle...
    boolean useBeagle = !arguments.hasOption("beagle_off");
    if (arguments.hasOption("beagle_CPU")) {
        beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
    }
    if (arguments.hasOption("beagle_GPU")) {
        beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
    }
    if (arguments.hasOption("beagle_cuda")) {
        beagleFlags |= BeagleFlag.FRAMEWORK_CUDA.getMask();
    }
    if (arguments.hasOption("beagle_opencl")) {
        beagleFlags |= BeagleFlag.FRAMEWORK_OPENCL.getMask();
    }
    if (!arguments.hasOption("beagle_SSE_off")) {
        beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
    }
    //        }
    if (arguments.hasOption("beagle_single")) {
        beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
    } else {
        beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
    }
    if (arguments.hasOption("beagle_async")) {
        beagleFlags |= BeagleFlag.COMPUTATION_ASYNCH.getMask();
    }
    if (arguments.hasOption("beagle_order")) {
        System.setProperty("beagle.resource.order", arguments.getStringOption("beagle_order"));
    }
    if (arguments.hasOption("beagle_instances")) {
        System.setProperty("beagle.instance.count", Integer.toString(arguments.getIntegerOption("beagle_instances")));
    }
    if (arguments.hasOption("beagle_scaling")) {
        System.setProperty("beagle.scaling", arguments.getStringOption("beagle_scaling"));
    }
    if (arguments.hasOption("beagle_delay_scaling_off")) {
        System.setProperty("beagle.delay.scaling", Boolean.FALSE.toString());
    }
    if (arguments.hasOption("beagle_rescale")) {
        System.setProperty("beagle.rescale", Long.toString(arguments.getLongOption("beagle_rescale")));
    }
    // ============= Other settings =============
    if (arguments.hasOption("threads")) {
        // threadCount defaults to -1 unless the user specifies an option
        threadCount = arguments.getIntegerOption("threads");
        if (threadCount < 0) {
            printTitle();
            System.err.println("The the number of threads should be >= 0");
            System.exit(1);
        }
    }
    if (arguments.hasOption("seed")) {
        seed = arguments.getLongOption("seed");
        if (seed <= 0) {
            printTitle();
            System.err.println("The random number seed should be > 0");
            System.exit(1);
        }
    }
    if (arguments.hasOption("load_dump")) {
        String debugStateFile = arguments.getStringOption("load_dump");
        System.setProperty(BeastCheckpointer.LOAD_STATE_FILE, debugStateFile);
    }
    if (arguments.hasOption("dump_state")) {
        long debugWriteState = arguments.getLongOption("dump_state");
        System.setProperty(BeastCheckpointer.SAVE_STATE_AT, Long.toString(debugWriteState));
    }
    if (arguments.hasOption("dump_every")) {
        long debugWriteEvery = arguments.getLongOption("dump_every");
        System.setProperty(BeastCheckpointer.SAVE_STATE_EVERY, Long.toString(debugWriteEvery));
    }
    if (arguments.hasOption("save_dump")) {
        String debugStateFile = arguments.getStringOption("save_dump");
        System.setProperty(BeastCheckpointer.SAVE_STATE_FILE, debugStateFile);
    }
    if (arguments.hasOption("citations_file")) {
        String debugStateFile = arguments.getStringOption("citations_file");
        System.setProperty("citations.filename", debugStateFile);
    }
    if (useMPI) {
        String[] nullArgs = new String[0];
        try {
            BeastMPI.Init(nullArgs);
        } catch (Exception e) {
            throw new RuntimeException("Unable to access MPI.");
        }
        int rank = BeastMPI.COMM_WORLD.Rank();
        System.setProperty("mpi.rank.postfix", String.valueOf(rank));
    }
    String rankProp = System.getProperty("mpi.rank.postfix");
    if (rankProp != null) {
        int rank = Integer.valueOf(rankProp);
        seed = updateSeedByRank(seed, rank);
    }
    int maxErrorCount = 0;
    if (arguments.hasOption("errors")) {
        maxErrorCount = arguments.getIntegerOption("errors");
        if (maxErrorCount < 0) {
            maxErrorCount = 0;
        }
    }
    BeastConsoleApp consoleApp = null;
    String nameString = "BEAST " + version.getVersionString();
    if (window) {
        System.setProperty("com.apple.macos.useScreenMenuBar", "true");
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
        String titleString = "<html>" + "<div style=\"font: HelveticaNeue, Helvetica, Arial, sans-serif\">" + "<p style=\"font-weight: 100; font-size: 42px\">BEAST</p>" + "<p style=\"font-weight: 200; font-size: 12px\">Bayesian Evolutionary Analysis Sampling Trees</p>" + "<p style=\"font-weight: 300; font-size: 11px\">Version " + version.getVersionString() + ", " + version.getDateString() + "</p>" + "</div></html>";
        String aboutString = "<html>" + "<div style=\"font-family:HelveticaNeue-Light, 'Helvetica Neue Light', Helvetica, Arial, 'Lucida Grande',sans-serif; font-weight: 100\">" + "<center>" + version.getHTMLCredits() + "</div></center></div></html>";
        consoleApp = new BeastConsoleApp(nameString, titleString, aboutString, icon);
        consoleApp.initialize();
    }
    printTitle();
    File inputFile = null;
    if (options && !beagleShowInfo) {
        String titleString = "<html>" + "<div style=\"font: HelveticaNeue, Helvetica, Arial, sans-serif\">" + "<div style=\"font-weight: 100; font-size: 42px\">BEAST</div>" + "<div style=\"font-weight: 200; font-size: 11px\">Bayesian Evolutionary Analysis Sampling Trees</div>" + "<div style=\"font-weight: 300; font-size: 10px\">Version " + version.getVersionString() + ", " + version.getDateString() + "</div>" + "<div style=\"font-weight: 300; font-size: 10px\"><a href=\"" + version.getBuildString() + "\">" + version.getBuildString() + "</a></div>" + "</div></html>";
        javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
        BeastDialog dialog = new BeastDialog(new JFrame(), titleString, icon);
        dialog.setAllowOverwrite(allowOverwrite);
        dialog.setSeed(seed);
        dialog.setUseBeagle(useBeagle);
        if (BeagleFlag.PROCESSOR_GPU.isSet(beagleFlags)) {
            dialog.setPreferBeagleGPU();
        }
        dialog.setPreferBeagleSSE(BeagleFlag.VECTOR_SSE.isSet(beagleFlags));
        if (BeagleFlag.PRECISION_SINGLE.isSet(beagleFlags)) {
            dialog.setPreferBeagleSingle();
        }
        if (!dialog.showDialog(nameString)) {
            return;
        }
        if (dialog.allowOverwrite()) {
            allowOverwrite = true;
        }
        seed = dialog.getSeed();
        threadCount = dialog.getThreadPoolSize();
        useBeagle = dialog.useBeagle();
        if (useBeagle) {
            beagleShowInfo = dialog.showBeagleInfo();
            if (dialog.preferBeagleCPU()) {
                beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
            }
            if (dialog.preferBeagleSSE()) {
                beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
            } else {
                beagleFlags &= ~BeagleFlag.VECTOR_SSE.getMask();
            }
            if (dialog.preferBeagleGPU()) {
                beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
            }
            if (dialog.preferBeagleDouble()) {
                beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
            }
            if (dialog.preferBeagleSingle()) {
                beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
            }
            System.setProperty("beagle.scaling", dialog.scalingScheme());
        }
        inputFile = dialog.getInputFile();
        if (!beagleShowInfo && inputFile == null) {
            System.err.println("No input file specified");
            return;
        }
    }
    if (useBeagle) {
        BeagleInfo.printVersionInformation();
        if (BeagleInfo.getVersion().startsWith("1.")) {
            System.err.println("WARNING: You are currenly using BEAGLE v1.x. For best performance and compatibility\n" + "with models in BEAST, please upgrade to BEAGLE v2.x at http://github.com/beagle-dev/beagle-lib/\n");
        }
    }
    if (beagleShowInfo) {
        BeagleInfo.printResourceList();
        return;
    }
    if (inputFile == null) {
        String[] args2 = arguments.getLeftoverArguments();
        if (args2.length > 1) {
            System.err.println("Unknown option: " + args2[1]);
            System.err.println();
            printUsage(arguments);
            return;
        }
        String inputFileName = null;
        if (args2.length > 0) {
            inputFileName = args2[0];
            inputFile = new File(inputFileName);
        }
        if (inputFileName == null) {
            // No input file name was given so throw up a dialog box...
            inputFile = Utils.getLoadFile("BEAST " + version.getVersionString() + " - Select XML input file");
        }
    }
    if (inputFile != null && inputFile.getParent() != null && working) {
        System.setProperty("user.dir", inputFile.getParent());
    }
    if (window) {
        if (inputFile == null) {
            consoleApp.setTitle("null");
        } else {
            consoleApp.setTitle(inputFile.getName());
        }
    }
    if (useJava) {
        System.setProperty("java.only", "true");
    }
    if (fileNamePrefix != null && fileNamePrefix.trim().length() > 0) {
        System.setProperty("file.name.prefix", fileNamePrefix.trim());
    }
    if (allowOverwrite) {
        System.setProperty("log.allow.overwrite", "true");
    }
    if (useBeagle) {
        additionalParsers.add("beagle");
    }
    if (beagleFlags != 0) {
        System.setProperty("beagle.preferred.flags", Long.toString(beagleFlags));
    }
    if (threadCount >= 0) {
        System.setProperty("thread.count", String.valueOf(threadCount));
    }
    MathUtils.setSeed(seed);
    System.out.println("Random number seed: " + seed);
    try {
        new BeastMain(inputFile, consoleApp, maxErrorCount, verbose, warnings, strictXML, additionalParsers, useMC3, chainTemperatures, swapChainsEvery);
    } catch (RuntimeException rte) {
        rte.printStackTrace(System.err);
        if (window) {
            System.out.println();
            System.out.println("BEAST has terminated with an error. Please select QUIT from the menu.");
        // logger.severe will throw a RTE but we want to keep the console visible
        } else {
            System.out.flush();
            System.err.flush();
            System.exit(1);
        }
    }
    if (useMPI) {
        BeastMPI.Finalize();
    }
    if (!window) {
        System.exit(0);
    }
}
Also used : Arguments(dr.app.util.Arguments) IOException(java.io.IOException) javax.swing(javax.swing) File(java.io.File)

Example 20 with Arguments

use of dr.app.util.Arguments in project beast-mcmc by beast-dev.

the class BEASTGen method main.

public static void main(String[] args) {
    // There is a major issue with languages that use the comma as a decimal separator.
    // To ensure compatibility between programs in the package, enforce the US locale.
    Locale.setDefault(Locale.US);
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("date_order", "The order of the date field (negative numbers from last)"), new Arguments.StringOption("date_prefix", "prefix", "A string that is the prefix to the date field"), new Arguments.StringOption("date_regex", "regex", "A string that gives the regular expression to match the date"), new Arguments.StringOption("date_format", "format", "A string that gives the date format for parsing"), new Arguments.Option("date_precision", "Specifies the date is a variable precision yyyy-MM-dd format"), new Arguments.StringOption("tree", "tree-file-name", "Read a tree from a file"), new Arguments.StringOption("D", "\"key=value,key=value...\"", "Properties for exchange in templates"), new Arguments.Option("version", "Print the version and credits and stop"), new Arguments.Option("help", "Print this information and stop") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        printTitle();
        System.out.println();
        System.out.println(ae.getMessage());
        System.out.println();
        printUsage(arguments);
        System.exit(1);
    }
    DateGuesser guesser = new DateGuesser();
    if (arguments.hasOption("date_order")) {
        guesser.guessDates = true;
        int order = arguments.getIntegerOption("date_order");
        if (order < 0) {
            guesser.order = 1 + order;
            guesser.fromLast = true;
        } else if (order > 0) {
            guesser.order = order - 1;
            guesser.fromLast = false;
        } else {
            guesser.order = 0;
            guesser.fromLast = false;
        }
    }
    if (arguments.hasOption("date_prefix")) {
        guesser.guessDates = true;
        guesser.prefix = arguments.getStringOption("date_prefix");
        guesser.guessType = DateGuesser.GuessType.PREFIX;
    }
    if (arguments.hasOption("date_regex")) {
        guesser.guessDates = true;
        guesser.regex = arguments.getStringOption("date_regex");
        guesser.guessType = DateGuesser.GuessType.REGEX;
    }
    if (arguments.hasOption("date_format")) {
        guesser.guessDates = true;
        guesser.calendarDateFormat = arguments.getStringOption("date_format");
        guesser.parseCalendarDates = true;
    }
    if (arguments.hasOption("date_precision")) {
        guesser.guessDates = true;
        guesser.parseCalendarDatesAndPrecision = true;
    }
    String treeFileName = null;
    if (arguments.hasOption("tree")) {
        treeFileName = arguments.getStringOption("tree");
    }
    Map argumentMap = new HashMap();
    if (arguments.hasOption("D")) {
        String properties = arguments.getStringOption("D");
        for (String property : properties.split("\\s*,\\s*")) {
            String[] keyValue = property.split("=");
            if (keyValue.length != 2) {
                System.err.println("Properties should take the form: key=value");
                System.exit(1);
            }
            String key = keyValue[0].trim();
            String value = keyValue[1].trim();
            if (key.isEmpty()) {
                System.err.println("Properties should take the form: key=value");
                System.exit(1);
            }
            argumentMap.put(key, value);
        }
    }
    if (arguments.hasOption("help")) {
        printTitle();
        printUsage(arguments);
        System.exit(0);
    }
    if (arguments.hasOption("version")) {
        printTitle();
    }
    String[] args2 = arguments.getLeftoverArguments();
    if (args2.length < 1) {
        printTitle();
        printUsage(arguments);
        System.exit(0);
    }
    if (args2.length < 2 || args2.length > 3) {
        System.err.println("Unknown option: " + args2[0]);
        System.err.println();
        printUsage(arguments);
        System.exit(1);
    }
    try {
        new BEASTGen(guesser, argumentMap, treeFileName, args2[0], args2[1], (args2.length == 3 ? args2[2] : null));
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : DateGuesser(dr.app.beauti.options.DateGuesser) Arguments(dr.app.util.Arguments)

Aggregations

Arguments (dr.app.util.Arguments)35 IOException (java.io.IOException)4 File (java.io.File)3 javax.swing (javax.swing)3 ConsoleApplication (jam.console.ConsoleApplication)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ImportException (jebl.evolution.io.ImportException)2 RootedTree (jebl.evolution.trees.RootedTree)2 BeastParser (dr.app.beast.BeastParser)1 DateGuesser (dr.app.beauti.options.DateGuesser)1 ConstantPopulation (dr.evolution.coalescent.ConstantPopulation)1 DemographicFunction (dr.evolution.coalescent.DemographicFunction)1 ExponentialGrowth (dr.evolution.coalescent.ExponentialGrowth)1 LogisticGrowthN0 (dr.evomodel.epidemiology.LogisticGrowthN0)1 TraceException (dr.inference.trace.TraceException)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 Method (java.lang.reflect.Method)1 Set (java.util.Set)1