public Object parseXMLObject(XMLObject xo) throws XMLParseException { final String fileName = xo.getStringAttribute(FILE_NAME); // int burnin = 0; // if (xo.hasAttribute(BURNIN)) { // burnin = xo.getIntegerAttribute(BURNIN); // } Logger.getLogger("dr.evomodel") .info("Creating the empirical tree distribution model, '" + xo.getId() + "'"); TaxonList taxa = (TaxonList) xo.getChild(TaxonList.class); final File file = FileHelpers.getFile(fileName); Tree[] trees = null; try { FileReader reader = new FileReader(file); NexusImporter importer = new NexusImporter(reader); trees = importer.importTrees(taxa); } catch (FileNotFoundException e) { throw new XMLParseException(e.getMessage()); } catch (IOException e) { throw new XMLParseException(e.getMessage()); } catch (Importer.ImportException e) { throw new XMLParseException(e.getMessage()); } Logger.getLogger("dr.evomodel") .info(" Read " + trees.length + " trees from file, " + fileName); return new EmpiricalTreeDistributionModel(trees); }
/** * @param reader the readers to be analyzed * @param burnin the burnin in states * @param verbose true if progress should be logged to stdout * @return an analyses of the trees in a log file. * @throws java.io.IOException if general I/O error occurs */ public static ConditionalCladeFrequency analyzeLogFile( Reader[] reader, double e, int burnin, boolean verbose) throws IOException { TreeTrace[] trace = new TreeTrace[reader.length]; for (int i = 0; i < reader.length; i++) { try { trace[i] = TreeTrace.loadTreeTrace(reader[i]); } catch (Importer.ImportException ie) { throw new RuntimeException(ie.toString()); } reader[i].close(); } return new ConditionalCladeFrequency(trace, e, burnin, verbose); }
protected boolean readFromFile(File file) throws IOException { Reader reader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(reader); String line = bufferedReader.readLine(); while (line != null && line.length() == 0) { line = bufferedReader.readLine(); } boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS")); reader = new FileReader(file); Tree tree = null; try { if (isNexus) { NexusImporter importer = new NexusImporter(reader); tree = importer.importTree(taxa); } else { NewickImporter importer = new NewickImporter(reader); tree = importer.importTree(taxa); } } catch (Importer.ImportException ime) { JOptionPane.showMessageDialog( this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE); ime.printStackTrace(); return false; } catch (IOException ioex) { JOptionPane.showMessageDialog( this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE); ioex.printStackTrace(); return false; } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE); ex.printStackTrace(); return false; } if (tree == null) { JOptionPane.showMessageDialog( this, "The file is not in a suitable format or contains no trees.", "Error reading file", JOptionPane.ERROR_MESSAGE); return false; } FlexibleTree binaryTree = new FlexibleTree(tree, true); binaryTree.resolveTree(); trees.add(binaryTree); if (taxa == null) { taxa = binaryTree; } getExportTreeAction().setEnabled(true); getExportDataAction().setEnabled(true); return true; }