Search in sources :

Example 6 with Arguments

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

the class DistanceMatrixInsertionTest 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.StringOption("BEAST_XML", "FILENAME", "Specify a BEAST XML file"), new Arguments.StringOption("update_choice", "UPDATECHOICE", "Specify a function by which to update the tree"), new Arguments.Option("help", "Print this information and stop") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.out.println();
        System.out.println(ae.getMessage());
        System.out.println();
        //printUsage(arguments);
        System.exit(1);
    }
    String inputFile = null;
    if (arguments.hasOption("BEAST_XML")) {
        inputFile = arguments.getStringOption("BEAST_XML");
    } else {
        throw new RuntimeException("No BEAST XML file specified.");
    }
    String choice = "";
    if (arguments.hasOption("update_choice")) {
        choice = arguments.getStringOption("update_choice");
    } else {
        throw new RuntimeException("Update mechanism needs to be specified.");
    }
    CheckPointUpdaterApp.UpdateChoice chosen = null;
    for (CheckPointUpdaterApp.UpdateChoice ch : CheckPointUpdaterApp.UpdateChoice.values()) {
        if (choice.equals(ch.getName())) {
            chosen = ch;
            break;
        }
    }
    if (chosen == null) {
        throw new RuntimeException("Incorrect update mechanism specified.");
    }
    //Create and set up the window.
    JFrame frame = new JFrame("Test distance matrix");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DistanceMatrixInsertionTest test = new DistanceMatrixInsertionTest(inputFile, chosen);
    test.setOpaque(true);
    frame.setContentPane(test);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
//System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 7 with Arguments

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

the class ContinuousTreeToKML method main.

public static void main(String[] args) {
    // altitutude of the root of the 3D trees
    double altitude = 0;
    // required to convert heights to calendar dates
    double mostRecentDate = 2010;
    String coordinateLabel = "loc";
    boolean makeTreeSlices = false;
    double[] sliceTimes = null;
    double treeSliceBranchWidth = 3;
    // shows complete branch for slice if time is more recent than the branch's midpoint
    boolean showBranchAtMidPoint = false;
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption(ANNOTATION, "location annotation label", "specifies the label used for location coordinates annotation [default=location]"), new Arguments.RealOption(ALTITUDE, "specifies the altitude of the root of the 3D tree [default=no 3D tree]"), new Arguments.RealOption(MRSD, "specifies the most recent sampling data in fractional years to rescale time [default=2010]"), new Arguments.StringOption(SLICES, "time", "specifies a slice time-list [default=none]"), new Arguments.StringOption(SLICEMIDPOINT, falseTrue, false, "shows complete branch for sliced tree if time is more recent than the branch's midpoint [default=false"), 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 (args.length == 0 || arguments.hasOption(HELP)) {
        printUsage(arguments);
        System.exit(0);
    }
    if (arguments.hasOption(MRSD)) {
        mostRecentDate = arguments.getRealOption(MRSD);
    }
    if (arguments.hasOption(ALTITUDE)) {
        altitude = arguments.getRealOption(ALTITUDE);
    }
    String annotationLabel = arguments.getStringOption(ANNOTATION);
    if (annotationLabel != null) {
        coordinateLabel = annotationLabel;
    }
    String sliceString = arguments.getStringOption(SLICES);
    if (sliceString != null) {
        makeTreeSlices = true;
        try {
            sliceTimes = DiscreteTreeToKML.parseVariableLengthDoubleArray(sliceString);
        } catch (Arguments.ArgumentException ae) {
            System.err.println("error reading slice heights");
            ae.printStackTrace();
            return;
        }
        makeTreeSlices = true;
    }
    if (arguments.hasOption(SLICEBW)) {
        treeSliceBranchWidth = arguments.getRealOption(SLICEBW);
    }
    String midpointString = arguments.getStringOption(SLICEMIDPOINT);
    if (midpointString != null && midpointString.compareToIgnoreCase("true") == 0) {
        showBranchAtMidPoint = true;
    }
    final String[] args2 = arguments.getLeftoverArguments();
    String inputFileName = null;
    String outputFileName = null;
    switch(args2.length) {
        case 0:
            printUsage(arguments);
            System.exit(1);
        case 1:
            inputFileName = args2[0];
            outputFileName = inputFileName + ".kml";
            break;
        case 2:
            inputFileName = args2[0];
            outputFileName = args2[1];
            break;
        default:
            {
                System.err.println("Unknown option: " + args2[2]);
                System.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    RootedTree tree = null;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inputFileName));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    ContinuousKML exporter = new ContinuousKML(tree, inputFileName, altitude, mostRecentDate, coordinateLabel);
    try {
        BufferedWriter out1 = new BufferedWriter(new FileWriter(outputFileName));
        StringBuffer buffer = new StringBuffer();
        //we write the general tree stuff, but when making slices we do not include everything in the buffer compilation
        exporter.writeTreeToKML();
        if (makeTreeSlices) {
            for (int i = 0; i < sliceTimes.length; i++) {
                //                    System.out.println(sliceTimes[i]);
                exporter.writeTreeToKML(sliceTimes[i], treeSliceBranchWidth, showBranchAtMidPoint);
            }
        }
        exporter.compileBuffer(buffer, makeTreeSlices);
        out1.write(buffer.toString());
        out1.close();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}
Also used : NexusImporter(jebl.evolution.io.NexusImporter) Arguments(dr.app.util.Arguments) ImportException(jebl.evolution.io.ImportException) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter)

