Search in sources :

Example 6 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class LogCombiner method main.

/**
 * @param args
 */
public static void main(String[] args) {
    BEASTVersion2 version = new BEASTVersion2();
    final String versionString = version.getVersionString();
    String nameString = "LogCombiner " + versionString;
    String aboutString = "<html><center><p>" + versionString + ", " + version.getDateString() + "</p>" + "<p>by<br>" + "<p>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 2 package:<br>" + "<a href=\"http://beast2.cs.auckland.ac.nz/\">http://beast2.cs.auckland.ac.nz/</a></p>" + "</center></html>";
    LogCombiner combiner = new LogCombiner();
    try {
        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");
            // TODO: set up ICON
            java.net.URL url = LogCombiner.class.getResource("images/logcombiner.png");
            javax.swing.Icon icon = null;
            if (url != null) {
                icon = new javax.swing.ImageIcon(url);
            }
            String titleString = "<html><center><p>LogCombiner<br>" + "Version " + version.getVersionString() + ", " + version.getDateString() + "</p></center></html>";
            new ConsoleApplication(nameString, aboutString, icon, true);
            Log.info = System.out;
            Log.warning = System.out;
            Log.err = System.err;
            combiner.printTitle(aboutString);
            LogCombinerDialog dialog = new LogCombinerDialog(new JFrame(), titleString, icon);
            if (!dialog.showDialog(nameString)) {
                return;
            }
            // issue #437: ensure the table editor finished.
            // this way, the latest entered burn-in is captured, otherwise
            // the last editing action may be ignored
            TableCellEditor editor = dialog.filesTable.getCellEditor();
            if (editor != null) {
                editor.stopCellEditing();
            }
            combiner.m_bIsTreeLog = dialog.isTreeFiles();
            combiner.m_bUseDecimalFormat = dialog.convertToDecimal();
            if (combiner.m_bUseDecimalFormat) {
                combiner.format = new DecimalFormat("#.############", new DecimalFormatSymbols(Locale.US));
            }
            if (!dialog.renumberOutputStates()) {
                combiner.m_nSampleInterval = -1;
            }
            if (dialog.isResampling()) {
                combiner.m_nResample = dialog.getResampleFrequency();
            }
            String[] inputFiles = dialog.getFileNames();
            int[] burnins = dialog.getBurnins();
            combiner.m_sFileOut = dialog.getOutputFileName();
            if (combiner.m_sFileOut == null) {
                Log.warning.println("No output file specified");
            }
            try {
                combiner.combineLogs(inputFiles, burnins);
            } catch (Exception ex) {
                Log.warning.println("Exception: " + ex.getMessage());
                ex.printStackTrace();
            }
            System.out.println("Finished - Quit program to exit.");
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } else {
            combiner.printTitle(aboutString);
            combiner.parseArgs(args);
            if (combiner.m_sParticleDir == null) {
                // classical log combiner
                String[] logFiles = combiner.m_sLogFileName.toArray(new String[0]);
                int[] burnIns = new int[logFiles.length];
                Arrays.fill(burnIns, combiner.m_nBurninPercentage);
                combiner.combineLogs(logFiles, burnIns);
            } else {
                // particle log combiner
                combiner.combineParticleLogs();
                combiner.printCombinedLogs();
            }
        }
    } catch (Exception e) {
        System.out.println(getUsage());
        e.printStackTrace();
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConsoleApplication(jam.console.ConsoleApplication) JFrame(javax.swing.JFrame) TableCellEditor(javax.swing.table.TableCellEditor) BEASTVersion2(beast.app.BEASTVersion2)

Example 7 with BEASTVersion2

use of beast.app.BEASTVersion2 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)

Example 8 with BEASTVersion2

use of beast.app.BEASTVersion2 in project beast2 by CompEvol.

the class LogAnalyser method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        LogAnalyser analyser;
        // process args
        int burninPercentage = BURN_IN_PERCENTAGE;
        boolean oneLine = false;
        boolean quiet = false;
        List<String> files = new ArrayList<>();
        int i = 0;
        while (i < args.length) {
            String arg = args[i];
            switch(arg) {
                case "-b":
                case "-burnin":
                case "--burnin":
                    if (i + 1 >= args.length) {
                        Log.warning.println("-b argument requires another argument");
                        printUsageAndExit();
                    }
                    burninPercentage = Integer.parseInt(args[i + 1]);
                    i += 2;
                    break;
                case "-oneline":
                    oneLine = true;
                    i += 1;
                    break;
                case "-quiet":
                    quiet = true;
                    i += 1;
                    break;
                case "-h":
                case "-help":
                case "--help":
                    printUsageAndExit();
                    break;
                default:
                    if (arg.startsWith("-")) {
                        Log.warning.println("unrecognised command " + arg);
                        printUsageAndExit();
                    }
                    files.add(arg);
                    i++;
            }
        }
        if (files.size() == 0) {
            // no file specified, open file dialog to select one
            BEASTVersion2 version = new BEASTVersion2();
            File file = Utils.getLoadFile("LogAnalyser " + version.getVersionString() + " - Select log file to analyse", null, "BEAST log (*.log) Files", "log", "txt");
            if (file == null) {
                return;
            }
            analyser = new LogAnalyser(file.getAbsolutePath(), burninPercentage, quiet);
            analyser.print(System.out);
        } else {
            // process files
            if (oneLine) {
                for (int idx = 0; idx < files.size(); idx++) {
                    analyser = new LogAnalyser(files.get(idx), burninPercentage, true);
                    if (idx == 0)
                        analyser.printOneLineHeader(System.out);
                    analyser.printOneLine(System.out);
                }
            } else {
                for (String file : files) {
                    analyser = new LogAnalyser(file, burninPercentage, quiet);
                    analyser.print(System.out);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) BEASTVersion2(beast.app.BEASTVersion2) IOException(java.io.IOException)

Aggregations

BEASTVersion2 (beast.app.BEASTVersion2)8 IOException (java.io.IOException)7 File (java.io.File)4 JFrame (javax.swing.JFrame)4 ArrayList (java.util.ArrayList)3 BEASTInterface (beast.core.BEASTInterface)2 ConsoleApplication (jam.console.ConsoleApplication)2 PrintStream (java.io.PrintStream)2 Icon (javax.swing.Icon)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 BeastMCMC (beast.app.BeastMCMC)1 Arguments (beast.app.util.Arguments)1 XMLParserException (beast.util.XMLParserException)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1