Debian Codegraph @

src/dr/app/tools/OrderNexusTranslationTable.java

raw symbols SCIP
1 /*
2 * OrderNexusTranslationTable.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.tools;
27
28 import dr.evolution.io.Importer;
29 import dr.evolution.io.NexusImporter;
30 import dr.evolution.tree.Tree;
31
32 import java.io.IOException;
33 import java.io.FileReader;
34 import java.io.PrintStream;
35 import java.io.FileOutputStream;
36 import java.text.NumberFormat;
37
38 /**
39 * A simple routine to alphabetically order the taxa translation table
40 * in a nexus trees file.
41 *
42 * @author Alexei Drummond
43 */
44 public class OrderNexusTranslationTable {
45
46 public static void main(String[] args) throws Importer.ImportException, IOException {
47
48 NexusImporter importer = new NexusImporter(new FileReader(args[0]));
49
50 Tree[] trees = importer.importTrees(null);
51 System.out.println("Read " + trees.length + " trees from " + args[0]);
52
53 String newFileName = args[0] + ".new";
54
55 PrintStream ps = new PrintStream(new FileOutputStream(newFileName));
56
57 NexusExporter exporter = new NexusExporter(ps);
58
59 exporter.setTreePrefix("STATE_");
60 NumberFormat format = NumberFormat.getNumberInstance();
61 format.setMaximumFractionDigits(7);
62 exporter.setNumberFormat(format);
63 exporter.setSortedTranslationTable(true);
64
65 exporter.exportTrees(trees, false);
66
67 ps.flush();
68 ps.close();
69 System.out.println("Wrote " + trees.length + " trees to " + newFileName);
70 }
71
72 }