Search in sources :

Example 1 with Arguments

use of beast.app.util.Arguments in project beast2 by CompEvol.

the class PackageManager method main.

public static void main(String[] args) {
    try {
        Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("list", "List available packages"), new Arguments.StringOption("add", "NAME", "Install the <NAME> package"), new Arguments.StringOption("del", "NAME", "Uninstall the <NAME> package"), new Arguments.StringOption("version", "NAME", "Specify package version"), new Arguments.Option("useAppDir", "Use application (system wide) installation directory. Note this requires writing rights to the application directory. If not specified, the user's BEAST directory will be used."), new Arguments.StringOption("dir", "DIR", "Install/uninstall package in directory <DIR>. This overrides the useAppDir option"), new Arguments.Option("help", "Show help"), new Arguments.Option("update", "Check for updates, and ask to install if available"), new Arguments.Option("updatenow", "Check for updates and install without asking") });
        try {
            arguments.parseArguments(args);
        } catch (Arguments.ArgumentException ae) {
            Log.info.println();
            Log.info.println(ae.getMessage());
            Log.info.println();
            printUsageAndExit(arguments);
        }
        if (args.length == 0 || arguments.hasOption("help")) {
            printUsageAndExit(arguments);
        }
        if (arguments.hasOption("update")) {
            updatePackages(UpdateStatus.AUTO_CHECK_AND_ASK, false);
            return;
        }
        if (arguments.hasOption("updatenow")) {
            updatePackages(UpdateStatus.AUTO_UPDATE, false);
            return;
        }
        boolean useAppDir = arguments.hasOption("useAppDir");
        String customDir = arguments.getStringOption("dir");
        if (customDir != null) {
            String path = PackageManager.getBeastPacakgePathProperty();
            System.setProperty("BEAST_PACKAGE_PATH", (path != null ? path + ":" : "") + customDir);
        }
        List<URL> urlList = getRepositoryURLs();
        Log.debug.println("Packages user path : " + getPackageUserDir());
        for (URL url : urlList) {
            Log.debug.println("Access URL : " + url);
        }
        Log.debug.print("Getting list of packages ...");
        Map<String, Package> packageMap = new TreeMap<String, Package>(new Comparator<String>() {

            // String::compareToIgnoreCase
            @Override
            public int compare(String s1, String s2) {
                return s1.toLowerCase().compareTo(s2.toLowerCase());
            }
        });
        try {
            PackageManager.addInstalledPackages(packageMap);
            PackageManager.addAvailablePackages(packageMap);
        } catch (PackageListRetrievalException e) {
            Log.warning.println(e.getMessage());
            if (e.getCause() instanceof IOException)
                Log.warning.println(NO_CONNECTION_MESSAGE);
            return;
        }
        Log.debug.println("Done!\n");
        if (arguments.hasOption("list")) {
            prettyPrintPackageInfo(Log.info, packageMap);
        }
        if (arguments.hasOption("add")) {
            String name = arguments.getStringOption("add");
            boolean processed = false;
            for (Package aPackage : packageMap.values()) {
                if (aPackage.packageName.equals(name)) {
                    processed = true;
                    if (!aPackage.isInstalled() || arguments.hasOption("version")) {
                        Log.debug.println("Determine packages to install");
                        Map<Package, PackageVersion> packagesToInstall = new HashMap<Package, PackageVersion>();
                        if (arguments.hasOption("version")) {
                            String versionString = arguments.getStringOption("version");
                            PackageVersion version = new PackageVersion(versionString);
                            packagesToInstall.put(aPackage, version);
                            PackageManager.useArchive = true;
                        } else {
                            packagesToInstall.put(aPackage, aPackage.getLatestVersion());
                        }
                        try {
                            populatePackagesToInstall(packageMap, packagesToInstall);
                        } catch (DependencyResolutionException ex) {
                            Log.err("Installation aborted: " + ex.getMessage());
                        }
                        Log.debug.println("Start installation");
                        prepareForInstall(packagesToInstall, useAppDir, customDir);
                        Map<String, String> dirs = installPackages(packagesToInstall, useAppDir, customDir);
                        for (String pkgName : dirs.keySet()) Log.info.println("Package " + pkgName + " is installed in " + dirs.get(pkgName) + ".");
                    } else {
                        Log.info.println("Installation aborted: " + name + " is already installed.");
                        System.exit(1);
                    }
                }
            }
            if (!processed) {
                Log.info.println("Could not find package '" + name + "' (typo perhaps?)");
            }
        }
        if (arguments.hasOption("del")) {
            String name = arguments.getStringOption("del");
            boolean processed = false;
            for (Package aPackage : packageMap.values()) {
                if (aPackage.packageName.equals(name)) {
                    processed = true;
                    if (arguments.hasOption("version")) {
                        PackageManager.useArchive = true;
                        String versionString = arguments.getStringOption("version");
                        PackageVersion version = new PackageVersion(versionString);
                        String dir = uninstallPackage(aPackage, version, useAppDir, customDir);
                        Log.info.println("Package " + name + " is uninstalled from " + dir + ".");
                    } else {
                        if (aPackage.isInstalled()) {
                            List<String> deps = getInstalledDependencyNames(aPackage, packageMap);
                            if (deps.isEmpty()) {
                                Log.debug.println("Start un-installation");
                                String dir = uninstallPackage(aPackage, useAppDir, customDir);
                                Log.info.println("Package " + name + " is uninstalled from " + dir + ".");
                            } else {
                                Log.info.println("Un-installation aborted: " + name + " is used by these other packages: " + String.join(", ", deps) + ".");
                                Log.info.println("Remove these packages first.");
                                System.exit(1);
                            }
                        } else {
                            Log.info.println("Un-installation aborted: " + name + " is not installed yet.");
                            System.exit(1);
                        }
                    }
                }
            }
            if (!processed) {
                Log.info.println("Could not find package '" + name + "' (typo perhaps?)");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Arguments(beast.app.util.Arguments) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 2 with Arguments

use of beast.app.util.Arguments in project beast2 by CompEvol.

the class TreeAnnotator method main.

// Main method
public static void main(String[] args) throws 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);
    String targetTreeFileName = null;
    String inputFileName = null;
    String outputFileName = null;
    if (args.length == 0) {
        Utils.loadUIManager();
        System.setProperty("com.apple.macos.useScreenMenuBar", "true");
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        java.net.URL url = LogCombiner.class.getResource("/images/utility.png");
        javax.swing.Icon icon = null;
        if (url != null) {
            icon = new javax.swing.ImageIcon(url);
        }
        final String versionString = version.getVersionString();
        String nameString = "TreeAnnotator " + versionString;
        String aboutString = "<html><center><p>" + versionString + ", " + version.getDateString() + "</p>" + "<p>by<br>" + "Andrew Rambaut and Alexei J. Drummond</p>" + "<p>Institute of Evolutionary Biology, University of Edinburgh<br>" + "<a href=\"mailto:a.rambaut@ed.ac.uk\">a.rambaut@ed.ac.uk</a></p>" + "<p>Department of Computer Science, University of Auckland<br>" + "<a href=\"mailto:alexei@cs.auckland.ac.nz\">alexei@cs.auckland.ac.nz</a></p>" + "<p>Part of the BEAST package:<br>" + "<a href=\"http://beast.bio.ed.ac.uk/\">http://beast.bio.ed.ac.uk/</a></p>" + "</center></html>";
        new ConsoleApplication(nameString, aboutString, icon, true);
        Log.info = System.out;
        Log.err = System.err;
        // The ConsoleApplication will have overridden System.out so set progressStream
        // to capture the output to the window:
        progressStream = System.out;
        printTitle();
        TreeAnnotatorDialog dialog = new TreeAnnotatorDialog(new JFrame());
        if (!dialog.showDialog("TreeAnnotator " + versionString)) {
            return;
        }
        int burninPercentage = dialog.getBurninPercentage();
        if (burninPercentage < 0) {
            Log.warning.println("burnin percentage is " + burninPercentage + " but should be non-negative. Setting it to zero");
            burninPercentage = 0;
        }
        if (burninPercentage >= 100) {
            Log.err.println("burnin percentage is " + burninPercentage + " but should be less than 100.");
            return;
        }
        double posteriorLimit = dialog.getPosteriorLimit();
        double hpd2D = 0.80;
        Target targetOption = dialog.getTargetOption();
        HeightsSummary heightsOption = dialog.getHeightsOption();
        targetTreeFileName = dialog.getTargetFileName();
        if (targetOption == Target.USER_TARGET_TREE && targetTreeFileName == null) {
            Log.err.println("No target file specified");
            return;
        }
        inputFileName = dialog.getInputFileName();
        if (inputFileName == null) {
            Log.err.println("No input file specified");
            return;
        }
        outputFileName = dialog.getOutputFileName();
        if (outputFileName == null) {
            Log.err.println("No output file specified");
            return;
        }
        boolean lowMem = dialog.useLowMem();
        try {
            new TreeAnnotator(burninPercentage, lowMem, heightsOption, posteriorLimit, hpd2D, targetOption, targetTreeFileName, inputFileName, outputFileName);
        } catch (Exception ex) {
            Log.err.println("Exception: " + ex.getMessage());
        }
        progressStream.println("Finished - Quit program to exit.");
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { // new Arguments.StringOption("target", new String[] { "maxclade", "maxtree" }, false, "an option of 'maxclade' or 'maxtree'"),
    new Arguments.StringOption("heights", new String[] { "keep", "median", "mean", "ca" }, false, "an option of 'keep' (default), 'median', 'mean' or 'ca'"), new Arguments.IntegerOption("burnin", 0, 99, "the percentage of states to be considered as 'burn-in'"), // allow -b as burnin option, just like other apps
    new Arguments.IntegerOption("b", 0, 99, "the percentage of states to be considered as 'burn-in'"), new Arguments.RealOption("limit", "the minimum posterior probability for a node to be annotated"), new Arguments.StringOption("target", "target_file_name", "specifies a user target tree to be annotated"), new Arguments.Option("help", "option to print this message"), new Arguments.Option("forceDiscrete", "forces integer traits to be treated as discrete traits."), new Arguments.Option("lowMem", "use less memory, which is a bit slower."), new Arguments.RealOption("hpd2D", "the HPD interval to be used for the bivariate traits"), new Arguments.Option("nohpd2D", "suppress calculation of HPD intervals for the bivariate traits"), new Arguments.Option("noSA", "interpret the tree set as begin from a not being from a sampled ancestor analysis, even if there are zero branch lengths in the tree set") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        progressStream.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("nohpd2D")) {
        processBivariateAttributes = false;
    }
    if (arguments.hasOption("noSA")) {
        processSA = false;
    }
    if (arguments.hasOption("forceDiscrete")) {
        Log.info.println("  Forcing integer traits to be treated as discrete traits.");
        forceIntegerToDiscrete = true;
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    boolean lowMem = false;
    if (arguments.hasOption("lowMem")) {
        lowMem = true;
    }
    HeightsSummary heights = HeightsSummary.CA_HEIGHTS;
    if (arguments.hasOption("heights")) {
        String value = arguments.getStringOption("heights");
        if (value.equalsIgnoreCase("mean")) {
            heights = HeightsSummary.MEAN_HEIGHTS;
        } else if (value.equalsIgnoreCase("median")) {
            heights = HeightsSummary.MEDIAN_HEIGHTS;
        } else if (value.equalsIgnoreCase("ca")) {
            heights = HeightsSummary.CA_HEIGHTS;
            Log.info.println("Please cite: Heled and Bouckaert: Looking for trees in the forest:\n" + "summary tree from posterior samples. BMC Evolutionary Biology 2013 13:221.");
        }
    }
    int burnin = -1;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    } else if (arguments.hasOption("b")) {
        burnin = arguments.getIntegerOption("b");
    }
    if (burnin >= 100) {
        Log.err.println("burnin percentage is " + burnin + " but should be less than 100.");
        System.exit(1);
    }
    double posteriorLimit = 0.0;
    if (arguments.hasOption("limit")) {
        posteriorLimit = arguments.getRealOption("limit");
    }
    double hpd2D = 0.80;
    if (arguments.hasOption("hpd2D")) {
        hpd2D = arguments.getRealOption("hpd2D");
        if (hpd2D <= 0 || hpd2D >= 1) {
            Log.err.println("hpd2D is a fraction and should be in between 0.0 and 1.0.");
            System.exit(1);
        }
        processBivariateAttributes = true;
    }
    Target target = Target.MAX_CLADE_CREDIBILITY;
    if (arguments.hasOption("target")) {
        target = Target.USER_TARGET_TREE;
        targetTreeFileName = arguments.getStringOption("target");
    }
    final String[] args2 = arguments.getLeftoverArguments();
    switch(args2.length) {
        case 2:
            outputFileName = args2[1];
        // fall to
        case 1:
            inputFileName = args2[0];
            break;
        default:
            {
                Log.err.println("Unknown option: " + args2[2]);
                Log.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    try {
        new TreeAnnotator(burnin, lowMem, heights, posteriorLimit, hpd2D, target, targetTreeFileName, inputFileName, outputFileName);
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (args.length == 0) {
        // only need exit when in GUI mode
        System.exit(0);
    }
}
Also used : JFrame(javax.swing.JFrame) Arguments(beast.app.util.Arguments) ConsoleApplication(jam.console.ConsoleApplication)

Example 3 with Arguments

use of beast.app.util.Arguments in project beast2 by CompEvol.

the class BeastMain method main.

// Main method
public static void main(final String[] args) throws java.io.IOException {
    final List<String> MCMCargs = new ArrayList<>();
    // Utils.loadUIManager();
    final Arguments arguments = new Arguments(new Arguments.Option[] { // 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.StringOption("statefile", "STATEFILE", "Specify the filename for storing/restoring the state"), new Arguments.Option("overwrite", "Allow overwriting of log files"), new Arguments.Option("resume", "Allow appending of log files"), new Arguments.Option("validate", "Parse the XML, but do not run -- useful for debugging XML"), // RRB: not sure what effect this option has
    new Arguments.IntegerOption("errors", "Specify maximum number of numerical errors before stopping"), new Arguments.IntegerOption("threads", "The number of computational threads to use (default 1), -1 for number of cores"), new Arguments.Option("java", "Use Java only, no native implementations"), new Arguments.Option("noerr", "Suppress all output to standard error"), new Arguments.StringOption("loglevel", "LEVEL", "error,warning,info,debug,trace"), new Arguments.IntegerOption("instances", "divide site patterns amongst number of threads (use with -threads option)"), new Arguments.Option("beagle", "Use beagle library if available"), 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.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_single", "BEAGLE: use single precision if available"), new Arguments.Option("beagle_double", "BEAGLE: use double precision if available"), new Arguments.StringOption("beagle_scaling", new String[] { "default", "none", "dynamic", "always" }, false, "BEAGLE: specify scaling scheme to use"), new Arguments.Option("help", "Print this information and stop"), new Arguments.Option("version", "Print version and stop"), new Arguments.Option("strictversions", "Use only package versions as specified in the 'required' attribute"), new Arguments.StringOption("D", "DEFINITIONS", "attribute-value pairs to be replaced in the XML, e.g., -D \"arg1=10,arg2=20\"") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        Log.info.println();
        Log.info.println(ae.getMessage());
        Log.info.println();
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("version")) {
        Log.info.println((new BEASTVersion2()).getVersionString());
        System.exit(0);
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    // final boolean verbose = arguments.hasOption("verbose");
    // final boolean parserWarning = arguments.hasOption("warnings"); // if dev, then auto turn on, otherwise default to turn off
    // final boolean strictXML = arguments.hasOption("strict");
    final boolean window = arguments.hasOption("window");
    final boolean options = arguments.hasOption("options");
    final boolean working = arguments.hasOption("working");
    final boolean doNotRun = arguments.hasOption("validate");
    String fileNamePrefix = null;
    String stateFileName = null;
    // boolean allowOverwrite = arguments.hasOption("overwrite");
    long seed = Randomizer.getSeed();
    boolean useJava = false;
    int threadCount = 1;
    if (arguments.hasOption("java")) {
        useJava = true;
    }
    if (arguments.hasOption("prefix")) {
        fileNamePrefix = arguments.getStringOption("prefix");
    }
    if (arguments.hasOption("statefile")) {
        stateFileName = arguments.getStringOption("statefile");
    }
    long beagleFlags = 0;
    boolean useBeagle = arguments.hasOption("beagle") || arguments.hasOption("beagle_CPU") || arguments.hasOption("beagle_GPU") || arguments.hasOption("beagle_SSE") || arguments.hasOption("beagle_double") || arguments.hasOption("beagle_single") || arguments.hasOption("beagle_order");
    if (arguments.hasOption("beagle_scaling")) {
        System.setProperty("beagle.scaling", arguments.getStringOption("beagle_scaling"));
    }
    boolean beagleShowInfo = arguments.hasOption("beagle_info");
    boolean useSSE = true;
    if (arguments.hasOption("beagle_CPU")) {
        beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
        useSSE = false;
    }
    if (arguments.hasOption("beagle_GPU")) {
        beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
        useSSE = false;
    }
    if (arguments.hasOption("beagle_SSE")) {
        beagleFlags |= BeagleFlag.PROCESSOR_CPU.getMask();
        useSSE = true;
    }
    if (useSSE) {
        beagleFlags |= BeagleFlag.VECTOR_SSE.getMask();
    }
    if (arguments.hasOption("beagle_double")) {
        beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
    }
    if (arguments.hasOption("beagle_single")) {
        beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
    }
    if (arguments.hasOption("noerr")) {
        System.setErr(new PrintStream(new OutputStream() {

            @Override
            public void write(int b) {
            }
        }));
    }
    if (arguments.hasOption("beagle_order")) {
        System.setProperty("beagle.resource.order", arguments.getStringOption("beagle_order"));
    }
    if (arguments.hasOption("instances")) {
        System.setProperty("beast.instance.count", Integer.toString(arguments.getIntegerOption("instances")));
    }
    if (arguments.hasOption("beagle_scaling")) {
        System.setProperty("beagle.scaling", arguments.getStringOption("beagle_scaling"));
    }
    if (arguments.hasOption("threads")) {
        threadCount = arguments.getIntegerOption("threads");
    }
    if (threadCount <= 0) {
        threadCount = Runtime.getRuntime().availableProcessors();
        Log.warning.println("Setting number of threads to " + threadCount);
    }
    if (arguments.hasOption("seed")) {
        seed = arguments.getLongOption("seed");
        if (seed <= 0) {
            printTitle();
            Log.err.println("The random number seed should be > 0");
            System.exit(1);
        }
    }
    int maxErrorCount = 0;
    if (arguments.hasOption("errors")) {
        maxErrorCount = arguments.getIntegerOption("errors");
        if (maxErrorCount < 0) {
            maxErrorCount = 0;
        }
    }
    BeastConsoleApp consoleApp = null;
    final String nameString = "BEAST " + version.getVersionString();
    if (window) {
        Utils.loadUIManager();
        System.setProperty("com.apple.macos.useScreenMenuBar", "true");
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        System.setProperty("beast.useWindow", "true");
        final javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
        final String aboutString = "<html><div style=\"font-family:sans-serif;\"><center>" + "<div style=\"font-size:12;\"><p>Bayesian Evolutionary Analysis Sampling Trees<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p>" + version.getHTMLCredits() + "</div></center></div></html>";
        consoleApp = new BeastConsoleApp(nameString, aboutString, icon);
        // ensure error and info information is shown in console
        // but not warning, debug or trace, since that typically just
        // results in a lot of clutter
        Log.err = System.err;
        Log.info = System.out;
    }
    printTitle();
    File inputFile = null;
    if (options) {
        Utils.loadUIManager();
        final String titleString = "<html><center><p>Bayesian Evolutionary Analysis Sampling Trees<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p></center></html>";
        final javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
        final BeastDialog dialog = new BeastDialog(new JFrame(), titleString, icon);
        if (!dialog.showDialog(nameString, seed)) {
            System.exit(0);
        }
        // }
        switch(dialog.getLogginMode()) {
            case 0:
                /* do not ovewrite */
                break;
            case 1:
                MCMCargs.add("-overwrite");
                break;
            case 2:
                MCMCargs.add("-resume");
                break;
        }
        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();
            }
            if (dialog.preferBeagleGPU()) {
                beagleFlags |= BeagleFlag.PROCESSOR_GPU.getMask();
            }
            if (dialog.preferBeagleDouble()) {
                beagleFlags |= BeagleFlag.PRECISION_DOUBLE.getMask();
            }
            if (dialog.preferBeagleSingle()) {
                beagleFlags |= BeagleFlag.PRECISION_SINGLE.getMask();
            }
        }
        inputFile = dialog.getInputFile();
        if (!beagleShowInfo && inputFile == null) {
            Log.err.println("No input file specified");
            System.exit(1);
        }
        if (dialog.useStrictVersions()) {
            MCMCargs.add("-strictversions");
        }
    } else {
        if (arguments.hasOption("overwrite")) {
            MCMCargs.add("-overwrite");
        }
        if (arguments.hasOption("resume")) {
            MCMCargs.add("-resume");
        }
    }
    if (arguments.hasOption("strictversions")) {
        MCMCargs.add("-strictversions");
    }
    if (arguments.hasOption("D")) {
        MCMCargs.add("-D");
        MCMCargs.add(arguments.getStringOption("D"));
    }
    if (beagleShowInfo) {
        Log.info.println("\n--- BEAGLE RESOURCES ---\n");
        for (beagle.ResourceDetails details : BeagleFactory.getResourceDetails()) Log.info.println(details.toString());
        if (window)
            return;
        else
            System.exit(0);
    }
    if (inputFile == null) {
        final String[] args2 = arguments.getLeftoverArguments();
        if (args2.length > 1) {
            Log.err.println("Unknown option: " + args2[1]);
            Log.err.println();
            printUsage(arguments);
            System.exit(1);
        }
        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...
            String fileName = getFileNameByDialog("BEAST " + version.getVersionString() + " - Select XML input file");
            if (fileName == null) {
                System.exit(0);
            }
            inputFile = new File(fileName);
        }
    }
    if (inputFile != null && inputFile.getParent() != null && working) {
        System.setProperty("file.name.prefix", inputFile.getParentFile().getAbsolutePath() + File.separator);
    }
    if (window) {
        if (inputFile == null) {
            consoleApp.setTitle("null");
        } else {
            consoleApp.setTitle(inputFile.getName());
        }
    }
    if (useJava) {
        System.setProperty("java.only", "true");
    }
    if (arguments.hasOption("loglevel")) {
        String l = arguments.getStringOption("loglevel");
        switch(l) {
            case "error":
                Log.setLevel(Log.Level.error);
                break;
            case "warning":
                Log.setLevel(Log.Level.warning);
                break;
            case "info":
                Log.setLevel(Log.Level.info);
                break;
            case "debug":
                Log.setLevel(Log.Level.debug);
                break;
            case "trace":
                Log.setLevel(Log.Level.trace);
                break;
        }
    }
    if (fileNamePrefix != null && fileNamePrefix.trim().length() > 0) {
        System.setProperty("file.name.prefix", fileNamePrefix.trim());
    }
    if (stateFileName != null && stateFileName.trim().length() > 0) {
        System.setProperty("state.file.name", stateFileName.trim());
        Log.info.println("Writing state to file " + stateFileName);
    }
    if (beagleFlags != 0) {
        System.setProperty("beagle.preferred.flags", Long.toString(beagleFlags));
    }
    if (threadCount > 0) {
        System.setProperty("thread.count", String.valueOf(threadCount));
        MCMCargs.add("-threads");
        MCMCargs.add(threadCount + "");
    }
    MCMCargs.add("-seed");
    MCMCargs.add(seed + "");
    Randomizer.setSeed(seed);
    Log.info.println("Random number seed: " + seed);
    Log.info.println();
    // Construct the beast object
    final BeastMCMC beastMCMC = new BeastMCMC();
    try {
        // set all the settings...
        MCMCargs.add(inputFile.getAbsolutePath());
        beastMCMC.parseArgs(MCMCargs.toArray(new String[0]));
        if (!doNotRun) {
            new BeastMain(beastMCMC, consoleApp, maxErrorCount);
        } else {
            Log.info.println("Done!");
        }
    } catch (RuntimeException rte) {
        if (window) {
            // appears at the end of the console.
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Log.info.println();
            Log.info.println("BEAST has terminated with an error. Please select QUIT from the menu.");
        } else {
            rte.printStackTrace();
        }
    // logger.severe will throw a RTE but we want to keep the console visible
    } catch (XMLParserException e) {
        Log.info.println(e.getMessage());
        if (!window) {
            System.exit(1);
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (!window) {
            System.exit(1);
        }
    }
    if (!window) {
        System.exit(0);
    }
}
Also used : XMLParserException(beast.util.XMLParserException) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) BeastMCMC(beast.app.BeastMCMC) JFrame(javax.swing.JFrame) PrintStream(java.io.PrintStream) Arguments(beast.app.util.Arguments) XMLParserException(beast.util.XMLParserException) IOException(java.io.IOException) File(java.io.File) BEASTVersion2(beast.app.BEASTVersion2)

Aggregations

Arguments (beast.app.util.Arguments)3 JFrame (javax.swing.JFrame)2 BEASTVersion2 (beast.app.BEASTVersion2)1 BeastMCMC (beast.app.BeastMCMC)1 XMLParserException (beast.util.XMLParserException)1 ConsoleApplication (jam.console.ConsoleApplication)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1