Search in sources :

Example 6 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class TreeSpaceFrame method importDataFile.

public void importDataFile(File file) throws IOException, ImportException {
    Reader reader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(reader);
    String line = bufferedReader.readLine();
    while (line != null && line.length() == 0) {
        line = bufferedReader.readLine();
    }
    if ((line != null && line.toUpperCase().contains("#NEXUS"))) {
        int treeCount = 0;
        do {
            line = bufferedReader.readLine();
        } while (line != null && !line.contains("("));
        while (line != null) {
            if (line.contains("(")) {
                treeCount++;
                if (treeCount > 1) {
                    break;
                }
            }
            line = bufferedReader.readLine();
        }
        // is a NEXUS file
        RootedTree tree = importFirstTree(file);
        if (tree != null) {
            if (treeCount > 1) {
                InputFile inputFile = new InputFile(file, tree, -1);
                document.addTreeFile(inputFile);
                treePlotter.setTrees(loadTrees(inputFile));
                inputFile.setTreeCount(treeCount);
                document.fireDataChanged();
            } else {
                InputFile inputFile = new InputFile(file, tree);
                document.addTreeFile(inputFile);
                treePlotter.setTrees(loadTrees(inputFile));
                inputFile.setTreeCount(treeCount);
                document.fireDataChanged();
            }
        }
    } else {
        JOptionPane.showMessageDialog(this, "Error parsing imported file. This may not be a NEXUS file", "Error reading file", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : RootedTree(jebl.evolution.trees.RootedTree)

Example 7 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class TreeSpaceFrame method importFirstTree.

// nexus
private RootedTree importFirstTree(File file) throws IOException, ImportException {
    RootedTree tree = null;
    FileReader reader = new FileReader(file);
    NexusImporter importer = new NexusImporter(reader);
    tree = (RootedTree) importer.importNextTree();
    return tree;
}
Also used : NexusImporter(jebl.evolution.io.NexusImporter) RootedTree(jebl.evolution.trees.RootedTree)

Example 8 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class CoalGenApp method simulate.

public static void simulate(String inputFileName, String treesFileName, String outputFileName) throws IOException, TraceException, Importer.ImportException {
    File logFile = new File(inputFileName);
    System.out.println("Loading trace file: " + inputFileName);
    LogFileTraces traces = new LogFileTraces(inputFileName, logFile);
    traces.loadTraces();
    traces.setBurnIn(0);
    System.out.println(traces.getStateCount() + " states loaded");
    System.out.println();
    System.out.println("Opening trees file: " + treesFileName);
    //        BufferedReader reader = new BufferedReader(new FileReader(treesFileName));
    System.out.println("Simulating...");
    System.out.println("0              25             50             75            100");
    System.out.println("|--------------|--------------|--------------|--------------|");
    int stepSize = traces.getStateCount() / 60;
    if (stepSize < 1)
        stepSize = 1;
    PrintWriter writer = new PrintWriter(new FileWriter(outputFileName));
    FileReader fileReader = new FileReader(treesFileName);
    TreeImporter importer = new NexusImporter(fileReader);
    EmpiricalDemographicFunction demo = null;
    IntervalGenerator intervals = null;
    TreeSimulator sim = null;
    CoalGenData data = new CoalGenData();
    data.traces = traces;
    // const stepwise bsp
    data.setDemographicModel(7);
    data.setupSkyline();
    double[] popSizes = new double[data.popSizeCount];
    double[] groupSizes = new double[data.groupSizeCount];
    NewickExporter exporter = new NewickExporter(writer);
    int count = 0;
    try {
        while (importer.hasTree()) {
            RootedTree inTree = (RootedTree) importer.importNextTree();
            if (sim == null) {
                setSamplingTimes(inTree);
                sim = new TreeSimulator(inTree.getTaxa(), "date");
            }
            data.getNextSkyline(popSizes, groupSizes);
            double[] times = getTimes(inTree, groupSizes);
            demo = new EmpiricalDemographicFunction(popSizes, times, true);
            intervals = new CoalescentIntervalGenerator(demo);
            RootedTree outTree = sim.simulate(intervals);
            exporter.exportTree(outTree);
            writer.println();
            writer.flush();
            if (count > 0 && count % stepSize == 0) {
                System.out.print("*");
                System.out.flush();
            }
            count++;
        }
    } catch (ImportException e) {
        e.printStackTrace();
    }
    fileReader.close();
    writer.close();
}
Also used : TreeSimulator(jebl.evolution.treesimulation.TreeSimulator) NexusImporter(jebl.evolution.io.NexusImporter) NewickExporter(jebl.evolution.io.NewickExporter) ImportException(jebl.evolution.io.ImportException) CoalescentIntervalGenerator(jebl.evolution.treesimulation.CoalescentIntervalGenerator) RootedTree(jebl.evolution.trees.RootedTree) EmpiricalDemographicFunction(jebl.evolution.coalescent.EmpiricalDemographicFunction) LogFileTraces(dr.inference.trace.LogFileTraces) TreeImporter(jebl.evolution.io.TreeImporter) IntervalGenerator(jebl.evolution.treesimulation.IntervalGenerator) CoalescentIntervalGenerator(jebl.evolution.treesimulation.CoalescentIntervalGenerator)

Example 9 with RootedTree

use of jebl.evolution.trees.RootedTree 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 10 with RootedTree

use of jebl.evolution.trees.RootedTree 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

RootedTree (jebl.evolution.trees.RootedTree)12 NexusImporter (jebl.evolution.io.NexusImporter)8 ImportException (jebl.evolution.io.ImportException)6 TreeImporter (jebl.evolution.io.TreeImporter)6 Variate (dr.stats.Variate)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3 Node (jebl.evolution.graphs.Node)3 Arguments (dr.app.util.Arguments)2 Regression (dr.stats.Regression)2 NumberFormatter (dr.util.NumberFormatter)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Taxon (jebl.evolution.taxa.Taxon)2 LogFileTraces (dr.inference.trace.LogFileTraces)1 java.io (java.io)1 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 EmpiricalDemographicFunction (jebl.evolution.coalescent.EmpiricalDemographicFunction)1 NewickExporter (jebl.evolution.io.NewickExporter)1