Search in sources :

Example 1 with TreeTraceAnalysis

use of dr.evomodel.tree.TreeTraceAnalysis in project beast-mcmc by beast-dev.

the class TreeTraceAnalysisParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    try {
        Reader reader;
        String fileName = xo.getStringAttribute(FILE_NAME);
        String name;
        try {
            File file = new File(fileName);
            name = file.getName();
            String parent = file.getParent();
            if (!file.isAbsolute()) {
                parent = System.getProperty("user.dir");
            }
            //					System.out.println("Writing log file to "+parent+System.getProperty("path.separator")+name);
            reader = new FileReader(new File(parent, name));
        } catch (FileNotFoundException fnfe) {
            throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
        }
        // leaving the burnin attribute off will result in 10% being used
        int burnin = xo.getAttribute(BURN_IN, -1);
        double minCladeProbability = xo.getAttribute(MIN_CLADE_PROBABILITY, 0.5);
        double credSetProbability = xo.getAttribute(CRED_SET_PROBABILITY, 0.95);
        Tree referenceTree = null;
        Reader refReader;
        if (xo.hasAttribute(REFERENCE_TREE)) {
            String referenceName = xo.getStringAttribute(REFERENCE_TREE);
            try {
                File refFile = new File(referenceName);
                String refName = refFile.getName();
                String parent = refFile.getParent();
                if (!refFile.isAbsolute()) {
                    parent = System.getProperty("user.dir");
                }
                refReader = new FileReader(new File(parent, refName));
            } catch (FileNotFoundException fnfe) {
                throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
            }
            try {
                NewickImporter importTree = new NewickImporter(refReader);
                if (importTree.hasTree()) {
                    referenceTree = importTree.importNextTree();
                }
            } catch (Importer.ImportException iee) {
                throw new XMLParseException("Reference file '" + referenceName + "' is empty.");
            }
        }
        boolean shortReport = xo.getAttribute(SHORT_REPORT, false);
        TreeTraceAnalysis analysis = TreeTraceAnalysis.analyzeLogFile(new Reader[] { reader }, burnin, true);
        if (shortReport) {
            analysis.shortReport(name, referenceTree, true, credSetProbability);
        } else {
            analysis.report(minCladeProbability, credSetProbability, 0);
        }
        System.out.println();
        System.out.flush();
        return analysis;
    } catch (java.io.IOException ioe) {
        throw new XMLParseException(ioe.getMessage());
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Reader(java.io.Reader) TreeTraceAnalysis(dr.evomodel.tree.TreeTraceAnalysis) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree) FileReader(java.io.FileReader) File(java.io.File) Importer(dr.evolution.io.Importer) NewickImporter(dr.evolution.io.NewickImporter)

Example 2 with TreeTraceAnalysis

use of dr.evomodel.tree.TreeTraceAnalysis in project beast-mcmc by beast-dev.

the class TreeLogAnalyser method analyze.

private static void analyze(List<File> files, int burnin, Tree tree, boolean verbose, String exportFileName, double minSupport, double credibleSetProbability, int maxExport, boolean[] drawHeader) {
    if (combine) {
        try {
            Reader[] readers = new Reader[files.size()];
            for (int i = 0; i < readers.length; i++) {
                readers[i] = new FileReader(files.get(i));
            }
            TreeTraceAnalysis analysis = TreeTraceAnalysis.analyzeLogFile(readers, burnin, verbose);
            if (exportFileName != null) {
                PrintStream exportStream = new PrintStream(exportFileName);
                //System.err.println("Exporting trees ...");
                analysis.export(exportStream, minSupport, maxExport, verbose);
            } else {
                if (verbose) {
                    analysis.report(0.05, credibleSetProbability, (int) (minSupport + .5));
                } else {
                    final String name = files.size() > 1 ? "combined" : files.get(0).toString();
                    analysis.shortReport(name, tree, drawHeader[0]);
                    drawHeader[0] = false;
                }
            }
        } catch (IOException ioe) {
        //
        }
    } else {
        for (File file : files) {
            try {
                final Reader[] readers = { new FileReader(file) };
                TreeTraceAnalysis analysis = TreeTraceAnalysis.analyzeLogFile(readers, burnin, verbose);
                if (verbose) {
                    analysis.report((int) (minSupport + .5));
                } else {
                    analysis.shortReport(file.toString(), tree, drawHeader[0]);
                    drawHeader[0] = false;
                }
            } catch (IOException ioe) {
            //
            }
        }
    }
}
Also used : TreeTraceAnalysis(dr.evomodel.tree.TreeTraceAnalysis)

Aggregations

TreeTraceAnalysis (dr.evomodel.tree.TreeTraceAnalysis)2 Importer (dr.evolution.io.Importer)1 NewickImporter (dr.evolution.io.NewickImporter)1 Tree (dr.evolution.tree.Tree)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1