Search in sources :

Example 21 with Arguments

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

the class DiscreteRatePriorGenerator method main.

public static void main(String[] args) throws IOException {
    String outputFileName = null;
    String[] locations = null;
    Double[] latitudes = null;
    Double[] longitudes = null;
    Double[] densities = null;
    OutputFormat outputFormat = OutputFormat.XML;
    Model model = Model.PRIOR;
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption(COORDINATES, "coordinate file", "specifies a tab-delimited file with coordinates for the locations"), new Arguments.StringOption(DENSITIES, "density file", "specifies a tab-delimited file with densities for the locations"), new Arguments.StringOption(GENERICS, "generics file", "specifies a tab-delimited file-list to use as measures for the locations"), new Arguments.StringOption(FORMAT, TimeSlicer.enumNamesToStringArray(OutputFormat.values()), false, "prior output format [default = XML]"), new Arguments.StringOption(MODEL, TimeSlicer.enumNamesToStringArray(Model.values()), false, "model output [default = rate priors]"), //example: new Arguments.RealOption(MRSD,"specifies the most recent sampling data in fractional years to rescale time [default=0]"),
    new Arguments.Option(HELP, "option to print this message") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        progressStream.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (arguments.hasOption(HELP)) {
        printUsage(arguments);
        System.exit(0);
    }
    String coordinatesFileString = arguments.getStringOption(COORDINATES);
    if (coordinatesFileString != null) {
        ArrayList LocsLatsLongs = parseCoordinatesFile(coordinatesFileString, locations, latitudes, longitudes);
        locations = (String[]) LocsLatsLongs.get(0);
        latitudes = (Double[]) LocsLatsLongs.get(1);
        longitudes = (Double[]) LocsLatsLongs.get(2);
    }
    String densitiesFileString = arguments.getStringOption(DENSITIES);
    if (densitiesFileString != null) {
        ArrayList LocsDens = parseSingleMeasureFile(densitiesFileString, locations, densities);
        locations = (String[]) LocsDens.get(0);
        densities = (Double[]) LocsDens.get(1);
    }
    //TODO: support reading any measure (GENERICS)
    String summaryFormat = arguments.getStringOption(FORMAT);
    if (summaryFormat != null) {
        outputFormat = OutputFormat.valueOf(summaryFormat.toUpperCase());
    }
    String modelComponent = arguments.getStringOption(MODEL);
    if (modelComponent != null) {
        model = Model.valueOf(modelComponent.toUpperCase());
    }
    final String[] args2 = arguments.getLeftoverArguments();
    switch(args2.length) {
        case 0:
            printUsage(arguments);
            System.exit(1);
        case 1:
            outputFileName = args2[0];
            break;
        default:
            {
                System.err.println("Unknown option: " + args2[1]);
                System.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    DiscreteRatePriorGenerator rates = new DiscreteRatePriorGenerator(locations, latitudes, longitudes, densities);
    rates.output(outputFileName, outputFormat, model);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments) ArrayList(java.util.ArrayList)

Example 22 with Arguments

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

the class NodeStateAnalyser method main.

//Main method
public static void main(String[] args) throws IOException {
    printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in'"), new Arguments.RealOption("mrsd", "specifies the most recent sampling data in fractional years to rescale time [default=0]"), new Arguments.RealOption("scale", "Provide a scaling factor for the node heights [default=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);
    }
    if (arguments.hasOption("help")) {
        printUsage(arguments);
        System.exit(0);
    }
    int burnin = -1;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    }
    double scale = 1.0;
    if (arguments.hasOption("scale")) {
        scale = arguments.getRealOption("scale");
    }
    double mrsd = Double.NaN;
    if (arguments.hasOption("mrsd")) {
        mrsd = arguments.getRealOption("mrsd");
    }
    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("NodeStateAnalyser " + version.getVersionString() + " - Select tree 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());
    }
    new NodeStateAnalyser(burnin, mrsd, scale, inputFileName, outputFileName);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 23 with Arguments

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

the class NormaliseMeanTreeRate method main.

//Main method
public static void main(String[] args) throws java.io.IOException, TraceException {
    printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption("input-file-name", "infile", "Input file name"), new Arguments.StringOption("output-file-name", "outfile", "Output file name"), new Arguments.RealOption("normaliseMeanRateTo", "Mean rate we should normalise to"), 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);
    }
    String inputFileName = null;
    if (arguments.hasOption("input-file-name")) {
        inputFileName = arguments.getStringOption("input-file-name");
    }
    String outputFileName = null;
    if (arguments.hasOption("output-file-name")) {
        outputFileName = arguments.getStringOption("output-file-name");
    }
    double normaliseMeanRateTo = Double.NaN;
    if (arguments.hasOption("normaliseMeanRateTo")) {
        normaliseMeanRateTo = arguments.getRealOption("normaliseMeanRateTo");
    }
    if (inputFileName == null) {
        // No input file name was given so throw up a dialog box...
        inputFileName = Utils.getLoadFileName("NormaliseMeanTreeRate " + version.getVersionString() + " - Select log file to analyse");
    }
    if (outputFileName == null) {
        // No input file name was given so throw up a dialog box...
        outputFileName = Utils.getSaveFileName("NormaliseMeanTreeRate " + version.getVersionString() + " - Select file to save to");
    }
    if (Double.isNaN(normaliseMeanRateTo)) {
        System.out.println("Enter rate value to normalise to: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        normaliseMeanRateTo = Double.parseDouble(br.readLine());
    }
    new NormaliseMeanTreeRate(inputFileName, outputFileName, normaliseMeanRateTo);
    System.out.println("Please bear in mind that the trees files are unchanged and results may vary slightly from if you ran them internally");
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 24 with Arguments

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

the class TreeLogAnalyser 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);
    printTitle();
    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("export", "file-name", "name of file to export"), new Arguments.RealOption("limit", "don't export trees with support lower than limit [default = 0.0]"), new Arguments.RealOption("probability", "credible set probability limit [default = 0.95]"), new Arguments.IntegerOption("max", "export no more than max trees [default = all]"), new Arguments.Option("short", "use this option to produce a short report"), 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");
    }
    boolean shortReport = arguments.hasOption("short");
    String exportFileName = null;
    if (arguments.hasOption("export")) {
        exportFileName = arguments.getStringOption("export");
    }
    double minSupport = 0.0;
    if (arguments.hasOption("limit")) {
        minSupport = arguments.getRealOption("limit");
    }
    double credibleSetProbability = 0.95;
    if (arguments.hasOption("probability")) {
        credibleSetProbability = arguments.getRealOption("probability");
    }
    int maxExport = -1;
    if (arguments.hasOption("max")) {
        maxExport = arguments.getIntegerOption("max");
    }
    String inputFileName = null;
    String trueTreeFileName = 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) {
        trueTreeFileName = args2[1];
    }
    if (args2.length > 2) {
        outputFileName = args2[2];
    }
    if (inputFileName == null) {
        // No input file name was given so throw up a dialog box...
        inputFileName = Utils.getLoadFileName("TreeLogAnalyser " + version.getVersionString() + " - Select log file to analyse");
    }
    new TreeLogAnalyser(burnin, inputFileName, outputFileName, trueTreeFileName, exportFileName, minSupport, credibleSetProbability, maxExport, !shortReport);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 25 with Arguments

use of dr.app.util.Arguments 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)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