Search in sources :

Example 16 with NexusImporter

use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.

the class TreeLengthFinder method report.

/**
     * Recursively analyzes trees files.
     *
     * @param name       the file to analyze (if this is a directory then the files within it are analyzed)
     * @param burnin     the burnin to use
     */
private void report(String name, int burnin) {
    double treeLength = 0.0;
    int count = 0;
    try {
        FileReader fileReader = new FileReader(new File(name));
        TreeImporter importer = new NexusImporter(fileReader);
        while (importer.hasTree()) {
            Tree tree = importer.importNextTree();
            if (count >= burnin) {
                treeLength += TreeLength.FACTORY.createStatistic().getSummaryStatistic(tree)[0];
            }
            count++;
        }
        treeLength /= (count - burnin);
        System.out.println(name + "\t" + burnin + "\t" + treeLength);
    } catch (Importer.ImportException e) {
        System.err.println("Error Parsing Input Tree: " + e.getMessage());
    } catch (IOException e) {
        System.err.println("Error Parsing Input Tree: " + e.getMessage());
    }
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) TreeImporter(dr.evolution.io.TreeImporter) Tree(dr.evolution.tree.Tree) NexusImporter(dr.evolution.io.NexusImporter) TreeImporter(dr.evolution.io.TreeImporter) Importer(dr.evolution.io.Importer)

Example 17 with NexusImporter

use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.

the class TaxaOriginTrait method main.

/*
    * Arguments:
    * 0: Trait name
    * 1: File name for list of taxaNames of interest
    * 2: File name for trees (output from BranchJumpPlotter)
    * 3: Output file name root
    * */
public static void main(String[] args) {
    try {
        BufferedReader taxonReader = new BufferedReader(new FileReader(args[1]));
        HashSet<String> tempTaxa = new HashSet<String>();
        String line;
        while ((line = taxonReader.readLine()) != null) {
            tempTaxa.add(line);
        }
        String[] taxa = tempTaxa.toArray(new String[tempTaxa.size()]);
        NexusImporter importer = new NexusImporter(new FileReader(args[2]));
        importer.setSuppressWarnings(true);
        ArrayList<FlexibleTree> tempTrees = new ArrayList<FlexibleTree>();
        int count = 0;
        while (importer.hasTree()) {
            if (count % 100 == 0) {
                System.out.println("Loaded " + count + " trees");
            }
            tempTrees.add((FlexibleTree) importer.importNextTree());
            count++;
        }
        FlexibleTree[] trees = tempTrees.toArray(new FlexibleTree[tempTrees.size()]);
        TaxaOriginTrait examiner = new TaxaOriginTrait(taxa, trees, args[0], args[3]);
        examiner.tabulateOrigins();
    } catch (IOException e) {
        System.out.println("Failed to read files");
    } catch (Importer.ImportException e) {
        System.out.println("Failed to import trees");
    }
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) ArrayList(java.util.ArrayList) FlexibleTree(dr.evolution.tree.FlexibleTree) HashSet(java.util.HashSet) NexusImporter(dr.evolution.io.NexusImporter) Importer(dr.evolution.io.Importer)

Example 18 with NexusImporter

use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.

the class OrderNexusTranslationTable method main.

public static void main(String[] args) throws Importer.ImportException, IOException {
    NexusImporter importer = new NexusImporter(new FileReader(args[0]));
    Tree[] trees = importer.importTrees(null);
    System.out.println("Read " + trees.length + " trees from " + args[0]);
    String newFileName = args[0] + ".new";
    PrintStream ps = new PrintStream(new FileOutputStream(newFileName));
    NexusExporter exporter = new NexusExporter(ps);
    exporter.setTreePrefix("STATE_");
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(7);
    exporter.setNumberFormat(format);
    exporter.setSortedTranslationTable(true);
    exporter.exportTrees(trees, false);
    ps.flush();
    ps.close();
    System.out.println("Wrote " + trees.length + " trees to " + newFileName);
}
Also used : PrintStream(java.io.PrintStream) NexusImporter(dr.evolution.io.NexusImporter) FileOutputStream(java.io.FileOutputStream) Tree(dr.evolution.tree.Tree) FileReader(java.io.FileReader) NumberFormat(java.text.NumberFormat)