Example 8 with Arguments

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

the class TreeDensityKML 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.IntegerOption("skip", "skip over this many trees per sample [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");
    }
    int skipEvery = 1;
    if (arguments.hasOption("skip")) {
        skipEvery = arguments.getIntegerOption("skip");
    }
    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 TreeDensityKML(burnin, skipEvery, inputFileName, outputFileName);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 9 with Arguments

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

the class RootToTip 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 trees to be ignored as 'burn-in' [default = 0]"), new Arguments.StringOption("dateorder", "date_order", "order of date field in taxon name: first, last, 1, 2 etc. [default = last]"), //                        new Arguments.StringOption("outgroup", "{taxon list}", "one or more taxa that will be used to root the tree(s) [default = find root]"),
    new Arguments.Option("keeproot", "keep the existing root of the input trees [default = estimate root]"), new Arguments.Option("writetree", "Write the optimally rooted tree to the output file"), 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 = 0;
    if (arguments.hasOption("burnin")) {
        burnin = arguments.getIntegerOption("burnin");
    }
    String dateOrder = "LAST";
    if (arguments.hasOption("dateorder")) {
        dateOrder = arguments.getStringOption("dateorder").toUpperCase();
    }
    String outgroup = null;
    if (arguments.hasOption("outgroup")) {
        outgroup = arguments.getStringOption("dateorder").toUpperCase();
    }
    boolean keepRoot = arguments.hasOption("keeproot");
    boolean writeTree = arguments.hasOption("writetree");
    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) {
        System.err.println("Missing input file name");
        printUsage(arguments);
        System.exit(1);
    }
    inputFileName = args2[0];
    if (args2.length == 2) {
        outputFileName = args2[1];
    }
    new RootToTip(burnin, dateOrder, keepRoot, outgroup, writeTree, inputFileName, outputFileName);
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments)

Example 10 with Arguments

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

the class TransmissionTreeToVirusTree method main.

public static void main(String[] args) {
    ModelType model = ModelType.CONSTANT;
    double startNe = 1;
    double growthRate = 0;
    double t50 = 0;
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption(DEMOGRAPHIC_MODEL, demographics, false, "The type of within-host" + " demographic function to use, default = constant"), new Arguments.RealOption(STARTING_POPULATION_SIZE, "The effective population size at time zero" + " (used in all models), default = 1"), new Arguments.RealOption(GROWTH_RATE, "The effective population size growth rate (used in" + " exponential and logistic models), default = 0"), new Arguments.RealOption(T50, "The time point, relative to the time of infection in backwards " + "time, at which the population is equal to half its final asymptotic value, in the " + "logistic model default = 0") });
    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);
    }
    if (arguments.hasOption(DEMOGRAPHIC_MODEL)) {
        String modelString = arguments.getStringOption(DEMOGRAPHIC_MODEL);
        if (modelString.toLowerCase().startsWith("c")) {
            model = ModelType.CONSTANT;
        } else if (modelString.toLowerCase().startsWith("e")) {
            model = ModelType.EXPONENTIAL;
        } else if (modelString.toLowerCase().startsWith("l")) {
            model = ModelType.LOGISTIC;
        } else {
            progressStream.print("Unrecognised demographic model type");
            System.exit(1);
        }
    }
    if (arguments.hasOption(STARTING_POPULATION_SIZE)) {
        startNe = arguments.getRealOption(STARTING_POPULATION_SIZE);
    }
    if (arguments.hasOption(GROWTH_RATE) && model != ModelType.CONSTANT) {
        growthRate = arguments.getRealOption(GROWTH_RATE);
    }
    if (arguments.hasOption(T50) && model == ModelType.LOGISTIC) {
        t50 = arguments.getRealOption(T50);
    }
    DemographicFunction demoFunction = null;
    switch(model) {
        case CONSTANT:
            {
                demoFunction = new ConstantPopulation(Units.Type.YEARS);
                ((ConstantPopulation) demoFunction).setN0(startNe);
            }
        case EXPONENTIAL:
            {
                demoFunction = new ExponentialGrowth(Units.Type.YEARS);
                ((ExponentialGrowth) demoFunction).setN0(startNe);
                ((ExponentialGrowth) demoFunction).setGrowthRate(growthRate);
            }
        case LOGISTIC:
            {
                demoFunction = new LogisticGrowthN0(Units.Type.YEARS);
                ((LogisticGrowthN0) demoFunction).setN0(startNe);
                ((LogisticGrowthN0) demoFunction).setGrowthRate(growthRate);
                ((LogisticGrowthN0) demoFunction).setT50(t50);
            }
    }
    final String[] args2 = arguments.getLeftoverArguments();
    if (args2.length != 3) {
        printUsage(arguments);
        System.exit(1);
    }
    String infectionsFileName = args2[0];
    String samplesFileName = args2[1];
    String outputFileRoot = args2[2];
    TransmissionTreeToVirusTree instance = new TransmissionTreeToVirusTree(samplesFileName, infectionsFileName, demoFunction, outputFileRoot);
    try {
        instance.run();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ExponentialGrowth(dr.evolution.coalescent.ExponentialGrowth) Arguments(dr.app.util.Arguments) DemographicFunction(dr.evolution.coalescent.DemographicFunction) ConstantPopulation(dr.evolution.coalescent.ConstantPopulation) LogisticGrowthN0(dr.evomodel.epidemiology.LogisticGrowthN0)

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