Search in sources :

Example 6 with ImportException

use of jebl.evolution.io.ImportException in project beast-mcmc by beast-dev.

the class JumpHistoryAnalyser method main.

public static void main(String[] args) {
    String inputFileName = null;
    //        printTitle();
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in'"), new Arguments.StringOption("from", "from_states", "set of 'from' states to limit the history [default all states]"), new Arguments.StringOption("to", "to_states", "set of 'to' states to limit the history [default all states]"), new Arguments.Option("iterateFrom", "iterate over 'from' states [default combine states]"), new Arguments.Option("iterateTo", "iterate over 'to' states [default combine states]"), new Arguments.Option("backwardsTime", "time runs backwards [default false]"), new Arguments.IntegerOption("bins", "the number of discrete bins [default 100]"), new Arguments.RealOption("min", "the minimum bound of the time range"), new Arguments.RealOption("max", "the maximum bound of the time range"), new Arguments.RealOption("mrsd", "the date of the most recently sampled tip"), new Arguments.Option("help", "option to print this message") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        System.err.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 binCount = 100;
    if (arguments.hasOption("bins")) {
        binCount = arguments.getIntegerOption("bins");
    }
    double minTime = arguments.getRealOption("min");
    double maxTime = arguments.getRealOption("max");
    if (minTime >= maxTime) {
        System.err.println("The minimum time must be less than the maximum time");
        printUsage(arguments);
        System.exit(1);
    }
    double mrsd = arguments.getRealOption("mrsd");
    Set<String> fromStates = new HashSet<String>();
    Set<String> toStates = new HashSet<String>();
    if (arguments.hasOption("from")) {
        String stateString = arguments.getStringOption("from");
        String[] states = stateString.split("[\"\\s,]");
        for (String state : states) {
            if (state.length() > 0) {
                fromStates.add(state);
            }
        }
    }
    if (arguments.hasOption("to")) {
        String stateString = arguments.getStringOption("to");
        String[] states = stateString.split("[\"\\s,]");
        for (String state : states) {
            if (state.length() > 0) {
                toStates.add(state);
            }
        }
    }
    boolean iterateFrom = arguments.hasOption("iterateFrom");
    boolean iterateTo = arguments.hasOption("iterateTo");
    boolean backwardsTime = arguments.hasOption("backwardsTime");
    final String[] args2 = arguments.getLeftoverArguments();
    switch(args2.length) {
        case 1:
            inputFileName = args2[0];
            break;
        default:
            {
                System.err.println("Unknown option: " + args2[2]);
                System.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    // command line options to follow shortly...
    try {
        JumpHistoryAnalyser jumpHistory = new JumpHistoryAnalyser(inputFileName, fromStates, toStates, iterateFrom, iterateTo, burnin, binCount, minTime, maxTime, backwardsTime, mrsd);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ImportException e) {
        e.printStackTrace();
    } catch (TraceException e) {
        e.printStackTrace();
    }
    System.exit(0);
}
Also used : Arguments(dr.app.util.Arguments) IOException(java.io.IOException) ImportException(jebl.evolution.io.ImportException) TraceException(dr.inference.trace.TraceException) HashSet(java.util.HashSet)

Example 7 with ImportException

use of jebl.evolution.io.ImportException in project beast-mcmc by beast-dev.

the class TreeKMLGenerator method main.

public static void main(String[] args) {
    String inputTreeFile = args[0];
    RootedTree tree = null;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    TreeKMLGenerator generator = new TreeKMLGenerator(tree);
    Settings settings = new Settings(AnalysisType.CONTINUOUS);
    //        settings.getAltitudeTreeSettings().setTreeType(TreeType.ARC_TREE);
    //        settings.getAltitudeTreeSettings().getBranchStyle().setColorProperty("height");
    settings.getGroundTreeSettings().setTreeType(TreeType.SURFACE_TREE);
    settings.getGroundTreeSettings().getBranchStyle().setColorProperty("height");
    settings.setPlotAltitude(0);
    settings.setMostRecentDate(2003);
    //settings.setAgeCutOff(1995);
    settings.setTimeDivisionCount(0);
    settings.setTraitName("antigenic");
    settings.setLatitudeName("antigenic1");
    settings.setLongitudeName("antigenic2");
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(args[0] + ".kml"));
        Document doc = new Document(generator.generate(args[0], settings));
        try {
            XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
            outputter.output(doc, out);
        } catch (IOException e) {
            System.err.println(e);
        }
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) NexusImporter(jebl.evolution.io.NexusImporter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ImportException(jebl.evolution.io.ImportException) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter) FileReader(java.io.FileReader)

Example 8 with ImportException

use of jebl.evolution.io.ImportException in project beast-mcmc by beast-dev.

the class TreeGeoJSONGenerator method main.

public static void main(String[] args) {
    String inputTreeFile = args[0];
    RootedTree tree = null;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    TreeGeoJSONGenerator generator = new TreeGeoJSONGenerator(tree, null);
    try {
        generator.generate("", new PrintWriter(new File("output.geojson")));
    } catch (FileNotFoundException e) {
        //To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
}
Also used : ImportException(jebl.evolution.io.ImportException) NexusImporter(jebl.evolution.io.NexusImporter) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter)

Aggregations

ImportException (jebl.evolution.io.ImportException)8 NexusImporter (jebl.evolution.io.NexusImporter)6 RootedTree (jebl.evolution.trees.RootedTree)6 TreeImporter (jebl.evolution.io.TreeImporter)5 IOException (java.io.IOException)4 Arguments (dr.app.util.Arguments)2 TraceException (dr.inference.trace.TraceException)2 FileReader (java.io.FileReader)2 LogFileTraces (dr.inference.trace.LogFileTraces)1 Variate (dr.stats.Variate)1 java.io (java.io)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EmpiricalDemographicFunction (jebl.evolution.coalescent.EmpiricalDemographicFunction)1 NewickExporter (jebl.evolution.io.NewickExporter)1 CoalescentIntervalGenerator (jebl.evolution.treesimulation.CoalescentIntervalGenerator)1 IntervalGenerator (jebl.evolution.treesimulation.IntervalGenerator)1