Example 19 with NexusImporter

use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.

the class CoalGenFrame method importFromFile.

protected void importFromFile(File file) throws IOException, Importer.ImportException {
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String line = reader.readLine();
    Tree tree;
    if (line.toUpperCase().startsWith("#NEXUS")) {
        NexusImporter importer = new NexusImporter(reader);
        tree = importer.importTree(null);
    } else {
        NewickImporter importer = new NewickImporter(reader);
        tree = importer.importTree(null);
    }
    data.taxonList = tree;
    statusLabel.setText(Integer.toString(data.taxonList.getTaxonCount()) + " taxa loaded.");
    reader.close();
    fireTaxaChanged();
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree)

Example 20 with NexusImporter

use of dr.evolution.io.NexusImporter in project beast-mcmc by beast-dev.

the class GetNSCountsFromTrees method analyze.

private void analyze(File inputFile, int burnin, BranchSet branchSet, List<Set> inclusionSets, List<Set> exclusionSets, double[] siteList) {
    if (summary) {
        resultsStream.print("tree" + SEP + "cN" + SEP + "uN" + SEP + "cS" + SEP + "uS" + SEP + "cNrate" + SEP + "cSrate" + SEP + "dN/dS" + "\n");
    } else {
        resultsStream.print("tree" + SEP + "branch" + SEP + "N/S" + SEP + "site" + SEP + "height/date" + SEP + "fromState" + SEP + "toState");
        if (branchInfo) {
            resultsStream.print(SEP + "branchLength" + SEP + "branchCN/S" + SEP + "branchUN/S" + "\n");
        } else {
            resultsStream.print("\n");
        }
    }
    int totalTrees = 10000;
    int totalStars = 0;
    System.out.println("Reading and analyzing trees (bar assumes 10,000 trees)...");
    System.out.println("0              25             50             75            100");
    System.out.println("|--------------|--------------|--------------|--------------|");
    int stepSize = totalTrees / 60;
    if (stepSize < 1)
        stepSize = 1;
    int count = 0;
    int treeUsed = 1;
    try {
        FileReader fileReader = new FileReader(inputFile);
        TreeImporter importer = new NexusImporter(fileReader);
        while (importer.hasTree()) {
            Tree tree = importer.importNextTree();
            if (count >= burnin) {
                getNSCounts(tree, treeUsed, branchSet, inclusionSets, exclusionSets, siteList);
                treeUsed++;
            }
            count++;
            if (totalTrees > 0 && totalTrees % stepSize == 0) {
                System.out.print("*");
                totalStars++;
                if (totalStars % 61 == 0)
                    System.out.print("\n");
                System.out.flush();
            }
            totalTrees++;
        }
        System.out.print("\n");
    } catch (Importer.ImportException e) {
        progressStream.println("Error Parsing Input Tree: " + e.getMessage());
    } catch (IOException e) {
        progressStream.println("Error Parsing Input Tree: " + e.getMessage());
    }
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) TreeImporter(dr.evolution.io.TreeImporter) Tree(dr.evolution.tree.Tree) NexusImporter(dr.evolution.io.NexusImporter) Importer(dr.evolution.io.Importer) TreeImporter(dr.evolution.io.TreeImporter)

Aggregations

NexusImporter (dr.evolution.io.NexusImporter)29 Tree (dr.evolution.tree.Tree)17 Importer (dr.evolution.io.Importer)12 FileReader (java.io.FileReader)12 TreeImporter (dr.evolution.io.TreeImporter)10 NewickImporter (dr.evolution.io.NewickImporter)9 TaxonList (dr.evolution.util.TaxonList)4 FlexibleTree (dr.evolution.tree.FlexibleTree)3 BufferedReader (java.io.BufferedReader)3 Parameter (dr.inference.model.Parameter)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 JTreeDisplay (dr.app.gui.tree.JTreeDisplay)1 JTreePanel (dr.app.gui.tree.JTreePanel)1 SquareTreePainter (dr.app.gui.tree.SquareTreePainter)1 TreeSummaryStatistic (dr.app.treestat.statistics.TreeSummaryStatistic)1 Alignment (dr.evolution.alignment.Alignment)1 ExtractPairs (dr.evolution.alignment.ExtractPairs)1