Search in sources :

Example 1 with ConsoleApplication

use of jam.console.ConsoleApplication in project beast-mcmc by beast-dev.

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) {
        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);
        // 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 burninStates = dialog.getBurninStates();
        int burninTrees = dialog.getBurninTrees();
        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) {
            System.err.println("No target file specified");
            return;
        }
        inputFileName = dialog.getInputFileName();
        if (inputFileName == null) {
            System.err.println("No input file specified");
            return;
        }
        outputFileName = dialog.getOutputFileName();
        if (outputFileName == null) {
            System.err.println("No output file specified");
            return;
        }
        try {
            new TreeAnnotator(burninTrees, burninStates, heightsOption, posteriorLimit, hpd2D, targetOption, targetTreeFileName, inputFileName, outputFileName);
        } catch (Exception ex) {
            System.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", "the number of states to be considered as 'burn-in'"), new Arguments.IntegerOption("burninTrees", "the number of trees 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.StringOption("hpd2D", "the HPD interval to be used for the bivariate traits", "specifies a (vector of comma seperated) HPD proportion(s)") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        progressStream.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption("forceDiscrete")) {
        System.out.println("  Forcing integer traits to be treated as discrete traits.");
        forceIntegerToDiscrete = true;
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    HeightsSummary heights = HeightsSummary.KEEP_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;
            System.out.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 burninStates = -1;
    int burninTrees = -1;
    if (arguments.hasOption("burnin")) {
        burninStates = arguments.getIntegerOption("burnin");
    }
    if (arguments.hasOption("burninTrees")) {
        burninTrees = arguments.getIntegerOption("burninTrees");
    }
    double posteriorLimit = 0.0;
    if (arguments.hasOption("limit")) {
        posteriorLimit = arguments.getRealOption("limit");
    }
    double[] hpd2D = { 80 };
    if (arguments.hasOption("hpd2D")) {
        try {
            hpd2D = parseVariableLengthDoubleArray(arguments.getStringOption("hpd2D"));
        } catch (Arguments.ArgumentException e) {
            System.err.println("Error reading " + arguments.getStringOption("hpd2D"));
        }
    }
    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:
            {
                System.err.println("Unknown option: " + args2[2]);
                System.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    new TreeAnnotator(burninTrees, burninStates, heights, posteriorLimit, hpd2D, target, targetTreeFileName, inputFileName, outputFileName);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments) IOException(java.io.IOException) ConsoleApplication(jam.console.ConsoleApplication) javax.swing(javax.swing)

Example 2 with ConsoleApplication

use of jam.console.ConsoleApplication in project beast-mcmc by beast-dev.

the class LogCombiner 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);
    boolean treeFiles;
    boolean convertToDecimal;
    boolean stripAnnotations = false;
    boolean renumberOutput;
    long burnin;
    long resample = -1;
    double scale = 1.0;
    boolean useScale = false;
    if (args.length == 0) {
        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 = "LogCombiner " + 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>";
        ConsoleApplication consoleApp = new ConsoleApplication(nameString, aboutString, icon, true);
        printTitle();
        LogCombinerDialog dialog = new LogCombinerDialog(new JFrame());
        if (!dialog.showDialog("LogCombiner " + versionString)) {
            return;
        }
        treeFiles = dialog.isTreeFiles();
        convertToDecimal = dialog.convertToDecimal();
        renumberOutput = dialog.renumberOutputStates();
        if (dialog.isResampling()) {
            resample = dialog.getResampleFrequency();
        }
        String[] inputFiles = dialog.getFileNames();
        long[] burnins = dialog.getBurnins();
        String outputFileName = dialog.getOutputFileName();
        if (outputFileName == null) {
            System.err.println("No output file specified");
        }
        try {
            new LogCombiner(burnins, resample, inputFiles, outputFileName, treeFiles, convertToDecimal, stripAnnotations, renumberOutput, useScale, scale);
        } catch (Exception ex) {
            System.err.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 {
        printTitle();
        Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.Option("trees", "use this option to combine tree log files"), new Arguments.Option("decimal", "this option converts numbers from scientific to decimal notation"), new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in'"), new Arguments.IntegerOption("resample", "resample the log files to this frequency " + "(the original sampling frequency must be a factor of this value)"), new Arguments.RealOption("scale", "a scaling factor that will multiply any time units by this value"), new Arguments.Option("strip", "strip out all annotations (trees only)"), new Arguments.Option("renumber", "this option renumbers output states consecutively"), 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);
        }
        treeFiles = arguments.hasOption("trees");
        convertToDecimal = arguments.hasOption("decimal");
        stripAnnotations = arguments.hasOption("strip");
        renumberOutput = arguments.hasOption("renumber");
        burnin = -1;
        if (arguments.hasOption("burnin")) {
            burnin = arguments.getIntegerOption("burnin");
        }
        resample = -1;
        if (arguments.hasOption("resample")) {
            resample = arguments.getIntegerOption("resample");
        }
        scale = 1.0;
        useScale = false;
        if (arguments.hasOption("scale")) {
            scale = arguments.getRealOption("scale");
            useScale = true;
        }
        String[] args2 = arguments.getLeftoverArguments();
        if (args2.length < 2) {
            System.err.println("Requires a minimum of 1 input filename and 1 output filename");
            System.err.println();
            printUsage(arguments);
            System.exit(1);
        }
        String[] inputFileNames = new String[args2.length - 1];
        System.arraycopy(args2, 0, inputFileNames, 0, inputFileNames.length);
        String outputFileName = args2[args2.length - 1];
        new LogCombiner(new long[] { burnin }, resample, inputFileNames, outputFileName, treeFiles, convertToDecimal, stripAnnotations, renumberOutput, useScale, scale);
        System.out.println("Finished.");
    }
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments) ConsoleApplication(jam.console.ConsoleApplication) javax.swing(javax.swing)

Aggregations

Arguments (dr.app.util.Arguments)2 ConsoleApplication (jam.console.ConsoleApplication)2 javax.swing (javax.swing)2 IOException (java.io.IOException)1